[vlc_InputItemSubItemAdded] = "vlc_InputItemSubItemAdded",
[vlc_ServicesDiscoveryItemAdded] = "vlc_ServicesDiscoveryItemAdded",
[vlc_ServicesDiscoveryItemRemoved] = "vlc_ServicesDiscoveryItemRemoved"
-}
+};
#endif
/*****************************************************************************
{
vlc_event_listeners_group_t * listeners_group;
vlc_event_listener_t * listener;
- vlc_event_callback_t func = NULL;
- void * user_data = NULL;
+ vlc_event_listener_t * array_of_cached_listeners = NULL;
+ vlc_event_listener_t * cached_listener;
+ int i, i_cached_listeners = 0;
/* Fill event with the sending object now */
p_event->p_obj = p_em->p_obj;
FOREACH_ARRAY( listeners_group, p_em->listeners_groups )
if( listeners_group->event_type == p_event->type )
{
- /* We found the group, now send every one the event */
+ if( listeners_group->listeners.i_size <= 0 )
+ break;
+
+ /* Save the function to call */
+ i_cached_listeners = listeners_group->listeners.i_size;
+ array_of_cached_listeners = malloc(
+ sizeof(vlc_event_listener_t)*i_cached_listeners );
+ if( !array_of_cached_listeners )
+ {
+ msg_Err( p_em->p_parent_object, "Not enough memory in vlc_event_send" );
+ return;
+ }
+
+ cached_listener = array_of_cached_listeners;
FOREACH_ARRAY( listener, listeners_group->listeners )
- func = listener->pf_callback;
- user_data = listener->p_user_data;
+ memcpy( cached_listener, listener, sizeof(vlc_event_listener_t));
#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 );
+ cached_listener->psz_debug_name = strdup(cached_listener->psz_debug_name);
#endif
- /* This is safe to do that because we are sure
- * that there will be no object owned references
- * used after the lock. */
- vlc_mutex_unlock( &p_em->object_lock );
- func( p_event, user_data );
- vlc_mutex_lock( &p_em->object_lock );
+ cached_listener += sizeof(vlc_event_listener_t);
FOREACH_END()
+
break;
}
FOREACH_END()
vlc_mutex_unlock( &p_em->object_lock );
+
+ /* Call the function attached */
+ cached_listener = array_of_cached_listeners;
+ for( i = 0; i < i_cached_listeners; i++ )
+ {
+#ifdef DEBUG_EVENT
+ msg_Dbg( p_em->p_parent_object,
+ "Calling '%s' with a '%s' event (data %p)",
+ cached_listener->psz_debug_name,
+ ppsz_event_type_to_name[p_event->type],
+ cached_listener->p_user_data );
+ free(cached_listener->psz_debug_name);
+#endif
+
+ cached_listener->pf_callback( p_event, cached_listener->p_user_data );
+ cached_listener += sizeof(vlc_event_listener_t) ;
+ }
+ free( array_of_cached_listeners );
+
}
/**
{
ARRAY_APPEND( listeners_group->listeners, listener );
#ifdef DEBUG_EVENT
- msg_Dbg("Listening to '%s' event with '%s' (data %p)\n",
+ msg_Dbg( p_em->p_parent_object,
+ "Listening to '%s' event with '%s' (data %p)",
ppsz_event_type_to_name[event_type],
listener->psz_debug_name,
listener->p_user_data );
fe_idx /* This comes from the macro (and that's why
I hate macro) */ );
#ifdef DEBUG_EVENT
- msg_Dbg("Detaching '%s' from '%s' event (data %p)\n",
+ msg_Dbg( p_em->p_parent_object,
+ "Detaching '%s' from '%s' event (data %p)",
listener->psz_debug_name,
ppsz_event_type_to_name[event_type],
listener->p_user_data );