vlc_events.h

Go to the documentation of this file.
00001 /*****************************************************************************
00002  * events.h: events definitions
00003  * Interface used to send events.
00004  *****************************************************************************
00005  * Copyright (C) 2007 the VideoLAN team
00006  * $Id$
00007  *
00008  * Authors: Pierre d'Herbemont
00009  *
00010  * This program is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2 of the License, or
00013  * (at your option) any later version.
00014  *
00015  * This program is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  * GNU General Public License for more details.
00019  *
00020  * You should have received a copy of the GNU General Public License
00021  * along with this program; if not, write to the Free Software
00022  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
00023  *****************************************************************************/
00024 
00025 #ifndef VLC_EVENTS_H
00026 # define VLC_EVENTS_H
00027 
00028 #include <vlc_arrays.h>
00029 #include <vlc_meta.h>
00030 
00031 /**
00032  * \file
00033  * This file is the interface definition for events
00034  * (implementation in src/misc/events.c)
00035  */
00036 
00037 /*****************************************************************************
00038  * Documentation
00039  *****************************************************************************/
00040 /*
00041  **** Background
00042  *
00043  * This implements a way to send and receive event for an object (which can be
00044  * a simple C struct or less).
00045  *
00046  * This is in direct concurrency with the Variable based Callback
00047  * (see src/misc/variables.c).
00048  *
00049  * It has the following advantages over Variable based Callback:
00050  * - No need to implement the whole VLC_COMMON_MEMBERS in the object,
00051  * thus it reduce it size. This is especially true for input_item_t which
00052  * doesn't have VLC_COMMON_MEMBERS. This is the first reason of existence of
00053  * this implementation.
00054  * - Libvlc can easily be based upon that.
00055  * - Existing event are clearly declared (in include/vlc_events.h)
00056  *
00057  *
00058  **** Example usage
00059  *
00060  * (vlc_cool_object_t doesn't need to have the VLC_COMMON_MEMBERS.)
00061  *
00062  * struct vlc_cool_object_t
00063  * {
00064  *        ...
00065  *        vlc_event_manager_t p_event_manager;
00066  *        ...
00067  * }
00068  *
00069  * vlc_my_cool_object_new()
00070  * {
00071  *        ...
00072  *        vlc_event_manager_init( &p_self->p_event_manager, p_self, p_a_libvlc_object );
00073  *        vlc_event_manager_register_event_type(p_self->p_event_manager,
00074  *                vlc_MyCoolObjectDidSomething, p_e)
00075  *        ...
00076  * }
00077  *
00078  * vlc_my_cool_object_release()
00079  * {
00080  *         ...
00081  *         vlc_event_manager_fini( &p_self->p_event_manager );
00082  *         ...
00083  * }
00084  *
00085  * vlc_my_cool_object_do_something()
00086  * {
00087  *        ...
00088  *        vlc_event_t event;
00089  *        event.type = vlc_MyCoolObjectDidSomething;
00090  *        event.u.my_cool_object_did_something.what_it_did = kSomething;
00091  *        vlc_event_send( &p_self->p_event_manager, &event );
00092  * }
00093  * */
00094 
00095   /*****************************************************************************
00096  * Event Type
00097  *****************************************************************************/
00098 
00099 /* Private structure defined in misc/events.c */
00100 struct vlc_event_listeners_group_t;
00101 
00102 /* Event manager type */
00103 typedef struct vlc_event_manager_t
00104 {
00105     void * p_obj;
00106     vlc_mutex_t object_lock;
00107     vlc_mutex_t event_sending_lock;
00108     vlc_object_t *p_parent_object;
00109     DECL_ARRAY(struct vlc_event_listeners_group_t *) listeners_groups;
00110 } vlc_event_manager_t;
00111 
00112 /* List of event */
00113 /* Be sure to keep sync-ed with misc/events.c debug name table */
00114 typedef enum vlc_event_type_t {
00115     /* Input (thread) events */
00116     vlc_InputStateChanged,
00117     vlc_InputSelectedStreamChanged,
00118 
00119     /* Input item events */
00120     vlc_InputItemMetaChanged,
00121     vlc_InputItemSubItemAdded,
00122     vlc_InputItemDurationChanged,
00123     vlc_InputItemPreparsedChanged,
00124     vlc_InputItemNameChanged,
00125     vlc_InputItemInfoChanged,
00126     vlc_InputItemErrorWhenReadingChanged,
00127 
00128     /* Service Discovery event */
00129     vlc_ServicesDiscoveryItemAdded,
00130     vlc_ServicesDiscoveryItemRemoved,
00131     vlc_ServicesDiscoveryStarted,
00132     vlc_ServicesDiscoveryEnded
00133 } vlc_event_type_t;
00134 
00135 /* Event definition */
00136 typedef struct vlc_event_t
00137 {
00138     vlc_event_type_t type;
00139     void * p_obj; /* Sender object, automatically filled by vlc_event_send() */
00140     union vlc_event_type_specific
00141     {
00142         /* Input (thread) events */
00143         struct vlc_input_state_changed
00144         {
00145             int new_state;
00146         } input_state_changed;
00147         struct vlc_input_selected_stream_changed
00148         {
00149             void * unused;
00150         } input_selected_stream_changed;
00151 
00152         /* Input item events */
00153         struct vlc_input_item_meta_changed
00154         {
00155             vlc_meta_type_t meta_type;
00156         } input_item_meta_changed;
00157         struct vlc_input_item_subitem_added
00158         {
00159             input_item_t * p_new_child;
00160         } input_item_subitem_added;
00161         struct vlc_input_item_duration_changed
00162         {
00163             mtime_t new_duration;
00164         } input_item_duration_changed;
00165         struct vlc_input_item_preparsed_changed
00166         {
00167             int new_status;
00168         } input_item_preparsed_changed;
00169         struct vlc_input_item_name_changed
00170         {
00171             const char * new_name;
00172         } input_item_name_changed;
00173         struct vlc_input_item_info_changed
00174         {
00175             void * unused;
00176         } input_item_info_changed;
00177         struct input_item_error_when_reading_changed
00178         {
00179             bool new_value;
00180         } input_item_error_when_reading_changed;
00181 
00182         /* Service discovery events */
00183         struct vlc_services_discovery_item_added
00184         {
00185             input_item_t * p_new_item;
00186             const char * psz_category;
00187         } services_discovery_item_added;
00188         struct vlc_services_discovery_item_removed
00189         {
00190             input_item_t * p_item;
00191         } services_discovery_item_removed;
00192         struct vlc_services_discovery_started
00193         {
00194             void * unused;
00195         } services_discovery_started;
00196         struct vlc_services_discovery_ended
00197         {
00198             void * unused;
00199         } services_discovery_ended;
00200 
00201     } u;
00202 } vlc_event_t;
00203 
00204 /* Event callback type */
00205 typedef void ( *vlc_event_callback_t )( const vlc_event_t *, void * );
00206 
00207  /*****************************************************************************
00208  * Event manager
00209  *****************************************************************************/
00210 
00211 /*
00212  * p_obj points to the object that owns the event manager, and from
00213  * which events are sent
00214  * p_obj is here to give us a libvlc instance
00215  */
00216 #define vlc_event_manager_init_with_vlc_object(a,b) \
00217             vlc_event_manager_init( a, b, b )
00218 
00219 #define vlc_event_manager_init(a,b,c) \
00220             __vlc_event_manager_init(a, b, VLC_OBJECT(c))
00221 VLC_EXPORT(int, __vlc_event_manager_init, ( vlc_event_manager_t * p_em,
00222                                           void * p_obj, vlc_object_t * ));
00223 
00224 /*
00225  * Destroy
00226  */
00227 VLC_EXPORT(void, vlc_event_manager_fini, ( vlc_event_manager_t * p_em ));
00228 
00229 /*
00230  * Tells a specific event manager that it will handle event_type object
00231  */
00232 VLC_EXPORT(int, vlc_event_manager_register_event_type,
00233                 ( vlc_event_manager_t * p_em, vlc_event_type_t event_type ));
00234 
00235 /*
00236  * Send an event to the listener attached to this p_em.
00237  */
00238 VLC_EXPORT(void, vlc_event_send, ( vlc_event_manager_t * p_em,
00239                                    vlc_event_t * p_event ));
00240 
00241 /*
00242  * Add a callback for an event.
00243  */
00244 #define vlc_event_attach(a, b, c, d) __vlc_event_attach(a, b, c, d, #c)
00245 VLC_EXPORT(int, __vlc_event_attach, ( vlc_event_manager_t * p_event_manager,
00246                                       vlc_event_type_t event_type,
00247                                       vlc_event_callback_t pf_callback,
00248                                       void *p_user_data,
00249                                       const char * psz_debug_name ));
00250 
00251 /*
00252  * Remove a callback for an event.
00253  */
00254 VLC_EXPORT(int, vlc_event_detach, ( vlc_event_manager_t *p_event_manager,
00255                                     vlc_event_type_t event_type,
00256                                     vlc_event_callback_t pf_callback,
00257                                     void *p_user_data ));
00258 
00259 #endif /* VLC_EVENTS_H */

Generated on Wed Aug 13 08:02:37 2008 for VLC by  doxygen 1.5.1