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



commit f30425731660d10e70ea856f83aebb541385800a
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..e76980a 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 && domain != null) {
+                       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 35a7d1a..b92abe7 100644
--- a/src/tracker-store/tracker-main.vala
+++ b/src/tracker-store/tracker-main.vala
@@ -335,6 +335,9 @@ License which can be viewed at:
                if (!shutdown) {
                        main_loop = new MainLoop ();
 
+                       if (domain != null)
+                               Tracker.DBus.watch_domain (domain_ontology, main_loop);
+
                        initialize_signal_handler ();
 
                        main_loop.run ();


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