1 /*****************************************************************************
2 * vlc_events.h: events definitions
3 * Interface used to send events.
4 *****************************************************************************
5 * Copyright (C) 2007 VLC authors and VideoLAN
8 * Authors: Pierre d'Herbemont
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.
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.
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 *****************************************************************************/
28 #include <vlc_arrays.h>
33 * This file is the interface definition for events
34 * (implementation in src/misc/events.c)
37 /*****************************************************************************
39 *****************************************************************************/
43 * This implements a way to send and receive event for an object (which can be
44 * a simple C struct or less).
46 * This is in direct concurrency with the Variable based Callback
47 * (see src/misc/variables.c).
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)
60 * (vlc_cool_object_t doesn't need to have the VLC_COMMON_MEMBERS.)
62 * struct vlc_cool_object_t
65 * vlc_event_manager_t p_event_manager;
69 * vlc_my_cool_object_new()
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)
78 * vlc_my_cool_object_release()
81 * vlc_event_manager_fini( &p_self->p_event_manager );
85 * vlc_my_cool_object_do_something()
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 );
95 /*****************************************************************************
97 *****************************************************************************/
99 /* Private structure defined in misc/events.c */
100 struct vlc_event_listeners_group_t
;
102 /* Event manager type */
103 typedef struct vlc_event_manager_t
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
;
112 typedef enum vlc_event_type_t
{
113 /* Input item events */
114 vlc_InputItemMetaChanged
,
115 vlc_InputItemSubItemAdded
,
116 vlc_InputItemSubItemTreeAdded
,
117 vlc_InputItemDurationChanged
,
118 vlc_InputItemPreparsedChanged
,
119 vlc_InputItemNameChanged
,
120 vlc_InputItemInfoChanged
,
121 vlc_InputItemErrorWhenReadingChanged
,
122 vlc_InputItemPreparseEnded
,
124 /* Service Discovery event */
125 vlc_ServicesDiscoveryItemAdded
,
126 vlc_ServicesDiscoveryItemRemoved
,
127 vlc_ServicesDiscoveryItemRemoveAll
,
128 vlc_ServicesDiscoveryStarted
,
129 vlc_ServicesDiscoveryEnded
,
131 /* Renderer Discovery events */
132 vlc_RendererDiscoveryItemAdded
,
133 vlc_RendererDiscoveryItemRemoved
,
135 /* Addons Manager events */
137 vlc_AddonsDiscoveryEnded
,
141 /* Event definition */
142 typedef struct vlc_event_t
144 vlc_event_type_t type
;
145 void * p_obj
; /* Sender object, automatically filled by vlc_event_send() */
146 union vlc_event_type_specific
148 /* Input item events */
149 struct vlc_input_item_meta_changed
151 vlc_meta_type_t meta_type
;
152 } input_item_meta_changed
;
153 struct vlc_input_item_subitem_added
155 input_item_t
* p_new_child
;
156 } input_item_subitem_added
;
157 struct vlc_input_item_subitem_tree_added
159 input_item_node_t
* p_root
;
160 } input_item_subitem_tree_added
;
161 struct vlc_input_item_duration_changed
163 mtime_t new_duration
;
164 } input_item_duration_changed
;
165 struct vlc_input_item_preparsed_changed
168 } input_item_preparsed_changed
;
169 struct vlc_input_item_name_changed
171 const char * new_name
;
172 } input_item_name_changed
;
173 struct vlc_input_item_info_changed
176 } input_item_info_changed
;
177 struct input_item_error_when_reading_changed
180 } input_item_error_when_reading_changed
;
181 struct input_item_preparse_ended
184 } input_item_preparse_ended
;
186 /* Service discovery events */
187 struct vlc_services_discovery_item_added
189 input_item_t
* p_new_item
;
190 const char * psz_category
;
191 } services_discovery_item_added
;
192 struct vlc_services_discovery_item_removed
194 input_item_t
* p_item
;
195 } services_discovery_item_removed
;
196 struct vlc_services_discovery_started
199 } services_discovery_started
;
200 struct vlc_services_discovery_ended
203 } services_discovery_ended
;
205 /* Renderer discovery events */
206 struct vlc_renderer_discovery_item_added
208 vlc_renderer_item
* p_new_item
;
209 } renderer_discovery_item_added
;
210 struct vlc_renderer_discovery_item_removed
212 vlc_renderer_item
* p_item
;
213 } renderer_discovery_item_removed
;
216 struct vlc_addon_generic_event
218 addon_entry_t
* p_entry
;
219 } addon_generic_event
;
223 /* Event callback type */
224 typedef void ( *vlc_event_callback_t
)( const vlc_event_t
*, void * );
226 /*****************************************************************************
228 *****************************************************************************/
231 * p_obj points to the object that owns the event manager, and from
232 * which events are sent
234 VLC_API
int vlc_event_manager_init( vlc_event_manager_t
* p_em
, void * p_obj
);
239 VLC_API
void vlc_event_manager_fini( vlc_event_manager_t
* p_em
);
242 * Tells a specific event manager that it will handle event_type object
244 VLC_API
int vlc_event_manager_register_event_type( vlc_event_manager_t
* p_em
,
248 * Send an event to the listener attached to this p_em.
250 VLC_API
void vlc_event_send( vlc_event_manager_t
* p_em
, vlc_event_t
* );
253 * Add a callback for an event.
255 VLC_API
int vlc_event_attach( vlc_event_manager_t
* p_event_manager
,
256 vlc_event_type_t event_type
,
257 vlc_event_callback_t pf_callback
,
261 * Remove a callback for an event.
263 VLC_API
void vlc_event_detach( vlc_event_manager_t
*p_event_manager
,
264 vlc_event_type_t event_type
,
265 vlc_event_callback_t pf_callback
,
268 #endif /* VLC_EVENTS_H */