[tracker/writeback: 8/23] tracker-writeback: Hook writeback modules to the dispatcher.



commit f82e6a3ce13df2dcb1c7968ba462c6e3a979fed3
Author: Carlos Garnacho <carlos lanedo com>
Date:   Wed Nov 11 16:36:19 2009 +0100

    tracker-writeback: Hook writeback modules to the dispatcher.
    
    There's still work left to do, the dispatcher should maintain a mimetype/module
    hashtable, so it can create TrackerWriteback objects for each file, right now
    the first found module (currently the dummy one) is used.

 .../tracker-writeback-dispatcher.c                 |   61 +++++++++++++-------
 src/tracker-writeback/tracker-writeback-dummy.c    |   46 ++++++++++++++-
 src/tracker-writeback/tracker-writeback-module.c   |   12 +++-
 src/tracker-writeback/tracker-writeback-module.h   |    5 +-
 src/tracker-writeback/tracker-writeback.c          |   16 +++++
 src/tracker-writeback/tracker-writeback.h          |   15 ++++-
 6 files changed, 127 insertions(+), 28 deletions(-)
---
diff --git a/src/tracker-writeback/tracker-writeback-dispatcher.c b/src/tracker-writeback/tracker-writeback-dispatcher.c
index 51e6bca..1a0ba98 100644
--- a/src/tracker-writeback/tracker-writeback-dispatcher.c
+++ b/src/tracker-writeback/tracker-writeback-dispatcher.c
@@ -38,6 +38,11 @@ typedef struct {
 	TrackerClient *client;
 } TrackerWritebackDispatcherPrivate;
 
+typedef struct {
+        TrackerWritebackDispatcher *dispatcher;
+        GFile *file;
+} QueryData;
+
 #define TRACKER_WRITEBACK_DISPATCHER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), TRACKER_TYPE_WRITEBACK_DISPATCHER, TrackerWritebackDispatcherPrivate))
 
 #define TRACKER_SERVICE			"org.freedesktop.Tracker1"
@@ -196,7 +201,7 @@ tracker_writeback_dispatcher_init (TrackerWritebackDispatcher *dispatcher)
 	                                                     TRACKER_INTERFACE_RESOURCES);
 
 	dbus_g_proxy_add_signal (priv->dbus_data->tproxy, "Writeback",
-	                         TRACKER_TYPE_STR_STRV_MAP,
+	                         G_TYPE_STRV,
 	                         G_TYPE_INVALID);
 
 	dbus_g_proxy_connect_signal (priv->dbus_data->tproxy, "Writeback",
@@ -250,36 +255,48 @@ tracker_writeback_dispatcher_new ()
 }
 
 static void
-on_sparql_result_received (GPtrArray *result, 
-                           GError    *error, 
+on_sparql_result_received (GPtrArray *result,
+                           GError    *error,
                            gpointer   user_data)
 {
+	TrackerWritebackDispatcherPrivate *priv;
+        TrackerWritebackModule *module;
+        TrackerWriteback *writeback;
 	gchar *subject = user_data;
-	guint n;
+        GHashTableIter iter;
+        gpointer key, value;
+        QueryData *data;
 
-	g_print ("<%s> ", subject);
+        data = user_data;
+        priv = TRACKER_WRITEBACK_DISPATCHER_GET_PRIVATE (data->dispatcher);
 
-	for (n = 0; n < result->len; n++) {
-		const GStrv row = g_ptr_array_index (result, n);
+        /* FIXME: Lookup module by mimetype */
+        g_hash_table_iter_init (&iter, priv->modules);
 
-		if (n != 0)
-			g_print (";\n\t<%s> \"%s\"", row[0], row[1]);
-		else
-			g_print ("<%s> \"%s\"", row[0], row[1]);
-	}
+        if (!g_hash_table_iter_next (&iter, &key, &value)) {
+                return;
+        }
+
+        module = value;
+        writeback = tracker_writeback_module_create (module);
+
+        tracker_writeback_update_metadata (writeback, data->file, result);
 
-	g_print (" .\n");
+        g_object_unref (writeback);
 
+        g_object_unref (data->file);
+        g_slice_free (QueryData, data);
 	g_free (subject);
 }
 
-static void 
-on_writeback_cb (DBusGProxy                *proxy,
-                const gchar *const         *subjects,
-                TrackerWritebackDispatcher *object)
+static void
+on_writeback_cb (DBusGProxy                 *proxy,
+                 const gchar *const         *subjects,
+                 TrackerWritebackDispatcher *object)
 {
-	guint n;
 	TrackerWritebackDispatcherPrivate *priv;
+        QueryData *data;
+	guint n;
 
 	priv = TRACKER_WRITEBACK_DISPATCHER_GET_PRIVATE (object);
 
@@ -292,12 +309,14 @@ on_writeback_cb (DBusGProxy                *proxy,
 		                                "?predicate tracker:writeback true "
 		                         "}", subjects[n]);
 
+                data = g_slice_new (QueryData);
+                data->dispatcher = object;
+                data->file = g_file_new_for_uri (subjects[n]);
+
 		tracker_resources_sparql_query_async (priv->client,
 		                                      query,
 		                                      on_sparql_result_received,
-		                                      g_strdup (subjects[n]));
-
+                                                      data);
 		g_free (query);
 	}
 }
