[rygel] rygel: Re-add old DBus interface



commit 4bf83d1ea69b2a40c7e29deb5eef310c24644d24
Author: Jens Georg <mail jensge org>
Date:   Sun May 8 15:24:14 2022 +0200

    rygel: Re-add old DBus interface

 src/rygel/application.vala        | 12 ++++++++++++
 src/rygel/meson.build             |  3 ++-
 src/rygel/rygel-dbus-service.vala | 34 ++++++++++------------------------
 3 files changed, 24 insertions(+), 25 deletions(-)
---
diff --git a/src/rygel/application.vala b/src/rygel/application.vala
index 11d1eadc..3524757f 100644
--- a/src/rygel/application.vala
+++ b/src/rygel/application.vala
@@ -15,6 +15,7 @@ public class Rygel.Application : GLib.Application {
     private Configuration config;
     private LogHandler log_handler;
     private Acl acl;
+    private DBusService service;
 
     private bool activation_pending = false;
 
@@ -30,6 +31,17 @@ public class Rygel.Application : GLib.Application {
         Unix.signal_add (ProcessSignal.HUP, () => { this.release (); return false; });
     }
 
+    public override bool dbus_register (DBusConnection connection, string object_path) throws Error {
+        if (!base.dbus_register (connection, object_path)) {
+            return false;
+        }
+
+        service = new DBusService(this);
+        service.publish (connection);
+
+        return true;
+    }
+
     public override int handle_local_options (VariantDict options) {
         int count;
         if (options.lookup ("version", "b", out count)) {
diff --git a/src/rygel/meson.build b/src/rygel/meson.build
index 986ffd4d..0754d588 100644
--- a/src/rygel/meson.build
+++ b/src/rygel/meson.build
@@ -1,6 +1,7 @@
 rygel_sources = [
         'rygel-acl.vala',
-        'application.vala'
+        'application.vala',
+        'rygel-dbus-service.vala'
         ]
 executable('rygel',
            rygel_sources,
diff --git a/src/rygel/rygel-dbus-service.vala b/src/rygel/rygel-dbus-service.vala
index e3d55891..85a1fd8d 100644
--- a/src/rygel/rygel-dbus-service.vala
+++ b/src/rygel/rygel-dbus-service.vala
@@ -23,23 +23,22 @@
 
 [DBus (name = "org.gnome.Rygel1")]
 internal class Rygel.DBusService : Object, DBusInterface {
-    private Main main;
+    private Application main;
     private uint name_id;
     private uint connection_id;
 
-    public DBusService (Main main) {
+    public DBusService (Application main) {
         this.main = main;
     }
 
     public void shutdown () throws IOError, DBusError {
-        this.main.exit (0);
+        main.release ();
     }
 
-    internal void publish () {
-        this.name_id = Bus.own_name (BusType.SESSION,
+    internal void publish (DBusConnection connection) {
+        this.name_id = Bus.own_name_on_connection (connection,
                                      DBusInterface.SERVICE_NAME,
                                      BusNameOwnerFlags.NONE,
-                                     this.on_bus_aquired,
                                      this.on_name_available,
                                      this.on_name_lost);
     }
@@ -58,28 +57,15 @@ internal class Rygel.DBusService : Object, DBusInterface {
     }
 
 
-    private void on_bus_aquired (DBusConnection connection) {
-        try {
-            this.connection_id = connection.register_object
-                                        (DBusInterface.OBJECT_PATH,
-                                         this);
-        } catch (Error error) { }
-    }
-
     private void on_name_available (DBusConnection connection) {
-        this.main.dbus_available ();
+        try {
+            connection.register_object (DBusInterface.OBJECT_PATH, this);
+        } catch (IOError e) {
+            debug ("Failed to register legacy interface on connection: %s", e.message);
+        }
     }
 
     private void on_name_lost (DBusConnection? connection) {
-        if (connection == null) {
-            // This means there is no DBus available at all
-            this.main.dbus_available ();
-
-            return;
-        }
-
-        message (_("Another instance of Rygel is already running. Not starting."));
-        this.main.exit (-15);
     }
 }
 


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