VLC  4.0.0-dev
vlc_events.h
Go to the documentation of this file.
1 /*****************************************************************************
2  * vlc_events.h: events definitions
3  * Interface used to send events.
4  *****************************************************************************
5  * Copyright (C) 2007 VLC authors and VideoLAN
6  *
7  * Authors: Pierre d'Herbemont
8  *
9  * This program is free software; you can redistribute it and/or modify it
10  * under the terms of the GNU Lesser General Public License as published by
11  * the Free Software Foundation; either version 2.1 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public License
20  * along with this program; if not, write to the Free Software Foundation,
21  * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22  *****************************************************************************/
23 
24 #ifndef VLC_EVENTS_H
25 # define VLC_EVENTS_H
26 
27 #include <vlc_arrays.h>
28 #include <vlc_meta.h>
29 
30 /**
31  * \file
32  * This file is the interface definition for events
33  * (implementation in src/misc/events.c)
34  */
35 
36 /*****************************************************************************
37  * Documentation
38  *****************************************************************************/
39 /*
40  **** Background
41  *
42  * This implements a way to send and receive event for an object (which can be
43  * a simple C struct or less).
44  *
45  * This is in direct concurrency with the Variable based Callback
46  * (see src/misc/variables.c).
47  *
48  * It has the following advantages over Variable based Callback:
49  * - No need to implement the whole vlc_object_t in the object,
50  * thus it reduce it size. This is especially true for input_item_t which
51  * doesn't have vlc_object_t. This is the first reason of existence of
52  * this implementation.
53  * - Libvlc can easily be based upon that.
54  * - Existing event are clearly declared (in include/vlc_events.h)
55  *
56  *
57  **** Example usage
58  *
59  * (vlc_cool_object_t doesn't need to have the vlc_object_t.)
60  *
61  * struct vlc_cool_object_t
62  * {
63  * ...
64  * vlc_event_manager_t p_event_manager;
65  * ...
66  * }
67  *
68  * vlc_my_cool_object_new()
69  * {
70  * ...
71  * vlc_event_manager_init( &p_self->p_event_manager, p_self, p_a_libvlc_object );
72  * ...
73  * }
74  *
75  * vlc_my_cool_object_release()
76  * {
77  * ...
78  * vlc_event_manager_fini( &p_self->p_event_manager );
79  * ...
80  * }
81  *
82  * vlc_my_cool_object_do_something()
83  * {
84  * ...
85  * vlc_event_t event;
86  * event.type = vlc_MyCoolObjectDidSomething;
87  * event.u.my_cool_object_did_something.what_it_did = kSomething;
88  * vlc_event_send( &p_self->p_event_manager, &event );
89  * }
90  * */
91 
92  /*****************************************************************************
93  * Event Type
94  *****************************************************************************/
95 
96 /* List of event */
97 typedef enum vlc_event_type_t {
98  /* Input item events */
107 
109 {
112 
113 /* Event manager type */
114 typedef struct vlc_event_manager_t
115 {
116  void * p_obj;
120 
121 /* Event definition */
122 typedef struct vlc_event_t
123 {
125  void * p_obj; /* Sender object, automatically filled by vlc_event_send() */
127  {
128  /* Input item events */
130  {
134  {
138  {
142  {
146  {
147  int new_status;
150  {
151  const char * new_name;
154  {
155  void * unused;
158  {
159  bool new_value;
162  {
163  int new_status;
166  {
168  size_t count;
170  } u;
171 } vlc_event_t;
172 
173 /* Event callback type */
174 typedef void ( *vlc_event_callback_t )( const vlc_event_t *, void * );
175 
176  /*****************************************************************************
177  * Event manager
178  *****************************************************************************/
179 
180 /*
181  * p_obj points to the object that owns the event manager, and from
182  * which events are sent
183  */
184 void vlc_event_manager_init( vlc_event_manager_t * p_em, void * p_obj );
185 
186 /*
187  * Destroy
188  */
190 
191 /*
192  * Send an event to the listener attached to this p_em.
193  */
195 
196 /*
197  * Add a callback for an event.
198  */
199 VLC_API int vlc_event_attach( vlc_event_manager_t * p_event_manager,
200  vlc_event_type_t event_type,
201  vlc_event_callback_t pf_callback,
202  void *p_user_data );
203 
204 /*
205  * Remove a callback for an event.
206  */
207 VLC_API void vlc_event_detach( vlc_event_manager_t *p_event_manager,
208  vlc_event_type_t event_type,
209  vlc_event_callback_t pf_callback,
210  void *p_user_data );
211 
212 #endif /* VLC_EVENTS_H */
vlc_event_t::vlc_event_type_specific::input_item_error_when_reading_changed
Definition: vlc_events.h:158
vlc_event_t::vlc_event_type_specific::input_item_preparse_ended
struct vlc_event_t::vlc_event_type_specific::input_item_preparse_ended input_item_preparse_ended
VLC_API
#define VLC_API
Definition: fourcc_gen.c:31
vlc_event_listeners_group_t
struct vlc_event_listeners_group_t vlc_event_listeners_group_t
vlc_event_t::vlc_event_type_specific::input_item_preparse_ended::new_status
int new_status
Definition: vlc_events.h:164
vlc_InputItemPreparsedChanged
@ vlc_InputItemPreparsedChanged
Definition: vlc_events.h:106
vlc_event_listeners_group_t
Definition: vlc_events.h:109
vlc_InputItemMetaChanged
@ vlc_InputItemMetaChanged
Definition: vlc_events.h:104
vlc_event_t::p_obj
void * p_obj
Definition: vlc_events.h:126
input_attachment_t
Definition: vlc_input.h:159
vlc_event_listeners_group_t::listeners
struct vlc_event_listeners_group_t::@208 listeners
vlc_event_t::vlc_event_type_specific::input_item_meta_changed
struct vlc_event_t::vlc_event_type_specific::vlc_input_item_meta_changed input_item_meta_changed
vlc_event_t::vlc_event_type_specific::input_item_error_when_reading_changed
struct vlc_event_t::vlc_event_type_specific::input_item_error_when_reading_changed input_item_error_when_reading_changed
vlc_InputItemDurationChanged
@ vlc_InputItemDurationChanged
Definition: vlc_events.h:105
vlc_event_manager_t::p_obj
void * p_obj
Definition: vlc_events.h:117
vlc_common.h
vlc_event_t::vlc_event_type_specific::input_item_subitem_added
struct vlc_event_t::vlc_event_type_specific::vlc_input_item_subitem_added input_item_subitem_added
vlc_event_t::u
union vlc_event_t::vlc_event_type_specific u
vlc_event_t::vlc_event_type_specific::input_item_attachments_found
struct vlc_event_t::vlc_event_type_specific::input_item_attachments_found input_item_attachments_found
input_item_t
Describes an input and is used to spawn input_thread_t objects.
Definition: vlc_input_item.h:77
vlc_event_callback_t
void(* vlc_event_callback_t)(const vlc_event_t *, void *)
Definition: vlc_events.h:175
vlc_InputItemNameChanged
@ vlc_InputItemNameChanged
Definition: vlc_events.h:107
vlc_event_t::vlc_event_type_specific::input_item_duration_changed
struct vlc_event_t::vlc_event_type_specific::vlc_input_item_duration_changed input_item_duration_changed
vlc_event_t::vlc_event_type_specific::input_item_preparse_ended
Definition: vlc_events.h:162
vlc_event_t::vlc_event_type_specific::input_item_attachments_found::attachments
input_attachment_t ** attachments
Definition: vlc_events.h:168
vlc_event_manager_init
void vlc_event_manager_init(vlc_event_manager_t *p_em, void *p_obj)
Initialize event manager object p_obj is the object that contains the event manager.
Definition: events.c:65
vlc_event_t::vlc_event_type_specific::input_item_info_changed
struct vlc_event_t::vlc_event_type_specific::vlc_input_item_info_changed input_item_info_changed
vlc_event_t::vlc_event_type_specific
Definition: vlc_events.h:127
vlc_event_t
Definition: vlc_events.h:123
vlc_event_t::vlc_event_type_specific::vlc_input_item_name_changed
Definition: vlc_events.h:150
vlc_mutex_t
Mutex.
Definition: vlc_threads.h:225
vlc_event_t::vlc_event_type_specific::vlc_input_item_info_changed::unused
void * unused
Definition: vlc_events.h:156
vlc_event_t::vlc_event_type_specific::vlc_input_item_subitem_added::p_new_child
input_item_t * p_new_child
Definition: vlc_events.h:136
vlc_event_t::vlc_event_type_specific::vlc_input_item_subitem_tree_added::p_root
input_item_node_t * p_root
Definition: vlc_events.h:140
vlc_event_t::vlc_event_type_specific::input_item_error_when_reading_changed::new_value
bool new_value
Definition: vlc_events.h:160
vlc_event_t::vlc_event_type_specific::input_item_name_changed
struct vlc_event_t::vlc_event_type_specific::vlc_input_item_name_changed input_item_name_changed
vlc_event_t::vlc_event_type_specific::vlc_input_item_meta_changed::meta_type
vlc_meta_type_t meta_type
Definition: vlc_events.h:132
vlc_event_listener_t
Definition: events.c:48
vlc_tick_t
int64_t vlc_tick_t
High precision date or time interval.
Definition: vlc_tick.h:45
vlc_event_t::vlc_event_type_specific::input_item_subitem_tree_added
struct vlc_event_t::vlc_event_type_specific::vlc_input_item_subitem_tree_added input_item_subitem_tree_added
vlc_event_t::vlc_event_type_specific::vlc_input_item_name_changed::new_name
const char * new_name
Definition: vlc_events.h:152
vlc_InputItemErrorWhenReadingChanged
@ vlc_InputItemErrorWhenReadingChanged
Definition: vlc_events.h:109
vlc_event_manager_t::lock
vlc_mutex_t lock
Definition: vlc_events.h:118
vlc_event_manager_t
Definition: vlc_events.h:115
DECL_ARRAY
#define DECL_ARRAY(type)
Definition: vlc_arrays.h:181
vlc_event_t::vlc_event_type_specific::input_item_attachments_found
Definition: vlc_events.h:166
vlc_event_t::vlc_event_type_specific::input_item_preparsed_changed
struct vlc_event_t::vlc_event_type_specific::vlc_input_item_preparsed_changed input_item_preparsed_changed
vlc_InputItemAttachmentsFound
@ vlc_InputItemAttachmentsFound
Definition: vlc_events.h:110
vlc_event_manager_fini
void vlc_event_manager_fini(vlc_event_manager_t *p_em)
Destroy the event manager.
Definition: events.c:79
vlc_event_t::vlc_event_type_specific::vlc_input_item_meta_changed
Definition: vlc_events.h:130
vlc_event_t
struct vlc_event_t vlc_event_t
vlc_event_manager_t::events
vlc_event_listeners_group_t events[vlc_InputItemAttachmentsFound+1]
Definition: vlc_events.h:119
vlc_event_t::vlc_event_type_specific::vlc_input_item_subitem_added
Definition: vlc_events.h:134
vlc_event_type_t
vlc_event_type_t
Definition: vlc_events.h:98
vlc_event_t::vlc_event_type_specific::vlc_input_item_duration_changed::new_duration
vlc_tick_t new_duration
Definition: vlc_events.h:144
vlc_InputItemInfoChanged
@ vlc_InputItemInfoChanged
Definition: vlc_events.h:108
vlc_event_t::vlc_event_type_specific::vlc_input_item_info_changed
Definition: vlc_events.h:154
vlc_event_detach
VLC_EXPORT void vlc_event_detach(vlc_event_manager_t *p_event_manager, vlc_event_type_t event_type, vlc_event_callback_t pf_callback, void *p_user_data)
Remove a callback for an event.
Definition: events.c:143
vlc_event_t::vlc_event_type_specific::input_item_attachments_found::count
size_t count
Definition: vlc_events.h:169
vlc_arrays.h
vlc_event_t::vlc_event_type_specific::vlc_input_item_duration_changed
Definition: vlc_events.h:142
vlc_meta_type_t
vlc_meta_type_t
Definition: vlc_meta.h:33
input_item_node_t
Definition: vlc_input_item.h:194
vlc_event_t::vlc_event_type_specific::vlc_input_item_preparsed_changed::new_status
int new_status
Definition: vlc_events.h:148
vlc_meta.h
vlc_event_t::vlc_event_type_specific::vlc_input_item_subitem_tree_added
Definition: vlc_events.h:138
vlc_event_t::type
vlc_event_type_t type
Definition: vlc_events.h:125
vlc_event_manager_t
struct vlc_event_manager_t vlc_event_manager_t
vlc_event_t::vlc_event_type_specific::vlc_input_item_preparsed_changed
Definition: vlc_events.h:146
vlc_event_send
void vlc_event_send(vlc_event_manager_t *p_em, vlc_event_t *)
Send an event to the listener attached to this p_em.
Definition: events.c:97
vlc_event_attach
VLC_EXPORT int vlc_event_attach(vlc_event_manager_t *p_event_manager, vlc_event_type_t event_type, vlc_event_callback_t pf_callback, void *p_user_data)
Add a callback for an event.
Definition: events.c:118