-
diff --git a/src/tracker-writeback/tracker-writeback-dummy.c b/src/tracker-writeback/tracker-writeback-dummy.c
index 641fef2..32e0bb2 100644
--- a/src/tracker-writeback/tracker-writeback-dummy.c
+++ b/src/tracker-writeback/tracker-writeback-dummy.c
@@ -33,13 +33,19 @@ struct TrackerWritebackDummyClass {
         TrackerWritebackClass parent_class;
 };
 
-static GType tracker_writeback_dummy_get_type (void) G_GNUC_CONST;
+static GType    tracker_writeback_dummy_get_type        (void) G_GNUC_CONST;
+static gboolean tracker_writeback_dummy_update_metadata (TrackerWriteback *writeback,
+                                                         GFile            *file,
+                                                         GPtrArray        *values);
 
 G_DEFINE_DYNAMIC_TYPE (TrackerWritebackDummy, tracker_writeback_dummy, TRACKER_TYPE_WRITEBACK);
 
 static void
 tracker_writeback_dummy_class_init (TrackerWritebackDummyClass *klass)
 {
+        TrackerWritebackClass *writeback_class = TRACKER_WRITEBACK_CLASS (klass);
+
+        writeback_class->update_metadata = tracker_writeback_dummy_update_metadata;
 }
 
 static void
@@ -52,10 +58,46 @@ tracker_writeback_dummy_init (TrackerWritebackDummy *dummy)
 {
 }
 
+static gboolean
+tracker_writeback_dummy_update_metadata (TrackerWriteback *writeback,
+                                         GFile            *file,
+                                         GPtrArray        *values)
+{
+        gchar *uri;
+	guint n;
+
+        uri = g_file_get_uri (file);
+
+        g_print ("<%s> ", uri);
+
+	for (n = 0; n < values->len; n++) {
+		const GStrv row = g_ptr_array_index (values, n);
+
+		if (n != 0)
+			g_print (";\n\t<%s> \"%s\"", row[0], row[1]);
+		else
+			g_print ("<%s> \"%s\"", row[0], row[1]);
+	}
+
+	g_print (" .\n");
+
+        g_free (uri);
+
+        return TRUE;
+}
+
 TrackerWriteback *
-writeback_module_get (GTypeModule *module)
+writeback_module_create (GTypeModule *module)
 {
         tracker_writeback_dummy_register_type (module);
 
         return g_object_new (TRACKER_TYPE_WRITEBACK_DUMMY, NULL);
 }
+
+const GStrv
+writeback_module_get_mimetypes (void)
+{
+        static const gchar *mimetypes[] = { "*", NULL };
+
+        return (GStrv) mimetypes;
+}
diff --git a/src/tracker-writeback/tracker-writeback-module.c b/src/tracker-writeback/tracker-writeback-module.c
index d431808..22d4cdf 100644
--- a/src/tracker-writeback/tracker-writeback-module.c
+++ b/src/tracker-writeback/tracker-writeback-module.c
@@ -65,8 +65,10 @@ tracker_writeback_module_load (GTypeModule *module)
 
 	g_module_make_resident (writeback_module->module);
 
