[vlc-devel] [PATCH 5/6] Add Properties.GetAll support to all D-Bus interfaces

Alex Merry dev at randomguy3.me.uk
Tue Jan 29 01:55:22 CET 2013


---
 modules/control/dbus/dbus_introspect.h |  6 ++++
 modules/control/dbus/dbus_player.c     | 59 +++++++++++++++++++++++++++++++++-
 modules/control/dbus/dbus_root.c       | 13 +++++---
 modules/control/dbus/dbus_tracklist.c  | 47 +++++++++++++++++++++++++++
 4 files changed, 120 insertions(+), 5 deletions(-)

diff --git a/modules/control/dbus/dbus_introspect.h b/modules/control/dbus/dbus_introspect.h
index 31f4c9b..0b69167 100644
--- a/modules/control/dbus/dbus_introspect.h
+++ b/modules/control/dbus/dbus_introspect.h
@@ -4,10 +4,12 @@
  * Copyright © 2006-2011 Rafaël Carré
  * Copyright © 2007-2011 Mirsal Ennaime
  * Copyright © 2009-2011 The VideoLAN team
+ * Copyright © 2013      Alex Merry
  * $Id$
  *
  * Authors:    Mirsal Ennaime <mirsal at mirsal fr>
  *             Rafaël Carré <funman at videolanorg>
+ *             Alex Merry <dev at randomguy3 me uk>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -50,6 +52,10 @@ static const char* psz_introspection_xml =
 "      <arg direction=\"in\" type=\"s\"/>\n"
 "      <arg direction=\"in\" type=\"v\"/>\n"
 "    </method>\n"
+"    <method name=\"GetAll\">\n"
+"      <arg direction=\"in\" type=\"s\"/>\n"
+"      <arg direction=\"out\" type=\"a{sv}\"/>\n"
+"    </method>\n"
 "    <signal name=\"PropertiesChanged\">\n"
 "      <arg type=\"s\"/>\n"
 "      <arg type=\"a{sv}\"/>\n"
diff --git a/modules/control/dbus/dbus_player.c b/modules/control/dbus/dbus_player.c
index 411e449..791d464 100644
--- a/modules/control/dbus/dbus_player.c
+++ b/modules/control/dbus/dbus_player.c
@@ -670,6 +670,63 @@ DBUS_METHOD( SetProperty )
 #undef PROPERTY_SET_FUNC
 #undef PROPERTY_MAPPING_END
 
