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