-	if (!g_module_symbol (writeback_module->module, "writeback_module_get",
-			      (gpointer *) &writeback_module->get)) {
+	if (!g_module_symbol (writeback_module->module, "writeback_module_create",
+			      (gpointer *) &writeback_module->create) ||
+	    !g_module_symbol (writeback_module->module, "writeback_module_get_mimetypes",
+			      (gpointer *) &writeback_module->get_mimetypes)) {
 		g_warning ("Could not load module symbols for '%s': %s",
 			   writeback_module->name,
 			   g_module_error ());
@@ -145,3 +147,9 @@ tracker_writeback_modules_list (void)
 
         return list;
 }
+
+TrackerWriteback *
+tracker_writeback_module_create (TrackerWritebackModule *module)
+{
+        return (module->create) (G_TYPE_MODULE (module));
+}
diff --git a/src/tracker-writeback/tracker-writeback-module.h b/src/tracker-writeback/tracker-writeback-module.h
index a42236c..84796f0 100644
--- a/src/tracker-writeback/tracker-writeback-module.h
+++ b/src/tracker-writeback/tracker-writeback-module.h
@@ -40,7 +40,8 @@ struct TrackerWritebackModule {
 	GModule *module;
 	gchar *name;
 
-        TrackerWriteback * (* get) (GTypeModule *module);
+        TrackerWriteback * (* create)        (GTypeModule *module);
+        GStrv              (* get_mimetypes) (void);
 };
 
 struct TrackerWritebackModuleClass {
@@ -51,6 +52,8 @@ struct TrackerWritebackModuleClass {
 GType                     tracker_writeback_module_get_type               (void) G_GNUC_CONST;
 
 TrackerWritebackModule *  tracker_writeback_module_get                    (const gchar *name);
+
+TrackerWriteback *        tracker_writeback_module_create                 (TrackerWritebackModule *module);
 GList *                   tracker_writeback_modules_list                  (void);
 
 
diff --git a/src/tracker-writeback/tracker-writeback.c b/src/tracker-writeback/tracker-writeback.c
index a368d42..09e64a2 100644
--- a/src/tracker-writeback/tracker-writeback.c
+++ b/src/tracker-writeback/tracker-writeback.c
@@ -33,3 +33,19 @@ tracker_writeback_init (TrackerWriteback *writeback)
 {
 
 }
+
+gboolean
+tracker_writeback_update_metadata (TrackerWriteback *writeback,
+                                   GFile            *file,
+                                   GPtrArray        *values)
+{
+        g_return_val_if_fail (TRACKER_IS_WRITEBACK (writeback), FALSE);
+        g_return_val_if_fail (G_IS_FILE (file), FALSE);
+        g_return_val_if_fail (values != NULL, FALSE);
+
+        if (TRACKER_WRITEBACK_GET_CLASS (writeback)->update_metadata) {
+                return TRACKER_WRITEBACK_GET_CLASS (writeback)->update_metadata (writeback, file, values);
+        }
+
+        return FALSE;
+}
diff --git a/src/tracker-writeback/tracker-writeback.h b/src/tracker-writeback/tracker-writeback.h
index efd03ef..337115c 100644
--- a/src/tracker-writeback/tracker-writeback.h
+++ b/src/tracker-writeback/tracker-writeback.h
@@ -19,6 +19,7 @@
  */
 
 #include <glib-object.h>
+#include <gio/gio.h>
 
 #ifndef __TRACKER_WRITEBACK_H__
 #define __TRACKER_WRITEBACK_H__
@@ -41,12 +42,22 @@ struct TrackerWriteback {
 
 struct TrackerWritebackClass {
         GObjectClass parent_class;
+
+        gboolean (* update_metadata) (TrackerWriteback *writeback,
+                                      GFile            *file,
+                                      GPtrArray        *values);
 };
 
 GType          tracker_writeback_get_type (void) G_GNUC_CONST;
 
-/* Entry function to be defined by modules */
-TrackerWriteback * writeback_module_get (GTypeModule *module);
+/* Entry functions to be defined by modules */
+TrackerWriteback * writeback_module_create        (GTypeModule *module);
+const GStrv        writeback_module_get_mimetypes (void);
+
+gboolean tracker_writeback_update_metadata (TrackerWriteback *writeback,
+                                            GFile            *file,
+                                            GPtrArray        *values);
+
 
 G_END_DECLS
 



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