]> git.sesse.net Git - vlc/blob - lib/event_internal.h
demux: ts: rewrite/split IOD parsing
[vlc] / lib / event_internal.h
1 /*****************************************************************************
2  * event_internal.h : Definition of opaque structures for libvlc exported API
3  * Also contains some internal utility functions
4  *****************************************************************************
5  * Copyright (C) 2005-2009 VLC authors and VideoLAN
6  * $Id$
7  *
8  * Authors: ClĂ©ment Stenac <zorglub@videolan.org>
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 _LIBVLC_EVENT_H
26 #define _LIBVLC_EVENT_H 1
27
28 #ifdef HAVE_CONFIG_H
29 # include "config.h"
30 #endif
31
32 #include <vlc/libvlc_structures.h>
33 #include <vlc/libvlc.h>
34 #include <vlc/libvlc_events.h>
35
36 #include <vlc_common.h>
37
38
39 /*
40  * Event Handling
41  */
42
43 /* Example usage
44  *
45  * struct libvlc_cool_object_t
46  * {
47  *        ...
48  *        libvlc_event_manager_t * p_event_manager;
49  *        ...
50  * }
51  *
52  * libvlc_my_cool_object_new()
53  * {
54  *        ...
55  *        p_self->p_event_manager = libvlc_event_manager_new( p_self,
56  *                                                   p_self->p_libvlc_instance, p_e);
57  *        libvlc_event_manager_register_event_type(p_self->p_event_manager,
58  *                libvlc_MyCoolObjectDidSomething, p_e)
59  *        ...
60  * }
61  *
62  * libvlc_my_cool_object_release()
63  * {
64  *         ...
65  *         libvlc_event_manager_release( p_self->p_event_manager );
66  *         ...
67  * }
68  *
69  * libvlc_my_cool_object_do_something()
70  * {
71  *        ...
72  *        libvlc_event_t event;
73  *        event.type = libvlc_MyCoolObjectDidSomething;
74  *        event.u.my_cool_object_did_something.what_it_did = kSomething;
75  *        libvlc_event_send( p_self->p_event_manager, &event );
76  * }
77  * */
78
79 typedef struct libvlc_event_listener_t
80 {
81     libvlc_event_type_t event_type;
82     void *              p_user_data;
83     libvlc_callback_t   pf_callback;
84     bool                is_asynchronous;
85 } libvlc_event_listener_t;
86
87 typedef struct libvlc_event_manager_t
88 {
89     void * p_obj;
90     struct libvlc_instance_t * p_libvlc_instance;
91     vlc_array_t listeners_groups;
92     vlc_mutex_t object_lock;
93     vlc_mutex_t event_sending_lock;
94     struct libvlc_event_async_queue * async_event_queue;
95 } libvlc_event_sender_t;
96
97
98 static inline bool
99 listeners_are_equal( libvlc_event_listener_t * listener1,
100                     libvlc_event_listener_t * listener2 )
101 {
102     return listener1->event_type  == listener2->event_type &&
103     listener1->pf_callback == listener2->pf_callback &&
104     listener1->p_user_data == listener2->p_user_data &&
105     listener1->is_asynchronous == listener2->is_asynchronous;
106 }
107
108 /* event_async.c */
109 void libvlc_event_async_fini(libvlc_event_manager_t * p_em);
110 void libvlc_event_async_dispatch(libvlc_event_manager_t * p_em, libvlc_event_listener_t * listener, libvlc_event_t * event);
111 void libvlc_event_async_ensure_listener_removal(libvlc_event_manager_t * p_em, libvlc_event_listener_t * listener);
112
113 #endif