Use new D-Bus helpers wherever possible
authorMarcel Holtmann <marcel@holtmann.org>
Sat, 19 Dec 2009 09:19:13 +0000 (01:19 -0800)
committerMarcel Holtmann <marcel@holtmann.org>
Sat, 19 Dec 2009 09:19:13 +0000 (01:19 -0800)
src/device.c
src/element.c
src/manager.c
src/network.c
src/notifier.c
src/profile.c
src/provider.c
src/service.c

index 42cd670..0c5e418 100644 (file)
@@ -196,23 +196,16 @@ enum connman_service_type __connman_device_get_service_type(struct connman_devic
 static int powered_changed(struct connman_device *device)
 {
        DBusMessage *signal;
-       DBusMessageIter entry, value;
-       const char *key = "Powered";
+       DBusMessageIter iter;
 
        signal = dbus_message_new_signal(device->element.path,
                                CONNMAN_DEVICE_INTERFACE, "PropertyChanged");
        if (signal == NULL)
                return -ENOMEM;
 
-       dbus_message_iter_init_append(signal, &entry);
-
-       dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &key);
-
-       dbus_message_iter_open_container(&entry, DBUS_TYPE_VARIANT,
-                                       DBUS_TYPE_BOOLEAN_AS_STRING, &value);
-       dbus_message_iter_append_basic(&value, DBUS_TYPE_BOOLEAN,
-                                                       &device->powered);
-       dbus_message_iter_close_container(&entry, &value);
+       dbus_message_iter_init_append(signal, &iter);
+       connman_dbus_property_append_variant(&iter, "Powered",
+                                       DBUS_TYPE_BOOLEAN, &device->powered);
 
        g_dbus_send_message(connection, signal);
 
@@ -325,10 +318,7 @@ static DBusMessage *get_properties(DBusConnection *conn,
 
        dbus_message_iter_init_append(reply, &array);
 
-       dbus_message_iter_open_container(&array, DBUS_TYPE_ARRAY,
-                       DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
-                       DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_VARIANT_AS_STRING
-                       DBUS_DICT_ENTRY_END_CHAR_AS_STRING, &dict);
+       connman_dbus_dict_open(&array, &dict);
 
        if (device->name != NULL)
                connman_dbus_dict_append_variant(&dict, "Name",
@@ -370,7 +360,7 @@ static DBusMessage *get_properties(DBusConnection *conn,
                break;
        }
 
-       dbus_message_iter_close_container(&array, &dict);
+       connman_dbus_dict_close(&array, &dict);
 
        return reply;
 }
@@ -515,38 +505,19 @@ static GDBusSignalTable device_signals[] = {
        { },
 };
 
-static void append_devices(DBusMessageIter *entry)
-{
-       DBusMessageIter value, iter;
-       const char *key = "Devices";
-
-       dbus_message_iter_append_basic(entry, DBUS_TYPE_STRING, &key);
-
-       dbus_message_iter_open_container(entry, DBUS_TYPE_VARIANT,
-               DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_OBJECT_PATH_AS_STRING,
-                                                               &value);
-
-       dbus_message_iter_open_container(&value, DBUS_TYPE_ARRAY,
-                               DBUS_TYPE_OBJECT_PATH_AS_STRING, &iter);
-       __connman_element_list(NULL, CONNMAN_ELEMENT_TYPE_DEVICE, &iter);
-       dbus_message_iter_close_container(&value, &iter);
-
-       dbus_message_iter_close_container(entry, &value);
-}
-
 static void emit_devices_signal(void)
 {
        DBusMessage *signal;
-       DBusMessageIter entry;
+       DBusMessageIter iter;
 
        signal = dbus_message_new_signal(CONNMAN_MANAGER_PATH,
                                CONNMAN_MANAGER_INTERFACE, "PropertyChanged");
        if (signal == NULL)
                return;
 
-       dbus_message_iter_init_append(signal, &entry);
-
-       append_devices(&entry);
+       dbus_message_iter_init_append(signal, &iter);
+       connman_dbus_property_append_variable_array(&iter, "Devices",
+                               DBUS_TYPE_OBJECT_PATH, __connman_device_list);
 
        g_dbus_send_message(connection, signal);
 }
@@ -1273,23 +1244,16 @@ void __connman_device_cleanup_networks(struct connman_device *device)
 static void scanning_changed(struct connman_device *device)
 {
        DBusMessage *signal;
-       DBusMessageIter entry, value;
-       const char *key = "Scanning";
+       DBusMessageIter iter;
 
        signal = dbus_message_new_signal(device->element.path,
                                CONNMAN_DEVICE_INTERFACE, "PropertyChanged");
        if (signal == NULL)
                return;
 
-       dbus_message_iter_init_append(signal, &entry);
-
-       dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &key);
-
-       dbus_message_iter_open_container(&entry, DBUS_TYPE_VARIANT,
-                                       DBUS_TYPE_BOOLEAN_AS_STRING, &value);
-       dbus_message_iter_append_basic(&value, DBUS_TYPE_BOOLEAN,
-                                                       &device->scanning);
-       dbus_message_iter_close_container(&entry, &value);
+       dbus_message_iter_init_append(signal, &iter);
+       connman_dbus_property_append_variant(&iter, "Scanning",
+                                       DBUS_TYPE_BOOLEAN, &device->scanning);
 
        g_dbus_send_message(connection, signal);
 }
index 6917a29..ec494b1 100644 (file)
@@ -1250,23 +1250,10 @@ int __connman_element_set_ipv4(struct connman_element *element,
        return 0;
 }
 
-static void append_state(DBusMessageIter *entry, const char *state)
-{
-       DBusMessageIter value;
-       const char *key = "State";
-
-       dbus_message_iter_append_basic(entry, DBUS_TYPE_STRING, &key);
-
-       dbus_message_iter_open_container(entry, DBUS_TYPE_VARIANT,
-                                       DBUS_TYPE_STRING_AS_STRING, &value);
-       dbus_message_iter_append_basic(&value, DBUS_TYPE_STRING, &state);
-       dbus_message_iter_close_container(entry, &value);
-}
-
 static void emit_state_change(DBusConnection *conn, const char *state)
 {
        DBusMessage *signal;
-       DBusMessageIter entry;
+       DBusMessageIter iter;
 
        DBG("conn %p", conn);
 
@@ -1275,9 +1262,9 @@ static void emit_state_change(DBusConnection *conn, const char *state)
        if (signal == NULL)
                return;
 
-       dbus_message_iter_init_append(signal, &entry);
-
-       append_state(&entry, state);
+       dbus_message_iter_init_append(signal, &iter);
+       connman_dbus_property_append_variant(&iter, "State",
+                                               DBUS_TYPE_STRING, &state);
 
        g_dbus_send_message(conn, signal);
 
@@ -1286,8 +1273,8 @@ static void emit_state_change(DBusConnection *conn, const char *state)
        if (signal == NULL)
                return;
 
-       dbus_message_iter_init_append(signal, &entry);
-       dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &state);
+       dbus_message_iter_init_append(signal, &iter);
+       dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &state);
 
        g_dbus_send_message(conn, signal);
 }
