[vlc-commits] dbus: Implement the TrackList interface's PropertiesChanged signal

Mirsal Ennaime git at videolan.org
Sat Jun 4 20:39:01 CEST 2011


vlc | branch: master | Mirsal Ennaime <mirsal at mirsal.fr> | Tue May 31 19:30:38 2011 +0200| [ac0921949382de5936f5b4f139ff6f967156e9c9] | committer: Mirsal Ennaime

dbus: Implement the TrackList interface's PropertiesChanged signal

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

 modules/control/dbus/dbus.c           |   14 ++++++--
 modules/control/dbus/dbus_tracklist.c |   56 ++++++++++++++++++++++++++++++++-
 modules/control/dbus/dbus_tracklist.h |    1 +
 3 files changed, 67 insertions(+), 4 deletions(-)

diff --git a/modules/control/dbus/dbus.c b/modules/control/dbus/dbus.c
index 88cf956..d1ce578 100644
--- a/modules/control/dbus/dbus.c
+++ b/modules/control/dbus/dbus.c
@@ -545,8 +545,9 @@ static void ProcessEvents( intf_thread_t *p_intf,
     playlist_t *p_playlist = p_intf->p_sys->p_playlist;
     bool        b_can_play = p_intf->p_sys->b_can_play;
 
-    vlc_dictionary_t player_properties;
-    vlc_dictionary_init( &player_properties, 0 );
+    vlc_dictionary_t player_properties, tracklist_properties;
+    vlc_dictionary_init( &player_properties,    0 );
+    vlc_dictionary_init( &tracklist_properties, 0 );
 
     for( int i = 0; i < i_events; i++ )
     {
@@ -562,11 +563,14 @@ static void ProcessEvents( intf_thread_t *p_intf,
             PL_LOCK;
             b_can_play = playlist_CurrentSize( p_playlist ) > 0;
             PL_UNLOCK;
+
             if( b_can_play != p_intf->p_sys->b_can_play )
             {
                 p_intf->p_sys->b_can_play = b_can_play;
                 vlc_dictionary_insert( &player_properties, "CanPlay", NULL );
             }
+
+            vlc_dictionary_insert( &tracklist_properties, "Tracks", NULL );
             break;
         case SIGNAL_VOLUME_MUTED:
         case SIGNAL_VOLUME_CHANGE:
@@ -630,7 +634,11 @@ static void ProcessEvents( intf_thread_t *p_intf,
     if( vlc_dictionary_keys_count( &player_properties ) )
         PlayerPropertiesChangedEmit( p_intf, &player_properties );
 
-    vlc_dictionary_clear( &player_properties, NULL, NULL );
+    if( vlc_dictionary_keys_count( &tracklist_properties ) )
+        TrackListPropertiesChangedEmit( p_intf, &player_properties );
+
+    vlc_dictionary_clear( &player_properties,    NULL, NULL );
+    vlc_dictionary_clear( &tracklist_properties, NULL, NULL );
 }
 
 /**
diff --git a/modules/control/dbus/dbus_tracklist.c b/modules/control/dbus/dbus_tracklist.c
index cf36250..ee00421 100644
--- a/modules/control/dbus/dbus_tracklist.c
+++ b/modules/control/dbus/dbus_tracklist.c
@@ -229,7 +229,7 @@ DBUS_METHOD( Tracks )
     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 );
+    dbus_message_iter_open_container( &v,    DBUS_TYPE_ARRAY, "o", &tracks );
 
     PL_LOCK;
 
@@ -405,3 +405,57 @@ int TrackListChangeEmit( intf_thread_t *p_intf, int signal, int i_node )
 }
 
 #undef METHOD_FUNC
+
+/**
+ * PropertiesChangedSignal: synthetizes and sends the
+ * org.freedesktop.DBus.Properties.PropertiesChanged signal
+ */
+static DBusHandlerResult
+PropertiesChangedSignal( intf_thread_t    *p_intf,
+                         vlc_dictionary_t *p_changed_properties )
+{
+    DBusConnection  *p_conn = p_intf->p_sys->p_conn;
+    DBusMessageIter changed_properties, invalidated_properties, entry, variant;
+    const char *psz_interface_name = DBUS_MPRIS_TRACKLIST_INTERFACE;
+    char **ppsz_properties = NULL;
+    int i_properties = 0;
+
+    SIGNAL_INIT( DBUS_INTERFACE_PROPERTIES,
+                 DBUS_MPRIS_OBJECT_PATH,
+                 "PropertiesChanged" );
+
+    OUT_ARGUMENTS;
+    ADD_STRING( &psz_interface_name );
+    dbus_message_iter_open_container( &args, DBUS_TYPE_ARRAY, "{sv}",
+                                      &changed_properties );
+
+    dbus_message_iter_close_container( &args, &changed_properties );
+
+    dbus_message_iter_open_container( &args, DBUS_TYPE_ARRAY, "s",
+                                      &invalidated_properties );
+
+    i_properties    = vlc_dictionary_keys_count( p_changed_properties );
+    ppsz_properties = vlc_dictionary_all_keys( p_changed_properties );
+
+    for( int i = 0; i < i_properties; i++ )
+        if( !strcmp( ppsz_properties[i], "Tracks" ) )
+            dbus_message_iter_append_basic( &entry, DBUS_TYPE_STRING,
+                                            &ppsz_properties[i] );
+
+    dbus_message_iter_close_container( &args, &invalidated_properties );
+    SIGNAL_SEND;
+}
+
+/**
+ * TrackListPropertiesChangedEmit: Emits the
+ * org.freedesktop.DBus.Properties.PropertiesChanged signal
+ */
+int TrackListPropertiesChangedEmit( intf_thread_t    * p_intf,
+                                    vlc_dictionary_t * p_changed_properties )
+{
+    if( p_intf->p_sys->b_dead )
+        return VLC_SUCCESS;
+
+    PropertiesChangedSignal( p_intf, p_changed_properties );
+    return VLC_SUCCESS;
+}
diff --git a/modules/control/dbus/dbus_tracklist.h b/modules/control/dbus/dbus_tracklist.h
index c6cb599..ec6d945 100644
--- a/modules/control/dbus/dbus_tracklist.h
+++ b/modules/control/dbus/dbus_tracklist.h
@@ -45,5 +45,6 @@ static const DBusObjectPathVTable dbus_mpris_tracklist_vtable = {
 };
 
 int TrackListChangeEmit( intf_thread_t *, int, int );
+int TrackListPropertiesChangedEmit( intf_thread_t *, vlc_dictionary_t * );
 
 #endif //dbus_tracklist.h



More information about the vlc-commits mailing list