[tracker/tracker-0.10] miners/fs: Implement dispatcher



commit 5d38b0184c84d52931e401d78d0a8ffb6f5732ae
Author: Philip Van Hoof <philip codeminded be>
Date:   Mon Jul 18 11:58:12 2011 +0200

    miners/fs: Implement dispatcher

 src/miners/fs/tracker-writeback-dispatcher.c |  140 ++++++++++++++++++++++++--
 1 files changed, 133 insertions(+), 7 deletions(-)
---
diff --git a/src/miners/fs/tracker-writeback-dispatcher.c b/src/miners/fs/tracker-writeback-dispatcher.c
index bcfed0c..9226c95 100644
--- a/src/miners/fs/tracker-writeback-dispatcher.c
+++ b/src/miners/fs/tracker-writeback-dispatcher.c
@@ -25,10 +25,20 @@
 
 #include "tracker-writeback-dispatcher.h"
 
+#define TRACKER_WRITEBACK_SERVICE   "org.freedesktop.Tracker1.Writeback"
+#define TRACKER_WRITEBACK_PATH      "/org/freedesktop/Tracker1/Writeback"
+#define TRACKER_WRITEBACK_INTERFACE "org.freedesktop.Tracker1.Writeback"
+
+typedef struct {
+	GFile *file;
+	TrackerMinerFS *fs;
+} WritebackFileData;
 
 typedef struct {
 	TrackerMinerFiles *files_miner;
-	GDBusConnection *connection;
+	GDBusConnection *d_connection;
+	TrackerSparqlConnection *connection;
+	gulong signal_id;
 } TrackerWritebackDispatcherPrivate;
 
 enum {
@@ -50,6 +60,12 @@ static void     writeback_dispatcher_finalize        (GObject              *obje
 static gboolean writeback_dispatcher_initable_init   (GInitable            *initable,
                                                       GCancellable         *cancellable,
                                                       GError              **error);
+static void writeback_dispatcher_writeback_file      (TrackerMinerFS       *fs,
+                                                      GFile                *file,
+                                                      GStrv                 rdf_types,
+                                                      GPtrArray            *results,
+                                                      gpointer              user_data);
+
 
 static void
 writeback_dispatcher_initable_iface_init (GInitableIface *iface)
@@ -129,11 +145,21 @@ writeback_dispatcher_finalize (GObject *object)
 {
 	TrackerWritebackDispatcherPrivate *priv = TRACKER_WRITEBACK_DISPATCHER_GET_PRIVATE (object);
 
+	if (priv->signal_id != 0 && g_signal_handler_is_connected (object, priv->signal_id)) {
+		g_signal_handler_disconnect (object, priv->signal_id);
+	}
+
 	if (priv->connection) {
 		g_object_unref (priv->connection);
 	}
 
-	g_object_unref (priv->files_miner);
+	if (priv->d_connection) {
+		g_object_unref (priv->d_connection);
+	}
+
+	if (priv->files_miner) {
+		g_object_unref (priv->files_miner);
+	}
 }
 
 
@@ -144,27 +170,40 @@ tracker_writeback_dispatcher_init (TrackerWritebackDispatcher *object)
 
 static gboolean
 writeback_dispatcher_initable_init (GInitable    *initable,
-                         GCancellable *cancellable,
-                         GError       **error)
+                                    GCancellable *cancellable,
+                                    GError       **error)
 {
 	TrackerWritebackDispatcherPrivate *priv;
 	GError *internal_error = NULL;
 
 	priv = TRACKER_WRITEBACK_DISPATCHER_GET_PRIVATE (initable);
 
-	priv->connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &internal_error);
+	priv->connection = tracker_sparql_connection_get (NULL, &internal_error);
+
+	if (internal_error) {
+		g_propagate_error (error, internal_error);
+		return FALSE;
+	}
+
+	priv->d_connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &internal_error);
 
 	if (internal_error) {
 		g_propagate_error (error, internal_error);
 		return FALSE;
 	}
 