index f64f98e..4ca8df5 100644 (file)
 
 #include "connman.h"
 
-static void append_profiles(DBusMessageIter *dict)
-{
-       DBusMessageIter entry, value, iter;
-       const char *key = "Profiles";
-
-       dbus_message_iter_open_container(dict, DBUS_TYPE_DICT_ENTRY,
-                                                               NULL, &entry);
-
-       dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &key);
-
-       dbus_message_iter_open_container(&entry, DBUS_TYPE_VARIANT,
-               DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_OBJECT_PATH_AS_STRING,
-                                                               &value);
-
-       dbus_message_iter_open_container(&value, DBUS_TYPE_ARRAY,
-                               DBUS_TYPE_OBJECT_PATH_AS_STRING, &iter);
-       __connman_profile_list(&iter);
-       dbus_message_iter_close_container(&value, &iter);
-
-       dbus_message_iter_close_container(&entry, &value);
-
-       dbus_message_iter_close_container(dict, &entry);
-}
-
-static void append_services(DBusMessageIter *dict)
-{
-       DBusMessageIter entry, value, iter;
-       const char *key = "Services";
-
-       dbus_message_iter_open_container(dict, DBUS_TYPE_DICT_ENTRY,
-                                                               NULL, &entry);
-
-       dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &key);
-
-       dbus_message_iter_open_container(&entry, DBUS_TYPE_VARIANT,
-               DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_OBJECT_PATH_AS_STRING,
-                                                               &value);
-
-       dbus_message_iter_open_container(&value, DBUS_TYPE_ARRAY,
-                               DBUS_TYPE_OBJECT_PATH_AS_STRING, &iter);
-       __connman_service_list(&iter);
-       dbus_message_iter_close_container(&value, &iter);
-
-       dbus_message_iter_close_container(&entry, &value);
-
-       dbus_message_iter_close_container(dict, &entry);
-}
-
-
-static void append_providers(DBusMessageIter *dict)
-{
-       DBusMessageIter entry, value, iter;
-       const char *key = "Providers";
-
-       dbus_message_iter_open_container(dict, DBUS_TYPE_DICT_ENTRY,
-                                                               NULL, &entry);
-
-       dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &key);
-
-       dbus_message_iter_open_container(&entry, DBUS_TYPE_VARIANT,
-               DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_OBJECT_PATH_AS_STRING,
-                                                               &value);
-
-       dbus_message_iter_open_container(&value, DBUS_TYPE_ARRAY,
-                               DBUS_TYPE_OBJECT_PATH_AS_STRING, &iter);
-       __connman_provider_list(&iter);
-       dbus_message_iter_close_container(&value, &iter);
-
-       dbus_message_iter_close_container(&entry, &value);
-
-       dbus_message_iter_close_container(dict, &entry);
-}
-
-static void append_devices(DBusMessageIter *dict)
-{
-       DBusMessageIter entry, value, iter;
-       const char *key = "Devices";
-
-       dbus_message_iter_open_container(dict, DBUS_TYPE_DICT_ENTRY,
-                                                               NULL, &entry);
-
-       dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &key);
-
-       dbus_message_iter_open_container(&entry, DBUS_TYPE_VARIANT,
-               DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_OBJECT_PATH_AS_STRING,
-                                                               &value);
-
-       dbus_message_iter_open_container(&value, DBUS_TYPE_ARRAY,
-                               DBUS_TYPE_OBJECT_PATH_AS_STRING, &iter);
-       __connman_element_list(NULL, CONNMAN_ELEMENT_TYPE_DEVICE, &iter);
-       dbus_message_iter_close_container(&value, &iter);
-
-       dbus_message_iter_close_container(&entry, &value);
-
-       dbus_message_iter_close_container(dict, &entry);
-}
-
-static void append_available_technologies(DBusMessageIter *dict)
-{
-       DBusMessageIter entry, value, iter;
-       const char *key = "AvailableTechnologies";
-
-       dbus_message_iter_open_container(dict, DBUS_TYPE_DICT_ENTRY,
-                                                               NULL, &entry);
-
-       dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &key);
-
-       dbus_message_iter_open_container(&entry, DBUS_TYPE_VARIANT,
-                       DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_STRING_AS_STRING,
-                                                               &value);
-
-       dbus_message_iter_open_container(&value, DBUS_TYPE_ARRAY,
-                                       DBUS_TYPE_STRING_AS_STRING, &iter);
-       __connman_notifier_list_registered(&iter);
-       dbus_message_iter_close_container(&value, &iter);
-
-       dbus_message_iter_close_container(&entry, &value);
-
-       dbus_message_iter_close_container(dict, &entry);
-}
-
-static void append_enabled_technologies(DBusMessageIter *dict)
-{
-       DBusMessageIter entry, value, iter;
-       const char *key = "EnabledTechnologies";
-
-       dbus_message_iter_open_container(dict, DBUS_TYPE_DICT_ENTRY,
-                                                               NULL, &entry);
-
-       dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &key);
-
-       dbus_message_iter_open_container(&entry, DBUS_TYPE_VARIANT,
-                       DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_STRING_AS_STRING,
-                                                               &value);
-
-       dbus_message_iter_open_container(&value, DBUS_TYPE_ARRAY,
-                                       DBUS_TYPE_STRING_AS_STRING, &iter);
-       __connman_notifier_list_enabled(&iter);
-       dbus_message_iter_close_container(&value, &iter);
-
-       dbus_message_iter_close_container(&entry, &value);
-
-       dbus_message_iter_close_container(dict, &entry);
-}
-
-static void append_connected_technologies(DBusMessageIter *dict)
-{
-       DBusMessageIter entry, value, iter;
-       const char *key = "ConnectedTechnologies";
-
-       dbus_message_iter_open_container(dict, DBUS_TYPE_DICT_ENTRY,
-                                                               NULL, &entry);
-
-       dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &key);
-
-       dbus_message_iter_open_container(&entry, DBUS_TYPE_VARIANT,
-                       DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_STRING_AS_STRING,
-                                                               &value);
-
-       dbus_message_iter_open_container(&value, DBUS_TYPE_ARRAY,
-                                       DBUS_TYPE_STRING_AS_STRING, &iter);
-       __connman_notifier_list_connected(&iter);
-       dbus_message_iter_close_container(&value, &iter);
-
-       dbus_message_iter_close_container(&entry, &value);
-
-       dbus_message_iter_close_container(dict, &entry);
-}
-
-static void append_available_debugs(DBusMessageIter *dict)
-{
-       DBusMessageIter entry, value, iter;
-       const char *key = "AvailableDebugs";
-
-       dbus_message_iter_open_container(dict, DBUS_TYPE_DICT_ENTRY,
-                                                               NULL, &entry);
-
-       dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &key);
-
-       dbus_message_iter_open_container(&entry, DBUS_TYPE_VARIANT,
-                       DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_STRING_AS_STRING,
-                                                               &value);
-
-       dbus_message_iter_open_container(&value, DBUS_TYPE_ARRAY,
-                                       DBUS_TYPE_STRING_AS_STRING, &iter);
-       __connman_debug_list_available(&iter);
-       dbus_message_iter_close_container(&value, &iter);
-
-       dbus_message_iter_close_container(&entry, &value);
-
-       dbus_message_iter_close_container(dict, &entry);
-}
-
-static void append_enabled_debugs(DBusMessageIter *dict)
-{
-       DBusMessageIter entry, value, iter;
-       const char *key = "EnabledDebugs";
-
-       dbus_message_iter_open_container(dict, DBUS_TYPE_DICT_ENTRY,
-                                                               NULL, &entry);
-
-       dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &key);
-
-       dbus_message_iter_open_container(&entry, DBUS_TYPE_VARIANT,
-                       DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_STRING_AS_STRING,
-                                                               &value);
-
-       dbus_message_iter_open_container(&value, DBUS_TYPE_ARRAY,
-                                       DBUS_TYPE_STRING_AS_STRING, &iter);
-       __connman_debug_list_enabled(&iter);
-       dbus_message_iter_close_container(&value, &iter);
-
-       dbus_message_iter_close_container(&entry, &value);
-
-       dbus_message_iter_close_container(dict, &entry);
-}
-
 static DBusMessage *get_properties(DBusConnection *conn,
                                        DBusMessage *msg, void *data)
 {
@@ -264,21 +47,22 @@ static DBusMessage *get_properties(DBusConnection *conn,
 
        dbus_message_iter_init_append(reply, &array);
 
-       dbus_message_iter_open_container(&array, DBUS_TYPE_ARRAY,
-                       DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
-                       DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_VARIANT_AS_STRING
-                       DBUS_DICT_ENTRY_END_CHAR_AS_STRING, &dict);
+       connman_dbus_dict_open(&array, &dict);
 
        str = __connman_profile_active_path();
        if (str != NULL)
                connman_dbus_dict_append_variant(&dict, "ActiveProfile",
                                                DBUS_TYPE_OBJECT_PATH, &str);
 
-       append_profiles(&dict);
-       append_services(&dict);
-       append_providers(&dict);
+       connman_dbus_dict_append_variable_array(&dict, "Profiles",
+                       DBUS_TYPE_OBJECT_PATH, __connman_profile_list);
+       connman_dbus_dict_append_variable_array(&dict, "Services",
+                       DBUS_TYPE_OBJECT_PATH, __connman_service_list);
+       connman_dbus_dict_append_variable_array(&dict, "Providers",
+                       DBUS_TYPE_OBJECT_PATH, __connman_provider_list);
 
-       append_devices(&dict);
+       connman_dbus_dict_append_variable_array(&dict, "Providers",
+                       DBUS_TYPE_OBJECT_PATH, __connman_device_list);
 
        if (__connman_element_count(NULL, CONNMAN_ELEMENT_TYPE_CONNECTION) > 0)
                str = "online";
@@ -292,19 +76,24 @@ static DBusMessage *get_properties(DBusConnection *conn,
        connman_dbus_dict_append_variant(&dict, "OfflineMode",
                                        DBUS_TYPE_BOOLEAN, &offlinemode);
 
-       append_available_technologies(&dict);
-       append_enabled_technologies(&dict);
-       append_connected_technologies(&dict);
+       connman_dbus_dict_append_variable_array(&dict, "AvailableTechnologies",
+                       DBUS_TYPE_STRING, __connman_notifier_list_registered);
+       connman_dbus_dict_append_variable_array(&dict, "EnabledTechnologies",
+                       DBUS_TYPE_STRING, __connman_notifier_list_enabled);
+       connman_dbus_dict_append_variable_array(&dict, "ConnectedTechnologies",
+                       DBUS_TYPE_STRING, __connman_notifier_list_connected);
 
        str = __connman_service_default();
        if (str != NULL)
                connman_dbus_dict_append_variant(&dict, "DefaultTechnology",
                                                DBUS_TYPE_STRING, &str);
 
-       append_available_debugs(&dict);
-       append_enabled_debugs(&dict);
+       connman_dbus_dict_append_variable_array(&dict, "AvailableDebugs",
+                       DBUS_TYPE_STRING, __connman_debug_list_available);
+       connman_dbus_dict_append_variable_array(&dict, "EnabledDebugs",
+                       DBUS_TYPE_STRING, __connman_debug_list_enabled);
 
-       dbus_message_iter_close_container(&array, &dict);
+       connman_dbus_dict_close(&array, &dict);
 
        return reply;
 }
index 3ad649c..10a78ae 100644 (file)
@@ -111,10 +111,7 @@ static DBusMessage *get_properties(DBusConnection *conn,
 
        dbus_message_iter_init_append(reply, &array);
 
-       dbus_message_iter_open_container(&array, DBUS_TYPE_ARRAY,
-                       DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
-                       DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_VARIANT_AS_STRING
-                       DBUS_DICT_ENTRY_END_CHAR_AS_STRING, &dict);
+       connman_dbus_dict_open(&array, &dict);
 
        if (network->device) {
                const char *path = connman_device_get_path(network->device);
@@ -165,7 +162,7 @@ static DBusMessage *get_properties(DBusConnection *conn,
                connman_dbus_dict_append_variant(&dict, "WiFi.Passphrase",
                                DBUS_TYPE_STRING, &network->wifi.passphrase);
 
-       dbus_message_iter_close_container(&array, &dict);
+       connman_dbus_dict_close(&array, &dict);
 
        return reply;
 }
@@ -758,8 +755,7 @@ int connman_network_set_connected(struct connman_network *network,
                                                connman_bool_t connected)
 {
        DBusMessage *signal;
-       DBusMessageIter entry, value;
-       const char *key = "Connected";
+       DBusMessageIter iter;
 
        DBG("network %p connected %d", network, connected);
 
@@ -785,14 +781,9 @@ int connman_network_set_connected(struct connman_network *network,
        if (signal == NULL)
                return 0;
 
-       dbus_message_iter_init_append(signal, &entry);
-
-       dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &key);
-
-       dbus_message_iter_open_container(&entry, DBUS_TYPE_VARIANT,
-                                       DBUS_TYPE_BOOLEAN_AS_STRING, &value);
-       dbus_message_iter_append_basic(&value, DBUS_TYPE_BOOLEAN, &connected);
-       dbus_message_iter_close_container(&entry, &value);
+       dbus_message_iter_init_append(signal, &iter);
+       connman_dbus_property_append_variant(&iter, "Connected",
+                                       DBUS_TYPE_BOOLEAN, &connected);
 
        g_dbus_send_message(connection, signal);
 
index 8f7d4b0..768da7f 100644 (file)
@@ -128,8 +128,7 @@ static void technology_registered(enum connman_service_type type,
                                                connman_bool_t registered)
 {
        DBusMessage *signal;
-       DBusMessageIter entry, value, iter;
-       const char *key = "AvailableTechnologies";
+       DBusMessageIter iter;
 
        DBG("type %d registered %d", type, registered);
 
@@ -138,20 +137,10 @@ static void technology_registered(enum connman_service_type type,
        if (signal == NULL)
                return;
 
-       dbus_message_iter_init_append(signal, &entry);
-
-       dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &key);
-
-       dbus_message_iter_open_container(&entry, DBUS_TYPE_VARIANT,
-                       DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_STRING_AS_STRING,
-                                                               &value);
-
-       dbus_message_iter_open_container(&value, DBUS_TYPE_ARRAY,
-                                       DBUS_TYPE_STRING_AS_STRING, &iter);
-       __connman_notifier_list_registered(&iter);
-       dbus_message_iter_close_container(&value, &iter);
-
-       dbus_message_iter_close_container(&entry, &value);
+       dbus_message_iter_init_append(signal, &iter);
+       connman_dbus_property_append_variable_array(&iter,
+                               "AvailableTechnologies", DBUS_TYPE_STRING,
+                                       __connman_notifier_list_registered);
 
        g_dbus_send_message(connection, signal);
 }
@@ -159,10 +148,9 @@ static void technology_registered(enum connman_service_type type,
 static void technology_enabled(enum connman_service_type type,
                                                connman_bool_t enabled)
 {
-       GSList *list;
        DBusMessage *signal;
-       DBusMessageIter entry, value, iter;
-       const char *key = "EnabledTechnologies";
+       DBusMessageIter iter;
+       GSList *list;
 
        DBG("type %d enabled %d", type, enabled);
 
@@ -171,20 +159,10 @@ static void technology_enabled(enum connman_service_type type,
        if (signal == NULL)
                goto done;
 
-       dbus_message_iter_init_append(signal, &entry);
-
-       dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &key);
-
-       dbus_message_iter_open_container(&entry, DBUS_TYPE_VARIANT,
-                       DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_STRING_AS_STRING,
-                                                               &value);
-
-       dbus_message_iter_open_container(&value, DBUS_TYPE_ARRAY,
-                                       DBUS_TYPE_STRING_AS_STRING, &iter);
-       __connman_notifier_list_enabled(&iter);
-       dbus_message_iter_close_container(&value, &iter);
-
-       dbus_message_iter_close_container(&entry, &value);
+       dbus_message_iter_init_append(signal, &iter);
+       connman_dbus_property_append_variable_array(&iter,
+                               "EnabledTechnologies", DBUS_TYPE_STRING,
+                                       __connman_notifier_list_enabled);
 
        g_dbus_send_message(connection, signal);
 
@@ -201,8 +179,7 @@ static void technology_connected(enum connman_service_type type,
                                                connman_bool_t connected)
 {
        DBusMessage *signal;
-       DBusMessageIter entry, value, iter;
-       const char *key = "ConnectedTechnologies";
+       DBusMessageIter iter;
 
        DBG("type %d connected %d", type, connected);
 
@@ -211,20 +188,10 @@ static void technology_connected(enum connman_service_type type,
        if (signal == NULL)
                return;
 
-       dbus_message_iter_init_append(signal, &entry);
-
-       dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &key);
-
-       dbus_message_iter_open_container(&entry, DBUS_TYPE_VARIANT,
-                       DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_STRING_AS_STRING,
-                                                               &value);
-
-       dbus_message_iter_open_container(&value, DBUS_TYPE_ARRAY,
-                                       DBUS_TYPE_STRING_AS_STRING, &iter);
-       __connman_notifier_list_connected(&iter);
-       dbus_message_iter_close_container(&value, &iter);
-
-       dbus_message_iter_close_container(&entry, &value);
+       dbus_message_iter_init_append(signal, &iter);
+       connman_dbus_property_append_variable_array(&iter,
+                               "ConnectedTechnologies", DBUS_TYPE_STRING,
+                                       __connman_notifier_list_connected);
 
        g_dbus_send_message(connection, signal);
 }
@@ -358,8 +325,8 @@ void __connman_notifier_disconnect(enum connman_service_type type)
 static void technology_default(enum connman_service_type type)
 {
        DBusMessage *signal;
-       DBusMessageIter entry, value;
-       const char *str, *key = "DefaultTechnology";
+       DBusMessageIter iter;
+       const char *str;
 
        str = __connman_service_type2string(type);
        if (str == NULL)
@@ -370,14 +337,9 @@ static void technology_default(enum connman_service_type type)
        if (signal == NULL)
                return;
 
-       dbus_message_iter_init_append(signal, &entry);
-
-       dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &key);
-
-       dbus_message_iter_open_container(&entry, DBUS_TYPE_VARIANT,
-                                       DBUS_TYPE_STRING_AS_STRING, &value);
-       dbus_message_iter_append_basic(&value, DBUS_TYPE_STRING, &str);
-       dbus_message_iter_close_container(&entry, &value);
+       dbus_message_iter_init_append(signal, &iter);
+       connman_dbus_property_append_variant(&iter, "DefaultTechnology",
+                                               DBUS_TYPE_STRING, &str);
 
        g_dbus_send_message(connection, signal);
 }
@@ -400,8 +362,7 @@ void __connman_notifier_default_changed(struct connman_service *service)
 static void offlinemode_changed(dbus_bool_t enabled)
 {
        DBusMessage *signal;
-       DBusMessageIter entry, value;
-       const char *key = "OfflineMode";
+       DBusMessageIter iter;
 
        DBG("enabled %d", enabled);
 
@@ -410,14 +371,9 @@ static void offlinemode_changed(dbus_bool_t enabled)
        if (signal == NULL)
                return;
 
-       dbus_message_iter_init_append(signal, &entry);
-
-       dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &key);
-
-       dbus_message_iter_open_container(&entry, DBUS_TYPE_VARIANT,
-                                       DBUS_TYPE_BOOLEAN_AS_STRING, &value);
-       dbus_message_iter_append_basic(&value, DBUS_TYPE_BOOLEAN, &enabled);
-       dbus_message_iter_close_container(&entry, &value);
+       dbus_message_iter_init_append(signal, &iter);
+       connman_dbus_property_append_variant(&iter, "OfflineMode",
+                                       DBUS_TYPE_BOOLEAN, &enabled);
 
        g_dbus_send_message(connection, signal);
 }
index 35a2f16..84059fc 100644 (file)
@@ -60,29 +60,10 @@ void __connman_profile_list(DBusMessageIter *iter)
        g_hash_table_foreach(profile_hash, append_path, iter);
 }
 
-static void append_profiles(DBusMessageIter *entry)
-{
-       DBusMessageIter value, iter;
-       const char *key = "Profiles";
-
-       dbus_message_iter_append_basic(entry, DBUS_TYPE_STRING, &key);
-
-       dbus_message_iter_open_container(entry, DBUS_TYPE_VARIANT,
-               DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_OBJECT_PATH_AS_STRING,
-                                                               &value);
-
-       dbus_message_iter_open_container(&value, DBUS_TYPE_ARRAY,
-                               DBUS_TYPE_OBJECT_PATH_AS_STRING, &iter);
-       __connman_profile_list(&iter);
-       dbus_message_iter_close_container(&value, &iter);
-
-       dbus_message_iter_close_container(entry, &value);
-}
-
 static void profiles_changed(void)
 {
        DBusMessage *signal;
-       DBusMessageIter entry;
+       DBusMessageIter iter;
 
        DBG("");
 
@@ -91,16 +72,17 @@ static void profiles_changed(void)
        if (signal == NULL)
                return;
 
-       dbus_message_iter_init_append(signal, &entry);
-       append_profiles(&entry);
+       dbus_message_iter_init_append(signal, &iter);
+       connman_dbus_property_append_variable_array(&iter, "Profiles",
+                               DBUS_TYPE_OBJECT_PATH, __connman_profile_list);
+
        g_dbus_send_message(connection, signal);
 }
 
 static void name_changed(struct connman_profile *profile)
 {
        DBusMessage *signal;
-       DBusMessageIter entry, value;
-       const char *key = "Name";
+       DBusMessageIter iter;
 
        DBG("profile %p", profile);
 
@@ -109,15 +91,9 @@ static void name_changed(struct connman_profile *profile)
        if (signal == NULL)
                return;
 
-       dbus_message_iter_init_append(signal, &entry);
-
-       dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &key);
-
-       dbus_message_iter_open_container(&entry, DBUS_TYPE_VARIANT,
-                                       DBUS_TYPE_STRING_AS_STRING, &value);
-       dbus_message_iter_append_basic(&value, DBUS_TYPE_STRING,
-                                                       &profile->name);
-       dbus_message_iter_close_container(&entry, &value);
+       dbus_message_iter_init_append(signal, &iter);
+       connman_dbus_property_append_variant(&iter, "Name",
+                                       DBUS_TYPE_STRING, &profile->name);
 
        g_dbus_send_message(connection, signal);
 }
@@ -125,8 +101,7 @@ static void name_changed(struct connman_profile *profile)
 static void offlinemode_changed(struct connman_profile *profile)
 {
        DBusMessage *signal;
-       DBusMessageIter entry, value;
-       const char *key = "OfflineMode";
+       DBusMessageIter iter;
 
        DBG("profile %p", profile);
 
@@ -135,15 +110,9 @@ static void offlinemode_changed(struct connman_profile *profile)
        if (signal == NULL)
                return;
 
-       dbus_message_iter_init_append(signal, &entry);
-
-       dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &key);
-
-       dbus_message_iter_open_container(&entry, DBUS_TYPE_VARIANT,
-                                       DBUS_TYPE_BOOLEAN_AS_STRING, &value);
-       dbus_message_iter_append_basic(&value, DBUS_TYPE_BOOLEAN,
-                                               &profile->offlinemode);
-       dbus_message_iter_close_container(&entry, &value);
+       dbus_message_iter_init_append(signal, &iter);
+       connman_dbus_property_append_variant(&iter, "OfflineMode",
+                               DBUS_TYPE_BOOLEAN, &profile->offlinemode);
 
        g_dbus_send_message(connection, signal);
 }
@@ -203,36 +172,13 @@ const char *__connman_profile_active_path(void)
        return default_profile->path;
 }
 
-static void append_services(struct connman_profile *profile,
-                                               DBusMessageIter *entry)
-{
-       DBusMessageIter value, iter;
-       const char *key = "Services";
-
-       dbus_message_iter_append_basic(entry, DBUS_TYPE_STRING, &key);
-
-       dbus_message_iter_open_container(entry, DBUS_TYPE_VARIANT,
-               DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_OBJECT_PATH_AS_STRING,
-                                                               &value);
-
-       dbus_message_iter_open_container(&value, DBUS_TYPE_ARRAY,
-                               DBUS_TYPE_OBJECT_PATH_AS_STRING, &iter);
-
-       if (g_strcmp0(profile->ident, PROFILE_DEFAULT_IDENT) == 0)
-               __connman_service_list(&iter);
-
-       dbus_message_iter_close_container(&value, &iter);
-
-       dbus_message_iter_close_container(entry, &value);
-}
-
 static guint changed_timeout = 0;
 
 static gboolean services_changed(gpointer user_data)
 {
        struct connman_profile *profile = default_profile;
        DBusMessage *signal;
-       DBusMessageIter entry;
+       DBusMessageIter iter;
 
        changed_timeout = 0;
 
@@ -244,8 +190,14 @@ static gboolean services_changed(gpointer user_data)
        if (signal == NULL)
                return FALSE;
 
-       dbus_message_iter_init_append(signal, &entry);
-       append_services(profile, &entry);
+       dbus_message_iter_init_append(signal, &iter);
+       if (g_strcmp0(profile->ident, PROFILE_DEFAULT_IDENT) == 0)
+               connman_dbus_property_append_variable_array(&iter, "Services",
+                               DBUS_TYPE_OBJECT_PATH, __connman_service_list);
+       else
+               connman_dbus_property_append_variable_array(&iter, "Services",
+                                               DBUS_TYPE_OBJECT_PATH, NULL);
+
        g_dbus_send_message(connection, signal);
 
        if (g_strcmp0(profile->ident, PROFILE_DEFAULT_IDENT) != 0)
@@ -256,8 +208,10 @@ static gboolean services_changed(gpointer user_data)
        if (signal == NULL)
                return FALSE;
 
-       dbus_message_iter_init_append(signal, &entry);
-       append_services(profile, &entry);
+       dbus_message_iter_init_append(signal, &iter);
+       connman_dbus_property_append_variable_array(&iter, "Services",
+                               DBUS_TYPE_OBJECT_PATH, __connman_service_list);
+
        g_dbus_send_message(connection, signal);
 
        return FALSE;
@@ -321,7 +275,7 @@ static DBusMessage *get_properties(DBusConnection *conn,
 {
        struct connman_profile *profile = data;
        DBusMessage *reply;
-       DBusMessageIter array, dict, entry;
+       DBusMessageIter array, dict;
 
        DBG("conn %p", conn);
 
@@ -331,10 +285,7 @@ static DBusMessage *get_properties(DBusConnection *conn,
 
        dbus_message_iter_init_append(reply, &array);
 
-       dbus_message_iter_open_container(&array, DBUS_TYPE_ARRAY,
-                       DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
-                       DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_VARIANT_AS_STRING
-                       DBUS_DICT_ENTRY_END_CHAR_AS_STRING, &dict);
+       connman_dbus_dict_open(&array, &dict);
 
        if (profile->name != NULL)
                connman_dbus_dict_append_variant(&dict, "Name",
@@ -343,12 +294,10 @@ static DBusMessage *get_properties(DBusConnection *conn,
        connman_dbus_dict_append_variant(&dict, "OfflineMode",
                                DBUS_TYPE_BOOLEAN, &profile->offlinemode);
 
-       dbus_message_iter_open_container(&dict, DBUS_TYPE_DICT_ENTRY,
-                                                               NULL, &entry);
-       append_services(profile, &entry);
-       dbus_message_iter_close_container(&dict, &entry);
+       connman_dbus_dict_append_variable_array(&dict, "Services",
+                               DBUS_TYPE_OBJECT_PATH, __connman_service_list);
 
-       dbus_message_iter_close_container(&array, &dict);
+       connman_dbus_dict_close(&array, &dict);
 
        return reply;
 }
index 506892d..9a99424 100644 (file)
@@ -189,8 +189,8 @@ static int provider_probe(struct connman_provider *provider)
 static void state_changed(struct connman_provider *provider)
 {
        DBusMessage *signal;
-       DBusMessageIter entry, value;
-       const char *str, *key = "State";
+       DBusMessageIter iter;
+       const char *str;
 
        if (provider->path == NULL)
                return;
@@ -204,14 +204,9 @@ static void state_changed(struct connman_provider *provider)
        if (signal == NULL)
                return;
 
-       dbus_message_iter_init_append(signal, &entry);
-
-       dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &key);
-
-       dbus_message_iter_open_container(&entry, DBUS_TYPE_VARIANT,
-                               DBUS_TYPE_STRING_AS_STRING, &value);
-       dbus_message_iter_append_basic(&value, DBUS_TYPE_STRING, &str);
-       dbus_message_iter_close_container(&entry, &value);
+       dbus_message_iter_init_append(signal, &iter);
+       connman_dbus_property_append_variant(&iter, "State",
+                                               DBUS_TYPE_STRING, &str); 
 
        g_dbus_send_message(connection, signal);
 }
@@ -437,10 +432,7 @@ static DBusMessage *get_properties(DBusConnection *conn,
 
        dbus_message_iter_init_append(reply, &array);
 
-       dbus_message_iter_open_container(&array, DBUS_TYPE_ARRAY,
-                       DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
-                       DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_VARIANT_AS_STRING
-                       DBUS_DICT_ENTRY_END_CHAR_AS_STRING, &dict);
+       connman_dbus_dict_open(&array, &dict);
 
        if (provider->name != NULL)
                connman_dbus_dict_append_variant(&dict, "Name",
@@ -465,7 +457,7 @@ static DBusMessage *get_properties(DBusConnection *conn,
        connman_dbus_dict_append_variant(&dict, "PassphraseRequired",
                                         DBUS_TYPE_BOOLEAN, &required);
 
-       dbus_message_iter_close_container(&array, &dict);
+       connman_dbus_dict_close(&array, &dict);
 
        return reply;
 }
index 932f3ca..bfc2018 100644 (file)
@@ -286,9 +286,8 @@ static void mode_changed(struct connman_service *service)
                return;
 
        dbus_message_iter_init_append(signal, &iter);
-
-       connman_dbus_property_append_variant(&iter,
-                                       "Mode", DBUS_TYPE_STRING, &str);
+       connman_dbus_property_append_variant(&iter, "Mode",
+                                               DBUS_TYPE_STRING, &str);
 
        g_dbus_send_message(connection, signal);
 }
@@ -312,9 +311,8 @@ static void state_changed(struct connman_service *service)
                return;
 
        dbus_message_iter_init_append(signal, &iter);
-
-       connman_dbus_property_append_variant(&iter,
-                                       "State", DBUS_TYPE_STRING, &str);
+       connman_dbus_property_append_variant(&iter, "State",
+                                               DBUS_TYPE_STRING, &str);
 
        g_dbus_send_message(connection, signal);
 }
@@ -336,9 +334,8 @@ static void strength_changed(struct connman_service *service)
                return;
 
        dbus_message_iter_init_append(signal, &iter);
-
-       connman_dbus_property_append_variant(&iter,
-                       "Strength", DBUS_TYPE_BYTE, &service->strength);
+       connman_dbus_property_append_variant(&iter, "Strength",
+                                       DBUS_TYPE_BYTE, &service->strength);
 
        g_dbus_send_message(connection, signal);
 }
@@ -357,9 +354,8 @@ static void roaming_changed(struct connman_service *service)
                return;
 
        dbus_message_iter_init_append(signal, &iter);
-
-       connman_dbus_property_append_variant(&iter,
-                       "Roaming", DBUS_TYPE_BOOLEAN, &service->roaming);
+       connman_dbus_property_append_variant(&iter, "Roaming",
+                                       DBUS_TYPE_BOOLEAN, &service->roaming);
 
        g_dbus_send_message(connection, signal);
 }
@@ -378,9 +374,8 @@ static void autoconnect_changed(struct connman_service *service)
                return;
 
        dbus_message_iter_init_append(signal, &iter);
-
-       connman_dbus_property_append_variant(&iter,
-               "AutoConnect", DBUS_TYPE_BOOLEAN, &service->autoconnect);
+       connman_dbus_property_append_variant(&iter, "AutoConnect",
+                               DBUS_TYPE_BOOLEAN, &service->autoconnect);
 
        g_dbus_send_message(connection, signal);
 }
@@ -428,9 +423,8 @@ static void passphrase_changed(struct connman_service *service)
                return;
 
        dbus_message_iter_init_append(signal, &iter);
-
-       connman_dbus_property_append_variant(&iter,
-                       "PassphraseRequired", DBUS_TYPE_BOOLEAN, &required);
+       connman_dbus_property_append_variant(&iter, "PassphraseRequired",
+                                               DBUS_TYPE_BOOLEAN, &required);
 
        g_dbus_send_message(connection, signal);
 }
@@ -465,9 +459,8 @@ static void apn_changed(struct connman_service *service)
                return;
 
        dbus_message_iter_init_append(signal, &iter);
-
-       connman_dbus_property_append_variant(&iter,
-                       "SetupRequired", DBUS_TYPE_BOOLEAN, &required);
+       connman_dbus_property_append_variant(&iter, "SetupRequired",
+                                               DBUS_TYPE_BOOLEAN, &required);
 
        g_dbus_send_message(connection, signal);
 }
@@ -1358,9 +1351,8 @@ static void favorite_changed(struct connman_service *service)
                return;
 
        dbus_message_iter_init_append(signal, &iter);
-
-       connman_dbus_property_append_variant(&iter,
-                       "Favorite", DBUS_TYPE_BOOLEAN, &service->favorite);
+       connman_dbus_property_append_variant(&iter, "Favorite",
+                                       DBUS_TYPE_BOOLEAN, &service->favorite);
 
        g_dbus_send_message(connection, signal);
 }