[tracker] tracker-miner-flickr: Add refactored writeback code of libtracker-client



commit b9dace4c26bd7a96ab83e6a9722c3cdefa298f20
Author: Martyn Russell <martyn lanedo com>
Date:   Mon Aug 16 15:56:34 2010 +0100

    tracker-miner-flickr: Add refactored writeback code of libtracker-client
    
    libtracker-sparql doesn't have support for this because it is quite a
    specific use case right now.

 src/miners/flickr/Makefile.am               |    4 +-
 src/miners/flickr/tracker-miner-flickr.vala |   15 ++-
 src/miners/flickr/tracker-writeback.c       |  156 +++++++++++++++++++++++++++
 src/miners/flickr/tracker-writeback.h       |   48 ++++++++
 4 files changed, 218 insertions(+), 5 deletions(-)
---
diff --git a/src/miners/flickr/Makefile.am b/src/miners/flickr/Makefile.am
index 2e7f684..01f605a 100644
--- a/src/miners/flickr/Makefile.am
+++ b/src/miners/flickr/Makefile.am
@@ -31,7 +31,9 @@ tracker_miner_flickr_VALASOURCES =					\
 
 tracker_miner_flickr_SOURCES =						\
 	tracker-miner-flickr.vala.stamp                                 \
-	$(tracker_miner_flickr_VALASOURCES:.vala=.c)
+	$(tracker_miner_flickr_VALASOURCES:.vala=.c)			\
+	tracker-writeback.c						\
+	tracker-writeback.h
 
 tracker_miner_flickr_LDADD =						\
 	$(top_builddir)/src/libtracker-miner/libtracker-miner- TRACKER_API_VERSION@.la \
diff --git a/src/miners/flickr/tracker-miner-flickr.vala b/src/miners/flickr/tracker-miner-flickr.vala
index 45df0ab..4a470f7 100644
--- a/src/miners/flickr/tracker-miner-flickr.vala
+++ b/src/miners/flickr/tracker-miner-flickr.vala
@@ -17,6 +17,14 @@
  * Boston, MA  02110-1301, USA.
  */
 
