[tracker/tracker-0.10] libtracker-miner: Implement cancellation of writeback operations



commit e6016ba62cb17d928e882505d2e23adebb1e0bdb
Author: Carlos Garnacho <carlos lanedo com>
Date:   Tue Jul 26 15:23:00 2011 +0200

    libtracker-miner: Implement cancellation of writeback operations
    
    There are situations where we want writeback to be cancelled, so expose
    a GCancellable as with ::process-file.

 src/libtracker-miner/tracker-marshal.list    |    2 +-
 src/libtracker-miner/tracker-miner-fs.c      |   37 +++++++++++++-----------
 src/miners/fs/tracker-writeback-dispatcher.c |   40 ++++++++++++++++++++++++-
 3 files changed, 59 insertions(+), 20 deletions(-)
---
diff --git a/src/libtracker-miner/tracker-marshal.list b/src/libtracker-miner/tracker-marshal.list
index 4286b58..2980c7a 100644
--- a/src/libtracker-miner/tracker-marshal.list
+++ b/src/libtracker-miner/tracker-marshal.list
@@ -11,4 +11,4 @@ BOOL:OBJECT,OBJECT,OBJECT
 BOOL:OBJECT,OBJECT
 BOOL:OBJECT,POINTER
 BOOL:OBJECT
-BOOL:OBJECT,BOXED,BOXED
+BOOL:OBJECT,BOXED,BOXED,OBJECT
diff --git a/src/libtracker-miner/tracker-miner-fs.c b/src/libtracker-miner/tracker-miner-fs.c
index 6d74029..1f06522 100644
--- a/src/libtracker-miner/tracker-miner-fs.c
+++ b/src/libtracker-miner/tracker-miner-fs.c
@@ -129,6 +129,8 @@ typedef struct {
 	GFile     *file;
 	GPtrArray *results;
 	GStrv      rdf_types;
+	GCancellable *cancellable;
+	guint notified : 1;
 } ItemWritebackData;
 
 typedef struct {
@@ -680,7 +682,9 @@ tracker_miner_fs_class_init (TrackerMinerFSClass *klass)
 	 * TrackerMinerFS::writeback-file:
 	 * @miner_fs: the #TrackerMinerFS
 	 * @file: a #GFile
+	 * @rdf_types: the set of RDF types
 	 * @results: a set of results prepared by the preparation query
+	 * @cancellable: a #GCancellable
 	 *
 	 * The ::writeback-file signal is emitted whenever a file must be written
 	 * back
@@ -696,12 +700,13 @@ tracker_miner_fs_class_init (TrackerMinerFSClass *klass)
 		              G_STRUCT_OFFSET (TrackerMinerFSClass, writeback_file),
 		              NULL,
 		              NULL,
-		              tracker_marshal_BOOLEAN__OBJECT_BOXED_BOXED,
+		              tracker_marshal_BOOLEAN__OBJECT_BOXED_BOXED_OBJECT,
 		              G_TYPE_BOOLEAN,
-		              3,
+		              4,
 		              G_TYPE_FILE,
 		              G_TYPE_STRV,
-		              G_TYPE_PTR_ARRAY);
+		              G_TYPE_PTR_ARRAY,
+		              G_TYPE_CANCELLABLE);
 
 	g_type_class_add_private (object_class, sizeof (TrackerMinerFSPrivate));
 }
@@ -1227,6 +1232,8 @@ item_writeback_data_new (GFile     *file,
 	data->file = g_object_ref (file);
 	data->results = g_ptr_array_ref (results);
 	data->rdf_types = g_strdupv (rdf_types);
+	data->cancellable = g_cancellable_new ();
+	data->notified = FALSE;
 
 	return data;
 }
@@ -1237,6 +1244,7 @@ item_writeback_data_free (ItemWritebackData *data)
 	g_object_unref (data->file);
 	g_ptr_array_unref (data->results);
 	g_strfreev (data->rdf_types);
+	g_object_unref (data->cancellable);
 	g_slice_free (ItemWritebackData, data);
 }
 
@@ -2617,18 +2625,16 @@ item_queue_get_next_file (TrackerMinerFS  *fs,
 		               wdata->file,
 		               wdata->rdf_types,
 		               wdata->results,
+		               wdata->cancellable,
 		               &processing);
 
 		if (processing) {
 			TrackerTask *task;
-			gboolean *notified;
 
-			notified = g_new0 (gboolean, 1);
-			task = tracker_task_new (wdata->file, notified,
-			                         (GDestroyNotify) g_free);
+			task = tracker_task_new (wdata->file, wdata,
+			                         (GDestroyNotify) item_writeback_data_free);
 			tracker_task_pool_add (fs->priv->writeback_pool, task);
 
-			item_writeback_data_free (wdata);
 			return QUEUE_WRITEBACK;
 		} else {
 			item_writeback_data_free (wdata);
@@ -3556,7 +3562,7 @@ remove_writeback_task (TrackerMinerFS *fs,
 		       GFile          *file)
 {
 	TrackerTask *task;
-	gboolean *notified;
+	ItemWritebackData *data;
 
 	task = tracker_task_pool_find (fs->priv->writeback_pool, file);
 
@@ -3564,9 +3570,9 @@ remove_writeback_task (TrackerMinerFS *fs,
 		return FALSE;
 	}
 
-	notified = tracker_task_get_data (task);
+	data = tracker_task_get_data (task);
 
-	if (notified && *notified) {
+	if (data->notified) {
 		tracker_task_pool_remove (fs->priv->writeback_pool, task);
 		tracker_task_unref (task);
 		return TRUE;
@@ -4904,13 +4910,10 @@ tracker_miner_fs_writeback_notify (TrackerMinerFS *fs,
 
 		item_queue_handlers_set_up (fs);
 	} else {
-		gboolean *notified;
-
-		notified = tracker_task_get_data (task);
+		ItemWritebackData *data;
 
-		if (notified) {
-			*notified = TRUE;
-		}
+		data = tracker_task_get_data (task);
+		data->notified = TRUE;
 	}
 
 	/* Check monitor_item_updated_cb() for the remainder of this notify,
diff --git a/src/miners/fs/tracker-writeback-dispatcher.c b/src/miners/fs/tracker-writeback-dispatcher.c
index 0290da2..df0edb2 100644
--- a/src/miners/fs/tracker-writeback-dispatcher.c
+++ b/src/miners/fs/tracker-writeback-dispatcher.c
@@ -35,7 +35,10 @@ typedef struct {
 	GPtrArray *results;
 	GStrv rdf_types;
 	TrackerWritebackDispatcher *self; /* weak */
-	guint retry_timeout, retries;
+	GCancellable *cancellable;
+	guint cancel_id;
+	guint retry_timeout;
+	guint retries;
 } WritebackFileData;
 
 typedef struct {
@@ -68,6 +71,7 @@ static gboolean writeback_dispatcher_writeback_file  (TrackerMinerFS       *fs,
                                                       GFile                *file,
                                                       GStrv                 rdf_types,
                                                       GPtrArray            *results,
+                                                      GCancellable         *cancellable,
                                                       gpointer              user_data);
 static void     self_weak_notify                     (gpointer              data,
                                                       GObject              *where_the_object_was);
@@ -237,6 +241,8 @@ writeback_file_data_free (WritebackFileData *data)
 	g_object_unref (data->file);
 	g_strfreev (data->rdf_types);
 	g_ptr_array_unref (data->results);
+	g_cancellable_disconnect (data->cancellable, data->cancel_id);
+	g_object_unref (data->cancellable);
 	g_free (data);
 }
 
@@ -298,11 +304,37 @@ writeback_file_finished  (GObject      *source_object,
 	}
 }
 
+static void
+writeback_cancel_remote_operation (GCancellable      *cancellable,
+				   WritebackFileData *data)
+{
+	TrackerWritebackDispatcherPrivate *priv;
+	GDBusMessage *message;
+        gchar *uris[2];
+
+	priv = TRACKER_WRITEBACK_DISPATCHER_GET_PRIVATE (data->self);
+
+	uris[0] = g_file_get_uri (data->file);
+	uris[1] = NULL;
+
+	message = g_dbus_message_new_method_call (TRACKER_WRITEBACK_SERVICE,
+	                                          TRACKER_WRITEBACK_PATH,
+	                                          TRACKER_WRITEBACK_INTERFACE,
+	                                          "CancelTasks");
+
+	g_dbus_message_set_body (message, g_variant_new ("(^as)", uris));
+	g_dbus_connection_send_message (priv->d_connection, message,
+	                                G_DBUS_SEND_MESSAGE_FLAGS_NONE,
+	                                NULL, NULL);
+	g_free (uris[0]);
+}
+
 static gboolean
 writeback_dispatcher_writeback_file (TrackerMinerFS *fs,
                                      GFile          *file,
                                      GStrv           rdf_types,
                                      GPtrArray      *results,
+                                     GCancellable   *cancellable,
                                      gpointer        user_data)
 {
 	TrackerWritebackDispatcher *self = user_data;
@@ -351,6 +383,10 @@ writeback_dispatcher_writeback_file (TrackerMinerFS *fs,
 	data->file = g_object_ref (file);
 	data->results = g_ptr_array_ref (results);
 	data->rdf_types = g_strdupv (rdf_types);
+	data->cancellable = g_object_ref (cancellable);
+	data->cancel_id = g_cancellable_connect (data->cancellable,
+	                                         G_CALLBACK (writeback_cancel_remote_operation),
+	                                         data, NULL);
 
 	g_dbus_connection_call (priv->d_connection,
 	                        TRACKER_WRITEBACK_SERVICE,
@@ -361,7 +397,7 @@ writeback_dispatcher_writeback_file (TrackerMinerFS *fs,
 	                        NULL,
 	                        G_DBUS_CALL_FLAGS_NONE,
 	                        -1,
-	                        NULL,
+	                        cancellable,
 	                        (GAsyncReadyCallback) writeback_file_finished,
 	                        data);
 



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