1 /*****************************************************************************
2 * dbus.h : D-Bus control interface
3 *****************************************************************************
4 * Copyright (C) 2006 Rafaël Carré
7 * Author: Rafaël Carré <funman at videolanorg>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 /* DBUS IDENTIFIERS */
26 /* name registered on the session bus */
27 #define VLC_DBUS_SERVICE "org.freedesktop.MediaPlayer"
28 #define VLC_DBUS_INTERFACE "org.freedesktop.MediaPlayer"
29 #define VLC_DBUS_ROOT_PATH "/"
30 #define VLC_DBUS_PLAYER_PATH "/Player"
31 #define VLC_DBUS_TRACKLIST_PATH "/TrackList"
35 #define DBUS_METHOD( method_function ) \
36 static DBusHandlerResult method_function \
37 ( DBusConnection *p_conn, DBusMessage *p_from, void *p_this )
39 #define DBUS_SIGNAL( signal_function ) \
40 static DBusHandlerResult signal_function \
41 ( DBusConnection *p_conn, void *p_data )
44 DBusMessage* p_msg = dbus_message_new_method_return( p_from ); \
45 if( !p_msg ) return DBUS_HANDLER_RESULT_NEED_MEMORY; \
48 if( !dbus_connection_send( p_conn, p_msg, NULL ) ) \
49 return DBUS_HANDLER_RESULT_NEED_MEMORY; \
50 dbus_connection_flush( p_conn ); \
51 dbus_message_unref( p_msg ); \
52 return DBUS_HANDLER_RESULT_HANDLED
54 #define SIGNAL_INIT( signal ) \
55 DBusMessage *p_msg = dbus_message_new_signal( VLC_DBUS_PLAYER_PATH, \
56 VLC_DBUS_INTERFACE, signal ); \
57 if( !p_msg ) return DBUS_HANDLER_RESULT_NEED_MEMORY; \
60 if( !dbus_connection_send( p_conn, p_msg, NULL ) ) \
61 return DBUS_HANDLER_RESULT_NEED_MEMORY; \
62 dbus_message_unref( p_msg ); \
63 dbus_connection_flush( p_conn ); \
64 return DBUS_HANDLER_RESULT_HANDLED
66 #define OUT_ARGUMENTS \
67 DBusMessageIter args; \
68 dbus_message_iter_init_append( p_msg, &args )
70 #define DBUS_ADD( dbus_type, value ) \
71 if( !dbus_message_iter_append_basic( &args, dbus_type, value ) ) \
72 return DBUS_HANDLER_RESULT_NEED_MEMORY
74 #define ADD_STRING( s ) DBUS_ADD( DBUS_TYPE_STRING, s )
75 #define ADD_BOOL( b ) DBUS_ADD( DBUS_TYPE_BOOLEAN, b )
76 #define ADD_INT32( i ) DBUS_ADD( DBUS_TYPE_INT32, i )
77 #define ADD_BYTE( b ) DBUS_ADD( DBUS_TYPE_BYTE, b )
79 /* XML data to answer org.freedesktop.DBus.Introspectable.Introspect requests */
81 const char* psz_introspection_xml_data_root =
82 "<!DOCTYPE node PUBLIC \"-//freedesktop//DTD D-BUS Object Introspection 1.0//EN\"\n"
83 "\"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd\">\n"
85 " <interface name=\"org.freedesktop.DBus.Introspectable\">\n"
86 " <method name=\"Introspect\">\n"
87 " <arg name=\"data\" direction=\"out\" type=\"s\"/>\n"
90 " <interface name=\"org.freedesktop.MediaPlayer\">\n"
91 " <method name=\"Identity\">\n"
92 " <arg type=\"s\" direction=\"out\" />\n"
98 const char* psz_introspection_xml_data_player =
99 "<!DOCTYPE node PUBLIC \"-//freedesktop//DTD D-BUS Object Introspection 1.0//EN\"\n"
100 "\"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd\">\n"
102 " <interface name=\"org.freedesktop.DBus.Introspectable\">\n"
103 " <method name=\"Introspect\">\n"
104 " <arg name=\"data\" direction=\"out\" type=\"s\"/>\n"
107 " <interface name=\"org.videolan.vlc\">\n"
108 " <method name=\"GetStatus\">\n"
109 " <arg type=\"i\" direction=\"out\" />\n"
111 " <method name=\"Quit\">\n"
113 " <method name=\"Prev\">\n"
115 " <method name=\"Next\">\n"
117 " <method name=\"Stop\">\n"
119 " <method name=\"Play\">\n"
121 " <method name=\"Pause\">\n"
123 " <method name=\"VolumeSet\">\n"
124 " <arg type=\"i\" direction=\"in\" />\n"
126 " <method name=\"VolumeGet\">\n"
127 " <arg type=\"i\" direction=\"out\" />\n"
129 " <method name=\"PositionSet\">\n"
130 " <arg type=\"i\" direction=\"in\" />\n"
132 " <method name=\"PositionGet\">\n"
133 " <arg type=\"i\" direction=\"out\" />\n"
139 const char* psz_introspection_xml_data_tracklist =
140 "<!DOCTYPE node PUBLIC \"-//freedesktop//DTD D-BUS Object Introspection 1.0//EN\"\n"
141 "\"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd\">\n"
143 " <interface name=\"org.freedesktop.DBus.Introspectable\">\n"
144 " <method name=\"Introspect\">\n"
145 " <arg name=\"data\" direction=\"out\" type=\"s\"/>\n"
148 " <interface name=\"org.videolan.vlc\">\n"
149 " <method name=\"AddTrack\">\n"
150 " <arg type=\"s\" direction=\"in\" />\n"
151 " <arg type=\"b\" direction=\"in\" />\n"
153 " <method name=\"DelTrack\">\n"
154 " <arg type=\"i\" direction=\"in\" />\n"
156 " <method name=\"GetMetadata\">\n"
157 " <arg type=\"i\" direction=\"in\" />\n"
158 " <arg type=\"a{sv}\" direction=\"out\" />\n"
160 " <method name=\"GetCurrentTrack\">\n"
161 " <arg type=\"i\" direction=\"out\" />\n"
163 " <method name=\"GetLength\">\n"
164 " <arg type=\"i\" direction=\"out\" />\n"
170 #define VLC_DBUS_ROOT_PATH "/"
171 #define VLC_DBUS_PLAYER_PATH "/Player"
172 #define VLC_DBUS_TRACKLIST_PATH "/TrackList"
174 /* Handle messages reception */
175 DBUS_METHOD( handle_root );
176 DBUS_METHOD( handle_player );
177 DBUS_METHOD( handle_tracklist );
179 static DBusObjectPathVTable vlc_dbus_root_vtable = {
180 NULL, handle_root, /* handler function */
181 NULL, NULL, NULL, NULL
184 static DBusObjectPathVTable vlc_dbus_player_vtable = {
185 NULL, handle_player, /* handler function */
186 NULL, NULL, NULL, NULL
189 static DBusObjectPathVTable vlc_dbus_tracklist_vtable = {
190 NULL, handle_tracklist, /* handler function */
191 NULL, NULL, NULL, NULL