[tracker/writeback-refactor-rebase: 3/10] libtracker-miner: Integrate queues with writeback capability



commit 6504dc8f30ce49269825a9643c444570ca03c5f8
Author: Philip Van Hoof <philip codeminded be>
Date:   Thu Jul 7 12:58:12 2011 +0200

    libtracker-miner: Integrate queues with writeback capability

 src/libtracker-miner/tracker-miner-fs.c |  123 +++++++++++++++++++++++++++++-
 src/libtracker-miner/tracker-miner-fs.h |    2 +
 2 files changed, 120 insertions(+), 5 deletions(-)
---
diff --git a/src/libtracker-miner/tracker-miner-fs.c b/src/libtracker-miner/tracker-miner-fs.c
index 511d936..77f9de9 100644
--- a/src/libtracker-miner/tracker-miner-fs.c
+++ b/src/libtracker-miner/tracker-miner-fs.c
@@ -125,6 +125,11 @@ typedef struct {
 } ItemMovedData;
 
 typedef struct {
+	GFile *file;
+	/* TODO */
+} ItemWritebackData;
+
+typedef struct {
 	GFile    *file;
 	guint     recurse : 1;
 	guint     ref_count : 7;
@@ -176,6 +181,7 @@ struct _TrackerMinerFSPrivate {
 	GQueue         *items_updated;
 	GQueue         *items_deleted;
 	GQueue         *items_moved;
+	GQueue         *items_writeback;
 #ifdef EVENT_QUEUE_ENABLE_TRACE
 	guint           queue_status_timeout_id;
 #endif /* EVENT_QUEUE_ENABLE_TRACE */
@@ -250,7 +256,8 @@ typedef enum {
 	QUEUE_DELETED,
 	QUEUE_MOVED,
 	QUEUE_IGNORE_NEXT_UPDATE,
-	QUEUE_WAIT
+	QUEUE_WAIT,
+	QUEUE_WRITEBACK
 } QueueState;
 
 enum {
@@ -302,6 +309,7 @@ static void           directory_data_unref                (DirectoryData
 static ItemMovedData *item_moved_data_new                 (GFile                *file,
                                                            GFile                *source_file);
 static void           item_moved_data_free                (ItemMovedData        *data);
+static void           item_writeback_data_free            (ItemWritebackData    *data);
 static void           monitor_item_created_cb             (TrackerMonitor       *monitor,
                                                            GFile                *file,
                                                            gboolean              is_directory,
@@ -673,6 +681,7 @@ tracker_miner_fs_init (TrackerMinerFS *object)
 	priv->items_updated = g_queue_new ();
 	priv->items_deleted = g_queue_new ();
 	priv->items_moved = g_queue_new ();
+	priv->items_writeback = g_queue_new ();
 
 #ifdef EVENT_QUEUE_ENABLE_TRACE
 	priv->queue_status_timeout_id = g_timeout_add_seconds (EVENT_QUEUE_STATUS_TIMEOUT_SECS,
@@ -802,6 +811,9 @@ fs_finalize (GObject *object)
 	g_queue_foreach (priv->items_updated, (GFunc) g_object_unref, NULL);
 	g_queue_free (priv->items_updated);
 
+	g_queue_foreach (priv->items_writeback, (GFunc) item_writeback_data_free, NULL);
+	g_queue_free (priv->items_writeback);
+
 	g_queue_foreach (priv->items_created, (GFunc) g_object_unref, NULL);
 	g_queue_free (priv->items_created);
 
@@ -986,6 +998,7 @@ miner_resumed (TrackerMiner *miner)
 	if (g_queue_get_length (fs->priv->items_deleted) > 0 ||
 	    g_queue_get_length (fs->priv->items_created) > 0 ||
 	    g_queue_get_length (fs->priv->items_updated) > 0 ||
+	    g_queue_get_length (fs->priv->items_writeback) > 0 ||
 	    g_queue_get_length (fs->priv->items_moved) > 0) {
 		item_queue_handlers_set_up (fs);
 	}
@@ -1129,6 +1142,25 @@ item_moved_data_free (ItemMovedData *data)
 	g_slice_free (ItemMovedData, data);
 }
 
+static ItemWritebackData *
+item_writeback_data_new (GFile *file)
+{
+	ItemWritebackData *data;
+
+	/* TODO */
+	data = g_slice_new (ItemWritebackData);
+	data->file = g_object_ref (file);
+
+	return data;
+}
+
+static void
+item_writeback_data_free (ItemWritebackData *data)
+{
+	g_object_unref (data->file);
+	g_slice_free (ItemWritebackData, data);
+}
+
 static void
 processing_pool_task_finished_cb (TrackerProcessingTask *task,
                                   gpointer               user_data,
@@ -2395,6 +2427,7 @@ item_queue_get_next_file (TrackerMinerFS  *fs,
                           GFile          **source_file)
 {
 	ItemMovedData *data;
+	ItemWritebackData *wdata;
 	GFile *queue_file;
 
 	/* Deleted items first */
@@ -2585,6 +2618,22 @@ item_queue_get_next_file (TrackerMinerFS  *fs,
 		return QUEUE_MOVED;
 	}
 
+	wdata = g_queue_pop_head (fs->priv->items_writeback);
+	if (wdata) {
+		*file = g_object_ref (data->file);
+
+		*file = queue_file;
+		*source_file = NULL;
+
+		trace_eq_pop_head ("WRITEBACK", queue_file);
+
+		/* TODO */
+
+		item_writeback_data_free (wdata);
+
+		return QUEUE_WRITEBACK;
+	}
+
 	*file = NULL;
 	*source_file = NULL;
 
@@ -2609,6 +2658,7 @@ item_queue_get_progress (TrackerMinerFS *fs,
 	items_to_process += g_queue_get_length (fs->priv->items_deleted);
 	items_to_process += g_queue_get_length (fs->priv->items_created);
 	items_to_process += g_queue_get_length (fs->priv->items_updated);
+	items_to_process += g_queue_get_length (fs->priv->items_writeback);
 	items_to_process += g_queue_get_length (fs->priv->items_moved);
 
 	g_queue_foreach (fs->priv->crawled_directories,
@@ -2820,6 +2870,10 @@ item_queue_handlers_cb (gpointer user_data)
 	case QUEUE_IGNORE_NEXT_UPDATE:
 		keep_processing = item_ignore_next_update (fs, file, source_file);
 		break;
+	case QUEUE_WRITEBACK:
+		/* All work is already done at an earlier stage */
+		keep_processing = TRUE;
+		break;
 	default:
 		g_assert_not_reached ();
 	}
@@ -3263,15 +3317,30 @@ compare_moved_files (gconstpointer a,
 	return 1;
 }
 
-/* Checks previous created/updated/deleted/moved queues for
+static gint
+compare_writeback_files (gconstpointer a,
+                         gconstpointer b)
+{
+	const ItemWritebackData *data = a;
+	GFile *file = G_FILE (b);
+
+	/* Compare with dest file */
+	if (g_file_equal (data->file, file)) {
+		return 0;
+	}
+
+	return 1;
+}
+
+/* Checks previous created/updated/deleted/moved/writeback queues for
  * monitor events. Returns TRUE if the item should still
  * be added to the queue.
  */
 static gboolean
 check_item_queues (TrackerMinerFS *fs,
-		   QueueState      queue,
-		   GFile          *file,
-		   GFile          *other_file)
+                   QueueState      queue,
+                   GFile          *file,
+                   GFile          *other_file)
 {
 	GList *elem;
 
@@ -3297,6 +3366,12 @@ check_item_queues (TrackerMinerFS *fs,
 			g_debug ("  Found previous unhandled CREATED/UPDATED event");
 			return FALSE;
 		}
+	case QUEUE_WRITEBACK:
+		/* No further updates after a previous created/updated event */
+		if (g_queue_find_custom (fs->priv->items_writeback, file, compare_writeback_files)) {
+			g_debug ("  Found previous unhandled WRITEBACK event");
+			return FALSE;
+		}
 
 		return TRUE;
 	case QUEUE_DELETED:
@@ -4459,6 +4534,42 @@ tracker_miner_fs_check_file (TrackerMinerFS *fs,
 	g_free (path);
 }
 
+
+/**
+ * tracker_miner_fs_writeback_file:
+ * @fs: a #TrackerMinerFS
+ * @file: #GFile for the file to check
+ *
+ * Tells the filesystem miner to writeback a file.
+ *
+ * Since: 0.10.20
+ **/
+void
+tracker_miner_fs_writeback_file (TrackerMinerFS *fs,
+                                 GFile          *file)
+{
+	gchar *path;
+	ItemWritebackData *data;
+
+	g_return_if_fail (TRACKER_IS_MINER_FS (fs));
+	g_return_if_fail (G_IS_FILE (file));
+
+	path = g_file_get_path (file);
+
+	g_debug ("%s (WRITEBACK) (requested by application)",
+	         path);
+
+	trace_eq_push_tail ("UPDATED", file, "Requested by application");
+
+	data = item_writeback_data_new (file);
+	g_queue_push_tail (fs->priv->items_updated,
+	                   data);
+
+	item_queue_handlers_set_up (fs);
+
+	g_free (path);
+}
+
 /**
  * tracker_miner_fs_check_directory:
  * @fs: a #TrackerMinerFS
@@ -4865,6 +4976,7 @@ tracker_miner_fs_has_items_to_process (TrackerMinerFS *fs)
 	if (g_queue_get_length (fs->priv->items_deleted) > 0 ||
 	    g_queue_get_length (fs->priv->items_created) > 0 ||
 	    g_queue_get_length (fs->priv->items_updated) > 0 ||
+	    g_queue_get_length (fs->priv->items_writeback) > 0 ||
 	    g_queue_get_length (fs->priv->items_moved) > 0) {
 		return TRUE;
 	}
@@ -5000,6 +5112,7 @@ miner_fs_queues_status_trace_timeout_cb (gpointer data)
 	miner_fs_trace_queue_with_files (fs, "UPDATED", fs->priv->items_updated);
 	miner_fs_trace_queue_with_files (fs, "DELETED", fs->priv->items_deleted);
 	miner_fs_trace_queue_with_data  (fs, "MOVED",   fs->priv->items_moved);
+	miner_fs_trace_queue_with_files (fs, "WRITEBACK", fs->priv->items_writeback);
 
 	return TRUE;
 }
diff --git a/src/libtracker-miner/tracker-miner-fs.h b/src/libtracker-miner/tracker-miner-fs.h
index f5f1b7c..adeec7c 100644
--- a/src/libtracker-miner/tracker-miner-fs.h
+++ b/src/libtracker-miner/tracker-miner-fs.h
@@ -117,6 +117,8 @@ gboolean              tracker_miner_fs_directory_remove_full (TrackerMinerFS *fs
 void                  tracker_miner_fs_check_file           (TrackerMinerFS *fs,
                                                              GFile          *file,
                                                              gboolean        check_parents);
+void                  tracker_miner_fs_writeback_file       (TrackerMinerFS *fs,
+                                                             GFile          *file);
 void                  tracker_miner_fs_check_directory      (TrackerMinerFS *fs,
                                                              GFile          *file,
                                                              gboolean        check_parents);



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