Commit 8cc3dca1 authored by Pierre d'Herbemont's avatar Pierre d'Herbemont

misc/events.c: Add some debug code. (turnable on and off via #ifdef)

parent 3fdc5f7c
...@@ -104,10 +104,12 @@ typedef struct vlc_event_manager_t ...@@ -104,10 +104,12 @@ typedef struct vlc_event_manager_t
{ {
void * p_obj; void * p_obj;
vlc_mutex_t object_lock; vlc_mutex_t object_lock;
vlc_object_t *p_parent_object;
DECL_ARRAY(struct vlc_event_listeners_group_t *) listeners_groups; DECL_ARRAY(struct vlc_event_listeners_group_t *) listeners_groups;
} vlc_event_manager_t; } vlc_event_manager_t;
/* List of event */ /* List of event */
/* Be sure to keep sync-ed with misc/events.c debug name table */
typedef enum vlc_event_type_t { typedef enum vlc_event_type_t {
/* Input item events */ /* Input item events */
vlc_InputItemMetaChanged, vlc_InputItemMetaChanged,
...@@ -184,10 +186,12 @@ VLC_EXPORT(void, vlc_event_send, ( vlc_event_manager_t * p_em, ...@@ -184,10 +186,12 @@ VLC_EXPORT(void, vlc_event_send, ( vlc_event_manager_t * p_em,
/* /*
* Add a callback for an event. * Add a callback for an event.
*/ */
VLC_EXPORT(int, vlc_event_attach, ( vlc_event_manager_t * p_event_manager, #define vlc_event_attach(a, b, c, d) __vlc_event_attach(a, b, c, d, #c)
VLC_EXPORT(int, __vlc_event_attach, ( vlc_event_manager_t * p_event_manager,
vlc_event_type_t event_type, vlc_event_type_t event_type,
vlc_event_callback_t pf_callback, vlc_event_callback_t pf_callback,
void *p_user_data )); void *p_user_data,
const char * psz_debug_name ));
/* /*
* Remove a callback for an event. * Remove a callback for an event.
......
...@@ -39,6 +39,8 @@ ...@@ -39,6 +39,8 @@
* Documentation : Read vlc_events.h * Documentation : Read vlc_events.h
*****************************************************************************/ *****************************************************************************/
//#define DEBUG_EVENT
/***************************************************************************** /*****************************************************************************
* Private types. * Private types.
*****************************************************************************/ *****************************************************************************/
...@@ -47,6 +49,9 @@ typedef struct vlc_event_listener_t ...@@ -47,6 +49,9 @@ typedef struct vlc_event_listener_t
{ {
void * p_user_data; void * p_user_data;
vlc_event_callback_t pf_callback; vlc_event_callback_t pf_callback;
#ifdef DEBUG_EVENT
char * psz_debug_name;
#endif
} vlc_event_listener_t; } vlc_event_listener_t;
typedef struct vlc_event_listeners_group_t typedef struct vlc_event_listeners_group_t
...@@ -55,6 +60,16 @@ typedef struct vlc_event_listeners_group_t ...@@ -55,6 +60,16 @@ typedef struct vlc_event_listeners_group_t
DECL_ARRAY(struct vlc_event_listener_t *) listeners; DECL_ARRAY(struct vlc_event_listener_t *) listeners;
} vlc_event_listeners_group_t; } vlc_event_listeners_group_t;
#ifdef DEBUG_EVENT
static const char * ppsz_event_type_to_name[] =
{
[vlc_InputItemMetaChanged] = "vlc_InputItemMetaChanged",
[vlc_InputItemSubItemAdded] = "vlc_InputItemSubItemAdded",
[vlc_ServicesDiscoveryItemAdded] = "vlc_ServicesDiscoveryItemAdded",
[vlc_ServicesDiscoveryItemRemoved] = "vlc_ServicesDiscoveryItemRemoved"
}
#endif
/***************************************************************************** /*****************************************************************************
* *
*****************************************************************************/ *****************************************************************************/
...@@ -70,6 +85,7 @@ int vlc_event_manager_init( vlc_event_manager_t * p_em, void * p_obj, ...@@ -70,6 +85,7 @@ int vlc_event_manager_init( vlc_event_manager_t * p_em, void * p_obj,
vlc_object_t * p_parent_obj ) vlc_object_t * p_parent_obj )
{ {
p_em->p_obj = p_obj; p_em->p_obj = p_obj;
p_em->p_parent_object = p_parent_obj;
vlc_mutex_init( p_parent_obj, &p_em->object_lock ); vlc_mutex_init( p_parent_obj, &p_em->object_lock );
ARRAY_INIT( p_em->listeners_groups ); ARRAY_INIT( p_em->listeners_groups );
return VLC_SUCCESS; return VLC_SUCCESS;
...@@ -138,6 +154,12 @@ void vlc_event_send( vlc_event_manager_t * p_em, ...@@ -138,6 +154,12 @@ void vlc_event_send( vlc_event_manager_t * p_em,
FOREACH_ARRAY( listener, listeners_group->listeners ) FOREACH_ARRAY( listener, listeners_group->listeners )
func = listener->pf_callback; func = listener->pf_callback;
user_data = listener->p_user_data; user_data = listener->p_user_data;
#ifdef DEBUG_EVENT
msg_Dbg("Calling '%s' with a '%s' event (data %p)\n",
listener->psz_debug_name,
ppsz_event_type_to_name[event_type],
listener->p_user_data );
#endif
/* This is safe to do that because we are sure /* This is safe to do that because we are sure
* that there will be no object owned references * that there will be no object owned references
* used after the lock. */ * used after the lock. */
...@@ -154,10 +176,11 @@ void vlc_event_send( vlc_event_manager_t * p_em, ...@@ -154,10 +176,11 @@ void vlc_event_send( vlc_event_manager_t * p_em,
/** /**
* Add a callback for an event. * Add a callback for an event.
*/ */
int vlc_event_attach( vlc_event_manager_t * p_em, int __vlc_event_attach( vlc_event_manager_t * p_em,
vlc_event_type_t event_type, vlc_event_type_t event_type,
vlc_event_callback_t pf_callback, vlc_event_callback_t pf_callback,
void *p_user_data ) void *p_user_data,
const char * psz_debug_name )
{ {
vlc_event_listeners_group_t * listeners_group; vlc_event_listeners_group_t * listeners_group;
vlc_event_listener_t * listener; vlc_event_listener_t * listener;
...@@ -167,18 +190,30 @@ int vlc_event_attach( vlc_event_manager_t * p_em, ...@@ -167,18 +190,30 @@ int vlc_event_attach( vlc_event_manager_t * p_em,
listener->p_user_data = p_user_data; listener->p_user_data = p_user_data;
listener->pf_callback = pf_callback; listener->pf_callback = pf_callback;
#ifdef DEBUG_EVENT
listener->psz_debug_name = strdup( psz_debug_name );
#else
(void)psz_debug_name;
#endif
vlc_mutex_lock( &p_em->object_lock ); vlc_mutex_lock( &p_em->object_lock );
FOREACH_ARRAY( listeners_group, p_em->listeners_groups ) FOREACH_ARRAY( listeners_group, p_em->listeners_groups )
if( listeners_group->event_type == event_type ) if( listeners_group->event_type == event_type )
{ {
ARRAY_APPEND( listeners_group->listeners, listener ); ARRAY_APPEND( listeners_group->listeners, listener );
#ifdef DEBUG_EVENT
msg_Dbg("Listening to '%s' event with '%s' (data %p)\n",
ppsz_event_type_to_name[event_type],
listener->psz_debug_name,
listener->p_user_data );
#endif
vlc_mutex_unlock( &p_em->object_lock ); vlc_mutex_unlock( &p_em->object_lock );
return VLC_SUCCESS; return VLC_SUCCESS;
} }
FOREACH_END() FOREACH_END()
vlc_mutex_unlock( &p_em->object_lock ); vlc_mutex_unlock( &p_em->object_lock );
msg_Err( p_em->p_parent_object, "Can't attach to an object event manager event" );
free(listener); free(listener);
return VLC_EGENERIC; return VLC_EGENERIC;
} }
...@@ -206,6 +241,14 @@ int vlc_event_detach( vlc_event_manager_t *p_em, ...@@ -206,6 +241,14 @@ int vlc_event_detach( vlc_event_manager_t *p_em,
ARRAY_REMOVE( listeners_group->listeners, ARRAY_REMOVE( listeners_group->listeners,
fe_idx /* This comes from the macro (and that's why fe_idx /* This comes from the macro (and that's why
I hate macro) */ ); I hate macro) */ );
#ifdef DEBUG_EVENT
msg_Dbg("Detaching '%s' from '%s' event (data %p)\n",
listener->psz_debug_name,
ppsz_event_type_to_name[event_type],
listener->p_user_data );
free( listener->psz_debug_name );
#endif
free( listener ); free( listener );
vlc_mutex_unlock( &p_em->object_lock ); vlc_mutex_unlock( &p_em->object_lock );
return VLC_SUCCESS; return VLC_SUCCESS;
...@@ -215,7 +258,7 @@ int vlc_event_detach( vlc_event_manager_t *p_em, ...@@ -215,7 +258,7 @@ int vlc_event_detach( vlc_event_manager_t *p_em,
FOREACH_END() FOREACH_END()
vlc_mutex_unlock( &p_em->object_lock ); vlc_mutex_unlock( &p_em->object_lock );
msg_Warn( p_em->p_parent_object, "Can't detach to an object event manager event" );
return VLC_EGENERIC; return VLC_EGENERIC;
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment