[tracker-miners/wip/carlosg/dbus-api-changes: 85/85] tracker-index: Make service autoclose if there's no watched files



commit 27d26836fe1db60c73e13f08d0c5ba280b4f9997
Author: Carlos Garnacho <carlosg gnome org>
Date:   Sun Jun 21 10:55:07 2020 +0200

    tracker-index: Make service autoclose if there's no watched files
    
    This service is unnecessary if there's no current requests, we can
    close it and trust on DBus autostart to handle future requests.

 src/tracker-index/tracker-main.c              |  9 +++++++++
 src/tracker-index/tracker-miner-files-index.c | 17 +++++++++++++++++
 2 files changed, 26 insertions(+)
---
diff --git a/src/tracker-index/tracker-main.c b/src/tracker-index/tracker-main.c
index 0004ef447..d68ddb10d 100644
--- a/src/tracker-index/tracker-main.c
+++ b/src/tracker-index/tracker-main.c
@@ -103,6 +103,13 @@ initialize_signal_handler (void)
 #endif /* G_OS_WIN32 */
 }
 
+static void
+files_index_close_cb (GMainLoop *main_loop)
+{
+       g_debug ("No further watched folders, closing");
+       g_main_loop_quit (main_loop);
+}
+
 int
 main (gint argc, gchar *argv[])
 {
@@ -153,6 +160,8 @@ main (gint argc, gchar *argv[])
        main_loop = g_main_loop_new (NULL, FALSE);
 
        index = tracker_miner_files_index_new ();
+       g_signal_connect (index, "close",
+                         G_CALLBACK (files_index_close_cb), main_loop);
 
        /* Request DBus name */
        if (!tracker_dbus_request_name (connection,
diff --git a/src/tracker-index/tracker-miner-files-index.c b/src/tracker-index/tracker-miner-files-index.c
index 7508bbe42..c428e68a5 100644
--- a/src/tracker-index/tracker-miner-files-index.c
+++ b/src/tracker-index/tracker-miner-files-index.c
@@ -51,6 +51,13 @@ enum {
        PROP_FILES_MINER
 };
 
+enum {
+       CLOSE,
+       N_SIGNALS
+};
+
+static guint signals[N_SIGNALS] = { 0 };
+
 #define TRACKER_MINER_FILES_INDEX_GET_PRIVATE(o) (tracker_miner_files_index_get_instance_private 
(TRACKER_MINER_FILES_INDEX (o)))
 
 static void     index_finalize            (GObject              *object);
@@ -96,6 +103,13 @@ tracker_miner_files_index_class_init (TrackerMinerFilesIndexClass *klass)
        object_class = G_OBJECT_CLASS (klass);
 
        object_class->finalize = index_finalize;
+
+       signals[CLOSE] =
+               g_signal_new ("close",
+                             G_OBJECT_CLASS_TYPE (object_class),
+                             G_SIGNAL_RUN_LAST, 0,
+                             NULL, NULL, NULL,
+                             G_TYPE_NONE, 0);
 }
 
 static void
@@ -187,6 +201,9 @@ peer_listener_unwatch_file (TrackerMinerFilesPeerListener *listener,
        }
 
        update_indexed_files (index);
+
+       if (priv->indexed_files->len == 0)
+               g_signal_emit (index, signals[CLOSE], 0);
 }
 
 static void


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