[tracker/external-crawler: 9/37] libtracker-miner: Introduce MinerFSQueue for injecting file changes



commit df9a157a1cd5ea4868b0b2368475751b4f972ad1
Author: Martyn Russell <martyn lanedo com>
Date:   Wed May 7 13:31:36 2014 +0100

    libtracker-miner: Introduce MinerFSQueue for injecting file changes
    
    This is used to signal TrackerFileNotifier and TrackerMinerFS from external
    crawlers about files and what has happened regarding them.

 src/libtracker-miner/tracker-file-notifier.c |   54 ++++++++++++++------------
 src/libtracker-miner/tracker-file-notifier.h |   30 ++++++++------
 src/libtracker-miner/tracker-miner-fs.c      |   16 +++++--
 src/libtracker-miner/tracker-miner-fs.h      |   16 ++++++-
 4 files changed, 70 insertions(+), 46 deletions(-)
---
diff --git a/src/libtracker-miner/tracker-file-notifier.c b/src/libtracker-miner/tracker-file-notifier.c
index 17b3bf4..2903718 100644
--- a/src/libtracker-miner/tracker-file-notifier.c
+++ b/src/libtracker-miner/tracker-file-notifier.c
@@ -1668,38 +1668,42 @@ tracker_file_notifier_get_file_iri (TrackerFileNotifier *notifier,
 }
 
 gboolean
