Commit 393d7e42 authored by Mirsal Ennaime's avatar Mirsal Ennaime

dbus: Implement the mpris2 tracklist interface properties

 * Add a dispatcher method for tracklist properties
 * Implement Tracks and CanEditTracks
parent 04d158ef
......@@ -216,6 +216,79 @@ DBUS_METHOD( RemoveTrack )
REPLY_SEND;
}
DBUS_METHOD( Tracks )
{ /* Tracks property */
VLC_UNUSED( p_this );
REPLY_INIT;
OUT_ARGUMENTS;
DBusMessageIter tracks, v;
char *psz_track_id = NULL;
playlist_t *p_playlist = PL;
input_item_t *p_input = NULL;
dbus_message_iter_open_container( &args, DBUS_TYPE_VARIANT, "ao", &v );
dbus_message_iter_open_container( &v, DBUS_TYPE_ARRAY, "o", &tracks );
PL_LOCK;
for( int i = 0; i < playlist_CurrentSize( p_playlist ); i++ )
{
p_input = p_playlist->current.p_elems[i]->p_input;
if( ( -1 == asprintf( &psz_track_id,
MPRIS_TRACKID_FORMAT,
p_input->i_id ) ) ||
!dbus_message_iter_append_basic( &tracks,
DBUS_TYPE_OBJECT_PATH,
&psz_track_id ) )
{
PL_UNLOCK;
dbus_message_iter_abandon_container( &v, &tracks );
dbus_message_iter_abandon_container( &args, &v );
return DBUS_HANDLER_RESULT_NEED_MEMORY;
}
free( psz_track_id );
}
PL_UNLOCK;
if( !dbus_message_iter_close_container( &v, &tracks ) ||
!dbus_message_iter_close_container( &args, &v ) )
return DBUS_HANDLER_RESULT_NEED_MEMORY;
REPLY_SEND;
}
DBUS_METHOD( CanEditTracks )
{ /* CanEditTracks property */
VLC_UNUSED( p_this );
REPLY_INIT;
OUT_ARGUMENTS;
DBusMessageIter v;
const dbus_bool_t b_ret = TRUE;
if( !dbus_message_iter_open_container( &args, DBUS_TYPE_VARIANT, "b", &v ) )
return DBUS_HANDLER_RESULT_NEED_MEMORY;
if( !dbus_message_iter_append_basic( &v, DBUS_TYPE_BOOLEAN, &b_ret ) )
{
dbus_message_iter_abandon_container( &args, &v );
return DBUS_HANDLER_RESULT_NEED_MEMORY;
}
if( !dbus_message_iter_close_container( &args, &v ) )
{
dbus_message_iter_abandon_container( &args, &v );
return DBUS_HANDLER_RESULT_NEED_MEMORY;
}
REPLY_SEND;
}
/******************************************************************************
* TrackListChange: tracklist order / length change signal
*****************************************************************************/
......@@ -236,6 +309,48 @@ DBUS_SIGNAL( TrackListChangeSignal )
SIGNAL_SEND;
}
#define PROPERTY_MAPPING_BEGIN if( 0 ) {}
#define PROPERTY_FUNC( interface, property, function ) \
else if( !strcmp( psz_interface_name, interface ) && \
!strcmp( psz_property_name, property ) ) \
return function( p_conn, p_from, p_this );
#define PROPERTY_MAPPING_END return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
DBUS_METHOD( GetProperty )
{
DBusError error;
char *psz_interface_name = NULL;
char *psz_property_name = NULL;
dbus_error_init( &error );
dbus_message_get_args( p_from, &error,
DBUS_TYPE_STRING, &psz_interface_name,
DBUS_TYPE_STRING, &psz_property_name,
DBUS_TYPE_INVALID );
if( dbus_error_is_set( &error ) )
{
msg_Err( (vlc_object_t*) p_this, "D-Bus message reading : %s",
error.message );
dbus_error_free( &error );
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}
msg_Dbg( (vlc_object_t*) p_this, "Getting property %s",
psz_property_name );
PROPERTY_MAPPING_BEGIN
PROPERTY_FUNC( DBUS_MPRIS_TRACKLIST_INTERFACE, "Tracks", Tracks )
PROPERTY_FUNC( DBUS_MPRIS_TRACKLIST_INTERFACE, "CanEditTracks",
CanEditTracks )
PROPERTY_MAPPING_END
}
#undef PROPERTY_MAPPING_BEGIN
#undef PROPERTY_GET_FUNC
#undef PROPERTY_MAPPING_END
#define METHOD_FUNC( interface, method, function ) \
else if( dbus_message_is_method_call( p_from, interface, method ) )\
return function( p_conn, p_from, p_this )
......@@ -245,16 +360,15 @@ handle_tracklist ( DBusConnection *p_conn, DBusMessage *p_from, void *p_this )
{
if(0);
/* METHOD_FUNC( DBUS_INTERFACE_PROPERTIES, "Get", GetProperty );
METHOD_FUNC( DBUS_INTERFACE_PROPERTIES, "Set", SetProperty );
METHOD_FUNC( DBUS_INTERFACE_PROPERTIES, "GetAll", GetAllProperties ); */
METHOD_FUNC( DBUS_INTERFACE_PROPERTIES, "Get", GetProperty );
/* here D-Bus method names are associated to an handler */
METHOD_FUNC( DBUS_MPRIS_TRACKLIST_INTERFACE, "GetTracksMetadata", GetTracksMetadata );
METHOD_FUNC( DBUS_MPRIS_TRACKLIST_INTERFACE, "AddTrack", AddTrack );
METHOD_FUNC( DBUS_MPRIS_TRACKLIST_INTERFACE, "RemoveTrack", RemoveTrack );
METHOD_FUNC( DBUS_MPRIS_TRACKLIST_INTERFACE, "GoTo", GoTo );
METHOD_FUNC( DBUS_MPRIS_TRACKLIST_INTERFACE, "GoTo", GoTo );
METHOD_FUNC( DBUS_MPRIS_TRACKLIST_INTERFACE, "AddTrack", AddTrack );
METHOD_FUNC( DBUS_MPRIS_TRACKLIST_INTERFACE, "RemoveTrack", RemoveTrack );
METHOD_FUNC( DBUS_MPRIS_TRACKLIST_INTERFACE, "GetTracksMetadata",
GetTracksMetadata );
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}
......
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