Commit 461fd44c authored by Rafaël Carré's avatar Rafaël Carré

D-Bus module now uses new specification

TODO: playlist management
parent 33d29c3e
...@@ -30,50 +30,53 @@ import os ...@@ -30,50 +30,53 @@ import os
global position global position
global timer global timer
global playing #global playing
def itemchange_handler(item): def itemchange_handler(item):
gobject.timeout_add( 2000, timeset) gobject.timeout_add( 2000, timeset)
l_item.set_text(item) l_item.set_text(item)
bus = dbus.SessionBus() bus = dbus.SessionBus()
remote_object = bus.get_object("org.videolan.vlc", "/org/videolan/vlc") player_o = bus.get_object("org.freedesktop.MediaPlayer", "/Player")
interface = dbus.Interface(remote_object, "org.videolan.vlc") tracklist_o = bus.get_object("org.freedesktop.MediaPlayer", "/TrackList")
tracklist = dbus.Interface(tracklist_o, "org.freedesktop.MediaPlayer")
player = dbus.Interface(player_o, "org.freedesktop.MediaPlayer")
try: try:
remote_object.connect_to_signal("ItemChange", itemchange_handler, dbus_interface="org.videolan.vlc") player_o.connect_to_signal("TrackChange", itemchange_handler, dbus_interface="org.freedesktop.MediaPlayer")
except: except:
True True
def AddMRL(widget): def AddTrack(widget):
mrl = e_mrl.get_text() mrl = e_mrl.get_text()
if mrl != None and mrl != "": if mrl != None and mrl != "":
interface.AddMRL(mrl, True) tracklist.AddTrack(mrl, True)
else: else:
mrl = bt_file.get_filename() mrl = bt_file.get_filename()
if mrl != None and mrl != "": if mrl != None and mrl != "":
interface.AddMRL("directory://" + mrl, True) tracklist.AddTrack("directory://" + mrl, True)
def Next(widget): def Next(widget):
interface.Next(reply_handler=(lambda *args: None), error_handler=(lambda *args: None)) player.Next(reply_handler=(lambda *args: None), error_handler=(lambda *args: None))
update(0) update(0)
def Prev(widget): def Prev(widget):
interface.Prev(reply_handler=(lambda *args: None), error_handler=(lambda *args: None)) player.Prev(reply_handler=(lambda *args: None), error_handler=(lambda *args: None))
update(0) update(0)
def Stop(widget): def Stop(widget):
interface.Stop(reply_handler=(lambda *args: None), error_handler=(lambda *args: None)) player.Stop(reply_handler=(lambda *args: None), error_handler=(lambda *args: None))
update(0) update(0)
def update(widget): def update(widget):
itemchange_handler(str(interface.GetPlayingItem())) # itemchange_handler(str(player.GetPlayingItem()))
vol.set_value(interface.VolumeGet()) vol.set_value(player.VolumeGet())
GetPlayStatus(0) GetPlayStatus(0)
def GetPlayStatus(widget): def GetPlayStatus(widget):
global playing global playing
status = str(interface.GetPlayStatus()) status = str(player.GetStatus())
if status == "playing": if status == 0:
img_bt_toggle.set_from_stock("gtk-media-pause", gtk.ICON_SIZE_SMALL_TOOLBAR) img_bt_toggle.set_from_stock("gtk-media-pause", gtk.ICON_SIZE_SMALL_TOOLBAR)
playing = True playing = True
else: else:
...@@ -81,26 +84,25 @@ def GetPlayStatus(widget): ...@@ -81,26 +84,25 @@ def GetPlayStatus(widget):
playing = False playing = False
def Quit(widget): def Quit(widget):
interface.Quit(reply_handler=(lambda *args: None), error_handler=(lambda *args: None)) player.Quit(reply_handler=(lambda *args: None), error_handler=(lambda *args: None))
l_item.set_text("") l_item.set_text("")
def TogglePause(widget): def Pause(widget):
if interface.TogglePause() == True: player.Pause()
img_bt_toggle.set_from_stock(gtk.STOCK_MEDIA_PAUSE, gtk.ICON_SIZE_SMALL_TOOLBAR) # img_bt_toggle.set_from_stock(gtk.STOCK_MEDIA_PAUSE, gtk.ICON_SIZE_SMALL_TOOLBAR)
else: # img_bt_toggle.set_from_stock(gtk.STOCK_MEDIA_PLAY, gtk.ICON_SIZE_SMALL_TOOLBAR)
img_bt_toggle.set_from_stock(gtk.STOCK_MEDIA_PLAY, gtk.ICON_SIZE_SMALL_TOOLBAR)
update(0) update(0)
def volchange(widget, data): def volchange(widget, data):
interface.VolumeSet(vol.get_value_as_int(), reply_handler=(lambda *args: None), error_handler=(lambda *args: None)) player.VolumeSet(vol.get_value_as_int(), reply_handler=(lambda *args: None), error_handler=(lambda *args: None))
def timechange(widget, x=None, y=None): def timechange(widget, x=None, y=None):
interface.PositionSet(time_s.get_value(), reply_handler=(lambda *args: None), error_handler=(lambda *args: None)) player.PositionSet(time_s.get_value(), reply_handler=(lambda *args: None), error_handler=(lambda *args: None))
def timeset(): def timeset():
global playing # global playing
time_s.set_value(interface.PositionGet()) time_s.set_value(player.PositionGet())
return playing # return playing
def expander(widget): def expander(widget):
if exp.get_expanded() == False: if exp.get_expanded() == False:
...@@ -177,8 +179,8 @@ menu.attach_to_widget(eventbox,None) ...@@ -177,8 +179,8 @@ menu.attach_to_widget(eventbox,None)
bt_close.connect('clicked', destroy) bt_close.connect('clicked', destroy)
bt_quit.connect('clicked', Quit) bt_quit.connect('clicked', Quit)
bt_mrl.connect('clicked', AddMRL) bt_mrl.connect('clicked', AddTrack)
bt_toggle.connect('clicked', TogglePause) bt_toggle.connect('clicked', Pause)
bt_next.connect('clicked', Next) bt_next.connect('clicked', Next)
bt_prev.connect('clicked', Prev) bt_prev.connect('clicked', Prev)
bt_stop.connect('clicked', Stop) bt_stop.connect('clicked', Stop)
......
This diff is collapsed.
...@@ -23,12 +23,12 @@ ...@@ -23,12 +23,12 @@
/* DBUS IDENTIFIERS */ /* DBUS IDENTIFIERS */
/* this is also defined in src/libvlc-common.c for one-instance mode */
/* name registered on the session bus */ /* name registered on the session bus */
#define VLC_DBUS_SERVICE "org.videolan.vlc" #define VLC_DBUS_SERVICE "org.freedesktop.MediaPlayer"
#define VLC_DBUS_INTERFACE "org.videolan.vlc" #define VLC_DBUS_INTERFACE "org.freedesktop.MediaPlayer"
#define VLC_DBUS_OBJECT_PATH "/org/videolan/vlc" #define VLC_DBUS_ROOT_PATH "/"
#define VLC_DBUS_PLAYER_PATH "/Player"
#define VLC_DBUS_TRACKLIST_PATH "/TrackList"
/* MACROS */ /* MACROS */
...@@ -52,7 +52,7 @@ ...@@ -52,7 +52,7 @@
return DBUS_HANDLER_RESULT_HANDLED return DBUS_HANDLER_RESULT_HANDLED
#define SIGNAL_INIT( signal ) \ #define SIGNAL_INIT( signal ) \
DBusMessage *p_msg = dbus_message_new_signal( VLC_DBUS_OBJECT_PATH, \ DBusMessage *p_msg = dbus_message_new_signal( VLC_DBUS_PLAYER_PATH, \
VLC_DBUS_INTERFACE, signal ); \ VLC_DBUS_INTERFACE, signal ); \
if( !p_msg ) return DBUS_HANDLER_RESULT_NEED_MEMORY; \ if( !p_msg ) return DBUS_HANDLER_RESULT_NEED_MEMORY; \
...@@ -73,13 +73,12 @@ ...@@ -73,13 +73,12 @@
#define ADD_STRING( s ) DBUS_ADD( DBUS_TYPE_STRING, s ) #define ADD_STRING( s ) DBUS_ADD( DBUS_TYPE_STRING, s )
#define ADD_BOOL( b ) DBUS_ADD( DBUS_TYPE_BOOLEAN, b ) #define ADD_BOOL( b ) DBUS_ADD( DBUS_TYPE_BOOLEAN, b )
#define ADD_UINT32( i ) DBUS_ADD( DBUS_TYPE_UINT32, i ) #define ADD_INT32( i ) DBUS_ADD( DBUS_TYPE_INT32, i )
#define ADD_UINT16( i ) DBUS_ADD( DBUS_TYPE_UINT16, i )
#define ADD_BYTE( b ) DBUS_ADD( DBUS_TYPE_BYTE, b ) #define ADD_BYTE( b ) DBUS_ADD( DBUS_TYPE_BYTE, b )
/* XML data to answer org.freedesktop.DBus.Introspectable.Introspect requests */ /* XML data to answer org.freedesktop.DBus.Introspectable.Introspect requests */
const char* psz_introspection_xml_data = const char* psz_introspection_xml_data_root =
"<!DOCTYPE node PUBLIC \"-//freedesktop//DTD D-BUS Object Introspection 1.0//EN\"\n" "<!DOCTYPE node PUBLIC \"-//freedesktop//DTD D-BUS Object Introspection 1.0//EN\"\n"
"\"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd\">\n" "\"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd\">\n"
"<node>" "<node>"
...@@ -88,21 +87,26 @@ const char* psz_introspection_xml_data = ...@@ -88,21 +87,26 @@ const char* psz_introspection_xml_data =
" <arg name=\"data\" direction=\"out\" type=\"s\"/>\n" " <arg name=\"data\" direction=\"out\" type=\"s\"/>\n"
" </method>\n" " </method>\n"
" </interface>\n" " </interface>\n"
" <interface name=\"org.videolan.vlc\">\n" " <interface name=\"org.freedesktop.MediaPlayer\">\n"
" <method name=\"GetPlayStatus\">\n" " <method name=\"Identity\">\n"
" <arg type=\"s\" direction=\"out\" />\n"
" </method>\n"
" <method name=\"GetPlayingItem\">\n"
" <arg type=\"s\" direction=\"out\" />\n" " <arg type=\"s\" direction=\"out\" />\n"
" </method>\n" " </method>\n"
" <method name=\"TogglePause\">\n" " </interface>\n"
" <arg type=\"b\" direction=\"out\" />\n" "</node>\n"
" </method>\n" ;
" <method name=\"AddMRL\">\n"
" <arg type=\"s\" direction=\"in\" />\n" const char* psz_introspection_xml_data_player =
" <arg type=\"b\" direction=\"in\" />\n" "<!DOCTYPE node PUBLIC \"-//freedesktop//DTD D-BUS Object Introspection 1.0//EN\"\n"
"\"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd\">\n"
"<node>"
" <interface name=\"org.freedesktop.DBus.Introspectable\">\n"
" <method name=\"Introspect\">\n"
" <arg name=\"data\" direction=\"out\" type=\"s\"/>\n"
" </method>\n" " </method>\n"
" <method name=\"Nothing\">\n" " </interface>\n"
" <interface name=\"org.videolan.vlc\">\n"
" <method name=\"GetStatus\">\n"
" <arg type=\"i\" direction=\"out\" />\n"
" </method>\n" " </method>\n"
" <method name=\"Quit\">\n" " <method name=\"Quit\">\n"
" </method>\n" " </method>\n"
...@@ -112,36 +116,78 @@ const char* psz_introspection_xml_data = ...@@ -112,36 +116,78 @@ const char* psz_introspection_xml_data =
" </method>\n" " </method>\n"
" <method name=\"Stop\">\n" " <method name=\"Stop\">\n"
" </method>\n" " </method>\n"
" <method name=\"Play\">\n"
" </method>\n"
" <method name=\"Pause\">\n"
" </method>\n"
" <method name=\"VolumeSet\">\n" " <method name=\"VolumeSet\">\n"
" <arg type=\"q\" direction=\"in\" />\n" " <arg type=\"i\" direction=\"in\" />\n"
" </method>\n" " </method>\n"
" <method name=\"VolumeGet\">\n" " <method name=\"VolumeGet\">\n"
" <arg type=\"q\" direction=\"out\" />\n" " <arg type=\"i\" direction=\"out\" />\n"
" </method>\n" " </method>\n"
" <method name=\"PositionSet\">\n" " <method name=\"PositionSet\">\n"
" <arg type=\"q\" direction=\"in\" />\n" " <arg type=\"i\" direction=\"in\" />\n"
" </method>\n" " </method>\n"
" <method name=\"PositionGet\">\n" " <method name=\"PositionGet\">\n"
" <arg type=\"q\" direction=\"out\" />\n" " <arg type=\"i\" direction=\"out\" />\n"
" </method>\n" " </method>\n"
" <method name=\"PlaylistExport_XSPF\">\n" " </interface>\n"
"</node>\n"
;
const char* psz_introspection_xml_data_tracklist =
"<!DOCTYPE node PUBLIC \"-//freedesktop//DTD D-BUS Object Introspection 1.0//EN\"\n"
"\"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd\">\n"
"<node>"
" <interface name=\"org.freedesktop.DBus.Introspectable\">\n"
" <method name=\"Introspect\">\n"
" <arg name=\"data\" direction=\"out\" type=\"s\"/>\n"
" </method>\n"
" </interface>\n"
" <interface name=\"org.videolan.vlc\">\n"
" <method name=\"AddTrack\">\n"
" <arg type=\"s\" direction=\"in\" />\n" " <arg type=\"s\" direction=\"in\" />\n"
" <arg type=\"q\" direction=\"out\" />\n" " <arg type=\"b\" direction=\"in\" />\n"
" </method>\n"
" <method name=\"DelTrack\">\n"
" <arg type=\"i\" direction=\"in\" />\n"
" </method>\n"
" <method name=\"GetMetadata\">\n"
" <arg type=\"i\" direction=\"in\" />\n"
" <arg type=\"a{sv}\" direction=\"out\" />\n"
" </method>\n"
" <method name=\"GetCurrentTrack\">\n"
" <arg type=\"i\" direction=\"out\" />\n"
" </method>\n"
" <method name=\"GetLength\">\n"
" <arg type=\"i\" direction=\"out\" />\n"
" </method>\n" " </method>\n"
" </interface>\n" " </interface>\n"
"</node>\n" "</node>\n"
; ;
/* Handling of messages received onn VLC_DBUS_OBJECT_PATH */ #define VLC_DBUS_ROOT_PATH "/"
DBUS_METHOD( handle_messages ); /* handler function */ #define VLC_DBUS_PLAYER_PATH "/Player"
#define VLC_DBUS_TRACKLIST_PATH "/TrackList"
/* vtable passed to dbus_connection_register_object_path() */
static DBusObjectPathVTable vlc_dbus_vtable = { /* Handle messages reception */
NULL, /* Called when vtable is unregistered or its connection is freed*/ DBUS_METHOD( handle_root );
handle_messages, /* handler function */ DBUS_METHOD( handle_player );
NULL, DBUS_METHOD( handle_tracklist );
NULL,
NULL, static DBusObjectPathVTable vlc_dbus_root_vtable = {
NULL NULL, handle_root, /* handler function */
NULL, NULL, NULL, NULL
};
static DBusObjectPathVTable vlc_dbus_player_vtable = {
NULL, handle_player, /* handler function */
NULL, NULL, NULL, NULL
};
static DBusObjectPathVTable vlc_dbus_tracklist_vtable = {
NULL, handle_tracklist, /* handler function */
NULL, NULL, NULL, NULL
}; };
...@@ -63,13 +63,8 @@ ...@@ -63,13 +63,8 @@
#endif #endif
#ifdef HAVE_DBUS_3 #ifdef HAVE_DBUS_3
/* used for one-instance mode */
# include <dbus/dbus.h> # include <dbus/dbus.h>
/* this is also defined in modules/control/dbus.h */
/* names registered on the session bus */
#define VLC_DBUS_SERVICE "org.videolan.vlc"
#define VLC_DBUS_INTERFACE "org.videolan.vlc"
#define VLC_DBUS_OBJECT_PATH "/org/videolan/vlc"
#endif #endif
#ifdef HAVE_HAL #ifdef HAVE_HAL
...@@ -632,12 +627,12 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc, char *ppsz_argv[] ) ...@@ -632,12 +627,12 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc, char *ppsz_argv[] )
else else
{ {
/* we request the service org.videolan.vlc */ /* we request the service org.videolan.vlc */
i_dbus_service = dbus_bus_request_name( p_conn, VLC_DBUS_SERVICE, 0, i_dbus_service = dbus_bus_request_name( p_conn, "org.videolan.vlc", 0,
&dbus_error ); &dbus_error );
if( dbus_error_is_set( &dbus_error ) ) if( dbus_error_is_set( &dbus_error ) )
{ {
msg_Err( p_libvlc, "Error requesting %s service: %s\n", msg_Err( p_libvlc, "Error requesting org.videolan.vlc service: "
VLC_DBUS_SERVICE, dbus_error.message ); "%s\n", dbus_error.message );
dbus_error_free( &dbus_error ); dbus_error_free( &dbus_error );
} }
else else
...@@ -646,14 +641,14 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc, char *ppsz_argv[] ) ...@@ -646,14 +641,14 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc, char *ppsz_argv[] )
{ /* the name is already registered by another instance of vlc */ { /* the name is already registered by another instance of vlc */
if( config_GetInt( p_libvlc, "one-instance" ) ) if( config_GetInt( p_libvlc, "one-instance" ) )
{ {
/* check if /org/videolan/vlc exists /* check if a Media Player is available
* if not: D-Bus control is not enabled on the other * if not: D-Bus control is not enabled on the other
* instance and we can't pass MRLs to it */ * instance and we can't pass MRLs to it */
DBusMessage *p_test_msg, *p_test_reply; DBusMessage *p_test_msg, *p_test_reply;
p_test_msg = dbus_message_new_method_call( p_test_msg = dbus_message_new_method_call(
VLC_DBUS_SERVICE, VLC_DBUS_OBJECT_PATH, "org.freedesktop.MediaPlayer", "/",
VLC_DBUS_INTERFACE, "Nothing" ); "org.freedesktop.MediaPlayer", "Identity" );
/* block unti a reply arrives */ /* block until a reply arrives */
p_test_reply = dbus_connection_send_with_reply_and_block( p_test_reply = dbus_connection_send_with_reply_and_block(
p_conn, p_test_msg, -1, &dbus_error ); p_conn, p_test_msg, -1, &dbus_error );
dbus_message_unref( p_test_msg ); dbus_message_unref( p_test_msg );
...@@ -683,8 +678,8 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc, char *ppsz_argv[] ) ...@@ -683,8 +678,8 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc, char *ppsz_argv[] )
ppsz_argv[i_input] ); ppsz_argv[i_input] );
p_dbus_msg = dbus_message_new_method_call( p_dbus_msg = dbus_message_new_method_call(
VLC_DBUS_SERVICE, VLC_DBUS_OBJECT_PATH, "org.freedesktop.MediaPlayer", "/TrackList",
VLC_DBUS_INTERFACE, "AddMRL" ); "org.freedesktop.MediaPlayer", "AddTrack" );
if ( NULL == p_dbus_msg ) if ( NULL == p_dbus_msg )
{ {
...@@ -748,9 +743,8 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc, char *ppsz_argv[] ) ...@@ -748,9 +743,8 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc, char *ppsz_argv[] )
} /* we're not in one-instance mode */ } /* we're not in one-instance mode */
else else
{ {
msg_Dbg( p_libvlc, msg_Dbg( p_libvlc, "org.videolan.vlc is already registered "
"%s is already registered on the session bus\n", "on the session bus\n" );
VLC_DBUS_SERVICE );
} }
} /* the named is owned by something else */ } /* the named is owned by something else */
else else
...@@ -762,8 +756,8 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc, char *ppsz_argv[] ) ...@@ -762,8 +756,8 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc, char *ppsz_argv[] )
msg_Err( p_libvlc, "Out of memory" ); msg_Err( p_libvlc, "Out of memory" );
} }
msg_Dbg( p_libvlc, msg_Dbg( p_libvlc,
"We are the primary owner of %s on the session bus", "We are the primary owner of org.videolan.vlc on the "
VLC_DBUS_SERVICE ); " session bus" );
} }
} /* no error when requesting the name on the bus */ } /* no error when requesting the name on the bus */
/* we unreference the connection when we've finished with it */ /* we unreference the connection when we've finished with it */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment