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#include <vlc_threads.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_object_t in the object,
51 * thus it reduce it size. This is especially true for input_item_t which
52 * doesn't have vlc_object_t. 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_object_t.)
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 * ...
74 * }
75 *
76 * vlc_my_cool_object_release()
77 * {
78 * ...
79 * vlc_event_manager_fini( &p_self->p_event_manager );
80 * ...
81 * }
82 *
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 * */
92
93 /*****************************************************************************
94 * Event Type
95 *****************************************************************************/
96
97/* List of event */
98typedef enum vlc_event_type_t {
99 /* Input item events */
109#define VLC_EVENT_TYPE_COUNT (vlc_InputItemAttachmentsFound + 1)
111typedef struct vlc_event_listeners_group_t
116/* Event manager type */
117typedef struct vlc_event_manager_t
119 void * p_obj;
124/* Event definition */
125typedef struct vlc_event_t
128 void * p_obj; /* Sender object, automatically filled by vlc_event_send() */
131 /* Input item events */
150 int new_status;
154 const char * new_name;
158 void * unused;
162 bool new_value;
166 int new_status;
171 size_t count;
173 } u;
176/* Event callback type */
177typedef void ( *vlc_event_callback_t )( const vlc_event_t *, void * );
179 /*****************************************************************************
180 * Event manager
181 *****************************************************************************/
182
183/*
184 * p_obj points to the object that owns the event manager, and from
185 * which events are sent
186 */
187void vlc_event_manager_init( vlc_event_manager_t * p_em, void * p_obj );
188
189/*
190 * Destroy
191 */
193
194/*
195 * Send an event to the listener attached to this p_em.
196 */
198
199/*
200 * Add a callback for an event.
201 */
202VLC_API int vlc_event_attach( 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 );
206
207/*
208 * Remove a callback for an event.
209 */
210VLC_API void vlc_event_detach( vlc_event_manager_t *p_event_manager,
211 vlc_event_type_t event_type,
212 vlc_event_callback_t pf_callback,
213 void *p_user_data );
214
215#endif /* VLC_EVENTS_H */
#define VLC_API
Definition: fourcc_gen.c:31
Definition: vlc_input.h:161
Definition: vlc_input_item.h:205
Describes an input and is used to spawn input_thread_t objects.
Definition: vlc_input_item.h:89
Definition: events.c:49
Definition: vlc_events.h:113
struct vlc_event_listeners_group_t::@220 listeners
Definition: vlc_events.h:119
void * p_obj
Definition: vlc_events.h:120
vlc_mutex_t lock
Definition: vlc_events.h:121
vlc_event_listeners_group_t events[(vlc_InputItemAttachmentsFound+1)]
Definition: vlc_events.h:122
input_attachment_t ** attachments
Definition: vlc_events.h:171
vlc_meta_type_t meta_type
Definition: vlc_events.h:135
input_item_t * p_new_child
Definition: vlc_events.h:139
input_item_node_t * p_root
Definition: vlc_events.h:143
Definition: vlc_events.h:127
void * p_obj
Definition: vlc_events.h:129
union vlc_event_t::vlc_event_type_specific u
vlc_event_type_t type
Definition: vlc_events.h:128
Mutex.
Definition: vlc_threads.h:195
Definition: vlc_events.h:131
struct vlc_event_t::vlc_event_type_specific::input_item_preparse_ended input_item_preparse_ended
struct vlc_event_t::vlc_event_type_specific::vlc_input_item_meta_changed input_item_meta_changed
struct vlc_event_t::vlc_event_type_specific::vlc_input_item_name_changed input_item_name_changed
struct vlc_event_t::vlc_event_type_specific::vlc_input_item_preparsed_changed input_item_preparsed_changed
struct vlc_event_t::vlc_event_type_specific::vlc_input_item_subitem_added input_item_subitem_added
struct vlc_event_t::vlc_event_type_specific::vlc_input_item_duration_changed input_item_duration_changed
struct vlc_event_t::vlc_event_type_specific::vlc_input_item_subitem_tree_added input_item_subitem_tree_added
struct vlc_event_t::vlc_event_type_specific::input_item_error_when_reading_changed input_item_error_when_reading_changed
struct vlc_event_t::vlc_event_type_specific::vlc_input_item_info_changed input_item_info_changed
struct vlc_event_t::vlc_event_type_specific::input_item_attachments_found input_item_attachments_found
This file defines functions, structures and macros for handling arrays in vlc.
#define DECL_ARRAY(type)
Definition: vlc_arrays.h:179
This file is a collection of common definitions and types.
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
struct vlc_event_listeners_group_t vlc_event_listeners_group_t
struct vlc_event_t vlc_event_t
vlc_event_type_t
Definition: vlc_events.h:99
@ vlc_InputItemPreparsedChanged
Definition: vlc_events.h:103
@ vlc_InputItemErrorWhenReadingChanged
Definition: vlc_events.h:106
@ vlc_InputItemNameChanged
Definition: vlc_events.h:104
@ vlc_InputItemDurationChanged
Definition: vlc_events.h:102
@ vlc_InputItemAttachmentsFound
Definition: vlc_events.h:107
@ vlc_InputItemInfoChanged
Definition: vlc_events.h:105
@ vlc_InputItemMetaChanged
Definition: vlc_events.h:101
void vlc_event_manager_fini(vlc_event_manager_t *p_em)
Destroy the event manager.
Definition: events.c:79
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
#define VLC_EVENT_TYPE_COUNT
Definition: vlc_events.h:110
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
struct vlc_event_manager_t vlc_event_manager_t
void(* vlc_event_callback_t)(const vlc_event_t *, void *)
Definition: vlc_events.h:178
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
This file defines functions and structures for stream meta-data in vlc.
vlc_meta_type_t
Definition: vlc_meta.h:34
Thread primitive declarations.
int64_t vlc_tick_t
High precision date or time interval.
Definition: vlc_tick.h:45