]> git.sesse.net Git - vlc/blob - modules/control/dbus/dbus_common.h
dbus: monitor input state change through "intf-event"
[vlc] / modules / control / dbus / dbus_common.h
1 /*****************************************************************************
2  * dbus-common.h : Common header for D-Bus control modules
3  *****************************************************************************
4  * Copyright © 2006-2008 Rafaël Carré
5  * Copyright © 2007-2010 Mirsal Ennaime
6  * Copyright © 2009-2010 The VideoLAN team
7  * $Id$
8  *
9  * Authors:    Mirsal ENNAIME <mirsal dot ennaime at gmail dot com>
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
24  *****************************************************************************/
25
26 #ifndef _VLC_DBUS_COMMON_H
27 #define _VLC_DBUS_COMMON_H
28
29 #include <vlc_common.h>
30 #include <vlc_interface.h>
31 #include <dbus/dbus.h>
32
33 /* MACROS */
34
35 #define INTF ((intf_thread_t *)p_this)
36 #define PL   (INTF->p_sys->p_playlist)
37
38 #define DBUS_METHOD( method_function ) \
39     static DBusHandlerResult method_function \
40             ( DBusConnection *p_conn, DBusMessage *p_from, void *p_this )
41
42 #define DBUS_SIGNAL( signal_function ) \
43     static DBusHandlerResult signal_function \
44             ( DBusConnection *p_conn, void *p_data )
45
46 #define REPLY_INIT \
47     DBusMessage* p_msg = dbus_message_new_method_return( p_from ); \
48     if( !p_msg ) return DBUS_HANDLER_RESULT_NEED_MEMORY; \
49
50 #define REPLY_SEND \
51     if( !dbus_connection_send( p_conn, p_msg, NULL ) ) \
52         return DBUS_HANDLER_RESULT_NEED_MEMORY; \
53     dbus_connection_flush( p_conn ); \
54     dbus_message_unref( p_msg ); \
55     return DBUS_HANDLER_RESULT_HANDLED
56
57 #define SIGNAL_INIT( interface, path, signal ) \
58     DBusMessage *p_msg = dbus_message_new_signal( path, \
59         interface, signal ); \
60     if( !p_msg ) return DBUS_HANDLER_RESULT_NEED_MEMORY; \
61
62 #define SIGNAL_SEND \
63     if( !dbus_connection_send( p_conn, p_msg, NULL ) ) \
64         return DBUS_HANDLER_RESULT_NEED_MEMORY; \
65     dbus_message_unref( p_msg ); \
66     dbus_connection_flush( p_conn ); \
67     return DBUS_HANDLER_RESULT_HANDLED
68
69 #define OUT_ARGUMENTS \
70     DBusMessageIter args; \
71     dbus_message_iter_init_append( p_msg, &args )
72
73 #define DBUS_ADD( dbus_type, value ) \
74     if( !dbus_message_iter_append_basic( &args, dbus_type, value ) ) \
75         return DBUS_HANDLER_RESULT_NEED_MEMORY
76
77 #define ADD_STRING( s ) DBUS_ADD( DBUS_TYPE_STRING, s )
78 #define ADD_BOOL( b ) DBUS_ADD( DBUS_TYPE_BOOLEAN, b )
79 #define ADD_INT32( i ) DBUS_ADD( DBUS_TYPE_INT32, i )
80 #define ADD_BYTE( b ) DBUS_ADD( DBUS_TYPE_BYTE, b )
81
82 struct intf_sys_t
83 {
84     DBusConnection *p_conn;
85     playlist_t     *p_playlist;
86     bool            b_meta_read;
87     dbus_int32_t    i_caps;
88     dbus_int32_t    i_playing_state;
89     bool            b_dead;
90     vlc_array_t    *p_events;
91     vlc_mutex_t     lock;
92     input_thread_t *p_input;
93     bool            b_unique;
94 };
95
96 enum
97 {
98     SIGNAL_ITEM_CURRENT,
99     SIGNAL_INTF_CHANGE,
100     SIGNAL_PLAYLIST_ITEM_APPEND,
101     SIGNAL_PLAYLIST_ITEM_DELETED,
102     SIGNAL_RANDOM,
103     SIGNAL_REPEAT,
104     SIGNAL_LOOP,
105     SIGNAL_STATE
106 };
107
108 int GetInputMeta  ( input_item_t* p_input, DBusMessageIter *args );
109 int UpdateCaps    ( intf_thread_t* );
110
111 #endif //dbus-common.h