[PATCH v3 2/4] manager: Use helper function for adding arrays of objpath, dict

patrik.flykt at linux.intel.com patrik.flykt at linux.intel.com
Mon Feb 20 01:43:42 PST 2012


From: Patrik Flykt <patrik.flykt at linux.intel.com>

Use helper function for adding arrays of object path and
dictionary to D-Bus messages.
---
v3: Patch added

 src/manager.c |   46 ++++++++++++++--------------------------------
 1 files changed, 14 insertions(+), 32 deletions(-)

diff --git a/src/manager.c b/src/manager.c
index d0c66e4..1744231 100644
--- a/src/manager.c
+++ b/src/manager.c
@@ -127,11 +127,15 @@ static DBusMessage *set_property(DBusConnection *conn,
 	return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
 }
 
+static void append_technology_structs(DBusMessageIter *iter, void *user_data)
+{
+	__connman_technology_list_struct(iter);
+}
+
 static DBusMessage *get_technologies(DBusConnection *conn,
 		DBusMessage *msg, void *data)
 {
 	DBusMessage *reply;
-	DBusMessageIter iter, array;
 
 	DBG("");
 
@@ -139,21 +143,8 @@ static DBusMessage *get_technologies(DBusConnection *conn,
 	if (reply == NULL)
 		return NULL;
 
-	dbus_message_iter_init_append(reply, &iter);
-
-	dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
-			DBUS_STRUCT_BEGIN_CHAR_AS_STRING
-			DBUS_TYPE_OBJECT_PATH_AS_STRING
-			DBUS_TYPE_ARRAY_AS_STRING
-				DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
-					DBUS_TYPE_STRING_AS_STRING
-					DBUS_TYPE_VARIANT_AS_STRING
-				DBUS_DICT_ENTRY_END_CHAR_AS_STRING
-			DBUS_STRUCT_END_CHAR_AS_STRING, &array);
-
-	__connman_technology_list_struct(&array);
-
-	dbus_message_iter_close_container(&iter, &array);
+	__connman_dbus_append_objpath_dict_array(reply,
+			append_technology_structs, NULL);
 
 	return reply;
 }
@@ -208,31 +199,22 @@ static struct connman_notifier technology_notifier = {
 	.idle_state	= idle_state,
 };
 
+static void append_service_structs(DBusMessageIter *iter, void *user_data)
+{
+	__connman_service_list_struct(iter);
+}
+
 static DBusMessage *get_services(DBusConnection *conn,
 					DBusMessage *msg, void *data)
 {
 	DBusMessage *reply;
-	DBusMessageIter iter, array;
 
 	reply = dbus_message_new_method_return(msg);
 	if (reply == NULL)
 		return NULL;
 
-	dbus_message_iter_init_append(reply, &iter);
-
-	dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
-			DBUS_STRUCT_BEGIN_CHAR_AS_STRING
-			DBUS_TYPE_OBJECT_PATH_AS_STRING
-			DBUS_TYPE_ARRAY_AS_STRING
-				DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
-					DBUS_TYPE_STRING_AS_STRING
-					DBUS_TYPE_VARIANT_AS_STRING
-				DBUS_DICT_ENTRY_END_CHAR_AS_STRING
-			DBUS_STRUCT_END_CHAR_AS_STRING, &array);
-
-	__connman_service_list_struct(&array);
-
-	dbus_message_iter_close_container(&iter, &array);
+	__connman_dbus_append_objpath_dict_array(reply,
+			append_service_structs, NULL);
 
 	return reply;
 }
-- 
1.7.9




More information about the connman mailing list