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



commit f32ec0bea1f12558613330b2c7dbd2250d6d8182
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 |  124 +++++++++++++++++++++++++++++--
 src/libtracker-miner/tracker-miner-fs.h |    2 +
 2 files changed, 120 insertions(+), 6 deletions(-)
---
diff --git a/src/libtracker-miner/tracker-miner-fs.c b/src/libtracker-miner/tracker-miner-fs.c
index 05a0dd7..d6d3f57 100644
--- a/src/libtracker-miner/tracker-miner-fs.c
+++ b/src/libtracker-miner/tracker-miner-fs.c
@@ -126,6 +126,11 @@ typedef struct {
 } ItemMovedData;
 
 typedef struct {
+	GFile *file;
+	/* TODO */
+} ItemWritebackData;
+
+typedef struct {
 	GFile    *file;
 	guint     recurse : 1;
 	guint     ref_count : 7;
@@ -179,6 +184,7 @@ struct _TrackerMinerFSPrivate {
 	TrackerPriorityQueue *items_updated;
 	TrackerPriorityQueue *items_deleted;
 	TrackerPriorityQueue *items_moved;
+	TrackerPriorityQueue *items_writeback;
 #ifdef EVENT_QUEUE_ENABLE_TRACE
 	guint           queue_status_timeout_id;
 #endif /* EVENT_QUEUE_ENABLE_TRACE */
@@ -258,7 +264,8 @@ typedef enum {
 	QUEUE_DELETED,
 	QUEUE_MOVED,
 	QUEUE_IGNORE_NEXT_UPDATE,
-	QUEUE_WAIT
+	QUEUE_WAIT,
+	QUEUE_WRITEBACK
 } QueueState;
 
 enum {
@@ -311,6 +318,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,
@@ -678,6 +686,7 @@ tracker_miner_fs_init (TrackerMinerFS *object)
 	priv->items_updated = tracker_priority_queue_new ();
 	priv->items_deleted = tracker_priority_queue_new ();
 	priv->items_moved = tracker_priority_queue_new ();
+	priv->items_writeback = tracker_priority_queue_new ();
 
 	priv->directories = tracker_priority_queue_new ();
 
@@ -850,6 +859,11 @@ fs_finalize (GObject *object)
 	                                NULL);
 	tracker_priority_queue_unref (priv->items_created);
 
+	tracker_priority_queue_foreach (priv->items_writeback,
+					(GFunc) item_writeback_data_free,
+					NULL);
+	tracker_priority_queue_unref (priv->items_writeback);
+
 	g_list_foreach (priv->dirs_without_parent, (GFunc) g_object_unref, NULL);
 	g_list_free (priv->dirs_without_parent);
 
@@ -1166,6 +1180,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
 sparql_buffer_task_finished_cb (GObject      *object,
                                 GAsyncResult *result,
@@ -2467,6 +2500,7 @@ item_queue_get_next_file (TrackerMinerFS  *fs,
                           gint            *priority_out)
 {
 	ItemMovedData *data;
+	ItemWritebackData *wdata;
 	GFile *queue_file;
 	gint priority;
 
@@ -2667,6 +2701,23 @@ item_queue_get_next_file (TrackerMinerFS  *fs,
 		return QUEUE_MOVED;
 	}
 
+	wdata = tracker_priority_queue_pop (fs->priv->items_writeback,
+					    &priority);
+	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;
 
@@ -2704,6 +2755,7 @@ item_queue_get_progress (TrackerMinerFS *fs,
 	items_to_process += tracker_priority_queue_get_length (fs->priv->items_created);
 	items_to_process += tracker_priority_queue_get_length (fs->priv->items_updated);
 	items_to_process += tracker_priority_queue_get_length (fs->priv->items_moved);
+	items_to_process += tracker_priority_queue_get_length (fs->priv->items_writeback);
 
 	tracker_priority_queue_foreach (fs->priv->crawled_directories,
 	                                (GFunc) get_tree_progress_foreach,
@@ -2948,6 +3000,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 ();
 	}
@@ -3373,15 +3429,26 @@ moved_files_equal (gconstpointer a,
 	return g_file_equal (data->file, file);
 }
 
-/* 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 */
+	return g_file_equal (data->file, file);
+}
+
+/* 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)
 {
 	ItemMovedData *move_data;
 
@@ -3409,6 +3476,13 @@ check_item_queues (TrackerMinerFS *fs,
 			g_debug ("  Found previous unhandled CREATED/UPDATED event");
 			return FALSE;
 		}
+	case QUEUE_WRITEBACK:
+		/* No consecutive writebacks for the same file */
+		if (tracker_priority_queue_find (fs->priv->items_writeback, NULL,
+		                                 (GEqualFunc) compare_writeback_files, file)) {
+			g_debug ("  Found previous unhandled WRITEBACK event");
+			return FALSE;
+		}
 
 		return TRUE;
 	case QUEUE_DELETED:
@@ -4581,6 +4655,42 @@ tracker_miner_fs_check_file_with_priority (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_file:
  * @fs: a #TrackerMinerFS
@@ -5034,7 +5144,8 @@ tracker_miner_fs_has_items_to_process (TrackerMinerFS *fs)
 	    !tracker_priority_queue_is_empty (fs->priv->items_deleted) ||
 	    !tracker_priority_queue_is_empty (fs->priv->items_created) ||
 	    !tracker_priority_queue_is_empty (fs->priv->items_updated) ||
-	    !tracker_priority_queue_is_empty (fs->priv->items_moved)) {
+	    !tracker_priority_queue_is_empty (fs->priv->items_moved) ||
+	    !tracker_priority_queue_is_empty (fs->priv->items_writeback)) {
 		return TRUE;
 	}
 
@@ -5169,6 +5280,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 90db0a0..137912d 100644
--- a/src/libtracker-miner/tracker-miner-fs.h
+++ b/src/libtracker-miner/tracker-miner-fs.h
@@ -125,6 +125,8 @@ void                  tracker_miner_fs_check_directory_with_priority (TrackerMin
 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]