]> git.sesse.net Git - vlc/blob - modules/control/dbus.h
Revert [17878], that must not be made in libvlc, but rather in vlc
[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 #define VLC_DBUS_SERVICE        "org.videolan.vlc"
27 #define VLC_DBUS_INTERFACE      "org.videolan.vlc"
28 #define VLC_DBUS_OBJECT_PATH    "/org/videolan/vlc"
29
30 /* MACROS */
31
32 #define DBUS_METHOD( method_function ) \
33     static DBusHandlerResult method_function \
34             ( DBusConnection *p_conn, DBusMessage *p_from, void *p_this ) 
35
36 #define DBUS_SIGNAL( signal_function ) \
37     static DBusHandlerResult signal_function \
38             ( DBusConnection *p_conn, void *p_data )
39
40 #define REPLY_INIT \
41     DBusMessage* p_msg = dbus_message_new_method_return( p_from ); \
42     if( !p_msg ) return DBUS_HANDLER_RESULT_NEED_MEMORY; \
43     dbus_uint32_t i_serial = 0
44
45 #define REPLY_SEND \
46     if( !dbus_connection_send( p_conn, p_msg, &i_serial ) ) \
47         return DBUS_HANDLER_RESULT_NEED_MEMORY; \
48     dbus_connection_flush( p_conn ); \
49     dbus_message_unref( p_msg ); \
50     return DBUS_HANDLER_RESULT_HANDLED
51
52 #define SIGNAL_INIT( signal ) \
53     DBusMessage *p_msg = dbus_message_new_signal( VLC_DBUS_OBJECT_PATH, \
54         VLC_DBUS_INTERFACE, signal ); \
55     if( !p_msg ) return DBUS_HANDLER_RESULT_NEED_MEMORY; \
56     dbus_uint32_t i_serial = 0
57
58 #define SIGNAL_SEND \
59     if( !dbus_connection_send( p_conn, p_msg, &i_serial ) ) \
60     return DBUS_HANDLER_RESULT_NEED_MEMORY; \
61     dbus_message_unref( p_msg ); \
62     dbus_connection_flush( p_conn ); \
63     return DBUS_HANDLER_RESULT_HANDLED
64
65 #define OUT_ARGUMENTS \
66     DBusMessageIter args; \
67     dbus_message_iter_init_append( p_msg, &args )
68
69 #define DBUS_ADD( dbus_type, value ) \
70     if( !dbus_message_iter_append_basic( &args, dbus_type, value ) ) \
71         return DBUS_HANDLER_RESULT_NEED_MEMORY
72
73 #define ADD_STRING( s ) DBUS_ADD( DBUS_TYPE_STRING, s )
74 #define ADD_BOOL( b ) DBUS_ADD( DBUS_TYPE_BOOLEAN, b )
75 #define ADD_UINT32( i ) DBUS_ADD( DBUS_TYPE_UINT32, i )
76 #define ADD_UINT16( i ) DBUS_ADD( DBUS_TYPE_UINT16, 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 =
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.videolan.vlc\">\n"
91 "    <method name=\"GetPlayStatus\">\n"
92 "      <arg type=\"s\" direction=\"out\" />\n"
93 "    </method>\n"
94 "    <method name=\"GetPlayingItem\">\n"
95 "      <arg type=\"s\" direction=\"out\" />\n"
96 "    </method>\n"
97 "    <method name=\"TogglePause\">\n"
98 "      <arg type=\"b\" direction=\"out\" />\n"
99 "    </method>\n"
100 "    <method name=\"AddMRL\">\n"
101 "      <arg type=\"s\" direction=\"in\" />\n"
102 "      <arg type=\"b\" direction=\"in\" />\n"
103 "    </method>\n"
104 "    <method name=\"Nothing\">\n"
105 "    </method>\n"
106 "    <method name=\"Quit\">\n"
107 "    </method>\n"
108 "    <method name=\"Prev\">\n"
109 "    </method>\n"
110 "    <method name=\"Next\">\n"
111 "    </method>\n"
112 "    <method name=\"Stop\">\n"
113 "    </method>\n"
114 "    <method name=\"VolumeSet\">\n"
115 "      <arg type=\"q\" direction=\"in\" />\n"
116 "    </method>\n"
117 "    <method name=\"VolumeGet\">\n"
118 "      <arg type=\"q\" direction=\"out\" />\n"
119 "    </method>\n"
120 "    <method name=\"PositionSet\">\n"
121 "      <arg type=\"q\" direction=\"in\" />\n"
122 "    </method>\n"
123 "    <method name=\"PositionGet\">\n"
124 "      <arg type=\"q\" direction=\"out\" />\n"
125 "    </method>\n"
126 "  </interface>\n"
127 "</node>\n"
128 ;
129
130 /* Handling of messages received onn VLC_DBUS_OBJECT_PATH */
131 DBUS_METHOD( handle_messages ); /* handler function */
132
133 /* vtable passed to dbus_connection_register_object_path() */
134 static DBusObjectPathVTable vlc_dbus_vtable = {
135         NULL, /* Called when vtable is unregistered or its connection is freed*/
136         handle_messages, /* handler function */
137         NULL,
138         NULL,
139         NULL,
140         NULL
141 };
142