]> git.sesse.net Git - vlc/blob - modules/control/dbus.h
Add a method to export playlists
[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 /* this is also defined in src/libvlc-common.c for one-instance mode */
27
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"
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_OBJECT_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_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 )
79
80 /* XML data to answer org.freedesktop.DBus.Introspectable.Introspect requests */
81
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"
85 "<node>"
86 "  <interface name=\"org.freedesktop.DBus.Introspectable\">\n"
87 "    <method name=\"Introspect\">\n"
88 "      <arg name=\"data\" direction=\"out\" type=\"s\"/>\n"
89 "    </method>\n"
90 "  </interface>\n"
91 "  <interface name=\"org.videolan.vlc\">\n"
92 "    <method name=\"GetPlayStatus\">\n"
93 "      <arg type=\"s\" direction=\"out\" />\n"
94 "    </method>\n"
95 "    <method name=\"GetPlayingItem\">\n"
96 "      <arg type=\"s\" direction=\"out\" />\n"
97 "    </method>\n"
98 "    <method name=\"TogglePause\">\n"
99 "      <arg type=\"b\" direction=\"out\" />\n"
100 "    </method>\n"
101 "    <method name=\"AddMRL\">\n"
102 "      <arg type=\"s\" direction=\"in\" />\n"
103 "      <arg type=\"b\" direction=\"in\" />\n"
104 "    </method>\n"
105 "    <method name=\"Nothing\">\n"
106 "    </method>\n"
107 "    <method name=\"Quit\">\n"
108 "    </method>\n"
109 "    <method name=\"Prev\">\n"
110 "    </method>\n"
111 "    <method name=\"Next\">\n"
112 "    </method>\n"
113 "    <method name=\"Stop\">\n"
114 "    </method>\n"
115 "    <method name=\"VolumeSet\">\n"
116 "      <arg type=\"q\" direction=\"in\" />\n"
117 "    </method>\n"
118 "    <method name=\"VolumeGet\">\n"
119 "      <arg type=\"q\" direction=\"out\" />\n"
120 "    </method>\n"
121 "    <method name=\"PositionSet\">\n"
122 "      <arg type=\"q\" direction=\"in\" />\n"
123 "    </method>\n"
124 "    <method name=\"PositionGet\">\n"
125 "      <arg type=\"q\" direction=\"out\" />\n"
126 "    </method>\n"
127 "    <method name=\"PlaylistExport_XSPF\">\n"
128 "      <arg type=\"s\" direction=\"in\" />\n"
129 "      <arg type=\"q\" direction=\"out\" />\n"
130 "    </method>\n"
131 "  </interface>\n"
132 "</node>\n"
133 ;
134
135 /* Handling of messages received onn VLC_DBUS_OBJECT_PATH */
136 DBUS_METHOD( handle_messages ); /* handler function */
137
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 */
142         NULL,
143         NULL,
144         NULL,
145         NULL
146 };
147