[caribou] daemon: Start with D-Bus activation



commit 147d3ecde3ec5f9153ce05208a043a802d320b3d
Author: David King <amigadave amigadave com>
Date:   Mon Jun 24 08:21:22 2013 +0100

    daemon: Start with D-Bus activation
    
    Install the daemon to libexecdir. Make the daemon own a name on the
    session bus, and install a D-Bus service file for it. Allow the name
    to be replaced by another process, so that a D-Bus activated daemon can
    be replaced by a GSettings-key autostarted daemon. Handle run() being
    called multiple times.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=683712

 daemon/Makefile.am                                 |    2 +-
 daemon/daemon.vala                                 |   26 ++++++++++++++++++++
 data/Makefile.am                                   |   16 ++++++++++--
 ....desktop.in => caribou-autostart.desktop.in.in} |    2 +-
 data/org.gnome.Caribou.Daemon.service.in           |    3 ++
 5 files changed, 44 insertions(+), 5 deletions(-)
---
diff --git a/daemon/Makefile.am b/daemon/Makefile.am
index 13bca11..e6432ec 100644
--- a/daemon/Makefile.am
+++ b/daemon/Makefile.am
@@ -1,4 +1,4 @@
-bin_PROGRAMS = caribou
+libexec_PROGRAMS = caribou
 
 caribou_VALAFLAGS = \
        --vapidir=$(top_srcdir)/vapi \
diff --git a/daemon/daemon.vala b/daemon/daemon.vala
index 7192646..82b2c3f 100644
--- a/daemon/daemon.vala
+++ b/daemon/daemon.vala
@@ -11,13 +11,32 @@ namespace Caribou {
         public abstract void hide (uint32 timestamp) throws IOError;
     }
 
+    [DBus (name = "org.gnome.Caribou.Daemon")]
     class Daemon : Object {
         _Keyboard keyboard;
         Atspi.Accessible current_acc;
         unowned Gdk.Display display;
+        uint name_id;
 
         public Daemon () {
             display = Gdk.Display.get_default ();
+            name_id = Bus.own_name (BusType.SESSION,
+                                    "org.gnome.Caribou.Daemon",
+                                    BusNameOwnerFlags.ALLOW_REPLACEMENT
+                                    | BusNameOwnerFlags.REPLACE,
+                                    on_bus_acquired, null, quit);
+        }
+
+        ~Daemon () {
+            Bus.unown_name (name_id);
+        }
+
+        void on_bus_acquired (DBusConnection conn) {
+            try {
+                conn.register_object ("/org/gnome/Caribou/Daemon", this);
+            } catch (IOError e) {
+                error ("Could not register D-Bus service: %s", e.message);
+            }
         }
 
         void on_get_proxy_ready (GLib.Object? obj, GLib.AsyncResult res) {
@@ -144,6 +163,13 @@ namespace Caribou {
         }
 
         public void run () {
+            if (keyboard != null)
+            {
+                // This method is available over D-Bus, so ignore the request
+                // to run if the daemon is already running.
+                return;
+            }
+
             Bus.get_proxy.begin<_Keyboard> (BusType.SESSION,
                                             "org.gnome.Caribou.Keyboard",
                                             "/org/gnome/Caribou/Keyboard",
diff --git a/data/Makefile.am b/data/Makefile.am
index 2e83b85..97c663f 100644
--- a/data/Makefile.am
+++ b/data/Makefile.am
@@ -8,19 +8,28 @@ gsettings_schemas_in_files = \
 gsettings_SCHEMAS = $(gsettings_schemas_in_files:.gschema.xml.in=.gschema.xml)
 
 autostartdir    = $(sysconfdir)/xdg/autostart
-autostart_in_files = caribou-autostart.desktop.in
+autostart_in_in_files = caribou-autostart.desktop.in.in
+autostart_in_files = $(autostart_in_in_files:.desktop.in.in=.desktop.in)
 autostart_DATA   = $(autostart_in_files:.desktop.in=.desktop)
 
 servicefiledir = $(datadir)/dbus-1/services
-servicefile_in_files = org.gnome.Caribou.Antler.service.in
+servicefile_in_files = \
+       org.gnome.Caribou.Antler.service.in \
+       org.gnome.Caribou.Daemon.service.in
 servicefile_DATA = $(servicefile_in_files:.service.in=.service)
 
+caribou-autostart.desktop.in: caribou-autostart.desktop.in.in
+       $(AM_V_GEN)sed -e "s|[ ]libexecdir[@]|$(libexecdir)|" $< > $@
+
 org.gnome.Caribou.Antler.service: org.gnome.Caribou.Antler.service.in
        $(AM_V_GEN)sed -e "s|[ ]libexecdir[@]|$(libexecdir)|" $< > $@
 
+org.gnome.Caribou.Daemon.service: org.gnome.Caribou.Daemon.service.in
+       $(AM_V_GEN)sed -e "s|[ ]libexecdir[@]|$(libexecdir)|" $< > $@
+
 @INTLTOOL_DESKTOP_RULE@
 
-EXTRA_DIST = $(autostart_in_files) $(servicefile_in_files)
+EXTRA_DIST = $(autostart_in_in_files) $(servicefile_in_files)
 
 org.gnome.caribou.gschema.xml.in: $(top_srcdir)/caribou/settings/caribou_settings.py
        $(AM_V_GEN)$(PYTHON) -B $(top_srcdir)/tools/make_schema.py \
@@ -34,6 +43,7 @@ org.gnome.antler.gschema.xml.in: $(top_srcdir)/caribou/antler/antler_settings.py
 
 CLEANFILES = \
        $(autostart_DATA) \
+       $(autostart_in_files) \
        $(gsettings_schemas_in_files) \
        $(gsettings_SCHEMAS) \
        $(servicefile_DATA)
diff --git a/data/caribou-autostart.desktop.in b/data/caribou-autostart.desktop.in.in
similarity index 89%
rename from data/caribou-autostart.desktop.in
rename to data/caribou-autostart.desktop.in.in
index 445ad14..4bd1c03 100644
--- a/data/caribou-autostart.desktop.in
+++ b/data/caribou-autostart.desktop.in.in
@@ -1,7 +1,7 @@
 [Desktop Entry]
 Type=Application
 Name=Caribou
-Exec=caribou
+Exec= libexecdir@/caribou
 AutostartCondition=GSettings org.gnome.desktop.a11y.applications screen-keyboard-enabled
 X-GNOME-AutoRestart=true
 #X-GNOME-Autostart-Phase=Initialization
diff --git a/data/org.gnome.Caribou.Daemon.service.in b/data/org.gnome.Caribou.Daemon.service.in
new file mode 100644
index 0000000..a30d622
--- /dev/null
+++ b/data/org.gnome.Caribou.Daemon.service.in
@@ -0,0 +1,3 @@
+[D-BUS Service]
+Name=org.gnome.Caribou.Daemon
+Exec= libexecdir@/caribou


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