1 /*****************************************************************************
2 * dbus-root.c : dbus control module (mpris v1.0) - root object
3 *****************************************************************************
4 * Copyright © 2006-2008 Rafaël Carré
5 * Copyright © 2007-2010 Mirsal Ennaime
6 * Copyright © 2009-2010 The VideoLAN team
9 * Authors: Mirsal Ennaime <mirsal at mirsal fr>
10 * Rafaël Carré <funman at videolanorg>
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
25 *****************************************************************************/
31 #include <vlc_common.h>
32 #include <vlc_interface.h>
37 #include "dbus_root.h"
38 #include "dbus_common.h"
40 static const char const ppsz_supported_uri_schemes[][9] = {
41 "file", "http", "https", "rtsp", "realrtsp", "pnm", "ftp", "mtp", "smb",
42 "mms", "mmsu", "mmst", "mmsh", "unsv", "itpc", "icyx", "rtmp", "rtp",
43 "dccp", "dvd", "vcd", "vcdx"
46 static const char const ppsz_supported_mime_types[][26] = {
47 "audio/mpeg", "audio/x-mpeg",
48 "video/mpeg", "video/x-mpeg",
49 "video/mpeg-system", "video/x-mpeg-system",
54 "application/ogg", "application/x-ogg",
55 "video/x-ms-asf", "video/x-ms-asf-plugin",
56 "application/x-mplayer2",
58 "video/x-google-vlc-plugin",
59 "audio/wav", "audio/x-wav",
65 "video/flv", "video/x-flv",
68 "application/xspf+xml"
71 DBUS_METHOD( Identity )
77 const char *psz_identity = _("VLC media player");
80 dbus_message_iter_open_container( &args, DBUS_TYPE_VARIANT, "s", &v );
81 dbus_message_iter_append_basic( &v, DBUS_TYPE_STRING, &psz_identity );
83 if( !dbus_message_iter_close_container( &args, &v ) )
84 return DBUS_HANDLER_RESULT_NEED_MEMORY;
89 DBUS_METHOD( CanQuit )
95 const dbus_bool_t b_ret = TRUE;
98 dbus_message_iter_open_container( &args, DBUS_TYPE_VARIANT, "b", &v );
99 dbus_message_iter_append_basic( &v, DBUS_TYPE_BOOLEAN, &b_ret );
101 if( !dbus_message_iter_close_container( &args, &v ) )
102 return DBUS_HANDLER_RESULT_NEED_MEMORY;
107 DBUS_METHOD( CanRaise )
109 VLC_UNUSED( p_this );
113 const dbus_bool_t b_ret = FALSE;
116 dbus_message_iter_open_container( &args, DBUS_TYPE_VARIANT, "b", &v );
117 dbus_message_iter_append_basic( &v, DBUS_TYPE_BOOLEAN, &b_ret );
119 if( !dbus_message_iter_close_container( &args, &v ) )
120 return DBUS_HANDLER_RESULT_NEED_MEMORY;
125 DBUS_METHOD( HasTrackList )
127 VLC_UNUSED( p_this );
131 const dbus_bool_t b_ret = FALSE;
134 dbus_message_iter_open_container( &args, DBUS_TYPE_VARIANT, "b", &v );
135 dbus_message_iter_append_basic( &v, DBUS_TYPE_BOOLEAN, &b_ret );
137 if( !dbus_message_iter_close_container( &args, &v ) )
138 return DBUS_HANDLER_RESULT_NEED_MEMORY;
143 DBUS_METHOD( DesktopEntry )
145 VLC_UNUSED( p_this );
149 const char* psz_ret = PACKAGE;
152 dbus_message_iter_open_container( &args, DBUS_TYPE_VARIANT, "s", &v );
153 dbus_message_iter_append_basic( &v, DBUS_TYPE_STRING, &psz_ret );
155 if( !dbus_message_iter_close_container( &args, &v ) )
156 return DBUS_HANDLER_RESULT_NEED_MEMORY;
161 DBUS_METHOD( SupportedMimeTypes )
163 VLC_UNUSED( p_this );
167 DBusMessageIter ret, v;
168 dbus_message_iter_open_container( &args, DBUS_TYPE_VARIANT, "s", &v );
169 size_t i_len = sizeof( ppsz_supported_mime_types ) / sizeof( char* );
171 if( !dbus_message_iter_open_container( &v, DBUS_TYPE_ARRAY, "s", &ret ) )
172 return DBUS_HANDLER_RESULT_NEED_MEMORY;
174 for( size_t i = 0; i < i_len; ++i )
175 if( !dbus_message_iter_append_basic( &ret, DBUS_TYPE_STRING,
176 &ppsz_supported_mime_types[i] ) )
177 return DBUS_HANDLER_RESULT_NEED_MEMORY;
179 if( !dbus_message_iter_close_container( &v, &ret ) )
180 return DBUS_HANDLER_RESULT_NEED_MEMORY;
182 if( !dbus_message_iter_close_container( &args, &v ) )
183 return DBUS_HANDLER_RESULT_NEED_MEMORY;
188 DBUS_METHOD( SupportedUriSchemes )
190 VLC_UNUSED( p_this );
194 DBusMessageIter ret, v;
195 dbus_message_iter_open_container( &args, DBUS_TYPE_VARIANT, "s", &v );
196 size_t i_len = sizeof( ppsz_supported_uri_schemes ) / sizeof( char* );
198 if( !dbus_message_iter_open_container( &v, DBUS_TYPE_ARRAY, "s", &ret ) )
199 return DBUS_HANDLER_RESULT_NEED_MEMORY;
201 for( size_t i = 0; i < i_len; ++i )
202 if( !dbus_message_iter_append_basic( &ret, DBUS_TYPE_STRING,
203 &ppsz_supported_uri_schemes[i] ) )
204 return DBUS_HANDLER_RESULT_NEED_MEMORY;
206 if( !dbus_message_iter_close_container( &v, &ret ) )
207 return DBUS_HANDLER_RESULT_NEED_MEMORY;
209 if( !dbus_message_iter_close_container( &args, &v ) )
210 return DBUS_HANDLER_RESULT_NEED_MEMORY;
218 libvlc_Quit(INTF->p_libvlc);
223 {/* shows vlc's main window */
225 var_ToggleBool( INTF->p_libvlc, "intf-show" );
229 #define PROPERTY_MAPPING_BEGIN if( 0 ) {}
230 #define PROPERTY_FUNC( interface, property, function ) \
231 else if( !strcmp( psz_interface_name, interface ) && \
232 !strcmp( psz_property_name, property ) ) \
233 return function( p_conn, p_from, p_this );
234 #define PROPERTY_MAPPING_END return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
236 DBUS_METHOD( GetProperty )
240 char *psz_interface_name = NULL;
241 char *psz_property_name = NULL;
243 dbus_error_init( &error );
244 dbus_message_get_args( p_from, &error,
245 DBUS_TYPE_STRING, &psz_interface_name,
246 DBUS_TYPE_STRING, &psz_property_name,
249 if( dbus_error_is_set( &error ) )
251 msg_Err( (vlc_object_t*) p_this, "D-Bus message reading : %s",
253 dbus_error_free( &error );
254 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
257 msg_Dbg( (vlc_object_t*) p_this, "Getting property %s",
260 PROPERTY_MAPPING_BEGIN
261 PROPERTY_FUNC( DBUS_MPRIS_ROOT_INTERFACE, "Identity", Identity )
262 PROPERTY_FUNC( DBUS_MPRIS_ROOT_INTERFACE, "DesktopEntry", DesktopEntry )
263 PROPERTY_FUNC( DBUS_MPRIS_ROOT_INTERFACE, "SupportedMimeTypes", SupportedMimeTypes )
264 PROPERTY_FUNC( DBUS_MPRIS_ROOT_INTERFACE, "SupportedUriSchemes", SupportedUriSchemes )
265 PROPERTY_FUNC( DBUS_MPRIS_ROOT_INTERFACE, "HasTrackList", HasTrackList )
266 PROPERTY_FUNC( DBUS_MPRIS_ROOT_INTERFACE, "CanQuit", CanQuit )
267 PROPERTY_FUNC( DBUS_MPRIS_ROOT_INTERFACE, "CanRaise", CanRaise )
271 #undef PROPERTY_MAPPING_BEGIN
272 #undef PROPERTY_GET_FUNC
273 #undef PROPERTY_MAPPING_END
275 #define METHOD_MAPPING_BEGIN if( 0 ) {}
276 #define METHOD_FUNC( interface, method, function ) \
277 else if( dbus_message_is_method_call( p_from, interface, method ) )\
278 return function( p_conn, p_from, p_this )
279 #define METHOD_MAPPING_END return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
282 handle_root ( DBusConnection *p_conn, DBusMessage *p_from, void *p_this )
285 METHOD_FUNC( DBUS_INTERFACE_PROPERTIES, "Get", GetProperty );
286 METHOD_FUNC( DBUS_MPRIS_ROOT_INTERFACE, "Quit", Quit );
287 METHOD_FUNC( DBUS_MPRIS_ROOT_INTERFACE, "Raise", Raise );
291 #undef METHOD_MAPPING_BEGIN
293 #undef METHOD_MAPPING_END