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"
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( VLC_DBUS_PLAYER_PATH, \
57 VLC_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 )
82 p_tested_item = playlist_GetNextLeaf( p_playlist, \
83 p_playlist->p_root_onelevel, p_tested_item, VLC_FALSE, VLC_FALSE );
85 /* XML data to answer org.freedesktop.DBus.Introspectable.Introspect requests */
87 const char* psz_introspection_xml_data_root =
88 "<!DOCTYPE node PUBLIC \"-//freedesktop//DTD D-BUS Object Introspection 1.0//EN\"\n"
89 "\"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd\">\n"
91 " <interface name=\"org.freedesktop.DBus.Introspectable\">\n"
92 " <method name=\"Introspect\">\n"
93 " <arg name=\"data\" direction=\"out\" type=\"s\"/>\n"
96 " <interface name=\"org.freedesktop.MediaPlayer\">\n"
97 " <method name=\"Identity\">\n"
98 " <arg type=\"s\" direction=\"out\" />\n"
104 const char* psz_introspection_xml_data_player =
105 "<!DOCTYPE node PUBLIC \"-//freedesktop//DTD D-BUS Object Introspection 1.0//EN\"\n"
106 "\"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd\">\n"
108 " <interface name=\"org.freedesktop.DBus.Introspectable\">\n"
109 " <method name=\"Introspect\">\n"
110 " <arg name=\"data\" direction=\"out\" type=\"s\"/>\n"
113 " <interface name=\"org.videolan.vlc\">\n"
114 " <method name=\"GetStatus\">\n"
115 " <arg type=\"i\" direction=\"out\" />\n"
117 " <method name=\"Quit\">\n"
119 " <method name=\"Prev\">\n"
121 " <method name=\"Next\">\n"
123 " <method name=\"Stop\">\n"
125 " <method name=\"Play\">\n"
127 " <method name=\"Pause\">\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"
145 const char* psz_introspection_xml_data_tracklist =
146 "<!DOCTYPE node PUBLIC \"-//freedesktop//DTD D-BUS Object Introspection 1.0//EN\"\n"
147 "\"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd\">\n"
149 " <interface name=\"org.freedesktop.DBus.Introspectable\">\n"
150 " <method name=\"Introspect\">\n"
151 " <arg name=\"data\" direction=\"out\" type=\"s\"/>\n"
154 " <interface name=\"org.videolan.vlc\">\n"
155 " <method name=\"AddTrack\">\n"
156 " <arg type=\"s\" direction=\"in\" />\n"
157 " <arg type=\"b\" direction=\"in\" />\n"
159 " <method name=\"DelTrack\">\n"
160 " <arg type=\"i\" direction=\"in\" />\n"
162 " <method name=\"GetMetadata\">\n"
163 " <arg type=\"i\" direction=\"in\" />\n"
164 " <arg type=\"a{sv}\" direction=\"out\" />\n"
166 " <method name=\"GetCurrentTrack\">\n"
167 " <arg type=\"i\" direction=\"out\" />\n"
169 " <method name=\"GetLength\">\n"
170 " <arg type=\"i\" direction=\"out\" />\n"
176 #define VLC_DBUS_ROOT_PATH "/"
177 #define VLC_DBUS_PLAYER_PATH "/Player"
178 #define VLC_DBUS_TRACKLIST_PATH "/TrackList"
180 /* Handle messages reception */
181 DBUS_METHOD( handle_root );
182 DBUS_METHOD( handle_player );
183 DBUS_METHOD( handle_tracklist );
185 static DBusObjectPathVTable vlc_dbus_root_vtable = {
186 NULL, handle_root, /* handler function */
187 NULL, NULL, NULL, NULL
190 static DBusObjectPathVTable vlc_dbus_player_vtable = {
191 NULL, handle_player, /* handler function */
192 NULL, NULL, NULL, NULL
195 static DBusObjectPathVTable vlc_dbus_tracklist_vtable = {
196 NULL, handle_tracklist, /* handler function */
197 NULL, NULL, NULL, NULL