a3d0d35a10b8489066bf63ee575df78f027131c1
[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  * 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 #define DBUS_METHOD( method_function ) \
36     static DBusHandlerResult method_function \
37             ( DBusConnection *p_conn, DBusMessage *p_from, void *p_this ) 
38
39 #define DBUS_SIGNAL( signal_function ) \
40     static DBusHandlerResult signal_function \
41             ( DBusConnection *p_conn, void *p_data )
42
43 #define REPLY_INIT \
44     DBusMessage* p_msg = dbus_message_new_method_return( p_from ); \
45     if( !p_msg ) return DBUS_HANDLER_RESULT_NEED_MEMORY; \
46
47 #define REPLY_SEND \
48     if( !dbus_connection_send( p_conn, p_msg, NULL ) ) \
49         return DBUS_HANDLER_RESULT_NEED_MEMORY; \
50     dbus_connection_flush( p_conn ); \
51     dbus_message_unref( p_msg ); \
52     return DBUS_HANDLER_RESULT_HANDLED
53
54 #define SIGNAL_INIT( signal ) \
55     DBusMessage *p_msg = dbus_message_new_signal( VLC_DBUS_PLAYER_PATH, \
56         VLC_DBUS_INTERFACE, signal ); \
57     if( !p_msg ) return DBUS_HANDLER_RESULT_NEED_MEMORY; \
58
59 #define SIGNAL_SEND \
60     if( !dbus_connection_send( p_conn, p_msg, NULL ) ) \
61     return DBUS_HANDLER_RESULT_NEED_MEMORY; \
62     dbus_message_unref( p_msg ); \
63     dbus_connection_flush( p_conn ); \
64     return DBUS_HANDLER_RESULT_HANDLED
65
66 #define OUT_ARGUMENTS \
67     DBusMessageIter args; \
68     dbus_message_iter_init_append( p_msg, &args )
69
70 #define DBUS_ADD( dbus_type, value ) \
71     if( !dbus_message_iter_append_basic( &args, dbus_type, value ) ) \
72         return DBUS_HANDLER_RESULT_NEED_MEMORY
73
74 #define ADD_STRING( s ) DBUS_ADD( DBUS_TYPE_STRING, s )
75 #define ADD_BOOL( b ) DBUS_ADD( DBUS_TYPE_BOOLEAN, b )
76 #define ADD_INT32( i ) DBUS_ADD( DBUS_TYPE_INT32, i )
77 #define ADD_BYTE( b ) DBUS_ADD( DBUS_TYPE_BYTE, b )
78
79 /* XML data to answer org.freedesktop.DBus.Introspectable.Introspect requests */
80
81 const char* psz_introspection_xml_data_root =
82 "<!DOCTYPE node PUBLIC \"-//freedesktop//DTD D-BUS Object Introspection 1.0//EN\"\n"
83 "\"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd\">\n"
84 "<node>"
85 "  <interface name=\"org.freedesktop.DBus.Introspectable\">\n"
86 "    <method name=\"Introspect\">\n"
87 "      <arg name=\"data\" direction=\"out\" type=\"s\"/>\n"
88 "    </method>\n"
89 "  </interface>\n"
90 "  <interface name=\"org.freedesktop.MediaPlayer\">\n"
91 "    <method name=\"Identity\">\n"
92 "      <arg type=\"s\" direction=\"out\" />\n"
93 "    </method>\n"
94 "  </interface>\n"
95 "</node>\n"
96 ;
97
98 const char* psz_introspection_xml_data_player =
99 "<!DOCTYPE node PUBLIC \"-//freedesktop//DTD D-BUS Object Introspection 1.0//EN\"\n"
100 "\"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd\">\n"
101 "<node>"
102 "  <interface name=\"org.freedesktop.DBus.Introspectable\">\n"
103 "    <method name=\"Introspect\">\n"
104 "      <arg name=\"data\" direction=\"out\" type=\"s\"/>\n"
105 "    </method>\n"
106 "  </interface>\n"
107 "  <interface name=\"org.videolan.vlc\">\n"
108 "    <method name=\"GetStatus\">\n"
109 "      <arg type=\"i\" direction=\"out\" />\n"
110 "    </method>\n"
111 "    <method name=\"Quit\">\n"
112 "    </method>\n"
113 "    <method name=\"Prev\">\n"
114 "    </method>\n"
115 "    <method name=\"Next\">\n"
116 "    </method>\n"
117 "    <method name=\"Stop\">\n"
118 "    </method>\n"
119 "    <method name=\"Play\">\n"
120 "    </method>\n"
121 "    <method name=\"Pause\">\n"
122 "    </method>\n"
123 "    <method name=\"VolumeSet\">\n"
124 "      <arg type=\"i\" direction=\"in\" />\n"
125 "    </method>\n"
126 "    <method name=\"VolumeGet\">\n"
127 "      <arg type=\"i\" direction=\"out\" />\n"
128 "    </method>\n"
129 "    <method name=\"PositionSet\">\n"
130 "      <arg type=\"i\" direction=\"in\" />\n"
131 "    </method>\n"
132 "    <method name=\"PositionGet\">\n"
133 "      <arg type=\"i\" direction=\"out\" />\n"
134 "    </method>\n"
135 "  </interface>\n"
136 "</node>\n"
137 ;
138
139 const char* psz_introspection_xml_data_tracklist =
140 "<!DOCTYPE node PUBLIC \"-//freedesktop//DTD D-BUS Object Introspection 1.0//EN\"\n"
141 "\"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd\">\n"
142 "<node>"
143 "  <interface name=\"org.freedesktop.DBus.Introspectable\">\n"
144 "    <method name=\"Introspect\">\n"
145 "      <arg name=\"data\" direction=\"out\" type=\"s\"/>\n"
146 "    </method>\n"
147 "  </interface>\n"
148 "  <interface name=\"org.videolan.vlc\">\n"
149 "    <method name=\"AddTrack\">\n"
150 "      <arg type=\"s\" direction=\"in\" />\n"
151 "      <arg type=\"b\" direction=\"in\" />\n"
152 "    </method>\n"
153 "    <method name=\"DelTrack\">\n"
154 "      <arg type=\"i\" direction=\"in\" />\n"
155 "    </method>\n"
156 "    <method name=\"GetMetadata\">\n"
157 "      <arg type=\"i\" direction=\"in\" />\n"
158 "      <arg type=\"a{sv}\" direction=\"out\" />\n"
159 "    </method>\n"
160 "    <method name=\"GetCurrentTrack\">\n"
161 "      <arg type=\"i\" direction=\"out\" />\n"
162 "    </method>\n"
163 "    <method name=\"GetLength\">\n"
164 "      <arg type=\"i\" direction=\"out\" />\n"
165 "    </method>\n"
166 "  </interface>\n"
167 "</node>\n"
168 ;
169
170 #define VLC_DBUS_ROOT_PATH      "/"
171 #define VLC_DBUS_PLAYER_PATH    "/Player"
172 #define VLC_DBUS_TRACKLIST_PATH "/TrackList"
173
174 /* Handle  messages reception */
175 DBUS_METHOD( handle_root );
176 DBUS_METHOD( handle_player );
177 DBUS_METHOD( handle_tracklist );
178
179 static DBusObjectPathVTable vlc_dbus_root_vtable = {
180         NULL, handle_root, /* handler function */
181         NULL, NULL, NULL, NULL
182 };
183
184 static DBusObjectPathVTable vlc_dbus_player_vtable = {
185         NULL, handle_player, /* handler function */
186         NULL, NULL, NULL, NULL
187 };
188
189 static DBusObjectPathVTable vlc_dbus_tracklist_vtable = {
190         NULL, handle_tracklist, /* handler function */
191         NULL, NULL, NULL, NULL
192 };
193