-tracker_file_notifier_add_file (TrackerFileNotifier *notifier,
-                                GFile               *file)
+tracker_file_notifier_signal_file  (TrackerFileNotifier     *notifier,
+                                    TrackerMinerFSQueue      queue_type,
+                                    GFile                   *file,
+                                    GFileType                file_type)
 {
        g_return_val_if_fail (TRACKER_IS_FILE_NOTIFIER (notifier), FALSE);
        g_return_val_if_fail (G_IS_FILE (file), FALSE);
 
-       /* Hack, we use the created signal here from the
-        * TrackerMonitor, this way, the file is indoctrinated into
-        * the system nicely.
-        */
-       /* FIXME: Get IS DIRECTORY for boolean here */
-       monitor_item_created_cb (NULL, file, FALSE, notifier);
-
-       return TRUE;
-}
-
-gboolean
-tracker_file_notifier_add_files (TrackerFileNotifier *notifier,
-                                 GList               *files)
-{
-       GList *l;
-       gboolean success = TRUE;
+       switch (queue_type) {
+       case TRACKER_MINER_FS_QUEUE_CREATED:
+               monitor_item_created_cb (NULL,
+                                        file,
+                                        file_type == G_FILE_TYPE_DIRECTORY ? TRUE : FALSE,
+                                        notifier);
+               break;
 
-       g_return_val_if_fail (TRACKER_IS_FILE_NOTIFIER (notifier), FALSE);
-       g_return_val_if_fail (files != NULL, FALSE);
-       g_return_val_if_fail (g_list_length (files) > 0, FALSE);
+       case TRACKER_MINER_FS_QUEUE_UPDATED:
+               monitor_item_updated_cb (NULL,
+                                        file,
+                                        file_type == G_FILE_TYPE_DIRECTORY ? TRUE : FALSE,
+                                        notifier);
+               break;
 
-       for (l = files; l; l = l->next) {
-               GFile *file = l->data;
+       case TRACKER_MINER_FS_QUEUE_DELETED:
+               monitor_item_deleted_cb (NULL,
+                                        file,
+                                        file_type == G_FILE_TYPE_DIRECTORY ? TRUE : FALSE,
+                                        notifier);
+       case TRACKER_MINER_FS_QUEUE_MOVED:
+               g_critical ("Currently MOVE signalling is unsupported");
+               return FALSE;
 
-               success &= tracker_file_notifier_add_file (notifier, file);
+       default:
+               g_assert_not_reached ();
+               return FALSE;
        }
 
-       return success;
+       return TRUE;
 }
diff --git a/src/libtracker-miner/tracker-file-notifier.h b/src/libtracker-miner/tracker-file-notifier.h
index 1e08319..3c0438b 100644
--- a/src/libtracker-miner/tracker-file-notifier.h
+++ b/src/libtracker-miner/tracker-file-notifier.h
@@ -28,6 +28,7 @@
 
 #include <gio/gio.h>
 #include "tracker-indexing-tree.h"
+#include "tracker-miner-fs.h"
 
 G_BEGIN_DECLS
 
@@ -40,6 +41,7 @@ G_BEGIN_DECLS
 
 typedef struct _TrackerFileNotifier TrackerFileNotifier;
 typedef struct _TrackerFileNotifierClass TrackerFileNotifierClass;
+typedef enum _TrackerFileNotifierType TrackerFileNotifierType;
 
 struct _TrackerFileNotifier {
        GObject parent_instance;
@@ -73,22 +75,24 @@ struct _TrackerFileNotifierClass {
        void (* finished)           (TrackerFileNotifier *notifier);
 };
 
-GType         tracker_file_notifier_get_type      (void) G_GNUC_CONST;
+GType         tracker_file_notifier_get_type     (void) G_GNUC_CONST;
 
-TrackerFileNotifier* tracker_file_notifier_new  (TrackerIndexingTree *indexing_tree,
-                                                 gboolean             external_crawler);
+TrackerFileNotifier *
+              tracker_file_notifier_new          (TrackerIndexingTree     *indexing_tree,
+                                                  gboolean                 external_crawler);
 
-gboolean      tracker_file_notifier_start (TrackerFileNotifier *notifier);
-void          tracker_file_notifier_stop  (TrackerFileNotifier *notifier);
-gboolean      tracker_file_notifier_is_active (TrackerFileNotifier *notifier);
+gboolean      tracker_file_notifier_start        (TrackerFileNotifier     *notifier);
+void          tracker_file_notifier_stop         (TrackerFileNotifier     *notifier);
+gboolean      tracker_file_notifier_is_active    (TrackerFileNotifier     *notifier);
 
-const gchar * tracker_file_notifier_get_file_iri (TrackerFileNotifier *notifier,
-                                                  GFile               *file,
-                                                  gboolean             force);
-gboolean      tracker_file_notifier_add_file (TrackerFileNotifier *notifier,
-                                              GFile               *file);
-gboolean      tracker_file_notifier_add_files (TrackerFileNotifier *notifier,
-                                               GList               *files);
+const gchar * tracker_file_notifier_get_file_iri (TrackerFileNotifier     *notifier,
+                                                  GFile                   *file,
+                                                  gboolean                 force);
+
+gboolean      tracker_file_notifier_signal_file  (TrackerFileNotifier     *notifier,
+                                                  TrackerMinerFSQueue      queue_type,
+                                                  GFile                   *file,
+                                                  GFileType                file_type);
 
 G_END_DECLS
 
diff --git a/src/libtracker-miner/tracker-miner-fs.c b/src/libtracker-miner/tracker-miner-fs.c
index 9e1e9fb..c17c98c 100644
--- a/src/libtracker-miner/tracker-miner-fs.c
+++ b/src/libtracker-miner/tracker-miner-fs.c
@@ -3942,7 +3942,9 @@ tracker_miner_fs_get_indexing_tree (TrackerMinerFS *fs)
 /**
  * tracker_miner_fs_manually_notify_file:
  * @fs: a #TrackerMinerFS
+ * @queue_type: the type of operation to notify
  * @file: a #GFile
+ * @file_type: a #GFileType
  * @error: a #GError
  *
  * This API is only useful where the @fs was created using the
@@ -3962,9 +3964,11 @@ tracker_miner_fs_get_indexing_tree (TrackerMinerFS *fs)
  * Since: 1.2.
  **/
 gboolean
-tracker_miner_fs_manually_notify_file (TrackerMinerFS  *fs,
-                                       GFile           *file,
-                                       GError         **error)
+tracker_miner_fs_manually_notify_file (TrackerMinerFS       *fs,
+                                       TrackerMinerFSQueue   queue_type,
+                                       GFile                *file,
+                                       GFileType             file_type,
+                                       GError              **error)
 {
        TrackerMinerFSPrivate *priv;
 
@@ -3989,8 +3993,10 @@ tracker_miner_fs_manually_notify_file (TrackerMinerFS  *fs,
                return FALSE;
        }
 
-       /* FIXME: We need to know if this was created, updated, etc. */
-       return tracker_file_notifier_add_file (fs->priv->file_notifier, file);
+       return tracker_file_notifier_signal_file (fs->priv->file_notifier,
+                                                 queue_type,
+                                                 file,
+                                                 file_type);
 }
 
 
diff --git a/src/libtracker-miner/tracker-miner-fs.h b/src/libtracker-miner/tracker-miner-fs.h
index 54c53ca..6cf2582 100644
--- a/src/libtracker-miner/tracker-miner-fs.h
+++ b/src/libtracker-miner/tracker-miner-fs.h
@@ -118,6 +118,14 @@ typedef enum {
        TRACKER_MINER_FS_ERROR_HAVE_CRAWLER,
 } TrackerMinerFSError;
 
+typedef enum {
+       TRACKER_MINER_FS_QUEUE_NONE,
+       TRACKER_MINER_FS_QUEUE_CREATED,
+       TRACKER_MINER_FS_QUEUE_UPDATED,
+       TRACKER_MINER_FS_QUEUE_DELETED,
+       TRACKER_MINER_FS_QUEUE_MOVED
+} TrackerMinerFSQueue;
+
 
 GType                 tracker_miner_fs_get_type             (void) G_GNUC_CONST;
 GQuark                tracker_miner_fs_error_quark          (void);
@@ -179,9 +187,11 @@ void                  tracker_miner_fs_force_mtime_checking (TrackerMinerFS *fs,
                                                              GFile          *directory);
 
 TrackerIndexingTree * tracker_miner_fs_get_indexing_tree    (TrackerMinerFS *fs);
-gboolean tracker_miner_fs_manually_notify_file (TrackerMinerFS  *fs,
-                                                GFile           *file,
-                                                GError         **error);
+gboolean              tracker_miner_fs_manually_notify_file (TrackerMinerFS       *fs,
+                                                             TrackerMinerFSQueue   queue_type,
+                                                             GFile                *file,
+                                                             GFileType             file_type,
+                                                             GError              **error);
 
 G_END_DECLS
 


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