]> git.sesse.net Git - vlc/blob - modules/control/dbus.h
edb5904ed1968d9a9841560ccd58c693c22fc9bd
[vlc] / 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 /* MPRIS VERSION */
26 #define VLC_MPRIS_VERSION_MAJOR     1
27 #define VLC_MPRIS_VERSION_MINOR     0
28
29 /* DBUS IDENTIFIERS */
30
31 /* name registered on the session bus */
32 #define VLC_MPRIS_DBUS_SERVICE         "org.mpris.vlc"
33
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"
37
38 #define MPRIS_DBUS_ROOT_PATH        "/"
39 #define MPRIS_DBUS_PLAYER_PATH      "/Player"
40 #define MPRIS_DBUS_TRACKLIST_PATH   "/TrackList"
41
42 /* MACROS */
43
44 #define DBUS_METHOD( method_function ) \
45     static DBusHandlerResult method_function \
46             ( DBusConnection *p_conn, DBusMessage *p_from, void *p_this )
47
48 #define DBUS_SIGNAL( signal_function ) \
49     static DBusHandlerResult signal_function \
50             ( DBusConnection *p_conn, void *p_data )
51
52 #define REPLY_INIT \
53     DBusMessage* p_msg = dbus_message_new_method_return( p_from ); \
54     if( !p_msg ) return DBUS_HANDLER_RESULT_NEED_MEMORY; \
55
56 #define REPLY_SEND \
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
62
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; \
67
68 #define SIGNAL_SEND \
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
74
75 #define OUT_ARGUMENTS \
76     DBusMessageIter args; \
77     dbus_message_iter_init_append( p_msg, &args )
78
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
82
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 )
87
88 /* XML data to answer org.freedesktop.DBus.Introspectable.Introspect requests */
89
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"
93 "<node>\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"
99 "    </method>\n"
100 "  </interface>\n"
101 "  <interface name=\"org.freedesktop.MediaPlayer\">\n"
102 "    <method name=\"Identity\">\n"
103 "      <arg type=\"s\" direction=\"out\" />\n"
104 "    </method>\n"
105 "    <method name=\"MprisVersion\">\n"
106 "      <arg type=\"(qq)\" direction=\"out\" />\n"
107 "    </method>\n"
108 "    <method name=\"Quit\">\n"
109 "    </method>\n"
110 "  </interface>\n"
111 "</node>\n"
112 ;
113
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"
117 "<node>"
118 "  <interface name=\"org.freedesktop.DBus.Introspectable\">\n"
119 "    <method name=\"Introspect\">\n"
120 "      <arg name=\"data\" direction=\"out\" type=\"s\"/>\n"
121 "    </method>\n"
122 "  </interface>\n"
123 "  <interface name=\"org.freedesktop.MediaPlayer\">\n"
124 "    <method name=\"GetStatus\">\n"
125 "      <arg type=\"(iiii)\" direction=\"out\" />\n"
126 "    </method>\n"
127 "    <method name=\"Prev\">\n"
128 "    </method>\n"
129 "    <method name=\"Next\">\n"
130 "    </method>\n"
131 "    <method name=\"Stop\">\n"
132 "    </method>\n"
133 "    <method name=\"Play\">\n"
134 "    </method>\n"
135 "    <method name=\"Pause\">\n"
136 "    </method>\n"
137 "    <method name=\"Repeat\">\n"
138 "      <arg type=\"b\" direction=\"in\" />\n"
139 "    </method>\n"
140 "    <method name=\"VolumeSet\">\n"
141 "      <arg type=\"i\" direction=\"in\" />\n"
142 "    </method>\n"
143 "    <method name=\"VolumeGet\">\n"
144 "      <arg type=\"i\" direction=\"out\" />\n"
145 "    </method>\n"
146 "    <method name=\"PositionSet\">\n"
147 "      <arg type=\"i\" direction=\"in\" />\n"
148 "    </method>\n"
149 "    <method name=\"PositionGet\">\n"
150 "      <arg type=\"i\" direction=\"out\" />\n"
151 "    </method>\n"
152 "    <method name=\"GetMetadata\">\n"
153 "      <arg type=\"a{sv}\" direction=\"out\" />\n"
154 "    </method>\n"
155 "    <method name=\"GetCaps\">\n"
156 "      <arg type=\"i\" direction=\"out\" />\n"
157 "    </method>\n"
158 "    <signal name=\"TrackChange\">\n"
159 "      <arg type=\"a{sv}\"/>\n"
160 "    </signal>\n"
161 "    <signal name=\"StatusChange\">\n"
162 "      <arg type=\"(iiii)\"/>\n"
163 "    </signal>\n"
164 "    <signal name=\"CapsChange\">\n"
165 "      <arg type=\"i\"/>\n"
166 "    </signal>\n"
167 "  </interface>\n"
168 "</node>\n"
169 ;
170
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"
174 "<node>"
175 "  <interface name=\"org.freedesktop.DBus.Introspectable\">\n"
176 "    <method name=\"Introspect\">\n"
177 "      <arg name=\"data\" direction=\"out\" type=\"s\"/>\n"
178 "    </method>\n"
179 "  </interface>\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"
185 "    </method>\n"
186 "    <method name=\"DelTrack\">\n"
187 "      <arg type=\"i\" direction=\"in\" />\n"
188 "    </method>\n"
189 "    <method name=\"GetMetadata\">\n"
190 "      <arg type=\"i\" direction=\"in\" />\n"
191 "      <arg type=\"a{sv}\" direction=\"out\" />\n"
192 "    </method>\n"
193 "    <method name=\"GetCurrentTrack\">\n"
194 "      <arg type=\"i\" direction=\"out\" />\n"
195 "    </method>\n"
196 "    <method name=\"GetLength\">\n"
197 "      <arg type=\"i\" direction=\"out\" />\n"
198 "    </method>\n"
199 "    <method name=\"SetLoop\">\n"
200 "      <arg type=\"b\" direction=\"in\" />\n"
201 "    </method>\n"
202 "    <method name=\"SetRandom\">\n"
203 "      <arg type=\"b\" direction=\"in\" />\n"
204 "    </method>\n"
205 "    <signal name=\"TrackListChange\">\n"
206 "      <arg type=\"i\" />\n"
207 "    </signal>\n"
208 "  </interface>\n"
209 "</node>\n"
210 ;
211
212
213 /* Handle  messages reception */
214 DBUS_METHOD( handle_root );
215 DBUS_METHOD( handle_player );
216 DBUS_METHOD( handle_tracklist );
217
218 static const DBusObjectPathVTable vlc_dbus_root_vtable = {
219         NULL, handle_root, /* handler function */
220         NULL, NULL, NULL, NULL
221 };
222
223 static const DBusObjectPathVTable vlc_dbus_player_vtable = {
224         NULL, handle_player, /* handler function */
225         NULL, NULL, NULL, NULL
226 };
227
228 static const DBusObjectPathVTable vlc_dbus_tracklist_vtable = {
229         NULL, handle_tracklist, /* handler function */
230         NULL, NULL, NULL, NULL
231 };
232