manager: Use helper function for adding arrays of objpath, dict
authorPatrik Flykt <patrik.flykt@linux.intel.com>
Mon, 20 Feb 2012 09:43:42 +0000 (11:43 +0200)
committerSamuel Ortiz <sameo@linux.intel.com>
Fri, 24 Feb 2012 22:29:48 +0000 (23:29 +0100)
Use helper function for adding arrays of object path and
dictionary to D-Bus messages.

src/manager.c

index d0c66e4..1744231 100644 (file)
@@ -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;
 }