+#define ADD_PROPERTY( prop, signature ) \
+    if( VLC_SUCCESS != AddProperty( (intf_thread_t*) p_this, \
+                &dict, #prop, signature, Marshal##prop ) ) { \
+        dbus_message_iter_abandon_container( &args, &dict ); \
+        return VLC_ENOMEM; \
+    }
+
+DBUS_METHOD( GetAllProperties )
+{
+    REPLY_INIT;
+    OUT_ARGUMENTS;
+
+    DBusError error;
+    DBusMessageIter dict;
+
+    char *const psz_interface_name = NULL;
+
+    dbus_error_init( &error );
+    dbus_message_get_args( p_from, &error,
+            DBUS_TYPE_STRING, &psz_interface_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 All properties" );
+
+    if( !dbus_message_iter_open_container( &args, DBUS_TYPE_ARRAY, "{sv}", &dict ) )
+        return DBUS_HANDLER_RESULT_NEED_MEMORY;
+
+    ADD_PROPERTY ( Metadata,       "a{sv}" );
+    ADD_PROPERTY ( Position,       "x"     );
+    ADD_PROPERTY ( PlaybackStatus, "s"     );
+    ADD_PROPERTY ( LoopStatus,     "s"     );
+    ADD_PROPERTY ( Shuffle,        "b"     );
+    ADD_PROPERTY ( Volume,         "d"     );
+    ADD_PROPERTY ( Rate,           "d"     );
+    ADD_PROPERTY ( MinimumRate,    "d"     );
+    ADD_PROPERTY ( MaximumRate,    "d"     );
+    ADD_PROPERTY ( CanControl,     "b"     );
+    ADD_PROPERTY ( CanPlay,        "b"     );
+    ADD_PROPERTY ( CanPause,       "b"     );
+    ADD_PROPERTY ( CanSeek,        "b"     );
+
+    if( !dbus_message_iter_close_container( &args, &dict ))
+        return DBUS_HANDLER_RESULT_NEED_MEMORY;
+
+    REPLY_SEND;
+}
+
+#undef ADD_PROPERTY
+
 #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 )
@@ -680,7 +737,7 @@ handle_player ( 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,   "GetAll",     GetAllProperties );
 
     /* here D-Bus method names are associated to an handler */
 
diff --git a/modules/control/dbus/dbus_root.c b/modules/control/dbus/dbus_root.c
index 3bfa291..e74a69f 100644
--- a/modules/control/dbus/dbus_root.c
+++ b/modules/control/dbus/dbus_root.c
@@ -370,8 +370,10 @@ DBUS_METHOD( SetProperty )
 
 #define ADD_PROPERTY( prop, signature ) \
     if( VLC_SUCCESS != AddProperty( (intf_thread_t*) p_this, \
-                &dict, #prop, signature, Marshal##prop ) ) \
-        return VLC_ENOMEM;
+                &dict, #prop, signature, Marshal##prop ) ) { \
+        dbus_message_iter_abandon_container( &args, &dict ); \
+        return VLC_ENOMEM; \
+    }
 
 DBUS_METHOD( GetAllProperties )
 {
@@ -398,7 +400,8 @@ DBUS_METHOD( GetAllProperties )
 
     msg_Dbg( (vlc_object_t*) p_this, "Getting All properties" );
 
-    dbus_message_iter_open_container( &args, DBUS_TYPE_ARRAY, "{sv}", &dict );
+    if( !dbus_message_iter_open_container( &args, DBUS_TYPE_ARRAY, "{sv}", &dict ) )
+        return DBUS_HANDLER_RESULT_NEED_MEMORY;
 
     ADD_PROPERTY( Identity,            "s"  );
     ADD_PROPERTY( DesktopEntry,        "s"  );
@@ -410,7 +413,9 @@ DBUS_METHOD( GetAllProperties )
     ADD_PROPERTY( Fullscreen,          "b"  );
     ADD_PROPERTY( CanRaise,            "b"  );
 
-    dbus_message_iter_close_container( &args, &dict );
+    if( !dbus_message_iter_close_container( &args, &dict ))
+        return DBUS_HANDLER_RESULT_NEED_MEMORY;
+
     REPLY_SEND;
 }
 
diff --git a/modules/control/dbus/dbus_tracklist.c b/modules/control/dbus/dbus_tracklist.c
index 58df41f..8c17a51 100644
--- a/modules/control/dbus/dbus_tracklist.c
+++ b/modules/control/dbus/dbus_tracklist.c
@@ -403,6 +403,52 @@ DBUS_METHOD( GetProperty )
 #undef PROPERTY_SET_FUNC
 #undef PROPERTY_MAPPING_END
 
+#define ADD_PROPERTY( prop, signature ) \
+    if( VLC_SUCCESS != AddProperty( (intf_thread_t*) p_this, \
+                &dict, #prop, signature, Marshal##prop ) ) { \
+        dbus_message_iter_abandon_container( &args, &dict ); \
+        return VLC_ENOMEM; \
+    }
+
+DBUS_METHOD( GetAllProperties )
+{
+    REPLY_INIT;
+    OUT_ARGUMENTS;
+
+    DBusError error;
+    DBusMessageIter dict;
+
+    char *const psz_interface_name = NULL;
+
+    dbus_error_init( &error );
+    dbus_message_get_args( p_from, &error,
+            DBUS_TYPE_STRING, &psz_interface_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 All properties" );
+
+    if( !dbus_message_iter_open_container( &args, DBUS_TYPE_ARRAY, "{sv}", &dict ) )
+        return DBUS_HANDLER_RESULT_NEED_MEMORY;
+
+    ADD_PROPERTY ( Tracks,        "ao" )
+    ADD_PROPERTY ( CanEditTracks, "b"  )
+
+    if( !dbus_message_iter_close_container( &args, &dict ))
+        return DBUS_HANDLER_RESULT_NEED_MEMORY;
+
+    REPLY_SEND;
+}
+
+#undef ADD_PROPERTY
+
 #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 )
@@ -413,6 +459,7 @@ 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, "GetAll", GetAllProperties );
 
     /* here D-Bus method names are associated to an handler */
 
-- 
1.8.1.1




More information about the vlc-devel mailing list