VLC事件管理,定义在vlc_events.h中
typedef struct vlc_event_manager_t
{
void * p_obj;
vlc_mutex_t object_lock;
vlc_mutex_t event_sending_lock;
DECL_ARRAY(struct vlc_event_listeners_group_t *) listeners_groups;
} vlc_event_manager_t;
#define DECL_ARRAY(type) struct { \
int i_alloc; \
int i_size; \
type *p_elems; \
}
vlc_event_listeners_group_t的定义如下
typedef struct vlc_event_listener_t
{
void * p_user_data;
vlc_event_callback_t pf_callback;
} vlc_event_listener_t;
typedef struct vlc_event_listeners_group_t
{
vlc_event_type_t event_type;
DECL_ARRAY(struct vlc_event_listener_t *) listeners;
/* Used in vlc_event_send() to make sure to behave
Correctly when vlc_event_detach was called during
a callback */
bool b_sublistener_removed;
} vlc_event_listeners_group_t;
事件管理主要的函数有下面几个
VLC_API int vlc_event_manager_init( vlc_event_manager_t * p_em, void * p_obj );
初始化event_manager互斥体,初始化listeners_groups数组
VLC_API void vlc_event_manager_fini( vlc_event_manager_t * p_em );
销毁event_manager相关资源
VLC_API int vlc_event_manager_register_event_type( vlc_event_manager_t * p_em, vlc_event_type_t );
为对应的event_type创建vlc_event_listeners_group_t,并且插入到manager的listeners_groups数组中
VLC_API void vlc_event_send( vlc_event_manager_t * p_em, vlc_event_t * );
从listeners_groups中找到对应的listeners_group,分别调用其中每个group的listener的回调函数
VLC_API 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 );
/*
* Remove a callback for an event.
*/
VLC_API 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 );