+	priv->signal_id = g_signal_connect_object (priv->files_miner,
+	                                           "writeback-file",
+	                                           G_CALLBACK (writeback_dispatcher_writeback_file),
+	                                           initable,
+	                                           G_CONNECT_AFTER);
+
 	return TRUE;
 }
 
 TrackerWritebackDispatcher *
 tracker_writeback_dispatcher_new (TrackerMinerFiles  *miner_files,
-                                GError            **error)
+                                  GError            **error)
 {
 	GObject *miner;
 	GError *internal_error = NULL;
@@ -183,5 +222,92 @@ tracker_writeback_dispatcher_new (TrackerMinerFiles  *miner_files,
 	return (TrackerWritebackDispatcher *) miner;
 }
 
-	// tracker_miner_fs_writeback_file (TRACKER_MINER_FS (miner_files), file, ...);
+static void
+writeback_file_finished  (GObject      *source_object,
+                          GAsyncResult *res,
+                          gpointer      user_data)
+{
+	WritebackFileData *data = user_data;
+	GError *error = NULL;
+
+	g_dbus_connection_call_finish (G_DBUS_CONNECTION (source_object),
+	                               res, &error);
 
+	tracker_miner_fs_writeback_notify (data->fs, data->file, error);
+
+	g_object_unref (data->fs);
+	g_object_unref (data->file);
+	g_free (data);
+}
+
+static void
+writeback_dispatcher_writeback_file (TrackerMinerFS *fs,
+                                     GFile          *file,
+                                     GStrv           rdf_types,
+                                     GPtrArray      *results,
+                                     gpointer        user_data)
+{
+	TrackerWritebackDispatcher *self = user_data;
+	TrackerWritebackDispatcherPrivate *priv;
+	gchar *uri;
+	guint i;
+	GVariantBuilder builder;
+	WritebackFileData *data = g_new (WritebackFileData, 1);
+
+	priv = TRACKER_WRITEBACK_DISPATCHER_GET_PRIVATE (self);
+
+	uri = g_file_get_uri (file);
+	g_print ("Writeback: %s with:\n", uri);
+
+	g_variant_builder_init (&builder, G_VARIANT_TYPE ("(sasaas)"));
+
+	g_variant_builder_add (&builder, "s", uri);
+
+	g_variant_builder_open (&builder, G_VARIANT_TYPE ("as"));
+	for (i = 0; rdf_types[i] != NULL; i++) {
+		g_variant_builder_add (&builder, "s", rdf_types[i]);
+	}
+	g_variant_builder_close (&builder);
+
+	g_variant_builder_open (&builder, G_VARIANT_TYPE ("aas"));
+
+	for (i = 0; i< results->len; i++) {
+		GStrv row = g_ptr_array_index (results, i);
+		guint y;
+
+		g_variant_builder_open (&builder, G_VARIANT_TYPE ("as"));
+
+		g_print ("\t");
+		for (y = 0; row[y] != NULL; y++) {
+			g_variant_builder_add (&builder, "s", row[y]);
+
+			if (y != 0) {
+				g_print (",");
+			}
+			g_print ("%d=%s", y, row[y]);
+		}
+		g_print ("\n");
+
+		g_variant_builder_close (&builder);
+	}
+
+	g_variant_builder_close (&builder);
+
+	data->fs = g_object_ref (fs);
+	data->file = g_object_ref (file);
+
+	g_dbus_connection_call (priv->d_connection,
+	                        TRACKER_WRITEBACK_SERVICE,
+	                        TRACKER_WRITEBACK_PATH,
+	                        TRACKER_WRITEBACK_INTERFACE,
+	                        "PerformWriteback",
+	                        g_variant_ref_sink (g_variant_builder_end (&builder)),
+	                        NULL,
+	                        G_DBUS_CALL_FLAGS_NONE,
+	                        -1,
+	                        NULL,
+	                        (GAsyncReadyCallback) writeback_file_finished,
+	                        data);
+
+	g_free (uri);
+}



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