[vlc-commits] dbus: Update the TrackList interface implementation

Mirsal Ennaime git at videolan.org
Thu May 19 16:18:15 CEST 2011


vlc | branch: master | Mirsal Ennaime <mirsal at mirsal.fr> | Thu May 19 16:16:47 2011 +0200| [54ece28f9d1a3ff81b7393d40c375d2ee6c9b1e7] | committer: Mirsal Ennaime

dbus: Update the TrackList interface implementation

 * Remove legacy methods
 * Implement the GoTo method

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

 modules/control/dbus/dbus_tracklist.c |  115 +++++++++++----------------------
 1 files changed, 38 insertions(+), 77 deletions(-)

diff --git a/modules/control/dbus/dbus_tracklist.c b/modules/control/dbus/dbus_tracklist.c
index e4454eb..8bf66dd 100644
--- a/modules/control/dbus/dbus_tracklist.c
+++ b/modules/control/dbus/dbus_tracklist.c
@@ -1,9 +1,9 @@
 /*****************************************************************************
- * dbus-tracklist.c : dbus control module (mpris v1.0) - /TrackList object
+ * dbus-tracklist.c : dbus control module (mpris v2.1) - TrackList interface
  *****************************************************************************
  * Copyright © 2006-2011 Rafaël Carré
  * Copyright © 2007-2011 Mirsal Ennaime
- * Copyright © 2009-2010 The VideoLAN team
+ * Copyright © 2009-2011 The VideoLAN team
  * $Id$
  *
  * Authors:    Mirsal Ennaime <mirsal at mirsal fr>
@@ -68,21 +68,6 @@ DBUS_METHOD( AddTrack )
     REPLY_SEND;
 }
 
-DBUS_METHOD( GetCurrentTrack )
-{
-    REPLY_INIT;
-    OUT_ARGUMENTS;
-
-    playlist_t *p_playlist = PL;
-
-    PL_LOCK;
-    dbus_int32_t i_position = PL->i_current_index;
-    PL_UNLOCK;
-
-    ADD_INT32( &i_position );
-    REPLY_SEND;
-}
-
 DBUS_METHOD( GetTracksMetadata )
 {
     REPLY_INIT;
@@ -95,7 +80,6 @@ DBUS_METHOD( GetTracksMetadata )
     input_item_t *p_input = NULL;
 
     DBusMessageIter in_args, track_ids, meta;
-
     dbus_message_iter_init( p_from, &in_args );
 
     if( DBUS_TYPE_ARRAY != dbus_message_iter_get_arg_type( &in_args ) )
@@ -139,34 +123,19 @@ DBUS_METHOD( GetTracksMetadata )
     REPLY_SEND;
 }
 
-DBUS_METHOD( GetLength )
+DBUS_METHOD( GoTo )
 {
     REPLY_INIT;
-    OUT_ARGUMENTS;
-    playlist_t *p_playlist = PL;
-
-    PL_LOCK;
-    dbus_int32_t i_elements = PL->current.i_size;
-    PL_UNLOCK;
-
-    ADD_INT32( &i_elements );
-    REPLY_SEND;
-}
 
-DBUS_METHOD( RemoveTrack )
-{
-    REPLY_INIT;
+    int i_track_id = -1;
+    const char *psz_track_id = NULL;
+    playlist_t *p_playlist = PL;
 
     DBusError error;
     dbus_error_init( &error );
 
-    int   i_id = -1, i;
-    char *psz_id = NULL;
-    playlist_t *p_playlist = PL;
-    input_item_t *p_input  = NULL;
-
     dbus_message_get_args( p_from, &error,
-            DBUS_TYPE_OBJECT_PATH, &psz_id,
+            DBUS_TYPE_OBJECT_PATH, &psz_track_id,
             DBUS_TYPE_INVALID );
 
     if( dbus_error_is_set( &error ) )
@@ -177,21 +146,21 @@ DBUS_METHOD( RemoveTrack )
         return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
     }
 
-    if( 1 != sscanf( psz_id, MPRIS_TRACKID_FORMAT, &i_id ) )
+    if( 1 != sscanf( psz_track_id, MPRIS_TRACKID_FORMAT, &i_track_id ) )
     {
-        msg_Err( (vlc_object_t*) p_this, "Invalid track id: %s", psz_id );
+        msg_Err( (vlc_object_t*) p_this, "Invalid track id %s", psz_track_id );
         return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
     }
 
     PL_LOCK;
 
-    for( i = 0; i < playlist_CurrentSize( p_playlist ); i++ )
+    for( int i = 0; i < playlist_CurrentSize( p_playlist ); i++ )
     {
-        p_input = p_playlist->current.p_elems[i]->p_input;
-
-        if( i_id == p_input->i_id )
+        if( i_track_id == p_playlist->current.p_elems[i]->p_input->i_id )
         {
-            playlist_DeleteFromInput( p_playlist, p_input, true );
+            playlist_Control( p_playlist, PLAYLIST_VIEWPLAY, true,
+                              p_playlist->current.p_elems[i]->p_parent,
+                              p_playlist->current.p_elems[i] );
             break;
         }
     }
@@ -200,17 +169,20 @@ DBUS_METHOD( RemoveTrack )
     REPLY_SEND;
 }
 
-DBUS_METHOD( SetLoop )
+DBUS_METHOD( RemoveTrack )
 {
     REPLY_INIT;
-    OUT_ARGUMENTS;
 
     DBusError error;
-    dbus_bool_t b_loop;
-
     dbus_error_init( &error );
+
+    int   i_id = -1, i;
+    char *psz_id = NULL;
+    playlist_t *p_playlist = PL;
+    input_item_t *p_input  = NULL;
+
     dbus_message_get_args( p_from, &error,
-            DBUS_TYPE_BOOLEAN, &b_loop,
+            DBUS_TYPE_OBJECT_PATH, &psz_id,
             DBUS_TYPE_INVALID );
 
     if( dbus_error_is_set( &error ) )
@@ -221,34 +193,26 @@ DBUS_METHOD( SetLoop )
         return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
     }
 
-    var_SetBool( PL, "loop", ( b_loop == TRUE ) );
-
-    REPLY_SEND;
-}
-
-DBUS_METHOD( SetRandom )
-{
-    REPLY_INIT;
-    OUT_ARGUMENTS;
-
-    DBusError error;
-    dbus_bool_t b_random;
-
-    dbus_error_init( &error );
-    dbus_message_get_args( p_from, &error,
-            DBUS_TYPE_BOOLEAN, &b_random,
-            DBUS_TYPE_INVALID );
-
-    if( dbus_error_is_set( &error ) )
+    if( 1 != sscanf( psz_id, MPRIS_TRACKID_FORMAT, &i_id ) )
     {
-        msg_Err( (vlc_object_t*) p_this, "D-Bus message reading : %s",
-                error.message );
-        dbus_error_free( &error );
+        msg_Err( (vlc_object_t*) p_this, "Invalid track id: %s", psz_id );
         return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
     }
 
-    var_SetBool( PL, "random", ( b_random == TRUE ) );
+    PL_LOCK;
 
+    for( i = 0; i < playlist_CurrentSize( p_playlist ); i++ )
+    {
+        p_input = p_playlist->current.p_elems[i]->p_input;
+
+        if( i_id == p_input->i_id )
+        {
+            playlist_DeleteFromInput( p_playlist, p_input, true );
+            break;
+        }
+    }
+
+    PL_UNLOCK;
     REPLY_SEND;
 }
 
@@ -288,12 +252,9 @@ handle_tracklist ( DBusConnection *p_conn, DBusMessage *p_from, void *p_this )
     /* here D-Bus method names are associated to an handler */
 
     METHOD_FUNC( DBUS_MPRIS_TRACKLIST_INTERFACE, "GetTracksMetadata", GetTracksMetadata );
-    METHOD_FUNC( DBUS_MPRIS_TRACKLIST_INTERFACE, "GetCurrentTrack", GetCurrentTrack );
-    METHOD_FUNC( DBUS_MPRIS_TRACKLIST_INTERFACE, "GetLength",       GetLength );
     METHOD_FUNC( DBUS_MPRIS_TRACKLIST_INTERFACE, "AddTrack",        AddTrack );
     METHOD_FUNC( DBUS_MPRIS_TRACKLIST_INTERFACE, "RemoveTrack",     RemoveTrack );
-    METHOD_FUNC( DBUS_MPRIS_TRACKLIST_INTERFACE, "SetLoop",         SetLoop );
-    METHOD_FUNC( DBUS_MPRIS_TRACKLIST_INTERFACE, "SetRandom",       SetRandom );
+    METHOD_FUNC( DBUS_MPRIS_TRACKLIST_INTERFACE, "GoTo",            GoTo );
 
     return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
 }



More information about the vlc-commits mailing list