Skip to content

Commit

Permalink
dbus: fix naming of multiple instances
Browse files Browse the repository at this point in the history
The do-not-queue flag is necessary to ensure that the bus name is
obtained immediately or not at all. Without it, each VLC instances gets
put into the queue for the same name.

Also, failure must be checked from the return value of the function,
not (typically) the low-level error flag.
  • Loading branch information
Rémi Denis-Courmont committed Jun 18, 2017
1 parent 2699b1d commit 05b779f
Showing 1 changed file with 5 additions and 14 deletions.
19 changes: 5 additions & 14 deletions modules/control/dbus/dbus.c
Expand Up @@ -193,14 +193,11 @@ static int Open( vlc_object_t *p_this )
&dbus_mpris_vtable, p_this ); &dbus_mpris_vtable, p_this );


/* Try to register org.mpris.MediaPlayer2.vlc */ /* Try to register org.mpris.MediaPlayer2.vlc */
const unsigned bus_flags = DBUS_NAME_FLAG_DO_NOT_QUEUE;
var_Create(p_intf->obj.libvlc, "dbus-mpris-name", VLC_VAR_STRING); var_Create(p_intf->obj.libvlc, "dbus-mpris-name", VLC_VAR_STRING);
dbus_bus_request_name( p_conn, DBUS_MPRIS_BUS_NAME, 0, &error ); if( dbus_bus_request_name( p_conn, DBUS_MPRIS_BUS_NAME, bus_flags, NULL )
if( dbus_error_is_set( &error ) ) != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER )
{ {
msg_Dbg( p_this, "Failed to get service name %s: %s",
DBUS_MPRIS_BUS_NAME, error.message );
dbus_error_free( &error );

/* Register an instance-specific well known name of the form /* Register an instance-specific well known name of the form
* org.mpris.MediaPlayer2.vlc.instanceXXXX where XXXX is the * org.mpris.MediaPlayer2.vlc.instanceXXXX where XXXX is the
* current Process ID */ * current Process ID */
Expand All @@ -211,14 +208,8 @@ static int Open( vlc_object_t *p_this )
DBUS_MPRIS_BUS_NAME"."DBUS_INSTANCE_ID_PREFIX"%"PRIu32, DBUS_MPRIS_BUS_NAME"."DBUS_INSTANCE_ID_PREFIX"%"PRIu32,
(uint32_t)getpid() ); (uint32_t)getpid() );


dbus_bus_request_name( p_conn, unique_service, 0, &error ); if( dbus_bus_request_name( p_conn, unique_service, bus_flags, NULL )
if( dbus_error_is_set( &error ) ) == DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER )
{
msg_Err( p_this, "Failed to get service name %s: %s",
DBUS_MPRIS_BUS_NAME, error.message );
dbus_error_free( &error );
}
else
{ {
msg_Dbg( p_intf, "listening on dbus as: %s", unique_service ); msg_Dbg( p_intf, "listening on dbus as: %s", unique_service );
var_SetString(p_intf->obj.libvlc, "dbus-mpris-name", var_SetString(p_intf->obj.libvlc, "dbus-mpris-name",
Expand Down

0 comments on commit 05b779f

Please sign in to comment.