Implement Volume control
[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 /* MACROS */
25
26 #define DBUS_METHOD( method_function ) \
27     static DBusHandlerResult method_function \
28             ( DBusConnection *p_conn, DBusMessage *p_from, void *p_this ) 
29
30 #define DBUS_SIGNAL( signal_function ) \
31     static DBusHandlerResult signal_function \
32             ( DBusConnection *p_conn, void *p_data )
33
34 #define REPLY_INIT \
35     DBusMessage* p_msg = dbus_message_new_method_return( p_from ); \
36     if( !p_msg ) return DBUS_HANDLER_RESULT_NEED_MEMORY; \
37     dbus_uint32_t i_serial = 0
38
39 #define REPLY_SEND \
40     if( !dbus_connection_send( p_conn, p_msg, &i_serial ) ) \
41         return DBUS_HANDLER_RESULT_NEED_MEMORY; \
42     dbus_connection_flush( p_conn ); \
43     dbus_message_unref( p_msg ); \
44     return DBUS_HANDLER_RESULT_HANDLED
45
46 #define SIGNAL_INIT( signal ) \
47     DBusMessage *p_msg = dbus_message_new_signal( VLC_DBUS_OBJECT_PATH, \
48         VLC_DBUS_INTERFACE, signal ); \
49     if( !p_msg ) return DBUS_HANDLER_RESULT_NEED_MEMORY; \
50     dbus_uint32_t i_serial = 0
51
52 #define SIGNAL_SEND \
53     if( !dbus_connection_send( p_conn, p_msg, &i_serial ) ) \
54     return DBUS_HANDLER_RESULT_NEED_MEMORY; \
55     dbus_message_unref( p_msg ); \
56     dbus_connection_flush( p_conn ); \
57     return DBUS_HANDLER_RESULT_HANDLED
58
59 #define OUT_ARGUMENTS \
60     DBusMessageIter args; \
61     dbus_message_iter_init_append( p_msg, &args )
62
63 #define DBUS_ADD( dbus_type, value ) \
64     if( !dbus_message_iter_append_basic( &args, dbus_type, value ) ) \
65         return DBUS_HANDLER_RESULT_NEED_MEMORY
66
67 #define ADD_STRING( s ) DBUS_ADD( DBUS_TYPE_STRING, s )
68 #define ADD_BOOL( b ) DBUS_ADD( DBUS_TYPE_BOOLEAN, b )
69 #define ADD_UINT32( i ) DBUS_ADD( DBUS_TYPE_UINT32, i )
70 #define ADD_UINT16( i ) DBUS_ADD( DBUS_TYPE_UINT16, i )
71
72 /* XML data to answer org.freedesktop.DBus.Introspectable.Introspect requests */
73
74 const char* psz_introspection_xml_data =
75 "<!DOCTYPE node PUBLIC \"-//freedesktop//DTD D-BUS Object Introspection 1.0//EN\"\n"
76 "\"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd\">\n"
77 "<node>"
78 "  <interface name=\"org.freedesktop.DBus.Introspectable\">\n"
79 "    <method name=\"Introspect\">\n"
80 "      <arg name=\"data\" direction=\"out\" type=\"s\"/>\n"
81 "    </method>\n"
82 "  </interface>\n"
83 "  <interface name=\"org.videolan.vlc\">\n"
84 "    <method name=\"GetPlayStatus\">\n"
85 "      <arg type=\"s\" direction=\"out\" />\n"
86 "    </method>\n"
87 "    <method name=\"GetPlayingItem\">\n"
88 "      <arg type=\"s\" direction=\"out\" />\n"
89 "    </method>\n"
90 "    <method name=\"TogglePause\">\n"
91 "      <arg type=\"b\" direction=\"out\" />\n"
92 "    </method>\n"
93 "    <method name=\"AddMRL\">\n"
94 "      <arg type=\"s\" direction=\"in\" />\n"
95 "      <arg type=\"b\" direction=\"in\" />\n"
96 "    </method>\n"
97 "    <method name=\"Nothing\">\n"
98 "    </method>\n"
99 "    <method name=\"Quit\">\n"
100 "    </method>\n"
101 "    <method name=\"Prev\">\n"
102 "    </method>\n"
103 "    <method name=\"Next\">\n"
104 "    </method>\n"
105 "    <method name=\"Stop\">\n"
106 "    </method>\n"
107 "    <method name=\"VolumeSet\">\n"
108 "      <arg type=\"q\" direction=\"in\" />\n"
109 "    </method>\n"
110 "    <method name=\"VolumeGet\">\n"
111 "      <arg type=\"q\" direction=\"out\" />\n"
112 "    </method>\n"
113 "  </interface>\n"
114 "</node>\n"
115 ;
116
117 /* Handling of messages received onn VLC_DBUS_OBJECT_PATH */
118 DBUS_METHOD( handle_messages ); /* handler function */
119
120 /* vtable passed to dbus_connection_register_object_path() */
121 static DBusObjectPathVTable vlc_dbus_vtable = {
122         NULL, /* Called when vtable is unregistered or its connection is freed*/
123         handle_messages, /* handler function */
124         NULL,
125         NULL,
126         NULL,
127         NULL
128 };
129