[PATCH] service: Fix ServiceRemoved signals

patrik.flykt at linux.intel.com patrik.flykt at linux.intel.com
Wed Feb 29 06:25:44 PST 2012


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

Removed services hash table need not be consulted when sending
ServicesAdded signals as the service structures have already been
deleted. Also clean up both added and removed hash tables after the
signals have been sent.
---
 src/service.c |   15 +++++----------
 1 files changed, 5 insertions(+), 10 deletions(-)

diff --git a/src/service.c b/src/service.c
index c76f63c..410a8da 100644
--- a/src/service.c
+++ b/src/service.c
@@ -3312,25 +3312,20 @@ static void service_send_removed(void)
 
 	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)
 {
 	struct connman_service *service = data;
 	DBusMessageIter *iter = user_data;
-	gpointer value;
 
 	if (service == NULL || service->path == NULL) {
 		DBG("service %p or path is NULL", service);
 		return;
 	}
 
-	value = g_hash_table_lookup(services_notify->remove, service->path);
-	if (GPOINTER_TO_INT(value) == TRUE) {
-		g_hash_table_remove(services_notify->remove, service->path);
-		return;
-	}
-
 	DBG("added %s", service->path);
 
 	if (g_hash_table_lookup(services_notify->add, service->path) != NULL) {
@@ -3360,6 +3355,8 @@ static void service_send_added(void)
 
 	dbus_connection_send(connection, signal, NULL);
 	dbus_message_unref(signal);
+
+	g_hash_table_remove_all(services_notify->add);
 }
 
 static gboolean service_send_signals(gpointer data)
@@ -3369,8 +3366,6 @@ static gboolean service_send_signals(gpointer data)
 
 	if (g_hash_table_size(services_notify->add) > 0)
 		service_send_added();
-	else
-		g_hash_table_remove_all(services_notify->remove);
 
 	services_notify->id = 0;
 	return FALSE;
@@ -3405,7 +3400,7 @@ static void service_schedule_removed(struct connman_service *service)
 
 	g_hash_table_remove(services_notify->add, service->path);
 	g_hash_table_insert(services_notify->remove, g_strdup(service->path),
-			GINT_TO_POINTER(TRUE));
+			NULL);
 
 	service_schedule_signals();
 }
-- 
1.7.9




More information about the connman mailing list