Commit 6ae4c72d authored by Alex Merry's avatar Alex Merry Committed by Mirsal Ennaime

dbus: Standardise property getters

There was a lot of repeated code, some of which properly checked return
values and some of which didn't.  This is all replaced and folded into
the GetProperty function of each interface.

A side-effect is that it should be more efficient (we only check the
interface argument once instead of once for each property, and there
should be a smaller overall code size).
Signed-off-by: default avatarMirsal Ennaime <mirsal@videolan.org>
parent 3aa9a4ad
This diff is collapsed.
......@@ -86,22 +86,6 @@ MarshalIdentity( intf_thread_t *p_intf, DBusMessageIter *container )
return VLC_SUCCESS;
}
DBUS_METHOD( Identity )
{
REPLY_INIT;
OUT_ARGUMENTS;
DBusMessageIter v;
dbus_message_iter_open_container( &args, DBUS_TYPE_VARIANT, "s", &v );
MarshalIdentity( p_this, &v );
if( !dbus_message_iter_close_container( &args, &v ) )
return DBUS_HANDLER_RESULT_NEED_MEMORY;
REPLY_SEND;
}
static int
MarshalCanSetFullscreen( intf_thread_t *p_intf, DBusMessageIter *container )
{
......@@ -127,22 +111,6 @@ MarshalCanSetFullscreen( intf_thread_t *p_intf, DBusMessageIter *container )
return VLC_SUCCESS;
}
DBUS_METHOD( CanSetFullscreen )
{
REPLY_INIT;
OUT_ARGUMENTS;
DBusMessageIter v;
dbus_message_iter_open_container( &args, DBUS_TYPE_VARIANT, "b", &v );
MarshalCanSetFullscreen( p_this, &v );
if( !dbus_message_iter_close_container( &args, &v ) )
return DBUS_HANDLER_RESULT_NEED_MEMORY;
REPLY_SEND;
}
static int
MarshalFullscreen( intf_thread_t *p_intf, DBusMessageIter *container )
{
......@@ -160,24 +128,6 @@ MarshalFullscreen( intf_thread_t *p_intf, DBusMessageIter *container )
return VLC_SUCCESS;
}
DBUS_METHOD( FullscreenGet )
{
REPLY_INIT;
OUT_ARGUMENTS;
DBusMessageIter v;
if( !dbus_message_iter_open_container( &args, DBUS_TYPE_VARIANT, "b", &v ) )
return DBUS_HANDLER_RESULT_NEED_MEMORY;
MarshalFullscreen( p_this, &v );
if( !dbus_message_iter_close_container( &args, &v ) )
return DBUS_HANDLER_RESULT_NEED_MEMORY;
REPLY_SEND;
}
DBUS_METHOD( FullscreenSet )
{
REPLY_INIT;
......@@ -214,22 +164,6 @@ MarshalCanQuit( intf_thread_t *p_intf, DBusMessageIter *container )
return VLC_SUCCESS;
}
DBUS_METHOD( CanQuit )
{
REPLY_INIT;
OUT_ARGUMENTS;
DBusMessageIter v;
dbus_message_iter_open_container( &args, DBUS_TYPE_VARIANT, "b", &v );
MarshalCanQuit( p_this, &v );
if( !dbus_message_iter_close_container( &args, &v ) )
return DBUS_HANDLER_RESULT_NEED_MEMORY;
REPLY_SEND;
}
static int
MarshalCanRaise( intf_thread_t *p_intf, DBusMessageIter *container )
{
......@@ -242,22 +176,6 @@ MarshalCanRaise( intf_thread_t *p_intf, DBusMessageIter *container )
return VLC_SUCCESS;
}
DBUS_METHOD( CanRaise )
{
REPLY_INIT;
OUT_ARGUMENTS;
DBusMessageIter v;
dbus_message_iter_open_container( &args, DBUS_TYPE_VARIANT, "b", &v );
MarshalCanRaise( p_this, &v );
if( !dbus_message_iter_close_container( &args, &v ) )
return DBUS_HANDLER_RESULT_NEED_MEMORY;
REPLY_SEND;
}
static int
MarshalHasTrackList( intf_thread_t *p_intf, DBusMessageIter *container )
{
......@@ -270,22 +188,6 @@ MarshalHasTrackList( intf_thread_t *p_intf, DBusMessageIter *container )
return VLC_SUCCESS;
}
DBUS_METHOD( HasTrackList )
{
REPLY_INIT;
OUT_ARGUMENTS;
DBusMessageIter v;
dbus_message_iter_open_container( &args, DBUS_TYPE_VARIANT, "b", &v );
MarshalHasTrackList( p_this, &v );
if( !dbus_message_iter_close_container( &args, &v ) )
return DBUS_HANDLER_RESULT_NEED_MEMORY;
REPLY_SEND;
}
static int
MarshalDesktopEntry( intf_thread_t *p_intf, DBusMessageIter *container )
{
......@@ -298,22 +200,6 @@ MarshalDesktopEntry( intf_thread_t *p_intf, DBusMessageIter *container )
return VLC_SUCCESS;
}
DBUS_METHOD( DesktopEntry )
{
REPLY_INIT;
OUT_ARGUMENTS;
DBusMessageIter v;
dbus_message_iter_open_container( &args, DBUS_TYPE_VARIANT, "s", &v );
MarshalDesktopEntry( p_this, &v );
if( !dbus_message_iter_close_container( &args, &v ) )
return DBUS_HANDLER_RESULT_NEED_MEMORY;
REPLY_SEND;
}
static int
MarshalSupportedMimeTypes( intf_thread_t *p_intf, DBusMessageIter *container )
{
......@@ -343,23 +229,6 @@ MarshalSupportedMimeTypes( intf_thread_t *p_intf, DBusMessageIter *container )
return VLC_SUCCESS;
}
DBUS_METHOD( SupportedMimeTypes )
{
REPLY_INIT;
OUT_ARGUMENTS;
DBusMessageIter v;
dbus_message_iter_open_container( &args, DBUS_TYPE_VARIANT, "as", &v );
if( VLC_SUCCESS != MarshalSupportedMimeTypes( p_this, &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
MarshalSupportedUriSchemes( intf_thread_t *p_intf, DBusMessageIter *container )
{
......@@ -389,24 +258,6 @@ MarshalSupportedUriSchemes( intf_thread_t *p_intf, DBusMessageIter *container )
return VLC_SUCCESS;
}
DBUS_METHOD( SupportedUriSchemes )
{
VLC_UNUSED( p_this );
REPLY_INIT;
OUT_ARGUMENTS;
DBusMessageIter v;
dbus_message_iter_open_container( &args, DBUS_TYPE_VARIANT, "as", &v );
if( VLC_SUCCESS != MarshalSupportedUriSchemes( p_this, &v ) )
return DBUS_HANDLER_RESULT_NEED_MEMORY;
if( !dbus_message_iter_close_container( &args, &v ) )
return DBUS_HANDLER_RESULT_NEED_MEMORY;
REPLY_SEND;
}
DBUS_METHOD( Quit )
{ /* exits vlc */
REPLY_INIT;
......@@ -422,11 +273,22 @@ DBUS_METHOD( Raise )
}
#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;
#define PROPERTY_GET_FUNC( prop, signature ) \
else if( !strcmp( psz_property_name, #prop ) ) { \
if( !dbus_message_iter_open_container( &args, DBUS_TYPE_VARIANT, signature, &v ) ) \
return DBUS_HANDLER_RESULT_NEED_MEMORY; \
if( VLC_SUCCESS != Marshal##prop( p_this, &v ) ) { \
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; \
}
#define PROPERTY_SET_FUNC( prop ) \
else if( !strcmp( psz_property_name, #prop ) ) { \
return prop##Set( p_conn, p_from, p_this ); \
}
#define PROPERTY_MAPPING_END else { return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; }
DBUS_METHOD( GetProperty )
{
......@@ -452,17 +314,27 @@ DBUS_METHOD( GetProperty )
msg_Dbg( (vlc_object_t*) p_this, "Getting property %s",
psz_property_name );
if( strcmp( psz_interface_name, DBUS_MPRIS_ROOT_INTERFACE ) ) {
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}
REPLY_INIT;
OUT_ARGUMENTS;
DBusMessageIter v;
PROPERTY_MAPPING_BEGIN
PROPERTY_FUNC( DBUS_MPRIS_ROOT_INTERFACE, "Identity", Identity )
PROPERTY_FUNC( DBUS_MPRIS_ROOT_INTERFACE, "DesktopEntry", DesktopEntry )
PROPERTY_FUNC( DBUS_MPRIS_ROOT_INTERFACE, "SupportedMimeTypes", SupportedMimeTypes )
PROPERTY_FUNC( DBUS_MPRIS_ROOT_INTERFACE, "SupportedUriSchemes", SupportedUriSchemes )
PROPERTY_FUNC( DBUS_MPRIS_ROOT_INTERFACE, "HasTrackList", HasTrackList )
PROPERTY_FUNC( DBUS_MPRIS_ROOT_INTERFACE, "CanQuit", CanQuit )
PROPERTY_FUNC( DBUS_MPRIS_ROOT_INTERFACE, "CanSetFullscreen", CanSetFullscreen )
PROPERTY_FUNC( DBUS_MPRIS_ROOT_INTERFACE, "Fullscreen", FullscreenGet )
PROPERTY_FUNC( DBUS_MPRIS_ROOT_INTERFACE, "CanRaise", CanRaise )
PROPERTY_GET_FUNC( Identity, "s" )
PROPERTY_GET_FUNC( CanSetFullscreen, "b" )
PROPERTY_GET_FUNC( Fullscreen, "b" )
PROPERTY_GET_FUNC( CanQuit, "b" )
PROPERTY_GET_FUNC( CanRaise, "b" )
PROPERTY_GET_FUNC( HasTrackList, "b" )
PROPERTY_GET_FUNC( DesktopEntry, "s" )
PROPERTY_GET_FUNC( SupportedMimeTypes, "as" )
PROPERTY_GET_FUNC( SupportedUriSchemes, "as" )
PROPERTY_MAPPING_END
REPLY_SEND;
}
DBUS_METHOD( SetProperty )
......@@ -487,12 +359,13 @@ DBUS_METHOD( SetProperty )
}
PROPERTY_MAPPING_BEGIN
PROPERTY_FUNC( DBUS_MPRIS_ROOT_INTERFACE, "Fullscreen", FullscreenSet )
PROPERTY_SET_FUNC( Fullscreen )
PROPERTY_MAPPING_END
}
#undef PROPERTY_MAPPING_BEGIN
#undef PROPERTY_GET_FUNC
#undef PROPERTY_SET_FUNC
#undef PROPERTY_MAPPING_END
#define ADD_PROPERTY( prop, signature ) \
......
......@@ -328,28 +328,6 @@ MarshalTracks( intf_thread_t *p_intf, DBusMessageIter *container )
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 )
{
......@@ -362,37 +340,25 @@ MarshalCanEditTracks( intf_thread_t *p_intf, DBusMessageIter *container )
return VLC_SUCCESS;
}
DBUS_METHOD( CanEditTracks )
{ /* CanEditTracks property */
REPLY_INIT;
OUT_ARGUMENTS;
DBusMessageIter v;
if( !dbus_message_iter_open_container( &args, DBUS_TYPE_VARIANT, "b", &v ) )
return DBUS_HANDLER_RESULT_NEED_MEMORY;
if( MarshalCanEditTracks( p_this, &v ) != VLC_SUCCESS )
{
dbus_message_iter_abandon_container( &args, &v );
return DBUS_HANDLER_RESULT_NEED_MEMORY;
#define PROPERTY_MAPPING_BEGIN if( 0 ) {}
#define PROPERTY_GET_FUNC( prop, signature ) \
else if( !strcmp( psz_property_name, #prop ) ) { \
if( !dbus_message_iter_open_container( &args, DBUS_TYPE_VARIANT, signature, &v ) ) \
return DBUS_HANDLER_RESULT_NEED_MEMORY; \
if( VLC_SUCCESS != Marshal##prop( p_this, &v ) ) { \
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; \
}
if( !dbus_message_iter_close_container( &args, &v ) )
{
dbus_message_iter_abandon_container( &args, &v );
return DBUS_HANDLER_RESULT_NEED_MEMORY;
#define PROPERTY_SET_FUNC( prop ) \
else if( !strcmp( psz_property_name, #prop ) ) { \
return prop##Set( p_conn, p_from, p_this ); \
}
#define PROPERTY_MAPPING_END else { return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; }
REPLY_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 )
{
......@@ -418,15 +384,25 @@ DBUS_METHOD( GetProperty )
msg_Dbg( (vlc_object_t*) p_this, "Getting property %s",
psz_property_name );
if( strcmp( psz_interface_name, DBUS_MPRIS_TRACKLIST_INTERFACE ) ) {
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}
REPLY_INIT;
OUT_ARGUMENTS;
DBusMessageIter v;
PROPERTY_MAPPING_BEGIN
PROPERTY_FUNC( DBUS_MPRIS_TRACKLIST_INTERFACE, "Tracks", Tracks )
PROPERTY_FUNC( DBUS_MPRIS_TRACKLIST_INTERFACE, "CanEditTracks",
CanEditTracks )
PROPERTY_GET_FUNC( Tracks, "ao" )
PROPERTY_GET_FUNC( CanEditTracks, "b" )
PROPERTY_MAPPING_END
REPLY_SEND;
}
#undef PROPERTY_MAPPING_BEGIN
#undef PROPERTY_GET_FUNC
#undef PROPERTY_SET_FUNC
#undef PROPERTY_MAPPING_END
#define METHOD_FUNC( interface, method, function ) \
......
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