]> git.sesse.net Git - vlc/blob - modules/control/dbus/dbus_root.c
Use var_Inherit* instead of var_CreateGet*.
[vlc] / modules / control / dbus / dbus_root.c
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
7  * $Id$
8  *
9  * Authors:    Mirsal ENNAIME <mirsal dot ennaime at gmail dot com>
10  *
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.
15  *
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.
20  *
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  *****************************************************************************/
25
26 #ifdef HAVE_CONFIG_H
27 # include "config.h"
28 #endif
29
30 #include <vlc_common.h>
31 #include <vlc_interface.h>
32
33 #include "dbus_root.h"
34 #include "dbus_common.h"
35
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"
40 "<node>\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"
46 "    </method>\n"
47 "  </interface>\n"
48 "  <interface name=\"org.freedesktop.MediaPlayer\">\n"
49 "    <method name=\"Identity\">\n"
50 "      <arg type=\"s\" direction=\"out\" />\n"
51 "    </method>\n"
52 "    <method name=\"MprisVersion\">\n"
53 "      <arg type=\"(qq)\" direction=\"out\" />\n"
54 "    </method>\n"
55 "    <method name=\"Quit\">\n"
56 "    </method>\n"
57 "  </interface>\n"
58 "</node>\n"
59 ;
60
61 DBUS_METHOD( Identity )
62 {
63     VLC_UNUSED(p_this);
64     REPLY_INIT;
65     OUT_ARGUMENTS;
66     char *psz_identity;
67
68     if( asprintf( &psz_identity, "%s %s", PACKAGE, VERSION ) != -1 )
69     {
70         ADD_STRING( &psz_identity );
71         free( psz_identity );
72     }
73     else
74         return DBUS_HANDLER_RESULT_NEED_MEMORY;
75
76     REPLY_SEND;
77 }
78
79 DBUS_METHOD( MprisVersion )
80 { /*implemented version of the mpris spec */
81     REPLY_INIT;
82     OUT_ARGUMENTS;
83     VLC_UNUSED( p_this );
84     dbus_uint16_t i_major = DBUS_MPRIS_VERSION_MAJOR;
85     dbus_uint16_t i_minor = DBUS_MPRIS_VERSION_MINOR;
86     DBusMessageIter version;
87
88     if( !dbus_message_iter_open_container( &args, DBUS_TYPE_STRUCT, NULL,
89             &version ) )
90         return DBUS_HANDLER_RESULT_NEED_MEMORY;
91
92     if( !dbus_message_iter_append_basic( &version, DBUS_TYPE_UINT16,
93             &i_major ) )
94         return DBUS_HANDLER_RESULT_NEED_MEMORY;
95
96     if( !dbus_message_iter_append_basic( &version, DBUS_TYPE_UINT16,
97             &i_minor ) )
98         return DBUS_HANDLER_RESULT_NEED_MEMORY;
99
100     if( !dbus_message_iter_close_container( &args, &version ) )
101         return DBUS_HANDLER_RESULT_NEED_MEMORY;
102     REPLY_SEND;
103 }
104
105 DBUS_METHOD( Quit )
106 { /* exits vlc */
107     REPLY_INIT;
108     libvlc_Quit(INTF->p_libvlc);
109     REPLY_SEND;
110 }
111
112 DBUS_METHOD( handle_introspect_root )
113 { /* handles introspection of root object */
114     VLC_UNUSED(p_this);
115     REPLY_INIT;
116     OUT_ARGUMENTS;
117     ADD_STRING( &psz_root_introspection_xml );
118     REPLY_SEND;
119 }
120
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 )
124
125 DBusHandlerResult
126 handle_root ( DBusConnection *p_conn, DBusMessage *p_from, void *p_this )
127 {
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 );
131
132     /* here D-Bus method names are associated to an handler */
133
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 );
137
138     return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
139 }
140
141 #undef METHOD_FUNC