1 /*****************************************************************************
2 * dbus-root.c : dbus control module (mpris v1.0) - root object
3 *****************************************************************************
4 * Copyright © 2006-2008 Rafaël Carré
5 * Copyright © 2007-2010 Mirsal Ennaime
6 * Copyright © 2009-2010 The VideoLAN team
9 * Authors: Mirsal ENNAIME <mirsal dot ennaime at gmail dot com>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
24 *****************************************************************************/
30 #include <vlc_common.h>
31 #include <vlc_interface.h>
33 #include "dbus_root.h"
34 #include "dbus_common.h"
36 /* XML data to answer org.freedesktop.DBus.Introspectable.Introspect requests */
37 static const char* psz_root_introspection_xml =
38 "<!DOCTYPE node PUBLIC \"-//freedesktop//DTD D-BUS Object Introspection 1.0//EN\"\n"
39 "\"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd\">\n"
41 " <node name=\"Player\"/>\n"
42 " <node name=\"TrackList\"/>\n"
43 " <interface name=\"org.freedesktop.DBus.Introspectable\">\n"
44 " <method name=\"Introspect\">\n"
45 " <arg name=\"data\" direction=\"out\" type=\"s\"/>\n"
48 " <interface name=\"org.freedesktop.MediaPlayer\">\n"
49 " <method name=\"Identity\">\n"
50 " <arg type=\"s\" direction=\"out\" />\n"
52 " <method name=\"MprisVersion\">\n"
53 " <arg type=\"(qq)\" direction=\"out\" />\n"
55 " <method name=\"Quit\">\n"
61 DBUS_METHOD( Identity )
68 if( asprintf( &psz_identity, "%s %s", PACKAGE, VERSION ) != -1 )
70 ADD_STRING( &psz_identity );
74 return DBUS_HANDLER_RESULT_NEED_MEMORY;
79 DBUS_METHOD( MprisVersion )
80 { /*implemented version of the mpris spec */
84 dbus_uint16_t i_major = DBUS_MPRIS_VERSION_MAJOR;
85 dbus_uint16_t i_minor = DBUS_MPRIS_VERSION_MINOR;
86 DBusMessageIter version;
88 if( !dbus_message_iter_open_container( &args, DBUS_TYPE_STRUCT, NULL,
90 return DBUS_HANDLER_RESULT_NEED_MEMORY;
92 if( !dbus_message_iter_append_basic( &version, DBUS_TYPE_UINT16,
94 return DBUS_HANDLER_RESULT_NEED_MEMORY;
96 if( !dbus_message_iter_append_basic( &version, DBUS_TYPE_UINT16,
98 return DBUS_HANDLER_RESULT_NEED_MEMORY;
100 if( !dbus_message_iter_close_container( &args, &version ) )
101 return DBUS_HANDLER_RESULT_NEED_MEMORY;
108 libvlc_Quit(INTF->p_libvlc);
112 DBUS_METHOD( handle_introspect_root )
113 { /* handles introspection of root object */
117 ADD_STRING( &psz_root_introspection_xml );
121 #define METHOD_FUNC( interface, method, function ) \
122 else if( dbus_message_is_method_call( p_from, interface, method ) )\
123 return function( p_conn, p_from, p_this )
126 handle_root ( DBusConnection *p_conn, DBusMessage *p_from, void *p_this )
128 if( dbus_message_is_method_call( p_from,
129 DBUS_INTERFACE_INTROSPECTABLE, "Introspect" ) )
130 return handle_introspect_root( p_conn, p_from, p_this );
132 /* here D-Bus method names are associated to an handler */
134 METHOD_FUNC( DBUS_MPRIS_ROOT_INTERFACE, "Identity", Identity );
135 METHOD_FUNC( DBUS_MPRIS_ROOT_INTERFACE, "MprisVersion", MprisVersion );
136 METHOD_FUNC( DBUS_MPRIS_ROOT_INTERFACE, "Quit", Quit );
138 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;