[tracker/writeback-refactor-0.10: 3/63] libtracker-miner: Integrate queues with writeback capability



commit 6a7b72fe8e7d8ab93f80ccf8917bd586f24f432d
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 371ef08..9a3412d 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 */
@@ -259,7 +265,8 @@ typedef enum {
 	QUEUE_DELETED,
 	QUEUE_MOVED,
 	QUEUE_IGNORE_NEXT_UPDATE,
-	QUEUE_WAIT
+	QUEUE_WAIT,
+	QUEUE_WRITEBACK
 } QueueState;
 
 enum {
@@ -312,6 +319,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,
@@ -679,6 +687,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 ();
 
@@ -852,6 +861,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);
 
@@ -1165,6 +1179,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,
@@ -2521,6 +2554,7 @@ item_queue_get_next_file (TrackerMinerFS  *fs,
                           gint            *priority_out)
 {
 	ItemMovedData *data;
+	ItemWritebackData *wdata;
 	GFile *queue_file;
 	gint priority;
 
@@ -2721,6 +2755,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;
 
@@ -2758,6 +2809,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,
@@ -2999,6 +3051,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 ();
 	}
@@ -3423,15 +3479,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;
 
@@ -3459,6 +3526,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:
@@ -4628,6 +4702,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
@@ -5081,7 +5191,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;
 	}
 
@@ -5216,6 +5327,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 041fa0f..cdd60df 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]