[tracker/wip/carlosg/domain-ontologies: 17/21] tracker-store: If a domain is set, set a watch on it



commit 6e65185b4869a9aa0d94764da417d6fe5f8280f9
Author: Carlos Garnacho <carlosg gnome org>
Date:   Wed Jun 21 21:10:37 2017 +0200

    tracker-store: If a domain is set, set a watch on it
    
    Tracker-store will wait till there are no elements left before
    exiting, in order to ensure it does so cleanly.

 src/tracker-store/tracker-dbus.vala |   23 +++++++++++++++++++++++
 src/tracker-store/tracker-main.vala |    3 +++
 2 files changed, 26 insertions(+), 0 deletions(-)
---
diff --git a/src/tracker-store/tracker-dbus.vala b/src/tracker-store/tracker-dbus.vala
index 1a44a97..483ffc9 100644
--- a/src/tracker-store/tracker-dbus.vala
+++ b/src/tracker-store/tracker-dbus.vala
@@ -35,6 +35,8 @@ public class Tracker.DBus {
        static Tracker.Backup backup;
        static uint backup_id;
        static Tracker.Config config;
+       static uint domain_watch_id;
+       static MainLoop watch_main_loop;
 
        static bool dbus_register_service (string name) {
                message ("Registering D-Bus service...\n  Name:'%s'", name);
@@ -90,6 +92,22 @@ public class Tracker.DBus {
                return dbus_register_service (service_name);
        }
 
+       public static void on_domain_name_disappeared (DBusConnection connection, string name) {
+               notifier.wait ();
+               yield;
+               watch_main_loop.quit ();
+       }
+
+       public static void watch_domain (string? domain, MainLoop main_loop) {
+               if (domain_watch_id == 0) {
+                       watch_main_loop = main_loop;
+                       domain_watch_id = GLib.Bus.watch_name_on_connection (connection,
+                                                                            domain,
+                                                                            GLib.BusNameWatcherFlags.NONE,
+                                                                            null, 
on_domain_name_disappeared);
+               }
+       }
+
        public static bool init (Tracker.Config config_p) {
                /* Don't reinitialize */
                config = config_p;
@@ -154,6 +172,11 @@ public class Tracker.DBus {
                        notifier_id = 0;
                }
 
+               if (domain_watch_id != 0) {
+                       GLib.Bus.unwatch_name (domain_watch_id);
+                       domain_watch_id = 0;
+               }
+
                connection = null;
        }
 
diff --git a/src/tracker-store/tracker-main.vala b/src/tracker-store/tracker-main.vala
index 000415a..12a0e7d 100644
--- a/src/tracker-store/tracker-main.vala
+++ b/src/tracker-store/tracker-main.vala
@@ -336,6 +336,9 @@ License which can be viewed at:
                if (!shutdown) {
                        main_loop = new MainLoop ();
 
+                       if (domain != null)
+                               Tracker.DBus.watch_domain (domain, main_loop);
+
                        initialize_signal_handler ();
 
                        main_loop.run ();


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