diff options
author | Patrik Flykt <patrik.flykt@linux.intel.com> | 2012-04-03 12:13:35 +0300 |
---|---|---|
committer | Patrik Flykt <patrik.flykt@linux.intel.com> | 2012-04-11 17:02:50 +0300 |
commit | 365528e5155e1a1efe4aa81018d99502aaaf8558 (patch) | |
tree | b31ee2e6d78c6fa197170829e7a268a03ffc1ec9 /src | |
parent | 0f4fe909f200db6077458dba07a459f8d294e6cc (diff) | |
download | connman-365528e5155e1a1efe4aa81018d99502aaaf8558.tar.gz connman-365528e5155e1a1efe4aa81018d99502aaaf8558.tar.bz2 connman-365528e5155e1a1efe4aa81018d99502aaaf8558.zip |
service: Add ServicesChanged signal
Send ServicesChanged signal instead of consecutive ServicesAdded and
ServicesRemoved signals.
Diffstat (limited to 'src')
-rw-r--r-- | src/manager.c | 3 | ||||
-rw-r--r-- | src/service.c | 95 |
2 files changed, 39 insertions, 59 deletions
diff --git a/src/manager.c b/src/manager.c index e475d32d..f4863251 100644 --- a/src/manager.c +++ b/src/manager.c @@ -425,8 +425,7 @@ static GDBusSignalTable manager_signals[] = { { "PropertyChanged", "sv" }, { "TechnologyAdded", "oa{sv}" }, { "TechnologyRemoved", "o" }, - { "ServicesAdded", "a(oa{sv})" }, - { "ServicesRemoved", "ao" }, + { "ServicesChanged", "a(oa{sv})ao" }, { }, }; diff --git a/src/service.c b/src/service.c index 5b5dac6b..05395523 100644 --- a/src/service.c +++ b/src/service.c @@ -3550,40 +3550,7 @@ static struct _services_notify { GHashTable *remove; } *services_notify; -static void append_removed(gpointer key, gpointer value, gpointer user_data) -{ - char *objpath = key; - DBusMessageIter *iter = user_data; - - DBG("removed %s", objpath); - dbus_message_iter_append_basic(iter, DBUS_TYPE_OBJECT_PATH, &objpath); -} - -static void service_send_removed(void) -{ - DBusMessage *signal; - DBusMessageIter iter, array; - - signal = dbus_message_new_signal(CONNMAN_MANAGER_PATH, - CONNMAN_MANAGER_INTERFACE, "ServicesRemoved"); - if (signal == NULL) - return; - - dbus_message_iter_init_append(signal, &iter); - dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, - DBUS_TYPE_OBJECT_PATH_AS_STRING, &array); - - g_hash_table_foreach(services_notify->remove, append_removed, &array); - - dbus_message_iter_close_container(&iter, &array); - - dbus_connection_send(connection, signal, NULL); - dbus_message_unref(signal); - - g_hash_table_remove_all(services_notify->remove); -} - -static void service_send_added_foreach(gpointer data, gpointer user_data) +static void service_append_added_foreach(gpointer data, gpointer user_data) { struct connman_service *service = data; DBusMessageIter *iter = user_data; @@ -3593,57 +3560,71 @@ static void service_send_added_foreach(gpointer data, gpointer user_data) return; } - DBG("added %s", service->path); - if (g_hash_table_lookup(services_notify->add, service->path) != NULL) { + DBG("new %s", service->path); + append_struct(service, iter); g_hash_table_remove(services_notify->add, service->path); } else { + DBG("changed %s", service->path); + append_struct_service(iter, NULL, service); } } -static void service_send_added_ordered(DBusMessageIter *iter, void *user_data) +static void service_append_ordered(DBusMessageIter *iter, void *user_data) +{ + g_sequence_foreach(service_list, service_append_added_foreach, iter); +} + +static void append_removed(gpointer key, gpointer value, gpointer user_data) { - g_sequence_foreach(service_list, service_send_added_foreach, iter); + char *objpath = key; + DBusMessageIter *iter = user_data; + + DBG("removed %s", objpath); + dbus_message_iter_append_basic(iter, DBUS_TYPE_OBJECT_PATH, &objpath); } -static void service_send_added(void) +static gboolean service_send_changed(gpointer data) { DBusMessage *signal; + DBusMessageIter iter, array; + + DBG(""); signal = dbus_message_new_signal(CONNMAN_MANAGER_PATH, - CONNMAN_MANAGER_INTERFACE, "ServicesAdded"); + CONNMAN_MANAGER_INTERFACE, "ServicesChanged"); if (signal == NULL) - return; + return FALSE; __connman_dbus_append_objpath_dict_array(signal, - service_send_added_ordered, NULL); + service_append_ordered, NULL); + + dbus_message_iter_init_append(signal, &iter); + dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, + DBUS_TYPE_OBJECT_PATH_AS_STRING, &array); + + g_hash_table_foreach(services_notify->remove, append_removed, &array); + + dbus_message_iter_close_container(&iter, &array); dbus_connection_send(connection, signal, NULL); dbus_message_unref(signal); + g_hash_table_remove_all(services_notify->remove); g_hash_table_remove_all(services_notify->add); -} - -static gboolean service_send_signals(gpointer data) -{ - if (g_hash_table_size(services_notify->remove) > 0) - service_send_removed(); - - if (g_hash_table_size(services_notify->add) > 0) - service_send_added(); services_notify->id = 0; return FALSE; } -static void service_schedule_signals(void) +static void service_schedule_changed(void) { if (services_notify->id != 0) - g_source_remove(services_notify->id); + return; - services_notify->id = g_timeout_add(100, service_send_signals, NULL); + services_notify->id = g_timeout_add(100, service_send_changed, NULL); } static void service_schedule_added(struct connman_service *service) @@ -3653,7 +3634,7 @@ static void service_schedule_added(struct connman_service *service) g_hash_table_remove(services_notify->remove, service->path); g_hash_table_insert(services_notify->add, service->path, service); - service_schedule_signals(); + service_schedule_changed(); } static void service_schedule_removed(struct connman_service *service) @@ -3669,7 +3650,7 @@ static void service_schedule_removed(struct connman_service *service) g_hash_table_insert(services_notify->remove, g_strdup(service->path), NULL); - service_schedule_signals(); + service_schedule_changed(); } static GDBusMethodTable service_methods[] = { @@ -5869,7 +5850,7 @@ void __connman_service_cleanup(void) if (services_notify->id != 0) { g_source_remove(services_notify->id); - service_send_signals(NULL); + service_send_changed(NULL); g_hash_table_destroy(services_notify->remove); g_hash_table_destroy(services_notify->add); } |