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: 50cbc61912b8d051eaf79e3914d5bc417937fcb9 $
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_InputItemSubItemTreeAdded,
00123     vlc_InputItemDurationChanged,
00124     vlc_InputItemPreparsedChanged,
00125     vlc_InputItemNameChanged,
00126     vlc_InputItemInfoChanged,
00127     vlc_InputItemErrorWhenReadingChanged,
00128 
00129     /* Service Discovery event */
00130     vlc_ServicesDiscoveryItemAdded,
00131     vlc_ServicesDiscoveryItemRemoved,
00132     vlc_ServicesDiscoveryStarted,
00133     vlc_ServicesDiscoveryEnded
00134 } vlc_event_type_t;
00135 
00136 /* Event definition */
00137 typedef struct vlc_event_t
00138 {
00139     vlc_event_type_t type;
00140     void * p_obj; /* Sender object, automatically filled by vlc_event_send() */
00141     union vlc_event_type_specific
00142     {
00143         /* Input (thread) events */
00144         struct vlc_input_state_changed
00145         {
00146             int new_state;
00147         } input_state_changed;
00148         struct vlc_input_selected_stream_changed
00149         {
00150             void * unused;
00151         } input_selected_stream_changed;
00152 
00153         /* Input item events */
00154         struct vlc_input_item_meta_changed
00155         {
00156             vlc_meta_type_t meta_type;
00157         } input_item_meta_changed;
00158         struct vlc_input_item_subitem_added
00159         {
00160             input_item_t * p_new_child;
00161         } input_item_subitem_added;
00162         struct vlc_input_item_subitem_tree_added
00163         {
00164             input_item_node_t * p_root;
00165         } input_item_subitem_tree_added;
00166         struct vlc_input_item_duration_changed
00167         {
00168             mtime_t new_duration;
00169         } input_item_duration_changed;
00170         struct vlc_input_item_preparsed_changed
00171         {
00172             int new_status;
00173         } input_item_preparsed_changed;
00174         struct vlc_input_item_name_changed
00175         {
00176             const char * new_name;
00177         } input_item_name_changed;
00178         struct vlc_input_item_info_changed
00179         {
00180             void * unused;
00181         } input_item_info_changed;
00182         struct input_item_error_when_reading_changed
00183         {
00184             bool new_value;
00185         } input_item_error_when_reading_changed;
00186 
00187         /* Service discovery events */
00188         struct vlc_services_discovery_item_added
00189         {
00190             input_item_t * p_new_item;
00191             const char * psz_category;
00192         } services_discovery_item_added;
00193         struct vlc_services_discovery_item_removed
00194         {
00195             input_item_t * p_item;
00196         } services_discovery_item_removed;
00197         struct vlc_services_discovery_started
00198         {
00199             void * unused;
00200         } services_discovery_started;
00201         struct vlc_services_discovery_ended
00202         {
00203             void * unused;
00204         } services_discovery_ended;
00205 
00206     } u;
00207 } vlc_event_t;
00208 
00209 /* Event callback type */
00210 typedef void ( *vlc_event_callback_t )( const vlc_event_t *, void * );
00211 
00212  /*****************************************************************************
00213  * Event manager
00214  *****************************************************************************/
00215 
00216 /*
00217  * p_obj points to the object that owns the event manager, and from
00218  * which events are sent
00219  * p_obj is here to give us a libvlc instance
00220  */
00221 #define vlc_event_manager_init_with_vlc_object(a,b) \
00222             vlc_event_manager_init( a, b, b )
00223 
00224 VLC_EXPORT(int, vlc_event_manager_init, ( vlc_event_manager_t * p_em,
00225                                           void * p_obj, vlc_object_t * ));
00226 #define vlc_event_manager_init(a,b,c) \
00227             vlc_event_manager_init(a, b, VLC_OBJECT(c))
00228 
00229 /*
00230  * Destroy
00231  */
00232 VLC_EXPORT(void, vlc_event_manager_fini, ( vlc_event_manager_t * p_em ));
00233 
00234 /*
00235  * Tells a specific event manager that it will handle event_type object
00236  */
00237 VLC_EXPORT(int, vlc_event_manager_register_event_type,
00238                 ( vlc_event_manager_t * p_em, vlc_event_type_t event_type ));
00239 
00240 /*
00241  * Send an event to the listener attached to this p_em.
00242  */
00243 VLC_EXPORT(void, vlc_event_send, ( vlc_event_manager_t * p_em,
00244                                    vlc_event_t * p_event ));
00245 
00246 /*
00247  * Add a callback for an event.
00248  */
00249 VLC_EXPORT(int, vlc_event_attach, ( vlc_event_manager_t * p_event_manager,
00250                                     vlc_event_type_t event_type,
00251                                     vlc_event_callback_t pf_callback,
00252                                     void *p_user_data,
00253                                     const char * psz_debug_name ));
00254 #define vlc_event_attach(a, b, c, d) vlc_event_attach(a, b, c, d, #c)
00255 
00256 /*
00257  * Remove a callback for an event.
00258  */
00259 VLC_EXPORT(int, vlc_event_detach, ( vlc_event_manager_t *p_event_manager,
00260                                     vlc_event_type_t event_type,
00261                                     vlc_event_callback_t pf_callback,
00262                                     void *p_user_data ));
00263 
00264 #endif /* VLC_EVENTS_H */

Generated on Mon Nov 22 07:55:19 2010 for VLC by  doxygen 1.5.6