+public delegate void TrackerWritebackCallback (HashTable<string,void*> resources);
+
+public extern void  tracker_writeback_init       ();
+public extern void  tracker_writeback_shutdown   ();
+public extern uint  tracker_writeback_connect    (TrackerWritebackCallback callback,
+												  void                    *user_data);
+public extern void  tracker_writeback_disconnect (uint                     handle);
+
 namespace Tracker {
 
 private errordomain RestCallError {
@@ -85,8 +93,8 @@ public class MinerFlickr : Tracker.MinerWeb {
 
 		rest = new Rest.Proxy (FLICKR_REST_URL, false);
 
-		// FIXME: Add support for this, it won't be in libtracker-sparql though.
-		// tracker_client.writeback_connect (writeback);
+		tracker_writeback_init ();
+		tracker_writeback_connect (writeback, null);
 
 		init_datasource ();
 
@@ -94,6 +102,7 @@ public class MinerFlickr : Tracker.MinerWeb {
 	}
 
 	public void shutdown () {
+		tracker_writeback_shutdown ();
 		status = "Shutting down";
 		associated = false;
 	}
@@ -783,8 +792,6 @@ public class MinerFlickr : Tracker.MinerWeb {
 		} catch (Error tracker_error) {
 			throw tracker_error;
 		}
-
-		return null;
 	}
 
 	public void update_triple_string (Tracker.Sparql.Builder builder, string graph, string urn, string property, string new_value) {
diff --git a/src/miners/flickr/tracker-writeback.c b/src/miners/flickr/tracker-writeback.c
new file mode 100644
index 0000000..befffe0
--- /dev/null
+++ b/src/miners/flickr/tracker-writeback.c
@@ -0,0 +1,156 @@
+/*
+ * Copyright (C) 2010, Nokia <ivan frade nokia com>
+ * Copyright (C) 2010, Codeminded BVBA <abustany gnome org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA  02110-1301, USA.
+ */
+
+#include "config.h"
+
+#include <libtracker-common/tracker-common.h>
+#include <libtracker-sparql/tracker-sparql.h>
+
+#include "tracker-writeback.h"
+
+typedef struct {
+	guint id;
+	TrackerWritebackCallback func;
+	gpointer data;
+} WritebackCallback;
+
+static DBusGConnection *connection;
+static DBusGProxy *proxy_resources;
+static GList *writeback_callbacks;
+static guint writeback_callback_id;
+
+static void
+writeback_cb (DBusGProxy       *proxy,
+              const GHashTable *resources,
+              gpointer          user_data)
+{
+	WritebackCallback *cb;
+	GList *l;
+
+	g_return_if_fail (resources != NULL);
+
+	for (l = writeback_callbacks; l; l = l->next) {
+		cb = l->data;
+		cb->func (resources, cb->data);
+	}
+}
+
+void
+tracker_writeback_init (void)
+{
+	GError *error = NULL;
+
+	connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
+
+	if (!connection || error) {
+		g_warning ("Could not connect to D-Bus session bus, %s\n",
+			   error ? error->message : "no error given");
+		g_clear_error (&error);
+		return;
+	}
+
+	proxy_resources =
+		dbus_g_proxy_new_for_name (connection,
+		                           TRACKER_DBUS_SERVICE,
+		                           TRACKER_DBUS_OBJECT_RESOURCES,
+		                           TRACKER_DBUS_INTERFACE_RESOURCES);
+
+	dbus_g_proxy_add_signal (proxy_resources,
+	                         "Writeback",
+	                         TRACKER_TYPE_STR_STRV_MAP,
+	                         G_TYPE_INVALID);
+}
+
+void
+tracker_writeback_shutdown (void)
+{
+	GList *l;
+
+	if (proxy_resources) {
+		g_object_unref (proxy_resources);
+		proxy_resources = NULL;
+	}
+
+	for (l = writeback_callbacks; l; l = l->next) {
+		WritebackCallback *cb = l->data;
+
+		if (!cb) {
+			continue;
+		}
+
+		g_slice_free (WritebackCallback, l->data);
+	}
+
+	g_list_free (writeback_callbacks);
+}
+
+guint
+tracker_writeback_connect (TrackerWritebackCallback callback,
+			   gpointer                 user_data)
+{
+	WritebackCallback *cb;
+
+	g_return_val_if_fail (callback != NULL, 0);
+
+	/* Connect the DBus signal if needed */
+	if (!writeback_callbacks) {
+		dbus_g_proxy_connect_signal (proxy_resources,
+		                             "Writeback",
+		                             G_CALLBACK (writeback_cb),
+					     NULL,
+		                             NULL);
+	}
+
+	cb = g_slice_new0 (WritebackCallback);
+	cb->id = ++writeback_callback_id;
+	cb->func = callback;
+	cb->data = user_data;
+
+	writeback_callbacks = g_list_prepend (writeback_callbacks, cb);
+
+	return cb->id;
+}
+
+void
+tracker_writeback_disconnect (guint handle)
+{
+	GList *l;
+
+	for (l = writeback_callbacks; l; l = l->next) {
+		WritebackCallback *cb = l->data;
+
+		if (!cb) {
+			continue;
+		}
+
+		if (cb->id == handle) {
+			g_slice_free (WritebackCallback, l->data);
+			writeback_callbacks = g_list_remove (writeback_callbacks, l);
+		}
+	}
+
+	/* Disconnect the DBus signal if not needed anymore */
+	if (!writeback_callbacks) {
+		dbus_g_proxy_disconnect_signal (proxy_resources,
+		                                "Writeback",
+		                                G_CALLBACK (writeback_cb),
+		                                NULL);
+	}
+}
diff --git a/src/miners/flickr/tracker-writeback.h b/src/miners/flickr/tracker-writeback.h
new file mode 100644
index 0000000..c6c38aa
--- /dev/null
+++ b/src/miners/flickr/tracker-writeback.h
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2010, Nokia <ivan frade nokia com>
+ * Copyright (C) 2010, Codeminded BVBA <abustany gnome org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA  02110-1301, USA.
+ */
+
+#ifndef __TRACKER_WRITEBACK_H__
+#define __TRACKER_WRITEBACK_H__
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+/**
+ * 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);
+
+void  tracker_writeback_init       (void);
+void  tracker_writeback_shutdown   (void);
+guint tracker_writeback_connect    (TrackerWritebackCallback callback,
+				    gpointer                 user_data);
+void  tracker_writeback_disconnect (guint                    handle);
+
+G_END_DECLS
+
+#endif /* __TRACKER_WRITEBACK_H__ */



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