[tracker] libtracker-miner: Add filter_event vmethod



commit 379b27a868d8fbd7e67b8df7bfd6f6304fd124f4
Author: Carlos Garnacho <carlosg gnome org>
Date:   Sun Jul 2 13:05:31 2017 +0200

    libtracker-miner: Add filter_event vmethod
    
    This is not a signal because external users of a TrackerMiner have no
    business in modifying behavior at this level, this is reserved for
    subclasses that presumably know what they are doing.
    
    This vmethod is toggled for every event that gets received from the
    TrackerFileNotifier, before the file gets to hit any processing queue.

 src/libtracker-miner/tracker-miner-fs.c |   27 +++++++++++++++++++++++++++
 src/libtracker-miner/tracker-miner-fs.h |   14 +++++++++++++-
 2 files changed, 40 insertions(+), 1 deletions(-)
---
diff --git a/src/libtracker-miner/tracker-miner-fs.c b/src/libtracker-miner/tracker-miner-fs.c
index 2944090..deef0d1 100644
--- a/src/libtracker-miner/tracker-miner-fs.c
+++ b/src/libtracker-miner/tracker-miner-fs.c
@@ -2472,6 +2472,20 @@ check_item_queues (TrackerMinerFS *fs,
        return TRUE;
 }
 
+static gboolean
+filter_event (TrackerMinerFS          *fs,
+              TrackerMinerFSEventType  type,
+              GFile                   *file,
+              GFile                   *source_file)
+{
+       TrackerMinerFSClass *klass = TRACKER_MINER_FS_GET_CLASS (fs);
+
+       if (!klass->filter_event)
+               return FALSE;
+
+       return klass->filter_event (fs, type, file, source_file);
+}
+
 static void
 file_notifier_file_created (TrackerFileNotifier  *notifier,
                             GFile                *file,
@@ -2479,6 +2493,9 @@ file_notifier_file_created (TrackerFileNotifier  *notifier,
 {
        TrackerMinerFS *fs = user_data;
 
+       if (filter_event (fs, TRACKER_MINER_FS_EVENT_CREATED, file, NULL))
+               return;
+
        if (check_item_queues (fs, QUEUE_CREATED, file, NULL)) {
                miner_fs_queue_file (fs, fs->priv->items_created, file, FALSE);
                item_queue_handlers_set_up (fs);
@@ -2492,6 +2509,9 @@ file_notifier_file_deleted (TrackerFileNotifier  *notifier,
 {
        TrackerMinerFS *fs = user_data;
 
+       if (filter_event (fs, TRACKER_MINER_FS_EVENT_DELETED, file, NULL))
+               return;
+
        if (tracker_file_notifier_get_file_type (notifier, file) == G_FILE_TYPE_DIRECTORY) {
                /* Cancel all pending tasks on files inside the path given by file */
                tracker_task_pool_foreach (fs->priv->task_pool,
@@ -2516,6 +2536,10 @@ file_notifier_file_updated (TrackerFileNotifier  *notifier,
 {
        TrackerMinerFS *fs = user_data;
 
+       if (!attributes_only &&
+           filter_event (fs, TRACKER_MINER_FS_EVENT_UPDATED, file, NULL))
+               return;
+
        /* Writeback tasks would receive an updated after move,
         * consequence of the data being written back in the
         * copy, and its monitor events being propagated to
@@ -2547,6 +2571,9 @@ file_notifier_file_moved (TrackerFileNotifier *notifier,
 {
        TrackerMinerFS *fs = user_data;
 
+       if (filter_event (fs, TRACKER_MINER_FS_EVENT_MOVED, dest, source))
+               return;
+
        if (check_item_queues (fs, QUEUE_MOVED, source, dest)) {
                gint priority;
 
diff --git a/src/libtracker-miner/tracker-miner-fs.h b/src/libtracker-miner/tracker-miner-fs.h
index 8d4d2f2..c063964 100644
--- a/src/libtracker-miner/tracker-miner-fs.h
+++ b/src/libtracker-miner/tracker-miner-fs.h
@@ -42,6 +42,13 @@ G_BEGIN_DECLS
 #define TRACKER_IS_MINER_FS_CLASS(c)  (G_TYPE_CHECK_CLASS_TYPE ((c),  TRACKER_TYPE_MINER_FS))
 #define TRACKER_MINER_FS_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), TRACKER_TYPE_MINER_FS, 
TrackerMinerFSClass))
 
+typedef enum {
+       TRACKER_MINER_FS_EVENT_CREATED,
+       TRACKER_MINER_FS_EVENT_UPDATED,
+       TRACKER_MINER_FS_EVENT_DELETED,
+       TRACKER_MINER_FS_EVENT_MOVED,
+} TrackerMinerFSEventType;
+
 typedef struct _TrackerMinerFS        TrackerMinerFS;
 typedef struct _TrackerMinerFSPrivate TrackerMinerFSPrivate;
 
@@ -105,8 +112,13 @@ typedef struct {
                                               GFile                *dest,
                                               gboolean              recursive);
 
+       gboolean (* filter_event)             (TrackerMinerFS          *fs,
+                                              TrackerMinerFSEventType  type,
+                                              GFile                   *file,
+                                              GFile                   *source_file);
+
        /* <Private> */
-       gpointer padding[8];
+       gpointer padding[20];
 } TrackerMinerFSClass;
 
 /**


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