[tracker/miner-writeback: 1/2] libtracker-client: Add writeback functions



commit 69dbc318b97a75d6e75bdbed99ea7fc664dd4c7a
Author: Adrien Bustany <abustany gnome org>
Date:   Thu Mar 25 13:35:24 2010 -0300

    libtracker-client: Add writeback functions
    
    This commits adds two new functions tracker_resources_writeback_connect and
    tracker_resources_writeback_disconnect to connect (and disconnect) to the
    Writeback signal emitted by the store.

 src/libtracker-client/tracker.c |   95 +++++++++++++++++++++++++++++++++++++++
 src/libtracker-client/tracker.h |   19 ++++++++
 2 files changed, 114 insertions(+), 0 deletions(-)
---
diff --git a/src/libtracker-client/tracker.c b/src/libtracker-client/tracker.c
index 4967dd0..c47f0bb 100644
--- a/src/libtracker-client/tracker.c
+++ b/src/libtracker-client/tracker.c
@@ -99,6 +99,8 @@ typedef struct {
 	gint timeout;
 	gboolean enable_warnings;
 
+	GList *writeback_callbacks;
+
 	gboolean is_constructed;
 } TrackerClientPrivate;
 
@@ -121,6 +123,11 @@ typedef struct {
 	guint id;
 } CallbackVoid;
 
+typedef struct {
+	TrackerWritebackCallback func;
+	gpointer data;
+} WritebackCallback;
+
 #ifndef TRACKER_DISABLE_DEPRECATED
 
 /* Deprecated and only used for 0.6 API */
@@ -190,6 +197,28 @@ pending_call_new (TrackerClient  *client,
 }
 
 static void
+writeback_cb (DBusGProxy       *proxy,
+              const GHashTable *resources,
+              gpointer          user_data)
+{
+	TrackerClientPrivate *private;
+	WritebackCallback *cb;
+	GList *current_callback;
+
+	g_return_if_fail (resources != NULL);
+	g_return_if_fail (user_data != NULL);
+
+	private = user_data;
+
+	for (current_callback = private->writeback_callbacks;
+	     current_callback;
+	     current_callback = g_list_next (current_callback)) {
+		cb = current_callback->data;
+		(*(TrackerWritebackCallback) cb->func) (resources, cb->data);
+	}
+}
+
+static void
 tracker_client_class_init (TrackerClientClass *klass)
 {
 	GObjectClass *object_class;
@@ -229,6 +258,7 @@ tracker_client_init (TrackerClient *client)
 	private->timeout = -1;
 	private->pending_calls = g_hash_table_new_full (NULL, NULL, NULL,
 	                                               (GDestroyNotify) pending_call_free);
+	private->writeback_callbacks = NULL;
 }
 
 static void
@@ -345,6 +375,16 @@ client_constructed (GObject *object)
 	dbus_g_proxy_set_default_timeout (private->proxy_resources, 
 	                                  private->timeout);
 
+	dbus_g_proxy_add_signal (private->proxy_resources,
+	                         "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;
 }
 
@@ -1396,6 +1436,61 @@ tracker_resources_batch_commit_async (TrackerClient    *client,
 	return cb->id;
 }
 
+/**
+ * tracker_resources_writeback_connect:
+ * @callback: a #TrackerWritebackCallback to call when the writeback signal is
+ *            emitted
+ *
+ * Registers a callback to be called when the writeback signal is emitted by
+ * the store.
+ *
+ * The writeback signal is emitted by the store everytime a property annotated
+ * 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.
+ */
+void
+tracker_resources_writeback_connect (TrackerClient            *client,
+                                     TrackerWritebackCallback  callback,
+                                     gpointer                  user_data)
+{
+	TrackerClientPrivate *private;
+	WritebackCallback *cb;
+
+	g_return_if_fail (TRACKER_IS_CLIENT (client));
+	g_return_if_fail (callback != NULL);
+
+	private = TRACKER_CLIENT_GET_PRIVATE (client);
+
+	cb = g_slice_new0 (WritebackCallback);
+	cb->func = callback;
+	cb->data = user_data;
+
+	private->writeback_callbacks = g_list_prepend (private->writeback_callbacks,
+	                                               cb);
+}
+
+/**
+ * tracker_resources_writeback_disconnect:
+ * @callback: the #TrackerWritebackCallback to disconnect
+ *
+ * Removes @callback from the writeback callbacks
+ */
+void
+tracker_resources_writeback_disconnect (TrackerClient            *client,
+                                        TrackerWritebackCallback  callback)
+{
+	TrackerClientPrivate *private;
+
+	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);
+}
+
 /* tracker_search_metadata_by_text_async is used by GTK+ */
 
 static void
diff --git a/src/libtracker-client/tracker.h b/src/libtracker-client/tracker.h
index c620cab..4f26ca5 100644
--- a/src/libtracker-client/tracker.h
+++ b/src/libtracker-client/tracker.h
@@ -85,6 +85,18 @@ typedef void (*TrackerReplyGPtrArray) (GPtrArray *result,
 typedef void (*TrackerReplyVoid)      (GError    *error,
                                        gpointer   user_data);
 
+/**
+ * TrackerWritebackCallback:
+ * @resources: a hash table where each key is the uri of a resources which
+ *             was modified. To each key is associated an array of strings,
+ *             which are the various RDF classes the uri belongs to.
+ *
+ * The callback is called everytime a property annotated with tracker:writeback
+ * is modified in the store.
+ */
+typedef void (*TrackerWritebackCallback) (const GHashTable *resources,
+                                          gpointer          user_data);
+
 GType          tracker_client_get_type                     (void) G_GNUC_CONST;
 TrackerClient *tracker_client_new                          (TrackerClientFlags      flags,
                                                             gint                    timeout);
@@ -149,6 +161,13 @@ guint          tracker_resources_batch_commit_async        (TrackerClient
                                                             TrackerReplyVoid        callback,
                                                             gpointer                user_data);
 
+/* Store signals */
+void           tracker_resources_writeback_connect         (TrackerClient            *client,
+                                                            TrackerWritebackCallback  callback,
+                                                            gpointer                  user_data);
+void           tracker_resources_writeback_disconnect      (TrackerClient            *client,
+                                                            TrackerWritebackCallback  callback);
+
 #ifndef TRACKER_DISABLE_DEPRECATED
 
 /* Deprecated APIs */



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