Commit 79a45df7 authored by Mirsal Ennaime's avatar Mirsal Ennaime Committed by Jean-Baptiste Kempf

Reorganize the dbus control module code

 * Split the module source code into several files

Functionality is unchanged, but the result is more maintainable.
Signed-off-by: default avatarJean-Baptiste Kempf <jb@videolan.org>
parent 597e38cb
...@@ -4746,6 +4746,7 @@ AC_CONFIG_FILES([ ...@@ -4746,6 +4746,7 @@ AC_CONFIG_FILES([
modules/codec/wmafixed/Makefile modules/codec/wmafixed/Makefile
modules/control/Makefile modules/control/Makefile
modules/control/http/Makefile modules/control/http/Makefile
modules/control/dbus/Makefile
modules/control/globalhotkeys/Makefile modules/control/globalhotkeys/Makefile
modules/demux/Makefile modules/demux/Makefile
modules/demux/asf/Makefile modules/demux/asf/Makefile
......
SUBDIRS = http globalhotkeys SUBDIRS = http globalhotkeys dbus
SOURCES_gestures = gestures.c SOURCES_gestures = gestures.c
SOURCES_netsync = netsync.c SOURCES_netsync = netsync.c
SOURCES_ntservice = ntservice.c SOURCES_ntservice = ntservice.c
SOURCES_hotkeys = hotkeys.c SOURCES_hotkeys = hotkeys.c
SOURCES_lirc = lirc.c SOURCES_lirc = lirc.c
SOURCES_oldrc = rc.c SOURCES_oldrc = rc.c
SOURCES_dbus = dbus.c dbus.h
if HAVE_DARWIN if HAVE_DARWIN
motion_extra = unimotion.c unimotion.h motion_extra = unimotion.c unimotion.h
else else
......
SOURCES_dbus = \
dbus.c \
dbus.h \
dbus_common.h \
dbus_root.h \
dbus_root.c \
dbus_player.h \
dbus_player.c \
dbus_tracklist.h \
dbus_tracklist.c \
$(NULL)
/*****************************************************************************
* dbus.h : D-Bus control interface
*****************************************************************************
* Copyright © 2006-2008 Rafaël Carré
* Copyright © 2007-2010 Mirsal Ennaime
* Copyright © 2009-2010 The VideoLAN team
* $Id$
*
* Authors: Rafaël Carré <funman at videolanorg>
* Mirsal ENNAIME <mirsal dot ennaime at gmail dot com>
*
* 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
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#ifndef _VLC_DBUS_H
#define _VLC_DBUS_H
#define DBUS_MPRIS_BUS_NAME "org.mpris.vlc"
#endif //dbus.h
/*****************************************************************************
* dbus-common.h : Common header for D-Bus control modules
*****************************************************************************
* Copyright © 2006-2008 Rafaël Carré
* Copyright © 2007-2010 Mirsal Ennaime
* Copyright © 2009-2010 The VideoLAN team
* $Id$
*
* Authors: Mirsal ENNAIME <mirsal dot ennaime at gmail dot com>
*
* 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
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#ifndef _VLC_DBUS_COMMON_H
#define _VLC_DBUS_COMMON_H
#include <vlc_common.h>
#include <vlc_interface.h>
#include <dbus/dbus.h>
/* MACROS */
#define INTF ((intf_thread_t *)p_this)
#define PL (INTF->p_sys->p_playlist)
#define DBUS_METHOD( method_function ) \
static DBusHandlerResult method_function \
( DBusConnection *p_conn, DBusMessage *p_from, void *p_this )
#define DBUS_SIGNAL( signal_function ) \
static DBusHandlerResult signal_function \
( DBusConnection *p_conn, void *p_data )
#define REPLY_INIT \
DBusMessage* p_msg = dbus_message_new_method_return( p_from ); \
if( !p_msg ) return DBUS_HANDLER_RESULT_NEED_MEMORY; \
#define REPLY_SEND \
if( !dbus_connection_send( p_conn, p_msg, NULL ) ) \
return DBUS_HANDLER_RESULT_NEED_MEMORY; \
dbus_connection_flush( p_conn ); \
dbus_message_unref( p_msg ); \
return DBUS_HANDLER_RESULT_HANDLED
#define SIGNAL_INIT( interface, path, signal ) \
DBusMessage *p_msg = dbus_message_new_signal( path, \
interface, signal ); \
if( !p_msg ) return DBUS_HANDLER_RESULT_NEED_MEMORY; \
#define SIGNAL_SEND \
if( !dbus_connection_send( p_conn, p_msg, NULL ) ) \
return DBUS_HANDLER_RESULT_NEED_MEMORY; \
dbus_message_unref( p_msg ); \
dbus_connection_flush( p_conn ); \
return DBUS_HANDLER_RESULT_HANDLED
#define OUT_ARGUMENTS \
DBusMessageIter args; \
dbus_message_iter_init_append( p_msg, &args )
#define DBUS_ADD( dbus_type, value ) \
if( !dbus_message_iter_append_basic( &args, dbus_type, value ) ) \
return DBUS_HANDLER_RESULT_NEED_MEMORY
#define ADD_STRING( s ) DBUS_ADD( DBUS_TYPE_STRING, s )
#define ADD_BOOL( b ) DBUS_ADD( DBUS_TYPE_BOOLEAN, b )
#define ADD_INT32( i ) DBUS_ADD( DBUS_TYPE_INT32, i )
#define ADD_BYTE( b ) DBUS_ADD( DBUS_TYPE_BYTE, b )
struct intf_sys_t
{
DBusConnection *p_conn;
playlist_t *p_playlist;
bool b_meta_read;
dbus_int32_t i_caps;
bool b_dead;
vlc_array_t *p_events;
vlc_mutex_t lock;
input_thread_t *p_input;
bool b_unique;
};
enum
{
SIGNAL_ITEM_CURRENT,
SIGNAL_INTF_CHANGE,
SIGNAL_PLAYLIST_ITEM_APPEND,
SIGNAL_PLAYLIST_ITEM_DELETED,
SIGNAL_RANDOM,
SIGNAL_REPEAT,
SIGNAL_LOOP,
SIGNAL_STATE
};
int GetInputMeta ( input_item_t* p_input, DBusMessageIter *args );
int UpdateCaps ( intf_thread_t* );
#endif //dbus-common.h
This diff is collapsed.
/*****************************************************************************
* dbus-player.h : dbus control module (mpris v1.0) - /Player object
*****************************************************************************
* Copyright © 2006-2008 Rafaël Carré
* Copyright © 2007-2010 Mirsal Ennaime
* Copyright © 2009-2010 The VideoLAN team
* $Id$
*
* Authors: Mirsal ENNAIME <mirsal dot ennaime at gmail dot com>
*
* 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
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#ifndef _VLC_DBUS_PLAYER_H
#define _VLC_DBUS_PLAYER_H
#include <vlc_interface.h>
#include "dbus_common.h"
#define DBUS_MPRIS_PLAYER_INTERFACE "org.freedesktop.MediaPlayer"
#define DBUS_MPRIS_PLAYER_PATH "/Player"
/* Handle incoming dbus messages */
DBusHandlerResult handle_player ( DBusConnection *p_conn,
DBusMessage *p_from,
void *p_this );
static const DBusObjectPathVTable dbus_mpris_player_vtable = {
NULL, handle_player, /* handler function */
NULL, NULL, NULL, NULL
};
/* GetCaps() capabilities */
enum
{
CAPS_NONE = 0,
CAPS_CAN_GO_NEXT = 1 << 0,
CAPS_CAN_GO_PREV = 1 << 1,
CAPS_CAN_PAUSE = 1 << 2,
CAPS_CAN_PLAY = 1 << 3,
CAPS_CAN_SEEK = 1 << 4,
CAPS_CAN_PROVIDE_METADATA = 1 << 5,
CAPS_CAN_HAS_TRACKLIST = 1 << 6
};
int StatusChangeEmit ( intf_thread_t * );
int CapsChangeEmit ( intf_thread_t * );
int TrackChangeEmit ( intf_thread_t *, input_item_t * );
#endif //dbus_player.h
/*****************************************************************************
* dbus-root.c : dbus control module (mpris v1.0) - root object
*****************************************************************************
* Copyright © 2006-2008 Rafaël Carré
* Copyright © 2007-2010 Mirsal Ennaime
* Copyright © 2009-2010 The VideoLAN team
* $Id$
*
* Authors: Mirsal ENNAIME <mirsal dot ennaime at gmail dot com>
*
* 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
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <vlc_common.h>
#include <vlc_interface.h>
#include "dbus_root.h"
#include "dbus_common.h"
/* XML data to answer org.freedesktop.DBus.Introspectable.Introspect requests */
static const char* psz_root_introspection_xml =
"<!DOCTYPE node PUBLIC \"-//freedesktop//DTD D-BUS Object Introspection 1.0//EN\"\n"
"\"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd\">\n"
"<node>\n"
" <node name=\"Player\"/>\n"
" <node name=\"TrackList\"/>\n"
" <interface name=\"org.freedesktop.DBus.Introspectable\">\n"
" <method name=\"Introspect\">\n"
" <arg name=\"data\" direction=\"out\" type=\"s\"/>\n"
" </method>\n"
" </interface>\n"
" <interface name=\"org.freedesktop.MediaPlayer\">\n"
" <method name=\"Identity\">\n"
" <arg type=\"s\" direction=\"out\" />\n"
" </method>\n"
" <method name=\"MprisVersion\">\n"
" <arg type=\"(qq)\" direction=\"out\" />\n"
" </method>\n"
" <method name=\"Quit\">\n"
" </method>\n"
" </interface>\n"
"</node>\n"
;
DBUS_METHOD( Identity )
{
VLC_UNUSED(p_this);
REPLY_INIT;
OUT_ARGUMENTS;
char *psz_identity;
if( asprintf( &psz_identity, "%s %s", PACKAGE, VERSION ) != -1 )
{
ADD_STRING( &psz_identity );
free( psz_identity );
}
else
return DBUS_HANDLER_RESULT_NEED_MEMORY;
REPLY_SEND;
}
DBUS_METHOD( MprisVersion )
{ /*implemented version of the mpris spec */
REPLY_INIT;
OUT_ARGUMENTS;
VLC_UNUSED( p_this );
dbus_uint16_t i_major = DBUS_MPRIS_VERSION_MAJOR;
dbus_uint16_t i_minor = DBUS_MPRIS_VERSION_MINOR;
DBusMessageIter version;
if( !dbus_message_iter_open_container( &args, DBUS_TYPE_STRUCT, NULL,
&version ) )
return DBUS_HANDLER_RESULT_NEED_MEMORY;
if( !dbus_message_iter_append_basic( &version, DBUS_TYPE_UINT16,
&i_major ) )
return DBUS_HANDLER_RESULT_NEED_MEMORY;
if( !dbus_message_iter_append_basic( &version, DBUS_TYPE_UINT16,
&i_minor ) )
return DBUS_HANDLER_RESULT_NEED_MEMORY;
if( !dbus_message_iter_close_container( &args, &version ) )
return DBUS_HANDLER_RESULT_NEED_MEMORY;
REPLY_SEND;
}
DBUS_METHOD( Quit )
{ /* exits vlc */
REPLY_INIT;
libvlc_Quit(INTF->p_libvlc);
REPLY_SEND;
}
DBUS_METHOD( handle_introspect_root )
{ /* handles introspection of root object */
VLC_UNUSED(p_this);
REPLY_INIT;
OUT_ARGUMENTS;
ADD_STRING( &psz_root_introspection_xml );
REPLY_SEND;
}
#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 )
DBusHandlerResult
handle_root ( DBusConnection *p_conn, DBusMessage *p_from, void *p_this )
{
if( dbus_message_is_method_call( p_from,
DBUS_INTERFACE_INTROSPECTABLE, "Introspect" ) )
return handle_introspect_root( p_conn, p_from, p_this );
/* here D-Bus method names are associated to an handler */
METHOD_FUNC( DBUS_MPRIS_ROOT_INTERFACE, "Identity", Identity );
METHOD_FUNC( DBUS_MPRIS_ROOT_INTERFACE, "MprisVersion", MprisVersion );
METHOD_FUNC( DBUS_MPRIS_ROOT_INTERFACE, "Quit", Quit );
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}
#undef METHOD_FUNC
/*****************************************************************************
* dbus-root.h : dbus control module (mpris v1.0) - root object
*****************************************************************************
* Copyright © 2006-2008 Rafaël Carré
* Copyright © 2007-2010 Mirsal Ennaime
* Copyright © 2009-2010 The VideoLAN team
* $Id$
*
* Authors: Mirsal ENNAIME <mirsal dot ennaime at gmail dot com>
*
* 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
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#ifndef _VLC_DBUS_ROOT_H
#define _VLC_DBUS_ROOT_H
#include "dbus_common.h"
/* MPRIS VERSION */
#define DBUS_MPRIS_VERSION_MAJOR 2
#define DBUS_MPRIS_VERSION_MINOR 0
/* DBUS IDENTIFIERS */
#define DBUS_MPRIS_ROOT_INTERFACE "org.freedesktop.MediaPlayer"
#define DBUS_MPRIS_ROOT_PATH "/"
/* Handle incoming dbus messages */
DBusHandlerResult handle_root ( DBusConnection *p_conn,
DBusMessage *p_from,
void *p_this );
static const DBusObjectPathVTable dbus_mpris_root_vtable = {
NULL, handle_root, /* handler function */
NULL, NULL, NULL, NULL
};
#endif //dbus-root.h
This diff is collapsed.
/*****************************************************************************
* dbus-tracklist.h : dbus control module (mpris v1.0) - /TrackList object
*****************************************************************************
* Copyright © 2006-2008 Rafaël Carré
* Copyright © 2007-2010 Mirsal Ennaime
* Copyright © 2009-2010 The VideoLAN team
* $Id$
*
* Authors: Mirsal ENNAIME <mirsal dot ennaime at gmail dot com>
*
* 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
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#ifndef _VLC_DBUS_TRACKLIST_H
#define _VLC_DBUS_TRACKLIST_H
#include <vlc_common.h>
#include <vlc_interface.h>
#include "dbus_common.h"
#define DBUS_MPRIS_TRACKLIST_INTERFACE "org.freedesktop.MediaPlayer"
#define DBUS_MPRIS_TRACKLIST_PATH "/TrackList"
/* Handle incoming dbus messages */
DBusHandlerResult handle_tracklist ( DBusConnection *p_conn,
DBusMessage *p_from,
void *p_this );
static const DBusObjectPathVTable dbus_mpris_tracklist_vtable = {
NULL, handle_tracklist, /* handler function */
NULL, NULL, NULL, NULL
};
int TrackListChangeEmit( intf_thread_t *, int, int );
#endif //dbus_tracklist.h
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