1 /*****************************************************************************
2 * dbus.h : D-Bus control interface
3 *****************************************************************************
4 * Copyright (C) 2006 Rafaël Carré
7 * Authors: Rafaël Carré <funman at videolanorg>
8 * Mirsal ENNAIME <mirsal dot ennaime at gmail dot com>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
25 /* DBUS IDENTIFIERS */
27 /* name registered on the session bus */
28 #define VLC_MPRIS_DBUS_SERVICE "org.mpris.vlc"
29 #define MPRIS_DBUS_INTERFACE "org.freedesktop.MediaPlayer"
30 #define MPRIS_DBUS_ROOT_PATH "/"
31 #define MPRIS_DBUS_PLAYER_PATH "/Player"
32 #define MPRIS_DBUS_TRACKLIST_PATH "/TrackList"
36 #define DBUS_METHOD( method_function ) \
37 static DBusHandlerResult method_function \
38 ( DBusConnection *p_conn, DBusMessage *p_from, void *p_this )
40 #define DBUS_SIGNAL( signal_function ) \
41 static DBusHandlerResult signal_function \
42 ( DBusConnection *p_conn, void *p_data )
45 DBusMessage* p_msg = dbus_message_new_method_return( p_from ); \
46 if( !p_msg ) return DBUS_HANDLER_RESULT_NEED_MEMORY; \
49 if( !dbus_connection_send( p_conn, p_msg, NULL ) ) \
50 return DBUS_HANDLER_RESULT_NEED_MEMORY; \
51 dbus_connection_flush( p_conn ); \
52 dbus_message_unref( p_msg ); \
53 return DBUS_HANDLER_RESULT_HANDLED
55 #define SIGNAL_INIT( signal ) \
56 DBusMessage *p_msg = dbus_message_new_signal( MPRIS_DBUS_PLAYER_PATH, \
57 MPRIS_DBUS_INTERFACE, signal ); \
58 if( !p_msg ) return DBUS_HANDLER_RESULT_NEED_MEMORY; \
61 if( !dbus_connection_send( p_conn, p_msg, NULL ) ) \
62 return DBUS_HANDLER_RESULT_NEED_MEMORY; \
63 dbus_message_unref( p_msg ); \
64 dbus_connection_flush( p_conn ); \
65 return DBUS_HANDLER_RESULT_HANDLED
67 #define OUT_ARGUMENTS \
68 DBusMessageIter args; \
69 dbus_message_iter_init_append( p_msg, &args )
71 #define DBUS_ADD( dbus_type, value ) \
72 if( !dbus_message_iter_append_basic( &args, dbus_type, value ) ) \
73 return DBUS_HANDLER_RESULT_NEED_MEMORY
75 #define ADD_STRING( s ) DBUS_ADD( DBUS_TYPE_STRING, s )
76 #define ADD_BOOL( b ) DBUS_ADD( DBUS_TYPE_BOOLEAN, b )
77 #define ADD_INT32( i ) DBUS_ADD( DBUS_TYPE_INT32, i )
78 #define ADD_BYTE( b ) DBUS_ADD( DBUS_TYPE_BYTE, b )
80 /* XML data to answer org.freedesktop.DBus.Introspectable.Introspect requests */
82 const char* psz_introspection_xml_data_root =
83 "<!DOCTYPE node PUBLIC \"-//freedesktop//DTD D-BUS Object Introspection 1.0//EN\"\n"
84 "\"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd\">\n"
86 " <node name=\"Player\"/>\n"
87 " <node name=\"TrackList\"/>\n"
88 " <interface name=\"org.freedesktop.DBus.Introspectable\">\n"
89 " <method name=\"Introspect\">\n"
90 " <arg name=\"data\" direction=\"out\" type=\"s\"/>\n"
93 " <interface name=\"org.freedesktop.MediaPlayer\">\n"
94 " <method name=\"Identity\">\n"
95 " <arg type=\"s\" direction=\"out\" />\n"
101 const char* psz_introspection_xml_data_player =
102 "<!DOCTYPE node PUBLIC \"-//freedesktop//DTD D-BUS Object Introspection 1.0//EN\"\n"
103 "\"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd\">\n"
105 " <interface name=\"org.freedesktop.DBus.Introspectable\">\n"
106 " <method name=\"Introspect\">\n"
107 " <arg name=\"data\" direction=\"out\" type=\"s\"/>\n"
110 " <interface name=\"org.freedesktop.MediaPlayer\">\n"
111 " <method name=\"GetStatus\">\n"
112 " <arg type=\"(iiii)\" direction=\"out\" />\n"
114 " <method name=\"Quit\">\n"
116 " <method name=\"Prev\">\n"
118 " <method name=\"Next\">\n"
120 " <method name=\"Stop\">\n"
122 " <method name=\"Play\">\n"
124 " <method name=\"Pause\">\n"
126 " <method name=\"Repeat\">\n"
127 " <arg type=\"b\" direction=\"in\" />\n"
129 " <method name=\"VolumeSet\">\n"
130 " <arg type=\"i\" direction=\"in\" />\n"
132 " <method name=\"VolumeGet\">\n"
133 " <arg type=\"i\" direction=\"out\" />\n"
135 " <method name=\"PositionSet\">\n"
136 " <arg type=\"i\" direction=\"in\" />\n"
138 " <method name=\"PositionGet\">\n"
139 " <arg type=\"i\" direction=\"out\" />\n"
141 " <method name=\"GetMetadata\">\n"
142 " <arg type=\"a{sv}\" direction=\"out\" />\n"
144 " <method name=\"GetCaps\">\n"
145 " <arg type=\"i\" direction=\"out\" />\n"
147 " <signal name=\"TrackChange\">\n"
148 " <arg type=\"a{sv}\"/>\n"
150 " <signal name=\"StatusChange\">\n"
151 " <arg type=\"(iiii)\"/>\n"
153 " <signal name=\"CapsChange\">\n"
154 " <arg type=\"i\"/>\n"
160 const char* psz_introspection_xml_data_tracklist =
161 "<!DOCTYPE node PUBLIC \"-//freedesktop//DTD D-BUS Object Introspection 1.0//EN\"\n"
162 "\"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd\">\n"
164 " <interface name=\"org.freedesktop.DBus.Introspectable\">\n"
165 " <method name=\"Introspect\">\n"
166 " <arg name=\"data\" direction=\"out\" type=\"s\"/>\n"
169 " <interface name=\"org.freedesktop.MediaPlayer\">\n"
170 " <method name=\"AddTrack\">\n"
171 " <arg type=\"s\" direction=\"in\" />\n"
172 " <arg type=\"b\" direction=\"in\" />\n"
174 " <method name=\"DelTrack\">\n"
175 " <arg type=\"i\" direction=\"in\" />\n"
177 " <method name=\"GetMetadata\">\n"
178 " <arg type=\"i\" direction=\"in\" />\n"
179 " <arg type=\"a{sv}\" direction=\"out\" />\n"
181 " <method name=\"GetCurrentTrack\">\n"
182 " <arg type=\"i\" direction=\"out\" />\n"
184 " <method name=\"GetLength\">\n"
185 " <arg type=\"i\" direction=\"out\" />\n"
187 " <method name=\"Loop\">\n"
188 " <arg type=\"b\" direction=\"in\" />\n"
190 " <method name=\"Random\">\n"
191 " <arg type=\"b\" direction=\"in\" />\n"
193 " <signal name=\"TrackListChange\">\n"
194 " <arg type=\"i\" />\n"
200 #define MPRIS_DBUS_ROOT_PATH "/"
201 #define MPRIS_DBUS_PLAYER_PATH "/Player"
202 #define MPRIS_DBUS_TRACKLIST_PATH "/TrackList"
204 /* Handle messages reception */
205 DBUS_METHOD( handle_root );
206 DBUS_METHOD( handle_player );
207 DBUS_METHOD( handle_tracklist );
209 static DBusObjectPathVTable vlc_dbus_root_vtable = {
210 NULL, handle_root, /* handler function */
211 NULL, NULL, NULL, NULL
214 static DBusObjectPathVTable vlc_dbus_player_vtable = {
215 NULL, handle_player, /* handler function */
216 NULL, NULL, NULL, NULL
219 static DBusObjectPathVTable vlc_dbus_tracklist_vtable = {
220 NULL, handle_tracklist, /* handler function */
221 NULL, NULL, NULL, NULL