[tracker/tracker-client-writeback: 3/3] libtracker-client: Connect writeback signal on demand



commit de90cbfba0e3e4694201c4d87fede13390c31aad
Author: Adrien Bustany <abustany gnome org>
Date:   Fri Apr 9 09:31:31 2010 -0400

    libtracker-client: Connect writeback signal on demand
    
    The previous behaviour of the client regarding writeback was to connect the
    DBus signal at init time, and then to register or unregister user callbacks.
    With that behaviour, the client would still be woken up by DBus signals, even
    when not needed. This commit connects the signal when it's first needed, and
    disconnects it when it's not needed anymore.

 src/libtracker-client/tracker.c |   22 +++++++++++++++++-----
 1 files changed, 17 insertions(+), 5 deletions(-)
---
diff --git a/src/libtracker-client/tracker.c b/src/libtracker-client/tracker.c
index 5424a1b..fe2544a 100644
--- a/src/libtracker-client/tracker.c
+++ b/src/libtracker-client/tracker.c
@@ -379,11 +379,6 @@ client_constructed (GObject *object)
 	                         "Writeback",
 	                         dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_STRV),
 	                         G_TYPE_INVALID);
-	dbus_g_proxy_connect_signal (private->proxy_resources,
-	                             "Writeback",
-	                             G_CALLBACK (writeback_cb),
-	                             private,
-	                             NULL);
 
 	private->is_constructed = TRUE;
 }
@@ -1462,6 +1457,15 @@ tracker_resources_writeback_connect (TrackerClient            *client,
 
 	private = TRACKER_CLIENT_GET_PRIVATE (client);
 
+	/* Connect the DBus signal if needed */
+	if (g_list_length (private->writeback_callbacks) == 0) {
+		dbus_g_proxy_connect_signal (private->proxy_resources,
+		                             "Writeback",
+		                             G_CALLBACK (writeback_cb),
+		                             private,
+		                             NULL);
+	}
+
 	cb = g_slice_new0 (WritebackCallback);
 	cb->func = callback;
 	cb->data = user_data;
@@ -1489,6 +1493,14 @@ tracker_resources_writeback_disconnect (TrackerClient            *client,
 
 	private->writeback_callbacks = g_list_remove (private->writeback_callbacks,
 	                                              callback);
+
+	/* Disconnect the DBus signal if not needed anymore */
+	if (g_list_length (private->writeback_callbacks) == 0) {
+		dbus_g_proxy_disconnect_signal (private->proxy_resources,
+		                                "Writeback",
+		                                G_CALLBACK (writeback_cb),
+		                                private);
+	}
 }
 
 /* tracker_search_metadata_by_text_async is used by GTK+ */



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]