Returns object hierarchy with root object introspection data. Thanks to eean.
[vlc.git] / modules / control / dbus.h
1 /*****************************************************************************
2  * dbus.h : D-Bus control interface
3  *****************************************************************************
4  * Copyright (C) 2006 Rafaël Carré
5  * $Id$
6  *
7  * Authors:    Rafaël Carré <funman at videolanorg>
8  *             Mirsal ENNAIME <mirsal dot ennaime at gmail dot com>
9  *
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.
14  *
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.
19  *
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  *****************************************************************************/
24
25 /* DBUS IDENTIFIERS */
26
27 /* name registered on the session bus */
28 #define VLC_DBUS_SERVICE        "org.mpris.vlc"
29 #define VLC_DBUS_INTERFACE      "org.freedesktop.MediaPlayer"
30 #define VLC_DBUS_ROOT_PATH      "/"
31 #define VLC_DBUS_PLAYER_PATH    "/Player"
32 #define VLC_DBUS_TRACKLIST_PATH "/TrackList"
33
34 /* MACROS */
35
36 /* DBus related */
37 #define DBUS_METHOD( method_function ) \
38     static DBusHandlerResult method_function \
39             ( DBusConnection *p_conn, DBusMessage *p_from, void *p_this ) 
40
41 #define DBUS_SIGNAL( signal_function ) \
42     static DBusHandlerResult signal_function \
43             ( DBusConnection *p_conn, void *p_data )
44
45 #define REPLY_INIT \
46     DBusMessage* p_msg = dbus_message_new_method_return( p_from ); \
47     if( !p_msg ) return DBUS_HANDLER_RESULT_NEED_MEMORY; \
48
49 #define REPLY_SEND \
50     if( !dbus_connection_send( p_conn, p_msg, NULL ) ) \
51         return DBUS_HANDLER_RESULT_NEED_MEMORY; \
52     dbus_connection_flush( p_conn ); \
53     dbus_message_unref( p_msg ); \
54     return DBUS_HANDLER_RESULT_HANDLED
55
56 #define SIGNAL_INIT( signal ) \
57     DBusMessage *p_msg = dbus_message_new_signal( VLC_DBUS_PLAYER_PATH, \
58         VLC_DBUS_INTERFACE, signal ); \
59     if( !p_msg ) return DBUS_HANDLER_RESULT_NEED_MEMORY; \
60
61 #define SIGNAL_SEND \
62     if( !dbus_connection_send( p_conn, p_msg, NULL ) ) \
63         return DBUS_HANDLER_RESULT_NEED_MEMORY; \
64     dbus_message_unref( p_msg ); \
65     dbus_connection_flush( p_conn ); \
66     return DBUS_HANDLER_RESULT_HANDLED
67
68 #define OUT_ARGUMENTS \
69     DBusMessageIter args; \
70     dbus_message_iter_init_append( p_msg, &args )
71
72 #define DBUS_ADD( dbus_type, value ) \
73     if( !dbus_message_iter_append_basic( &args, dbus_type, value ) ) \
74         return DBUS_HANDLER_RESULT_NEED_MEMORY
75
76 #define ADD_STRING( s ) DBUS_ADD( DBUS_TYPE_STRING, s )
77 #define ADD_BOOL( b ) DBUS_ADD( DBUS_TYPE_BOOLEAN, b )
78 #define ADD_INT32( i ) DBUS_ADD( DBUS_TYPE_INT32, i )
79 #define ADD_BYTE( b ) DBUS_ADD( DBUS_TYPE_BYTE, b )
80
81 /* VLC related */
82 #define TEST_NEXT \
83     p_tested_item = playlist_GetNextLeaf( p_playlist, \
84             p_playlist->p_root_onelevel, p_tested_item, VLC_FALSE, VLC_FALSE );
85
86 /* XML data to answer org.freedesktop.DBus.Introspectable.Introspect requests */
87
88 const char* psz_introspection_xml_data_root =
89 "<!DOCTYPE node PUBLIC \"-//freedesktop//DTD D-BUS Object Introspection 1.0//EN\"\n"
90 "\"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd\">\n"
91 "<node>\n"
92 "  <node name=\"Player\"/>\n"
93 "  <node name=\"TrackList\"/>\n"
94 "  <interface name=\"org.freedesktop.DBus.Introspectable\">\n"
95 "    <method name=\"Introspect\">\n"
96 "      <arg name=\"data\" direction=\"out\" type=\"s\"/>\n"
97 "    </method>\n"
98 "  </interface>\n"
99 "  <interface name=\"org.freedesktop.MediaPlayer\">\n"
100 "    <method name=\"Identity\">\n"
101 "      <arg type=\"s\" direction=\"out\" />\n"
102 "    </method>\n"
103 "  </interface>\n"
104 "</node>\n"
105 ;
106
107 const char* psz_introspection_xml_data_player =
108 "<!DOCTYPE node PUBLIC \"-//freedesktop//DTD D-BUS Object Introspection 1.0//EN\"\n"
109 "\"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd\">\n"
110 "<node>"
111 "  <interface name=\"org.freedesktop.DBus.Introspectable\">\n"
112 "    <method name=\"Introspect\">\n"
113 "      <arg name=\"data\" direction=\"out\" type=\"s\"/>\n"
114 "    </method>\n"
115 "  </interface>\n"
116 "  <interface name=\"org.freedesktop.MediaPlayer\">\n"
117 "    <method name=\"GetStatus\">\n"
118 "      <arg type=\"i\" direction=\"out\" />\n"
119 "    </method>\n"
120 "    <method name=\"Quit\">\n"
121 "    </method>\n"
122 "    <method name=\"Prev\">\n"
123 "    </method>\n"
124 "    <method name=\"Next\">\n"
125 "    </method>\n"
126 "    <method name=\"Stop\">\n"
127 "    </method>\n"
128 "    <method name=\"Play\">\n"
129 "    </method>\n"
130 "    <method name=\"Pause\">\n"
131 "    </method>\n"
132 "    <method name=\"Repeat\">\n"
133 "      <arg type=\"b\" direction=\"in\" />\n"
134 "    </method>\n"
135 "    <method name=\"VolumeSet\">\n"
136 "      <arg type=\"i\" direction=\"in\" />\n"
137 "    </method>\n"
138 "    <method name=\"VolumeGet\">\n"
139 "      <arg type=\"i\" direction=\"out\" />\n"
140 "    </method>\n"
141 "    <method name=\"PositionSet\">\n"
142 "      <arg type=\"i\" direction=\"in\" />\n"
143 "    </method>\n"
144 "    <method name=\"PositionGet\">\n"
145 "      <arg type=\"i\" direction=\"out\" />\n"
146 "    </method>\n"
147 "    <method name=\"GetMetadata\">\n"
148 "      <arg type=\"a{sv}\" direction=\"out\" />\n"
149 "    </method>\n"
150 "    <method name=\"Disconnect\">\n"
151 "    </method>\n"
152 "  </interface>\n"
153 "</node>\n"
154 ;
155
156 const char* psz_introspection_xml_data_tracklist =
157 "<!DOCTYPE node PUBLIC \"-//freedesktop//DTD D-BUS Object Introspection 1.0//EN\"\n"
158 "\"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd\">\n"
159 "<node>"
160 "  <interface name=\"org.freedesktop.DBus.Introspectable\">\n"
161 "    <method name=\"Introspect\">\n"
162 "      <arg name=\"data\" direction=\"out\" type=\"s\"/>\n"
163 "    </method>\n"
164 "  </interface>\n"
165 "  <interface name=\"org.freedesktop.MediaPlayer\">\n"
166 "    <method name=\"AddTrack\">\n"
167 "      <arg type=\"s\" direction=\"in\" />\n"
168 "      <arg type=\"b\" direction=\"in\" />\n"
169 "    </method>\n"
170 "    <method name=\"DelTrack\">\n"
171 "      <arg type=\"i\" direction=\"in\" />\n"
172 "    </method>\n"
173 "    <method name=\"GetMetadata\">\n"
174 "      <arg type=\"i\" direction=\"in\" />\n"
175 "      <arg type=\"a{sv}\" direction=\"out\" />\n"
176 "    </method>\n"
177 "    <method name=\"GetCurrentTrack\">\n"
178 "      <arg type=\"i\" direction=\"out\" />\n"
179 "    </method>\n"
180 "    <method name=\"GetLength\">\n"
181 "      <arg type=\"i\" direction=\"out\" />\n"
182 "    </method>\n"
183 "    <method name=\"Loop\">\n"
184 "      <arg type=\"b\" direction=\"in\" />\n"
185 "    </method>\n"
186 "    <method name=\"Random\">\n"
187 "      <arg type=\"b\" direction=\"in\" />\n"
188 "    </method>\n"
189 "  </interface>\n"
190 "</node>\n"
191 ;
192
193 #define VLC_DBUS_ROOT_PATH      "/"
194 #define VLC_DBUS_PLAYER_PATH    "/Player"
195 #define VLC_DBUS_TRACKLIST_PATH "/TrackList"
196
197 /* Handle  messages reception */
198 DBUS_METHOD( handle_root );
199 DBUS_METHOD( handle_player );
200 DBUS_METHOD( handle_tracklist );
201
202 static DBusObjectPathVTable vlc_dbus_root_vtable = {
203         NULL, handle_root, /* handler function */
204         NULL, NULL, NULL, NULL
205 };
206
207 static DBusObjectPathVTable vlc_dbus_player_vtable = {
208         NULL, handle_player, /* handler function */
209         NULL, NULL, NULL, NULL
210 };
211
212 static DBusObjectPathVTable vlc_dbus_tracklist_vtable = {
213         NULL, handle_tracklist, /* handler function */
214         NULL, NULL, NULL, NULL
215 };
216