]> git.sesse.net Git - vlc/blob - modules/control/dbus.h
D-Bus control module
[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 /* DBUS IDENTIFIERS */
26
27 /* name registered on the session bus */
28 #define VLC_MPRIS_DBUS_SERVICE      "org.mpris.vlc"
29 #define MPRIS_DBUS_INTERFACE        "org.freedesktop.MediaPlayer"
30 #define MPRIS_DBUS_ROOT_PATH        "/"
31 #define MPRIS_DBUS_PLAYER_PATH      "/Player"
32 #define MPRIS_DBUS_TRACKLIST_PATH   "/TrackList"
33
34 /* MACROS */
35
36 #define DBUS_METHOD( method_function ) \
37     static DBusHandlerResult method_function \
38             ( DBusConnection *p_conn, DBusMessage *p_from, void *p_this )
39
40 #define DBUS_SIGNAL( signal_function ) \
41     static DBusHandlerResult signal_function \
42             ( DBusConnection *p_conn, void *p_data )
43
44 #define REPLY_INIT \
45     DBusMessage* p_msg = dbus_message_new_method_return( p_from ); \
46     if( !p_msg ) return DBUS_HANDLER_RESULT_NEED_MEMORY; \
47
48 #define REPLY_SEND \
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
54
55 #define SIGNAL_INIT( signal ) \
56     DBusMessage *p_msg = dbus_message_new_signal( MPRIS_DBUS_PLAYER_PATH, \
57         MPRIS_DBUS_INTERFACE, signal ); \
58     if( !p_msg ) return DBUS_HANDLER_RESULT_NEED_MEMORY; \
59
60 #define SIGNAL_SEND \
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
66
67 #define OUT_ARGUMENTS \
68     DBusMessageIter args; \
69     dbus_message_iter_init_append( p_msg, &args )
70
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
74
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 )
79
80 /* XML data to answer org.freedesktop.DBus.Introspectable.Introspect requests */
81
82 const char* psz_introspection_xml_data_root =
83 "<!DOCTYPE node PUBLIC \"-//freedesktop//DTD D-BUS Object Introspection 1.0//EN\"\n"
84 "\"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd\">\n"
85 "<node>\n"
86 "  <node name=\"Player\"/>\n"
87 "  <node name=\"TrackList\"/>\n"
88 "  <interface name=\"org.freedesktop.DBus.Introspectable\">\n"
89 "    <method name=\"Introspect\">\n"
90 "      <arg name=\"data\" direction=\"out\" type=\"s\"/>\n"
91 "    </method>\n"
92 "  </interface>\n"
93 "  <interface name=\"org.freedesktop.MediaPlayer\">\n"
94 "    <method name=\"Identity\">\n"
95 "      <arg type=\"s\" direction=\"out\" />\n"
96 "    </method>\n"
97 "  </interface>\n"
98 "</node>\n"
99 ;
100
101 const char* psz_introspection_xml_data_player =
102 "<!DOCTYPE node PUBLIC \"-//freedesktop//DTD D-BUS Object Introspection 1.0//EN\"\n"
103 "\"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd\">\n"
104 "<node>"
105 "  <interface name=\"org.freedesktop.DBus.Introspectable\">\n"
106 "    <method name=\"Introspect\">\n"
107 "      <arg name=\"data\" direction=\"out\" type=\"s\"/>\n"
108 "    </method>\n"
109 "  </interface>\n"
110 "  <interface name=\"org.freedesktop.MediaPlayer\">\n"
111 "    <method name=\"GetStatus\">\n"
112 "      <arg type=\"(iiii)\" direction=\"out\" />\n"
113 "    </method>\n"
114 "    <method name=\"Quit\">\n"
115 "    </method>\n"
116 "    <method name=\"Prev\">\n"
117 "    </method>\n"
118 "    <method name=\"Next\">\n"
119 "    </method>\n"
120 "    <method name=\"Stop\">\n"
121 "    </method>\n"
122 "    <method name=\"Play\">\n"
123 "    </method>\n"
124 "    <method name=\"Pause\">\n"
125 "    </method>\n"
126 "    <method name=\"Repeat\">\n"
127 "      <arg type=\"b\" direction=\"in\" />\n"
128 "    </method>\n"
129 "    <method name=\"VolumeSet\">\n"
130 "      <arg type=\"i\" direction=\"in\" />\n"
131 "    </method>\n"
132 "    <method name=\"VolumeGet\">\n"
133 "      <arg type=\"i\" direction=\"out\" />\n"
134 "    </method>\n"
135 "    <method name=\"PositionSet\">\n"
136 "      <arg type=\"i\" direction=\"in\" />\n"
137 "    </method>\n"
138 "    <method name=\"PositionGet\">\n"
139 "      <arg type=\"i\" direction=\"out\" />\n"
140 "    </method>\n"
141 "    <method name=\"GetMetadata\">\n"
142 "      <arg type=\"a{sv}\" direction=\"out\" />\n"
143 "    </method>\n"
144 "    <method name=\"GetCaps\">\n"
145 "      <arg type=\"i\" direction=\"out\" />\n"
146 "    </method>\n"
147 "    <signal name=\"TrackChange\">\n"
148 "      <arg type=\"a{sv}\"/>\n"
149 "    </signal>\n"
150 "    <signal name=\"StatusChange\">\n"
151 "      <arg type=\"(iiii)\"/>\n"
152 "    </signal>\n"
153 "    <signal name=\"CapsChange\">\n"
154 "      <arg type=\"i\"/>\n"
155 "    </signal>\n"
156 "  </interface>\n"
157 "</node>\n"
158 ;
159
160 const char* psz_introspection_xml_data_tracklist =
161 "<!DOCTYPE node PUBLIC \"-//freedesktop//DTD D-BUS Object Introspection 1.0//EN\"\n"
162 "\"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd\">\n"
163 "<node>"
164 "  <interface name=\"org.freedesktop.DBus.Introspectable\">\n"
165 "    <method name=\"Introspect\">\n"
166 "      <arg name=\"data\" direction=\"out\" type=\"s\"/>\n"
167 "    </method>\n"
168 "  </interface>\n"
169 "  <interface name=\"org.freedesktop.MediaPlayer\">\n"
170 "    <method name=\"AddTrack\">\n"
171 "      <arg type=\"s\" direction=\"in\" />\n"
172 "      <arg type=\"b\" direction=\"in\" />\n"
173 "    </method>\n"
174 "    <method name=\"DelTrack\">\n"
175 "      <arg type=\"i\" direction=\"in\" />\n"
176 "    </method>\n"
177 "    <method name=\"GetMetadata\">\n"
178 "      <arg type=\"i\" direction=\"in\" />\n"
179 "      <arg type=\"a{sv}\" direction=\"out\" />\n"
180 "    </method>\n"
181 "    <method name=\"GetCurrentTrack\">\n"
182 "      <arg type=\"i\" direction=\"out\" />\n"
183 "    </method>\n"
184 "    <method name=\"GetLength\">\n"
185 "      <arg type=\"i\" direction=\"out\" />\n"
186 "    </method>\n"
187 "    <method name=\"Loop\">\n"
188 "      <arg type=\"b\" direction=\"in\" />\n"
189 "    </method>\n"
190 "    <method name=\"Random\">\n"
191 "      <arg type=\"b\" direction=\"in\" />\n"
192 "    </method>\n"
193 "    <signal name=\"TrackListChange\">\n"
194 "      <arg type=\"i\" />\n"
195 "    </signal>\n"
196 "  </interface>\n"
197 "</node>\n"
198 ;
199
200 #define MPRIS_DBUS_ROOT_PATH      "/"
201 #define MPRIS_DBUS_PLAYER_PATH    "/Player"
202 #define MPRIS_DBUS_TRACKLIST_PATH "/TrackList"
203
204 /* Handle  messages reception */
205 DBUS_METHOD( handle_root );
206 DBUS_METHOD( handle_player );
207 DBUS_METHOD( handle_tracklist );
208
209 static DBusObjectPathVTable vlc_dbus_root_vtable = {
210         NULL, handle_root, /* handler function */
211         NULL, NULL, NULL, NULL
212 };
213
214 static DBusObjectPathVTable vlc_dbus_player_vtable = {
215         NULL, handle_player, /* handler function */
216         NULL, NULL, NULL, NULL
217 };
218
219 static DBusObjectPathVTable vlc_dbus_tracklist_vtable = {
220         NULL, handle_tracklist, /* handler function */
221         NULL, NULL, NULL, NULL
222 };
223