From 147d3ecde3ec5f9153ce05208a043a802d320b3d Mon Sep 17 00:00:00 2001 From: David King Date: Mon, 24 Jun 2013 08:21:22 +0100 Subject: 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 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) (limited to 'daemon') 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", -- cgit v1.2.1