access: bluray: unify behaviour of all random access
[vlc.git] / include / vlc_events.h
blob71d701fe038658dcd966fd6baf863c536893b437
1 /*****************************************************************************
2 * vlc_events.h: events definitions
3 * Interface used to send events.
4 *****************************************************************************
5 * Copyright (C) 2007 VLC authors and VideoLAN
6 * $Id$
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 *****************************************************************************/
25 #ifndef VLC_EVENTS_H
26 # define VLC_EVENTS_H
28 #include <vlc_arrays.h>
29 #include <vlc_meta.h>
31 /**
32 * \file
33 * This file is the interface definition for events
34 * (implementation in src/misc/events.c)
37 /*****************************************************************************
38 * Documentation
39 *****************************************************************************/
41 **** Background
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)
58 **** Example usage
60 * (vlc_cool_object_t doesn't need to have the vlc_common_members.)
62 * struct vlc_cool_object_t
63 * {
64 * ...
65 * vlc_event_manager_t p_event_manager;
66 * ...
67 * }
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 * ...
74 * }
76 * vlc_my_cool_object_release()
77 * {
78 * ...
79 * vlc_event_manager_fini( &p_self->p_event_manager );
80 * ...
81 * }
83 * vlc_my_cool_object_do_something()
84 * {
85 * ...
86 * vlc_event_t event;
87 * event.type = vlc_MyCoolObjectDidSomething;
88 * event.u.my_cool_object_did_something.what_it_did = kSomething;
89 * vlc_event_send( &p_self->p_event_manager, &event );
90 * }
91 * */
93 /*****************************************************************************
94 * Event Type
95 *****************************************************************************/
97 /* List of event */
98 typedef enum vlc_event_type_t {
99 /* Input item events */
100 vlc_InputItemMetaChanged,
101 vlc_InputItemDurationChanged,
102 vlc_InputItemPreparsedChanged,
103 vlc_InputItemNameChanged,
104 vlc_InputItemInfoChanged,
105 vlc_InputItemErrorWhenReadingChanged,
106 } vlc_event_type_t;
108 typedef struct vlc_event_listeners_group_t
110 DECL_ARRAY(struct vlc_event_listener_t *) listeners;
111 } vlc_event_listeners_group_t;
113 /* Event manager type */
114 typedef struct vlc_event_manager_t
116 void * p_obj;
117 vlc_mutex_t lock;
118 vlc_event_listeners_group_t events[vlc_InputItemErrorWhenReadingChanged + 1];
119 } vlc_event_manager_t;
121 /* Event definition */
122 typedef struct vlc_event_t
124 vlc_event_type_t type;
125 void * p_obj; /* Sender object, automatically filled by vlc_event_send() */
126 union vlc_event_type_specific
128 /* Input item events */
129 struct vlc_input_item_meta_changed
131 vlc_meta_type_t meta_type;
132 } input_item_meta_changed;
133 struct vlc_input_item_subitem_added
135 input_item_t * p_new_child;
136 } input_item_subitem_added;
137 struct vlc_input_item_subitem_tree_added
139 input_item_node_t * p_root;
140 } input_item_subitem_tree_added;
141 struct vlc_input_item_duration_changed
143 vlc_tick_t new_duration;
144 } input_item_duration_changed;
145 struct vlc_input_item_preparsed_changed
147 int new_status;
148 } input_item_preparsed_changed;
149 struct vlc_input_item_name_changed
151 const char * new_name;
152 } input_item_name_changed;
153 struct vlc_input_item_info_changed
155 void * unused;
156 } input_item_info_changed;
157 struct input_item_error_when_reading_changed
159 bool new_value;
160 } input_item_error_when_reading_changed;
161 struct input_item_preparse_ended
163 int new_status;
164 } input_item_preparse_ended;
165 } u;
166 } vlc_event_t;
168 /* Event callback type */
169 typedef void ( *vlc_event_callback_t )( const vlc_event_t *, void * );
171 /*****************************************************************************
172 * Event manager
173 *****************************************************************************/
176 * p_obj points to the object that owns the event manager, and from
177 * which events are sent
179 void vlc_event_manager_init( vlc_event_manager_t * p_em, void * p_obj );
182 * Destroy
184 void vlc_event_manager_fini( vlc_event_manager_t * p_em );
187 * Send an event to the listener attached to this p_em.
189 void vlc_event_send( vlc_event_manager_t * p_em, vlc_event_t * );
192 * Add a callback for an event.
194 VLC_API int vlc_event_attach( vlc_event_manager_t * p_event_manager,
195 vlc_event_type_t event_type,
196 vlc_event_callback_t pf_callback,
197 void *p_user_data );
200 * Remove a callback for an event.
202 VLC_API void vlc_event_detach( vlc_event_manager_t *p_event_manager,
203 vlc_event_type_t event_type,
204 vlc_event_callback_t pf_callback,
205 void *p_user_data );
207 #endif /* VLC_EVENTS_H */