[vlc-commits] single instance: Avoid initializing twice because of dbus activation
Mirsal Ennaime
git at videolan.org
Sun Aug 26 19:06:39 CEST 2012
vlc/vlc-2.0 | branch: master | Mirsal Ennaime <mirsal at videolan.org> | Sat May 12 15:27:18 2012 +0200| [1b573cdc750fed013c52557ab2112dd38b0b4b92] | committer: Jean-Baptiste Kempf
single instance: Avoid initializing twice because of dbus activation
The single instance mode currently tries to contact another VLC instance
through dbus in order to find out if one is running. With dbus activation,
it results to the dbus daemon launching a new VLC instance while the
first one blocks until the new one answers the call
This patch uses org.freedesktop.DBus.NameHasOwner instead in order to get
an answer from the dbus daemon without it launching a second instance.
(cherry picked from commit bcc158b70019bdd2d1ab647173cb1ea41751f706)
Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>
> http://git.videolan.org/gitweb.cgi/vlc/vlc-2.0.git/?a=commit;h=1b573cdc750fed013c52557ab2112dd38b0b4b92
---
src/libvlc.c | 38 ++++++++++++++++++++------------------
1 file changed, 20 insertions(+), 18 deletions(-)
diff --git a/src/libvlc.c b/src/libvlc.c
index 1a3931b..f77928b 100644
--- a/src/libvlc.c
+++ b/src/libvlc.c
@@ -343,6 +343,11 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc,
/* FIXME: could be replaced by using Unix sockets */
#ifdef HAVE_DBUS
+
+#define MPRIS_BUS_NAME "org.mpris.MediaPlayer2.vlc"
+#define MPRIS_OBJECT_PATH "/org/mpris/MediaPlayer2"
+#define MPRIS_TRACKLIST_INTERFACE "org.mpris.MediaPlayer2.TrackList"
+
dbus_threads_init_default();
if( var_InheritBool( p_libvlc, "one-instance" )
@@ -368,22 +373,16 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc,
/* check if VLC is available on the bus
* if not: D-Bus control is not enabled on the other
* instance and we can't pass MRLs to it */
- DBusMessage *p_test_msg = NULL;
- DBusMessage *p_test_reply = NULL;
-
- p_test_msg = dbus_message_new_method_call(
- "org.mpris.MediaPlayer2.vlc", "/org/mpris/MediaPlayer2",
- "org.freedesktop.DBus.Introspectable", "Introspect" );
-
- /* block until a reply arrives */
- p_test_reply = dbus_connection_send_with_reply_and_block(
- p_conn, p_test_msg, -1, &dbus_error );
- dbus_message_unref( p_test_msg );
- if( p_test_reply == NULL )
+ if( !dbus_bus_name_has_owner( p_conn, MPRIS_BUS_NAME, &dbus_error ) )
{
- dbus_error_free( &dbus_error );
- msg_Dbg( p_libvlc, "No Media Player is running. "
- "Continuing normally." );
+ if( dbus_error_is_set( &dbus_error ) )
+ {
+ msg_Err( p_libvlc, "D-Bus error: %s", dbus_error.message );
+ dbus_error_free( &dbus_error );
+ }
+ else
+ msg_Dbg( p_libvlc, "No Media Player is running. "
+ "Continuing normally." );
}
else
{
@@ -393,7 +392,6 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc,
DBusPendingCall* p_dbus_pending = NULL;
dbus_bool_t b_play;
- dbus_message_unref( p_test_reply );
msg_Warn( p_libvlc, "Another Media Player is running. Exiting");
for( i_input = vlc_optind; i_input < i_argc;i_input++ )
@@ -416,8 +414,8 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc,
psz_mrl );
p_dbus_msg = dbus_message_new_method_call(
- "org.mpris.MediaPlayer2.vlc", "/org/mpris/MediaPlayer2",
- "org.mpris.MediaPlayer2.TrackList", "AddTrack" );
+ MPRIS_BUS_NAME, MPRIS_OBJECT_PATH,
+ MPRIS_TRACKLIST_INTERFACE, "AddTrack" );
if ( NULL == p_dbus_msg )
{
@@ -491,6 +489,10 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc,
/* we unreference the connection when we've finished with it */
if( p_conn ) dbus_connection_unref( p_conn );
}
+#undef MPRIS_BUS_NAME
+#undef MPRIS_OBJECT_PATH
+#undef MPRIS_TRACKLIST_INTERFACE
+
#endif
/*
More information about the vlc-commits
mailing list