vlc_events.h

Go to the documentation of this file.
00001 /*****************************************************************************
00002  * vlc_events.h: events definitions
00003  * Interface used to send events.
00004  *****************************************************************************
00005  * Copyright (C) 2007 VLC authors and VideoLAN
00006  * $Id: 9e37f7f5753243d52a4fba2616d958598083a53f $
00007  *
00008  * Authors: Pierre d'Herbemont
00009  *
00010  * This program is free software; you can redistribute it and/or modify it
00011  * under the terms of the GNU Lesser General Public License as published by
00012  * the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
00019  *
00020  * You should have received a copy of the GNU Lesser General Public License
00021  * along with this program; if not, write to the Free Software Foundation,
00022  * 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     DECL_ARRAY(struct vlc_event_listeners_group_t *) listeners_groups;
00109 } vlc_event_manager_t;
00110 
00111 /* List of event */
00112 typedef enum vlc_event_type_t {
00113     /* Input (thread) events */
00114     vlc_InputStateChanged,
00115     vlc_InputSelectedStreamChanged,
00116 
00117     /* Input item events */
00118     vlc_InputItemMetaChanged,
00119     vlc_InputItemSubItemAdded,
00120     vlc_InputItemSubItemTreeAdded,
00121     vlc_InputItemDurationChanged,
00122     vlc_InputItemPreparsedChanged,
00123     vlc_InputItemNameChanged,
00124     vlc_InputItemInfoChanged,
00125     vlc_InputItemErrorWhenReadingChanged,
00126 
00127     /* Service Discovery event */
00128     vlc_ServicesDiscoveryItemAdded,
00129     vlc_ServicesDiscoveryItemRemoved,
00130     vlc_ServicesDiscoveryItemRemoveAll,
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_subitem_tree_added
00162         {
00163             input_item_node_t * p_root;
00164         } input_item_subitem_tree_added;
00165         struct vlc_input_item_duration_changed
00166         {
00167             mtime_t new_duration;
00168         } input_item_duration_changed;
00169         struct vlc_input_item_preparsed_changed
00170         {
00171             int new_status;
00172         } input_item_preparsed_changed;
00173         struct vlc_input_item_name_changed
00174         {
00175             const char * new_name;
00176         } input_item_name_changed;
00177         struct vlc_input_item_info_changed
00178         {
00179             void * unused;
00180         } input_item_info_changed;
00181         struct input_item_error_when_reading_changed
00182         {
00183             bool new_value;
00184         } input_item_error_when_reading_changed;
00185 
00186         /* Service discovery events */
00187         struct vlc_services_discovery_item_added
00188         {
00189             input_item_t * p_new_item;
00190             const char * psz_category;
00191         } services_discovery_item_added;
00192         struct vlc_services_discovery_item_removed
00193         {
00194             input_item_t * p_item;
00195         } services_discovery_item_removed;
00196         struct vlc_services_discovery_started
00197         {
00198             void * unused;
00199         } services_discovery_started;
00200         struct vlc_services_discovery_ended
00201         {
00202             void * unused;
00203         } services_discovery_ended;
00204 
00205     } u;
00206 } vlc_event_t;
00207 
00208 /* Event callback type */
00209 typedef void ( *vlc_event_callback_t )( const vlc_event_t *, void * );
00210 
00211  /*****************************************************************************
00212  * Event manager
00213  *****************************************************************************/
00214 
00215 /*
00216  * p_obj points to the object that owns the event manager, and from
00217  * which events are sent
00218  */
00219 VLC_API int vlc_event_manager_init( vlc_event_manager_t * p_em, void * p_obj );
00220 
00221 /*
00222  * Destroy
00223  */
00224 VLC_API void vlc_event_manager_fini( vlc_event_manager_t * p_em );
00225 
00226 /*
00227  * Tells a specific event manager that it will handle event_type object
00228  */
00229 VLC_API int vlc_event_manager_register_event_type( vlc_event_manager_t * p_em,
00230                                                    vlc_event_type_t );
00231 
00232 /*
00233  * Send an event to the listener attached to this p_em.
00234  */
00235 VLC_API void vlc_event_send( vlc_event_manager_t * p_em, vlc_event_t * );
00236 
00237 /*
00238  * Add a callback for an event.
00239  */
00240 VLC_API int vlc_event_attach( vlc_event_manager_t * p_event_manager,
00241                               vlc_event_type_t event_type,
00242                               vlc_event_callback_t pf_callback,
00243                               void *p_user_data );
00244 
00245 /*
00246  * Remove a callback for an event.
00247  */
00248 VLC_API void vlc_event_detach( vlc_event_manager_t *p_event_manager,
00249                                vlc_event_type_t event_type,
00250                                vlc_event_callback_t pf_callback,
00251                                void *p_user_data );
00252 
00253 #endif /* VLC_EVENTS_H */
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines