From 045e5e228235fb5f016960a4dffd957bb5f993d3 Mon Sep 17 00:00:00 2001 From: "Zeeshan Ali (Khattak)" Date: Mon, 8 Jun 2009 15:59:15 +0300 Subject: [PATCH] core: Start/shutdown rygel when upnp is enabled/disabled --- src/rygel/rygel-configuration.vala | 45 +++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/src/rygel/rygel-configuration.vala b/src/rygel/rygel-configuration.vala index 1da0d02..cb6e00b 100644 --- a/src/rygel/rygel-configuration.vala +++ b/src/rygel/rygel-configuration.vala @@ -41,17 +41,49 @@ public class Rygel.Configuration : GLib.Object { protected static const string LPCM_TRANSCODER_KEY = "enable-lpcm-transcoder"; + private const string DBUS_SERVICE = "org.freedesktop.DBus"; + private const string DBUS_PATH = "/org/freedesktop/DBus"; + private const string DBUS_INTERFACE = "org.freedesktop.DBus"; + + private const string RYGEL_SERVICE = "org.gnome.Rygel"; + private const string RYGEL_PATH = "/org/gnome/Rygel"; + private const string RYGEL_INTERFACE = "org.gnome.Rygel"; + // Our singleton private static Configuration config; protected GConf.Client gconf; + private dynamic DBus.Object dbus_obj; + private dynamic DBus.Object rygel_obj; + public bool upnp_enabled { get { return this.get_bool ("general", ENABLED_KEY, true); } set { - this.set_bool ("general", ENABLED_KEY, value); + if (value && !this.upnp_enabled) { + try { + uint32 res; + + this.dbus_obj.StartServiceByName (RYGEL_SERVICE, + (uint32) 0, + out res); + + this.set_bool ("general", ENABLED_KEY, value); + } catch (DBus.Error err) { + warning ("Failed to start Rygel service: %s\n", + err.message); + } + } else if (!value && this.upnp_enabled) { + try { + this.rygel_obj.Shutdown (); + this.set_bool ("general", ENABLED_KEY, value); + } catch (DBus.Error err) { + warning ("Failed to shutdown Rygel service: %s\n", + err.message); + } + } } } @@ -125,6 +157,17 @@ public class Rygel.Configuration : GLib.Object { public Configuration () { this.gconf = GConf.Client.get_default (); + + DBus.Connection connection = DBus.Bus.get (DBus.BusType.SESSION); + + // Create proxy to Rygel + this.rygel_obj = connection.get_object (RYGEL_SERVICE, + RYGEL_PATH, + RYGEL_INTERFACE); + // and DBus + this.dbus_obj = connection.get_object (DBUS_SERVICE, + DBUS_PATH, + DBUS_INTERFACE); } public bool get_enabled (string section) { -- 2.7.4