[tracker/tracker-client-writeback] libtracker-client: Use register handles for writeback



commit 909c3b661c1e9cb79e720b91afa3b6e22f13404a
Author: Adrien Bustany <abustany gnome org>
Date:   Fri Apr 9 10:13:53 2010 -0400

    libtracker-client: Use register handles for writeback
    
    This commit makes the function tracker_resources_writeback_connect return a
    handle that can be used later to disconnect the signal. It is a more reliable
    solution than passing the callback directly to the disconnect function.

 src/libtracker-client/tracker.c |   31 ++++++++++++++++++++++++-------
 src/libtracker-client/tracker.h |    4 ++--
 2 files changed, 26 insertions(+), 9 deletions(-)
---
diff --git a/src/libtracker-client/tracker.c b/src/libtracker-client/tracker.c
index fe2544a..8c7d1ab 100644
--- a/src/libtracker-client/tracker.c
+++ b/src/libtracker-client/tracker.c
@@ -124,6 +124,7 @@ typedef struct {
 } CallbackVoid;
 
 typedef struct {
+	guint id;
 	TrackerWritebackCallback func;
 	gpointer data;
 } WritebackCallback;
@@ -159,6 +160,7 @@ enum {
 };
 
 static guint pending_call_id = 0;
+static guint writeback_callback_id = 0;
 
 G_DEFINE_TYPE(TrackerClient, tracker_client, G_TYPE_OBJECT)
 
@@ -1443,8 +1445,12 @@ tracker_resources_batch_commit_async (TrackerClient    *client,
  * with tracker:writeback is changed. This annotation means that whenever
  * possible the changes in the RDF store should be reflected in the metadata of
  * the original file.
+ *
+ * Returns a handle that can be used to disconnect the signal later using
+ * tracker_resources_writeback_disconnect. The handle will always be greater
+ * than 0 on success.
  */
-void
+guint
 tracker_resources_writeback_connect (TrackerClient            *client,
                                      TrackerWritebackCallback  callback,
                                      gpointer                  user_data)
@@ -1452,8 +1458,8 @@ tracker_resources_writeback_connect (TrackerClient            *client,
 	TrackerClientPrivate *private;
 	WritebackCallback *cb;
 
-	g_return_if_fail (TRACKER_IS_CLIENT (client));
-	g_return_if_fail (callback != NULL);
+	g_return_val_if_fail (TRACKER_IS_CLIENT (client), 0);
+	g_return_val_if_fail (callback != NULL, 0);
 
 	private = TRACKER_CLIENT_GET_PRIVATE (client);
 
@@ -1467,11 +1473,14 @@ tracker_resources_writeback_connect (TrackerClient            *client,
 	}
 
 	cb = g_slice_new0 (WritebackCallback);
+	cb->id = ++writeback_callback_id;
 	cb->func = callback;
 	cb->data = user_data;
 
 	private->writeback_callbacks = g_list_prepend (private->writeback_callbacks,
 	                                               cb);
+
+	return cb->id;
 }
 
 /**
@@ -1482,17 +1491,25 @@ tracker_resources_writeback_connect (TrackerClient            *client,
  */
 void
 tracker_resources_writeback_disconnect (TrackerClient            *client,
-                                        TrackerWritebackCallback  callback)
+                                        guint                     handle)
 {
 	TrackerClientPrivate *private;
+	GList *current_callback;
 
 	g_return_if_fail (TRACKER_IS_CLIENT (client));
-	g_return_if_fail (callback != NULL);
 
 	private = TRACKER_CLIENT_GET_PRIVATE (client);
 
-	private->writeback_callbacks = g_list_remove (private->writeback_callbacks,
-	                                              callback);
+	for (current_callback = private->writeback_callbacks;
+	     current_callback;
+	     current_callback = g_list_next (current_callback)) {
+		if (((WritebackCallback*) current_callback->data)->id == handle) {
+			g_slice_free (WritebackCallback, current_callback->data);
+			private->writeback_callbacks = g_list_remove (private->writeback_callbacks,
+			                                              current_callback);
+			break;
+		}
+	}
 
 	/* Disconnect the DBus signal if not needed anymore */
 	if (g_list_length (private->writeback_callbacks) == 0) {
diff --git a/src/libtracker-client/tracker.h b/src/libtracker-client/tracker.h
index 8fd8983..0069907 100644
--- a/src/libtracker-client/tracker.h
+++ b/src/libtracker-client/tracker.h
@@ -162,11 +162,11 @@ guint          tracker_resources_batch_commit_async        (TrackerClient
                                                             gpointer                user_data);
 
 /* Store signals */
-void           tracker_resources_writeback_connect         (TrackerClient            *client,
+guint          tracker_resources_writeback_connect         (TrackerClient            *client,
                                                             TrackerWritebackCallback  callback,
                                                             gpointer                  user_data);
 void           tracker_resources_writeback_disconnect      (TrackerClient            *client,
-                                                            TrackerWritebackCallback  callback);
+                                                            guint handle);
 
 #ifndef TRACKER_DISABLE_DEPRECATED
 



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