]> git.sesse.net Git - vlc/blob - modules/control/dbus.h
DBUS: fix by Mr_Mirsal
[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  * Author:    Rafaël Carré <funman at videolanorg>
8  *
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.
13  *
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.
18  *
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  *****************************************************************************/
23
24 /* DBUS IDENTIFIERS */
25
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"
32
33 /* MACROS */
34
35 /* DBus related */
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( VLC_DBUS_PLAYER_PATH, \
57         VLC_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 /* VLC related */
81 #define TEST_NEXT \
82     p_tested_item = playlist_GetNextLeaf( p_playlist, \
83             p_playlist->p_root_onelevel, p_tested_item, VLC_FALSE, VLC_FALSE );
84
85 /* XML data to answer org.freedesktop.DBus.Introspectable.Introspect requests */
86
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"
90 "<node>"
91 "  <interface name=\"org.freedesktop.DBus.Introspectable\">\n"
92 "    <method name=\"Introspect\">\n"
93 "      <arg name=\"data\" direction=\"out\" type=\"s\"/>\n"
94 "    </method>\n"
95 "  </interface>\n"
96 "  <interface name=\"org.freedesktop.MediaPlayer\">\n"
97 "    <method name=\"Identity\">\n"
98 "      <arg type=\"s\" direction=\"out\" />\n"
99 "    </method>\n"
100 "  </interface>\n"
101 "</node>\n"
102 ;
103
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"
107 "<node>"
108 "  <interface name=\"org.freedesktop.DBus.Introspectable\">\n"
109 "    <method name=\"Introspect\">\n"
110 "      <arg name=\"data\" direction=\"out\" type=\"s\"/>\n"
111 "    </method>\n"
112 "  </interface>\n"
113 "  <interface name=\"org.videolan.vlc\">\n"
114 "    <method name=\"GetStatus\">\n"
115 "      <arg type=\"i\" direction=\"out\" />\n"
116 "    </method>\n"
117 "    <method name=\"Quit\">\n"
118 "    </method>\n"
119 "    <method name=\"Prev\">\n"
120 "    </method>\n"
121 "    <method name=\"Next\">\n"
122 "    </method>\n"
123 "    <method name=\"Stop\">\n"
124 "    </method>\n"
125 "    <method name=\"Play\">\n"
126 "    </method>\n"
127 "    <method name=\"Pause\">\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 "  </interface>\n"
142 "</node>\n"
143 ;
144
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"
148 "<node>"
149 "  <interface name=\"org.freedesktop.DBus.Introspectable\">\n"
150 "    <method name=\"Introspect\">\n"
151 "      <arg name=\"data\" direction=\"out\" type=\"s\"/>\n"
152 "    </method>\n"
153 "  </interface>\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"
158 "    </method>\n"
159 "    <method name=\"DelTrack\">\n"
160 "      <arg type=\"i\" direction=\"in\" />\n"
161 "    </method>\n"
162 "    <method name=\"GetMetadata\">\n"
163 "      <arg type=\"i\" direction=\"in\" />\n"
164 "      <arg type=\"a{sv}\" direction=\"out\" />\n"
165 "    </method>\n"
166 "    <method name=\"GetCurrentTrack\">\n"
167 "      <arg type=\"i\" direction=\"out\" />\n"
168 "    </method>\n"
169 "    <method name=\"GetLength\">\n"
170 "      <arg type=\"i\" direction=\"out\" />\n"
171 "    </method>\n"
172 "  </interface>\n"
173 "</node>\n"
174 ;
175
176 #define VLC_DBUS_ROOT_PATH      "/"
177 #define VLC_DBUS_PLAYER_PATH    "/Player"
178 #define VLC_DBUS_TRACKLIST_PATH "/TrackList"
179
180 /* Handle  messages reception */
181 DBUS_METHOD( handle_root );
182 DBUS_METHOD( handle_player );
183 DBUS_METHOD( handle_tracklist );
184
185 static DBusObjectPathVTable vlc_dbus_root_vtable = {
186         NULL, handle_root, /* handler function */
187         NULL, NULL, NULL, NULL
188 };
189
190 static DBusObjectPathVTable vlc_dbus_player_vtable = {
191         NULL, handle_player, /* handler function */
192         NULL, NULL, NULL, NULL
193 };
194
195 static DBusObjectPathVTable vlc_dbus_tracklist_vtable = {
196         NULL, handle_tracklist, /* handler function */
197         NULL, NULL, NULL, NULL
198 };
199