[tracker-miners/wip/carlosg/miner-files-queues: 4/10] libtracker-miner: Add a "high water" property to TrackerFileNotifier




commit 99936a2f1b5937a889f44b85adc671a00f888881
Author: Carlos Garnacho <carlosg gnome org>
Date:   Thu Dec 16 12:27:38 2021 +0100

    libtracker-miner: Add a "high water" property to TrackerFileNotifier
    
    This is not a panic "stop everything you're doing" call, but rather a
    soft hint that TrackerFileNotifier may stop for a while after finishing
    what it is doing at the moment.
    
    When the value is unset, the notifier can resume its operation (if it
    did ever stop).

 src/libtracker-miner/tracker-file-notifier.c | 33 ++++++++++++++++++++++++++++
 src/libtracker-miner/tracker-file-notifier.h |  3 +++
 2 files changed, 36 insertions(+)
---
diff --git a/src/libtracker-miner/tracker-file-notifier.c b/src/libtracker-miner/tracker-file-notifier.c
index 8422c7f4d..5815753cb 100644
--- a/src/libtracker-miner/tracker-file-notifier.c
+++ b/src/libtracker-miner/tracker-file-notifier.c
@@ -109,6 +109,8 @@ typedef struct {
        RootData *current_index_root;
 
        guint stopped : 1;
+       guint high_water : 1;
+       guint active : 1;
 } TrackerFileNotifierPrivate;
 
 static gboolean notifier_query_root_contents (TrackerFileNotifier *notifier);
@@ -551,6 +553,11 @@ crawl_directory_in_current_root (TrackerFileNotifier *notifier)
 
        priv = tracker_file_notifier_get_instance_private (notifier);
 
+       if (priv->high_water) {
+               priv->active = FALSE;
+               return TRUE;
+       }
+
        if (!priv->current_index_root)
                return FALSE;
 
@@ -566,6 +573,8 @@ crawl_directory_in_current_root (TrackerFileNotifier *notifier)
                if ((flags & TRACKER_DIRECTORY_FLAG_MONITOR) != 0)
                        tracker_monitor_add (priv->monitor, directory);
 
+               priv->active = TRUE;
+
                /* Begin crawling the directory non-recursively. */
                tracker_crawler_get (priv->crawler,
                                     directory,
@@ -849,6 +858,8 @@ notifier_query_root_contents (TrackerFileNotifier *notifier)
        tracker_sparql_statement_bind_string (priv->content_query, "root", uri);
        g_free (uri);
 
+       priv->active = TRUE;
+
        tracker_sparql_statement_execute_async (priv->content_query,
                                                priv->cancellable,
                                                (GAsyncReadyCallback) query_execute_cb,
@@ -1728,6 +1739,28 @@ tracker_file_notifier_new (TrackerIndexingTree     *indexing_tree,
                             NULL);
 }
 
+void
+tracker_file_notifier_set_high_water (TrackerFileNotifier *notifier,
+                                      gboolean             high_water)
+{
+       TrackerFileNotifierPrivate *priv;
+
+       g_return_if_fail (TRACKER_IS_FILE_NOTIFIER (notifier));
+
+       priv = tracker_file_notifier_get_instance_private (notifier);
+       if (priv->high_water == high_water)
+               return;
+
+       priv->high_water = high_water;
+
+       if (!high_water && !priv->active &&
+           tracker_file_notifier_is_active (notifier)) {
+               /* Maybe kick everything back into action */
+               if (!crawl_directory_in_current_root (notifier))
+                       finish_current_directory (notifier, FALSE);
+       }
+}
+
 gboolean
 tracker_file_notifier_start (TrackerFileNotifier *notifier)
 {
diff --git a/src/libtracker-miner/tracker-file-notifier.h b/src/libtracker-miner/tracker-file-notifier.h
index c6081bfda..f5c69b768 100644
--- a/src/libtracker-miner/tracker-file-notifier.h
+++ b/src/libtracker-miner/tracker-file-notifier.h
@@ -88,6 +88,9 @@ gboolean      tracker_file_notifier_start        (TrackerFileNotifier     *notif
 void          tracker_file_notifier_stop         (TrackerFileNotifier     *notifier);
 gboolean      tracker_file_notifier_is_active    (TrackerFileNotifier     *notifier);
 
+void          tracker_file_notifier_set_high_water (TrackerFileNotifier *notifier,
+                                                    gboolean             high_water);
+
 G_END_DECLS
 
 #endif /* __TRACKER_FILE_NOTIFIER_H__ */


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