[vlc-commits] dbus: Separate out property marshalling code in D-Bus interfaces
Alex Merry
git at videolan.org
Tue Jan 29 16:35:59 CET 2013
vlc | branch: master | Alex Merry <dev at randomguy3.me.uk> | Tue Jan 29 00:55:20 2013 +0000| [3aa9a4adb055b838b4fdda228a69c2d35b5c1eb5] | committer: Mirsal Ennaime
dbus: Separate out property marshalling code in D-Bus interfaces
Pull out code to marshal the various properties into separate functions
(and make sure the return type of those functions is int). This is in
preparation for adding org.freedesktop.DBus.Properties.GetAll support.
Signed-off-by: Mirsal Ennaime <mirsal at videolan.org>
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=3aa9a4adb055b838b4fdda228a69c2d35b5c1eb5
---
modules/control/dbus/dbus_player.c | 87 +++++++++++++++++++++++----------
modules/control/dbus/dbus_tracklist.c | 68 ++++++++++++++++++--------
2 files changed, 108 insertions(+), 47 deletions(-)
diff --git a/modules/control/dbus/dbus_player.c b/modules/control/dbus/dbus_player.c
index 60c3612..d92431d 100644
--- a/modules/control/dbus/dbus_player.c
+++ b/modules/control/dbus/dbus_player.c
@@ -41,17 +41,12 @@
static int MarshalLoopStatus ( intf_thread_t *, DBusMessageIter * );
-DBUS_METHOD( Position )
-{ /* returns position in microseconds */
- REPLY_INIT;
- OUT_ARGUMENTS;
- DBusMessageIter v;
+static int
+MarshalPosition( intf_thread_t *p_intf, DBusMessageIter *container )
+{
dbus_int64_t i_pos;
-
- if( !dbus_message_iter_open_container( &args, DBUS_TYPE_VARIANT, "x", &v ) )
- return DBUS_HANDLER_RESULT_NEED_MEMORY;
-
- input_thread_t *p_input = playlist_CurrentInput( PL );
+ input_thread_t *p_input;
+ p_input = playlist_CurrentInput( p_intf->p_sys->p_playlist );
if( !p_input )
i_pos = 0;
@@ -62,9 +57,23 @@ DBUS_METHOD( Position )
vlc_object_release( p_input );
}
- if( !dbus_message_iter_append_basic( &v, DBUS_TYPE_INT64, &i_pos ) )
+ if( !dbus_message_iter_append_basic( container, DBUS_TYPE_INT64, &i_pos ) )
+ return VLC_ENOMEM;
+
+ return VLC_SUCCESS;
+}
+
+DBUS_METHOD( Position )
+{ /* returns position in microseconds */
+ REPLY_INIT;
+ OUT_ARGUMENTS;
+ DBusMessageIter v;
+
+ if( !dbus_message_iter_open_container( &args, DBUS_TYPE_VARIANT, "x", &v ) )
return DBUS_HANDLER_RESULT_NEED_MEMORY;
+ MarshalPosition( p_this, &v );
+
if( !dbus_message_iter_close_container( &args, &v ) )
return DBUS_HANDLER_RESULT_NEED_MEMORY;
@@ -378,23 +387,31 @@ DBUS_METHOD( CanPause )
REPLY_SEND;
}
-DBUS_METHOD( CanControl )
+static int
+MarshalCanControl( intf_thread_t *p_intf, DBusMessageIter *container )
{
- VLC_UNUSED( p_this );
+ VLC_UNUSED( p_intf );
+ dbus_bool_t b_can_control = TRUE;
+
+ if( !dbus_message_iter_append_basic( container, DBUS_TYPE_BOOLEAN,
+ &b_can_control ) )
+ return VLC_ENOMEM;
+ return VLC_SUCCESS;
+}
+
+DBUS_METHOD( CanControl )
+{
REPLY_INIT;
OUT_ARGUMENTS;
DBusMessageIter v;
- dbus_bool_t b_can_control = 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_can_control ) )
- return DBUS_HANDLER_RESULT_NEED_MEMORY;
+ MarshalCanControl( p_this, &v );
if( !dbus_message_iter_close_container( &args, &v ) )
return DBUS_HANDLER_RESULT_NEED_MEMORY;
@@ -594,21 +611,29 @@ DBUS_METHOD( RateSet )
REPLY_SEND;
}
-DBUS_METHOD( MinimumRate )
+static int
+MarshalMinimumRate( intf_thread_t *p_intf, DBusMessageIter *container )
{
- VLC_UNUSED( p_this );
+ VLC_UNUSED( p_intf );
+ double d_min_rate = (double) INPUT_RATE_MIN / INPUT_RATE_DEFAULT;
+
+ if( !dbus_message_iter_append_basic( container, DBUS_TYPE_DOUBLE, &d_min_rate ) )
+ return VLC_ENOMEM;
+
+ return VLC_SUCCESS;
+}
+DBUS_METHOD( MinimumRate )
+{
REPLY_INIT;
OUT_ARGUMENTS;
DBusMessageIter v;
- double d_min_rate = (double) INPUT_RATE_MIN / INPUT_RATE_DEFAULT;
if( !dbus_message_iter_open_container( &args, DBUS_TYPE_VARIANT, "d", &v ) )
return DBUS_HANDLER_RESULT_NEED_MEMORY;
- if( !dbus_message_iter_append_basic( &v, DBUS_TYPE_DOUBLE, &d_min_rate ) )
- return DBUS_HANDLER_RESULT_NEED_MEMORY;
+ MarshalMinimumRate( p_this, &v );
if( !dbus_message_iter_close_container( &args, &v ) )
return DBUS_HANDLER_RESULT_NEED_MEMORY;
@@ -616,21 +641,29 @@ DBUS_METHOD( MinimumRate )
REPLY_SEND;
}
-DBUS_METHOD( MaximumRate )
+static int
+MarshalMaximumRate( intf_thread_t *p_intf, DBusMessageIter *container )
{
- VLC_UNUSED( p_this );
+ VLC_UNUSED( p_intf );
+ double d_max_rate = (double) INPUT_RATE_MAX / INPUT_RATE_DEFAULT;
+
+ if( !dbus_message_iter_append_basic( container, DBUS_TYPE_DOUBLE, &d_max_rate ) )
+ return VLC_ENOMEM;
+
+ return VLC_SUCCESS;
+}
+DBUS_METHOD( MaximumRate )
+{
REPLY_INIT;
OUT_ARGUMENTS;
DBusMessageIter v;
- double d_max_rate = (double) INPUT_RATE_MAX / INPUT_RATE_DEFAULT;
if( !dbus_message_iter_open_container( &args, DBUS_TYPE_VARIANT, "d", &v ) )
return DBUS_HANDLER_RESULT_NEED_MEMORY;
- if( !dbus_message_iter_append_basic( &v, DBUS_TYPE_DOUBLE, &d_max_rate ) )
- return DBUS_HANDLER_RESULT_NEED_MEMORY;
+ MarshalMaximumRate( p_this, &v );
if( !dbus_message_iter_close_container( &args, &v ) )
return DBUS_HANDLER_RESULT_NEED_MEMORY;
diff --git a/modules/control/dbus/dbus_tracklist.c b/modules/control/dbus/dbus_tracklist.c
index 1081343..b6b612c 100644
--- a/modules/control/dbus/dbus_tracklist.c
+++ b/modules/control/dbus/dbus_tracklist.c
@@ -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
@@ -286,20 +288,16 @@ 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;
+static int
+MarshalTracks( intf_thread_t *p_intf, DBusMessageIter *container )
+{
+ DBusMessageIter tracks;
+ char *psz_track_id = NULL;
+ playlist_t *p_playlist = p_intf->p_sys->p_playlist;
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( container, DBUS_TYPE_ARRAY, "o",
+ &tracks );
PL_LOCK;
@@ -315,9 +313,8 @@ DBUS_METHOD( Tracks )
&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;
+ dbus_message_iter_abandon_container( container, &tracks );
+ return VLC_ENOMEM;
}
free( psz_track_id );
@@ -325,26 +322,57 @@ DBUS_METHOD( Tracks )
PL_UNLOCK;
- if( !dbus_message_iter_close_container( &v, &tracks ) ||
- !dbus_message_iter_close_container( &args, &v ) )
+ if( !dbus_message_iter_close_container( container, &tracks ) )
+ return VLC_ENOMEM;
+
+ return VLC_SUCCESS;
+}
+
+
+DBUS_METHOD( Tracks )
+{ /* Tracks property */
+ REPLY_INIT;
+ OUT_ARGUMENTS;
+
+ DBusMessageIter v;
+
+ dbus_message_iter_open_container( &args, DBUS_TYPE_VARIANT, "ao", &v );
+
+ if( MarshalTracks( p_this, &v ) != VLC_SUCCESS )
+ {
+ dbus_message_iter_abandon_container( &args, &v );
+ return DBUS_HANDLER_RESULT_NEED_MEMORY;
+ }
+
+ if( !dbus_message_iter_close_container( &args, &v ) )
return DBUS_HANDLER_RESULT_NEED_MEMORY;
REPLY_SEND;
}
+static int
+MarshalCanEditTracks( intf_thread_t *p_intf, DBusMessageIter *container )
+{
+ VLC_UNUSED( p_intf );
+ const dbus_bool_t b_ret = TRUE;
+
+ if( !dbus_message_iter_append_basic( container, DBUS_TYPE_BOOLEAN, &b_ret ) )
+ return VLC_ENOMEM;
+
+ return VLC_SUCCESS;
+}
+
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 ) )
+ if( MarshalCanEditTracks( p_this, &v ) != VLC_SUCCESS )
{
dbus_message_iter_abandon_container( &args, &v );
return DBUS_HANDLER_RESULT_NEED_MEMORY;
More information about the vlc-commits
mailing list