1 /*****************************************************************************
2 * dbus.h : D-Bus control interface
3 *****************************************************************************
4 * Copyright (C) 2006 Rafaël Carré
7 * Author: Rafaël Carré <funman at videolanorg>
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.
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.
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 *****************************************************************************/
24 /* DBUS IDENTIFIERS */
26 /* this is also defined in src/libvlc-common.c for one-instance mode */
28 /* name registered on the session bus */
29 #define VLC_DBUS_SERVICE "org.videolan.vlc"
30 #define VLC_DBUS_INTERFACE "org.videolan.vlc"
31 #define VLC_DBUS_OBJECT_PATH "/org/videolan/vlc"
35 #define DBUS_METHOD( method_function ) \
36 static DBusHandlerResult method_function \
37 ( DBusConnection *p_conn, DBusMessage *p_from, void *p_this )
39 #define DBUS_SIGNAL( signal_function ) \
40 static DBusHandlerResult signal_function \
41 ( DBusConnection *p_conn, void *p_data )
44 DBusMessage* p_msg = dbus_message_new_method_return( p_from ); \
45 if( !p_msg ) return DBUS_HANDLER_RESULT_NEED_MEMORY; \
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
54 #define SIGNAL_INIT( signal ) \
55 DBusMessage *p_msg = dbus_message_new_signal( VLC_DBUS_OBJECT_PATH, \
56 VLC_DBUS_INTERFACE, signal ); \
57 if( !p_msg ) return DBUS_HANDLER_RESULT_NEED_MEMORY; \
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
66 #define OUT_ARGUMENTS \
67 DBusMessageIter args; \
68 dbus_message_iter_init_append( p_msg, &args )
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
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_UINT32( i ) DBUS_ADD( DBUS_TYPE_UINT32, i )
77 #define ADD_UINT16( i ) DBUS_ADD( DBUS_TYPE_UINT16, i )
78 #define ADD_BYTE( b ) DBUS_ADD( DBUS_TYPE_BYTE, b )
80 /* XML data to answer org.freedesktop.DBus.Introspectable.Introspect requests */
82 const char* psz_introspection_xml_data =
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"
86 " <interface name=\"org.freedesktop.DBus.Introspectable\">\n"
87 " <method name=\"Introspect\">\n"
88 " <arg name=\"data\" direction=\"out\" type=\"s\"/>\n"
91 " <interface name=\"org.videolan.vlc\">\n"
92 " <method name=\"GetPlayStatus\">\n"
93 " <arg type=\"s\" direction=\"out\" />\n"
95 " <method name=\"GetPlayingItem\">\n"
96 " <arg type=\"s\" direction=\"out\" />\n"
98 " <method name=\"TogglePause\">\n"
99 " <arg type=\"b\" direction=\"out\" />\n"
101 " <method name=\"AddMRL\">\n"
102 " <arg type=\"s\" direction=\"in\" />\n"
103 " <arg type=\"b\" direction=\"in\" />\n"
105 " <method name=\"Nothing\">\n"
107 " <method name=\"Quit\">\n"
109 " <method name=\"Prev\">\n"
111 " <method name=\"Next\">\n"
113 " <method name=\"Stop\">\n"
115 " <method name=\"VolumeSet\">\n"
116 " <arg type=\"q\" direction=\"in\" />\n"
118 " <method name=\"VolumeGet\">\n"
119 " <arg type=\"q\" direction=\"out\" />\n"
121 " <method name=\"PositionSet\">\n"
122 " <arg type=\"q\" direction=\"in\" />\n"
124 " <method name=\"PositionGet\">\n"
125 " <arg type=\"q\" direction=\"out\" />\n"
127 " <method name=\"PlaylistExport_XSPF\">\n"
128 " <arg type=\"s\" direction=\"in\" />\n"
129 " <arg type=\"q\" direction=\"out\" />\n"
135 /* Handling of messages received onn VLC_DBUS_OBJECT_PATH */
136 DBUS_METHOD( handle_messages ); /* handler function */
138 /* vtable passed to dbus_connection_register_object_path() */
139 static DBusObjectPathVTable vlc_dbus_vtable = {
140 NULL, /* Called when vtable is unregistered or its connection is freed*/
141 handle_messages, /* handler function */