]> git.sesse.net Git - vlc/blob - include/vlc_events.h
mediacodec: fix warning
[vlc] / include / vlc_events.h
1 /*****************************************************************************
2  * vlc_events.h: events definitions
3  * Interface used to send events.
4  *****************************************************************************
5  * Copyright (C) 2007 VLC authors and VideoLAN
6  * $Id$
7  *
8  * Authors: Pierre d'Herbemont
9  *
10  * This program is free software; you can redistribute it and/or modify it
11  * under the terms of the GNU Lesser General Public License as published by
12  * the Free Software Foundation; either version 2.1 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public License
21  * along with this program; if not, write to the Free Software Foundation,
22  * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23  *****************************************************************************/
24
25 #ifndef VLC_EVENTS_H
26 # define VLC_EVENTS_H
27
28 #include <vlc_arrays.h>
29 #include <vlc_meta.h>
30
31 /**
32  * \file
33  * This file is the interface definition for events
34  * (implementation in src/misc/events.c)
35  */
36
37 /*****************************************************************************
38  * Documentation
39  *****************************************************************************/
40 /*
41  **** Background
42  *
43  * This implements a way to send and receive event for an object (which can be
44  * a simple C struct or less).
45  *
46  * This is in direct concurrency with the Variable based Callback
47  * (see src/misc/variables.c).
48  *
49  * It has the following advantages over Variable based Callback:
50  * - No need to implement the whole VLC_COMMON_MEMBERS in the object,
51  * thus it reduce it size. This is especially true for input_item_t which
52  * doesn't have VLC_COMMON_MEMBERS. This is the first reason of existence of
53  * this implementation.
54  * - Libvlc can easily be based upon that.
55  * - Existing event are clearly declared (in include/vlc_events.h)
56  *
57  *
58  **** Example usage
59  *
60  * (vlc_cool_object_t doesn't need to have the VLC_COMMON_MEMBERS.)
61  *
62  * struct vlc_cool_object_t
63  * {
64  *        ...
65  *        vlc_event_manager_t p_event_manager;
66  *        ...
67  * }
68  *
69  * vlc_my_cool_object_new()
70  * {
71  *        ...
72  *        vlc_event_manager_init( &p_self->p_event_manager, p_self, p_a_libvlc_object );
73  *        vlc_event_manager_register_event_type(p_self->p_event_manager,
74  *                vlc_MyCoolObjectDidSomething, p_e)
75  *        ...
76  * }
77  *
78  * vlc_my_cool_object_release()
79  * {
80  *         ...
81  *         vlc_event_manager_fini( &p_self->p_event_manager );
82  *         ...
83  * }
84  *
85  * vlc_my_cool_object_do_something()
86  * {
87  *        ...
88  *        vlc_event_t event;
89  *        event.type = vlc_MyCoolObjectDidSomething;
90  *        event.u.my_cool_object_did_something.what_it_did = kSomething;
91  *        vlc_event_send( &p_self->p_event_manager, &event );
92  * }
93  * */
94
95   /*****************************************************************************
96  * Event Type
97  *****************************************************************************/
98
99 /* Private structure defined in misc/events.c */
100 struct vlc_event_listeners_group_t;
101
102 /* Event manager type */
103 typedef struct vlc_event_manager_t
104 {
105     void * p_obj;
106     vlc_mutex_t object_lock;
107     vlc_mutex_t event_sending_lock;
108     DECL_ARRAY(struct vlc_event_listeners_group_t *) listeners_groups;
109 } vlc_event_manager_t;
110
111 /* List of event */
112 typedef enum vlc_event_type_t {
113     /* Input (thread) events */
114     vlc_InputStateChanged,
115     vlc_InputSelectedStreamChanged,
116
117     /* Input item events */
118     vlc_InputItemMetaChanged,
119     vlc_InputItemSubItemAdded,
120     vlc_InputItemSubItemTreeAdded,
121     vlc_InputItemDurationChanged,
122     vlc_InputItemPreparsedChanged,
123     vlc_InputItemNameChanged,
124     vlc_InputItemInfoChanged,
125     vlc_InputItemErrorWhenReadingChanged,
126     vlc_InputItemPreparseEnded,
127
128     /* Service Discovery event */
129     vlc_ServicesDiscoveryItemAdded,
130     vlc_ServicesDiscoveryItemRemoved,
131     vlc_ServicesDiscoveryItemRemoveAll,
132     vlc_ServicesDiscoveryStarted,
133     vlc_ServicesDiscoveryEnded,
134
135     /* Addons Manager events */
136     vlc_AddonFound,
137     vlc_AddonsDiscoveryEnded,
138     vlc_AddonChanged
139 } vlc_event_type_t;
140
141 /* Event definition */
142 typedef struct vlc_event_t
143 {
144     vlc_event_type_t type;
145     void * p_obj; /* Sender object, automatically filled by vlc_event_send() */
146     union vlc_event_type_specific
147     {
148         /* Input (thread) events */
149         struct vlc_input_state_changed
150         {
151             int new_state;
152         } input_state_changed;
153         struct vlc_input_selected_stream_changed
154         {
155             void * unused;
156         } input_selected_stream_changed;
157
158         /* Input item events */
159         struct vlc_input_item_meta_changed
160         {
161             vlc_meta_type_t meta_type;
162         } input_item_meta_changed;
163         struct vlc_input_item_subitem_added
164         {
165             input_item_t * p_new_child;
166         } input_item_subitem_added;
167         struct vlc_input_item_subitem_tree_added
168         {
169             input_item_node_t * p_root;
170         } input_item_subitem_tree_added;
171         struct vlc_input_item_duration_changed
172         {
173             mtime_t new_duration;
174         } input_item_duration_changed;
175         struct vlc_input_item_preparsed_changed
176         {
177             int new_status;
178         } input_item_preparsed_changed;
179         struct vlc_input_item_name_changed
180         {
181             const char * new_name;
182         } input_item_name_changed;
183         struct vlc_input_item_info_changed
184         {
185             void * unused;
186         } input_item_info_changed;
187         struct input_item_error_when_reading_changed
188         {
189             bool new_value;
190         } input_item_error_when_reading_changed;
191
192         /* Service discovery events */
193         struct vlc_services_discovery_item_added
194         {
195             input_item_t * p_new_item;
196             const char * psz_category;
197         } services_discovery_item_added;
198         struct vlc_services_discovery_item_removed
199         {
200             input_item_t * p_item;
201         } services_discovery_item_removed;
202         struct vlc_services_discovery_started
203         {
204             void * unused;
205         } services_discovery_started;
206         struct vlc_services_discovery_ended
207         {
208             void * unused;
209         } services_discovery_ended;
210
211         /* Addons */
212         struct vlc_addon_generic_event
213         {
214             addon_entry_t * p_entry;
215         } addon_generic_event;
216     } u;
217 } vlc_event_t;
218
219 /* Event callback type */
220 typedef void ( *vlc_event_callback_t )( const vlc_event_t *, void * );
221
222  /*****************************************************************************
223  * Event manager
224  *****************************************************************************/
225
226 /*
227  * p_obj points to the object that owns the event manager, and from
228  * which events are sent
229  */
230 VLC_API int vlc_event_manager_init( vlc_event_manager_t * p_em, void * p_obj );
231
232 /*
233  * Destroy
234  */
235 VLC_API void vlc_event_manager_fini( vlc_event_manager_t * p_em );
236
237 /*
238  * Tells a specific event manager that it will handle event_type object
239  */
240 VLC_API int vlc_event_manager_register_event_type( vlc_event_manager_t * p_em,
241                                                    vlc_event_type_t );
242
243 /*
244  * Send an event to the listener attached to this p_em.
245  */
246 VLC_API void vlc_event_send( vlc_event_manager_t * p_em, vlc_event_t * );
247
248 /*
249  * Add a callback for an event.
250  */
251 VLC_API int vlc_event_attach( vlc_event_manager_t * p_event_manager,
252                               vlc_event_type_t event_type,
253                               vlc_event_callback_t pf_callback,
254                               void *p_user_data );
255
256 /*
257  * Remove a callback for an event.
258  */
259 VLC_API void vlc_event_detach( vlc_event_manager_t *p_event_manager,
260                                vlc_event_type_t event_type,
261                                vlc_event_callback_t pf_callback,
262                                void *p_user_data );
263
264 #endif /* VLC_EVENTS_H */