[vlc-commits] commit: dbus: add option --dbus-unique-service-id (default: false) ( Jean-Paul Saman )

git at videolan.org git at videolan.org
Tue Jun 15 11:35:28 CEST 2010


vlc | branch: master | Jean-Paul Saman <jean-paul.saman at m2x.nl> | Tue Apr  6 11:19:37 2010 +0200| [61b3abff8ab709fad647c42f724136208497ccdc] | committer: Jean-Paul Saman 

dbus: add option --dbus-unique-service-id (default: false)

The option --dbus-unique-service-id provides a unique name to identify a VLC instance on the DBUS session bus.
Each vlc instance will uses the following naming scheme on the dbus bus: org.mpris.vlc-<pid>, where <pid> is the PID of the vlc process.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=61b3abff8ab709fad647c42f724136208497ccdc
---

 modules/control/dbus.c |   32 +++++++++++++++++++++++++++++---
 1 files changed, 29 insertions(+), 3 deletions(-)

diff --git a/modules/control/dbus.c b/modules/control/dbus.c
index f3be831..d64ed69 100644
--- a/modules/control/dbus.c
+++ b/modules/control/dbus.c
@@ -113,6 +113,7 @@ struct intf_sys_t
     vlc_array_t    *p_events;
     vlc_mutex_t     lock;
     input_thread_t *p_input;
+    bool            b_unique;
 };
 
 typedef struct
@@ -129,6 +130,10 @@ typedef struct
 /*****************************************************************************
  * Module descriptor
  *****************************************************************************/
+#define DBUS_UNIQUE_TEXT N_("Unique DBUS service id (org.mpris.vlc-<pid>)")
+#define DBUS_UNIQUE_LONGTEXT N_( \
+    "Use a unique dbus service id to identify this VLC instance on the DBUS bus. " \
+    "The process identifier (PID) is added to the service name: org.mpris.vlc-<pid>" )
 
 vlc_module_begin ()
     set_shortname( N_("dbus"))
@@ -137,6 +142,8 @@ vlc_module_begin ()
     set_description( N_("D-Bus control interface") )
     set_capability( "interface", 0 )
     set_callbacks( Open, Close )
+    add_bool( "dbus-unique-service-id", false, NULL,
+              DBUS_UNIQUE_TEXT, DBUS_UNIQUE_LONGTEXT, true )
 vlc_module_end ()
 
 /*****************************************************************************
@@ -698,6 +705,7 @@ static int Open( vlc_object_t *p_this )
     playlist_t      *p_playlist;
     DBusConnection  *p_conn;
     DBusError       error;
+    char            *psz_service_name = NULL;
 
     if( !p_sys )
         return VLC_ENOMEM;
@@ -707,6 +715,21 @@ static int Open( vlc_object_t *p_this )
     p_sys->b_dead = false;
     p_sys->p_input = NULL;
 
+    p_sys->b_unique = var_CreateGetBool( p_intf, "dbus-unique-service-id" );
+    if( p_sys->b_unique )
+    {
+        if( asprintf( &psz_service_name, "%s-%d",
+            VLC_MPRIS_DBUS_SERVICE, getpid() ) < 0 )
+        {
+            free( p_sys );
+            return VLC_ENOMEM;
+        }
+    }
+    else
+    {
+        psz_service_name = strdup(VLC_MPRIS_DBUS_SERVICE);
+    }
+
     dbus_error_init( &error );
 
     /* connect to the session bus */
@@ -721,15 +744,18 @@ static int Open( vlc_object_t *p_this )
     }
 
     /* register a well-known name on the bus */
-    dbus_bus_request_name( p_conn, VLC_MPRIS_DBUS_SERVICE, 0, &error );
+    dbus_bus_request_name( p_conn, psz_service_name, 0, &error );
     if( dbus_error_is_set( &error ) )
     {
-        msg_Err( p_this, "Error requesting service " VLC_MPRIS_DBUS_SERVICE
-                 ": %s", error.message );
+        msg_Err( p_this, "Error requesting service %s: %s",
+                 psz_service_name, error.message );
         dbus_error_free( &error );
+        free( psz_service_name );
         free( p_sys );
         return VLC_EGENERIC;
     }
+    msg_Info( p_intf, "listening on dbus as: %s", psz_service_name );
+    free( psz_service_name );
 
     /* we register the objects */
     dbus_connection_register_object_path( p_conn, MPRIS_DBUS_ROOT_PATH,



More information about the vlc-commits mailing list