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 *****************************************************************************/
26 #define VLC_MPRIS_VERSION_MAJOR 1
27 #define VLC_MPRIS_VERSION_MINOR 0
29 /* DBUS IDENTIFIERS */
31 /* name registered on the session bus */
32 #define VLC_MPRIS_DBUS_SERVICE "org.mpris.vlc"
34 #define MPRIS_DBUS_ROOT_INTERFACE "org.freedesktop.MediaPlayer"
35 #define MPRIS_DBUS_PLAYER_INTERFACE "org.freedesktop.MediaPlayer"
36 #define MPRIS_DBUS_TRACKLIST_INTERFACE "org.freedesktop.MediaPlayer"
38 #define MPRIS_DBUS_ROOT_PATH "/"
39 #define MPRIS_DBUS_PLAYER_PATH "/Player"
40 #define MPRIS_DBUS_TRACKLIST_PATH "/TrackList"
44 #define DBUS_METHOD( method_function ) \
45 static DBusHandlerResult method_function \
46 ( DBusConnection *p_conn, DBusMessage *p_from, void *p_this )
48 #define DBUS_SIGNAL( signal_function ) \
49 static DBusHandlerResult signal_function \
50 ( DBusConnection *p_conn, void *p_data )
53 DBusMessage* p_msg = dbus_message_new_method_return( p_from ); \
54 if( !p_msg ) return DBUS_HANDLER_RESULT_NEED_MEMORY; \
57 if( !dbus_connection_send( p_conn, p_msg, NULL ) ) \
58 return DBUS_HANDLER_RESULT_NEED_MEMORY; \
59 dbus_connection_flush( p_conn ); \
60 dbus_message_unref( p_msg ); \
61 return DBUS_HANDLER_RESULT_HANDLED
63 #define SIGNAL_INIT( interface, path, signal ) \
64 DBusMessage *p_msg = dbus_message_new_signal( path, \
65 interface, signal ); \
66 if( !p_msg ) return DBUS_HANDLER_RESULT_NEED_MEMORY; \
69 if( !dbus_connection_send( p_conn, p_msg, NULL ) ) \
70 return DBUS_HANDLER_RESULT_NEED_MEMORY; \
71 dbus_message_unref( p_msg ); \
72 dbus_connection_flush( p_conn ); \
73 return DBUS_HANDLER_RESULT_HANDLED
75 #define OUT_ARGUMENTS \
76 DBusMessageIter args; \
77 dbus_message_iter_init_append( p_msg, &args )
79 #define DBUS_ADD( dbus_type, value ) \
80 if( !dbus_message_iter_append_basic( &args, dbus_type, value ) ) \
81 return DBUS_HANDLER_RESULT_NEED_MEMORY
83 #define ADD_STRING( s ) DBUS_ADD( DBUS_TYPE_STRING, s )
84 #define ADD_BOOL( b ) DBUS_ADD( DBUS_TYPE_BOOLEAN, b )
85 #define ADD_INT32( i ) DBUS_ADD( DBUS_TYPE_INT32, i )
86 #define ADD_BYTE( b ) DBUS_ADD( DBUS_TYPE_BYTE, b )
88 /* XML data to answer org.freedesktop.DBus.Introspectable.Introspect requests */
90 const char* psz_introspection_xml_data_root =
91 "<!DOCTYPE node PUBLIC \"-//freedesktop//DTD D-BUS Object Introspection 1.0//EN\"\n"
92 "\"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd\">\n"
94 " <node name=\"Player\"/>\n"
95 " <node name=\"TrackList\"/>\n"
96 " <interface name=\"org.freedesktop.DBus.Introspectable\">\n"
97 " <method name=\"Introspect\">\n"
98 " <arg name=\"data\" direction=\"out\" type=\"s\"/>\n"
101 " <interface name=\"org.freedesktop.MediaPlayer\">\n"
102 " <method name=\"Identity\">\n"
103 " <arg type=\"s\" direction=\"out\" />\n"
105 " <method name=\"MprisVersion\">\n"
106 " <arg type=\"(qq)\" direction=\"out\" />\n"
108 " <method name=\"Quit\">\n"
114 const char* psz_introspection_xml_data_player =
115 "<!DOCTYPE node PUBLIC \"-//freedesktop//DTD D-BUS Object Introspection 1.0//EN\"\n"
116 "\"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd\">\n"
118 " <interface name=\"org.freedesktop.DBus.Introspectable\">\n"
119 " <method name=\"Introspect\">\n"
120 " <arg name=\"data\" direction=\"out\" type=\"s\"/>\n"
123 " <interface name=\"org.freedesktop.MediaPlayer\">\n"
124 " <method name=\"GetStatus\">\n"
125 " <arg type=\"(iiii)\" direction=\"out\" />\n"
127 " <method name=\"Prev\">\n"
129 " <method name=\"Next\">\n"
131 " <method name=\"Stop\">\n"
133 " <method name=\"Play\">\n"
135 " <method name=\"Pause\">\n"
137 " <method name=\"Repeat\">\n"
138 " <arg type=\"b\" direction=\"in\" />\n"
140 " <method name=\"VolumeSet\">\n"
141 " <arg type=\"i\" direction=\"in\" />\n"
143 " <method name=\"VolumeGet\">\n"
144 " <arg type=\"i\" direction=\"out\" />\n"
146 " <method name=\"PositionSet\">\n"
147 " <arg type=\"i\" direction=\"in\" />\n"
149 " <method name=\"PositionGet\">\n"
150 " <arg type=\"i\" direction=\"out\" />\n"
152 " <method name=\"GetMetadata\">\n"
153 " <arg type=\"a{sv}\" direction=\"out\" />\n"
155 " <method name=\"GetCaps\">\n"
156 " <arg type=\"i\" direction=\"out\" />\n"
158 " <signal name=\"TrackChange\">\n"
159 " <arg type=\"a{sv}\"/>\n"
161 " <signal name=\"StatusChange\">\n"
162 " <arg type=\"(iiii)\"/>\n"
164 " <signal name=\"CapsChange\">\n"
165 " <arg type=\"i\"/>\n"
171 const char* psz_introspection_xml_data_tracklist =
172 "<!DOCTYPE node PUBLIC \"-//freedesktop//DTD D-BUS Object Introspection 1.0//EN\"\n"
173 "\"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd\">\n"
175 " <interface name=\"org.freedesktop.DBus.Introspectable\">\n"
176 " <method name=\"Introspect\">\n"
177 " <arg name=\"data\" direction=\"out\" type=\"s\"/>\n"
180 " <interface name=\"org.freedesktop.MediaPlayer\">\n"
181 " <method name=\"AddTrack\">\n"
182 " <arg type=\"s\" direction=\"in\" />\n"
183 " <arg type=\"b\" direction=\"in\" />\n"
184 " <arg type=\"i\" direction=\"out\" />\n"
186 " <method name=\"DelTrack\">\n"
187 " <arg type=\"i\" direction=\"in\" />\n"
189 " <method name=\"GetMetadata\">\n"
190 " <arg type=\"i\" direction=\"in\" />\n"
191 " <arg type=\"a{sv}\" direction=\"out\" />\n"
193 " <method name=\"GetCurrentTrack\">\n"
194 " <arg type=\"i\" direction=\"out\" />\n"
196 " <method name=\"GetLength\">\n"
197 " <arg type=\"i\" direction=\"out\" />\n"
199 " <method name=\"SetLoop\">\n"
200 " <arg type=\"b\" direction=\"in\" />\n"
202 " <method name=\"SetRandom\">\n"
203 " <arg type=\"b\" direction=\"in\" />\n"
205 " <signal name=\"TrackListChange\">\n"
206 " <arg type=\"i\" />\n"
213 /* Handle messages reception */
214 DBUS_METHOD( handle_root );
215 DBUS_METHOD( handle_player );
216 DBUS_METHOD( handle_tracklist );
218 static const DBusObjectPathVTable vlc_dbus_root_vtable = {
219 NULL, handle_root, /* handler function */
220 NULL, NULL, NULL, NULL
223 static const DBusObjectPathVTable vlc_dbus_player_vtable = {
224 NULL, handle_player, /* handler function */
225 NULL, NULL, NULL, NULL
228 static const DBusObjectPathVTable vlc_dbus_tracklist_vtable = {
229 NULL, handle_tracklist, /* handler function */
230 NULL, NULL, NULL, NULL