]> git.sesse.net Git - vlc/blob - modules/control/dbus/dbus_common.h
dbus: remove excessive main loop debugging
[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 #define DBUS_MPRIS_OBJECT_PATH "/org/mpris/MediaPlayer2"
35
36 /* MACROS */
37
38 #define INTF ((intf_thread_t *)p_this)
39 #define PL   (INTF->p_sys->p_playlist)
40
41 #define DBUS_METHOD( method_function ) \
42     static DBusHandlerResult method_function \
43             ( DBusConnection *p_conn, DBusMessage *p_from, void *p_this )
44
45 #define DBUS_SIGNAL( signal_function ) \
46     static DBusHandlerResult signal_function \
47             ( DBusConnection *p_conn, void *p_data )
48
49 #define REPLY_INIT \
50     DBusMessage* p_msg = dbus_message_new_method_return( p_from ); \
51     if( !p_msg ) return DBUS_HANDLER_RESULT_NEED_MEMORY; \
52
53 #define REPLY_SEND \
54     if( !dbus_connection_send( p_conn, p_msg, NULL ) ) \
55         return DBUS_HANDLER_RESULT_NEED_MEMORY; \
56     dbus_connection_flush( p_conn ); \
57     dbus_message_unref( p_msg ); \
58     return DBUS_HANDLER_RESULT_HANDLED
59
60 #define SIGNAL_INIT( interface, path, signal ) \
61     DBusMessage *p_msg = dbus_message_new_signal( path, \
62         interface, signal ); \
63     if( !p_msg ) return DBUS_HANDLER_RESULT_NEED_MEMORY; \
64
65 #define SIGNAL_SEND \
66     if( !dbus_connection_send( p_conn, p_msg, NULL ) ) \
67         return DBUS_HANDLER_RESULT_NEED_MEMORY; \
68     dbus_message_unref( p_msg ); \
69     dbus_connection_flush( p_conn ); \
70     return DBUS_HANDLER_RESULT_HANDLED
71
72 #define OUT_ARGUMENTS \
73     DBusMessageIter args; \
74     dbus_message_iter_init_append( p_msg, &args )
75
76 #define DBUS_ADD( dbus_type, value ) \
77     if( !dbus_message_iter_append_basic( &args, dbus_type, value ) ) \
78         return DBUS_HANDLER_RESULT_NEED_MEMORY
79
80 #define ADD_STRING( s ) DBUS_ADD( DBUS_TYPE_STRING, s )
81 #define ADD_DOUBLE( d ) DBUS_ADD( DBUS_TYPE_DOUBLE, d )
82 #define ADD_BOOL( b ) DBUS_ADD( DBUS_TYPE_BOOLEAN, b )
83 #define ADD_INT32( i ) DBUS_ADD( DBUS_TYPE_INT32, i )
84 #define ADD_INT64( i ) DBUS_ADD( DBUS_TYPE_INT64, i )
85 #define ADD_BYTE( b ) DBUS_ADD( DBUS_TYPE_BYTE, b )
86
87 #define MPRIS_TRACKID_FORMAT "/org/videolan/vlc/playlist/%d"
88
89 struct intf_sys_t
90 {
91     DBusConnection *p_conn;
92     playlist_t     *p_playlist;
93     bool            b_meta_read;
94     dbus_int32_t    i_player_caps;
95     dbus_int32_t    i_playing_state;
96     bool            b_can_play;
97     bool            b_dead;
98     vlc_array_t    *p_events;
99     vlc_array_t    *p_timeouts;
100     vlc_array_t    *p_watches;
101     int             p_pipe_fds[2];
102     vlc_mutex_t     lock;
103     input_thread_t *p_input;
104     mtime_t         i_last_input_pos; /* Only access it from the input thread */
105     mtime_t         i_last_input_pos_event; /* idem */
106 };
107
108 enum
109 {
110     SIGNAL_ITEM_CURRENT,
111     SIGNAL_INTF_CHANGE,
112     SIGNAL_PLAYLIST_ITEM_APPEND,
113     SIGNAL_PLAYLIST_ITEM_DELETED,
114     SIGNAL_INPUT_METADATA,
115     SIGNAL_RANDOM,
116     SIGNAL_REPEAT,
117     SIGNAL_LOOP,
118     SIGNAL_STATE,
119     SIGNAL_RATE,
120     SIGNAL_SEEK,
121     SIGNAL_CAN_SEEK,
122     SIGNAL_CAN_PAUSE,
123     SIGNAL_VOLUME_CHANGE,
124     SIGNAL_VOLUME_MUTED,
125     SIGNAL_FULLSCREEN
126 };
127
128 enum
129 {
130     PLAYBACK_STATE_INVALID = -1,
131     PLAYBACK_STATE_PLAYING = 0,
132     PLAYBACK_STATE_PAUSED  = 1,
133     PLAYBACK_STATE_STOPPED = 2
134 };
135
136 int DemarshalSetPropertyValue( DBusMessage *p_msg, void *p_arg );
137 int GetInputMeta  ( input_item_t* p_input, DBusMessageIter *args );
138
139 #endif //dbus-common.h