#include <vlc/libvlc.h>
#include <vlc_playlist.h>
-
/*
* Private functions
*/
-static vlc_bool_t
+static bool
listeners_are_equal( libvlc_event_listener_t * listener1,
libvlc_event_listener_t * listener2 )
{
listener1->p_user_data == listener2->p_user_data;
}
-static vlc_bool_t
+static bool
group_contains_listener( libvlc_event_listeners_group_t * group,
libvlc_event_listener_t * searched_listener )
{
for( i = 0; i < vlc_array_count(&group->listeners); i++ )
{
if( listeners_are_equal(searched_listener, vlc_array_item_at_index(&group->listeners, i)) )
- return VLC_TRUE;
+ return true;
}
- return VLC_FALSE;
+ return false;
}
/*
* Internal libvlc functions
*/
-/**************************************************************************
- * libvlc_event_init (internal) :
- *
- * initialization function.
- **************************************************************************/
-void libvlc_event_init( libvlc_instance_t *p_instance, libvlc_exception_t *p_e )
-{
- (void)p_instance;(void)p_e;
- /* Will certainly be used to install libvlc_instance event */
-}
-
-/**************************************************************************
- * libvlc_event_fini (internal) :
- *
- * finalization function.
- **************************************************************************/
-void libvlc_event_fini( libvlc_instance_t *p_instance )
-{
- (void)p_instance;
-}
-
/**************************************************************************
* libvlc_event_manager_init (internal) :
*
p_em->p_libvlc_instance = p_libvlc_inst;
libvlc_retain( p_libvlc_inst );
vlc_array_init( &p_em->listeners_groups );
- vlc_mutex_init( p_libvlc_inst->p_libvlc_int, &p_em->object_lock );
- vlc_mutex_init_recursive( p_libvlc_inst->p_libvlc_int, &p_em->event_sending_lock );
+ vlc_mutex_init( &p_em->object_lock );
+ vlc_mutex_init_recursive( &p_em->event_sending_lock );
return p_em;
}
void libvlc_event_send( libvlc_event_manager_t * p_em,
libvlc_event_t * p_event )
{
- libvlc_event_listeners_group_t * listeners_group;
+ libvlc_event_listeners_group_t * listeners_group = NULL;
libvlc_event_listener_t * listener_cached;
libvlc_event_listener_t * listener;
libvlc_event_listener_t * array_listeners_cached = NULL;
vlc_mutex_lock( &p_em->event_sending_lock );
listener_cached = array_listeners_cached;
- listeners_group->b_sublistener_removed = VLC_FALSE;
+ listeners_group->b_sublistener_removed = false;
for( i = 0; i < i_cached_listeners; i++ )
{
if( listeners_group->b_sublistener_removed )
{
/* If a callback was removed, this gets called */
- vlc_bool_t valid_listener;
+ bool valid_listener;
vlc_mutex_lock( &p_em->object_lock );
valid_listener = group_contains_listener( listeners_group, listener_cached );
vlc_mutex_unlock( &p_em->object_lock );
continue;
}
}
-
+
listener_cached->pf_callback( p_event, listener_cached->p_user_data );
listener_cached++;
}
*
* Get the char * name of an event type.
**************************************************************************/
-static const char * event_type_to_name[] =
+static const char event_type_to_name[][35] =
{
#define EVENT(a) [a]=#a
- EVENT(libvlc_MediaDescriptorMetaChanged),
- EVENT(libvlc_MediaDescriptorSubItemAdded),
- EVENT(libvlc_MediaDescriptorDurationChanged),
- EVENT(libvlc_MediaDescriptorPreparsedChanged),
- EVENT(libvlc_MediaDescriptorFreed),
- EVENT(libvlc_MediaDescriptorStateChanged),
-
- EVENT(libvlc_MediaInstancePlayed),
- EVENT(libvlc_MediaInstancePaused),
- EVENT(libvlc_MediaInstanceReachedEnd),
- EVENT(libvlc_MediaInstanceTimeChanged),
- EVENT(libvlc_MediaInstancePositionChanged),
+ EVENT(libvlc_MediaMetaChanged),
+ EVENT(libvlc_MediaSubItemAdded),
+ EVENT(libvlc_MediaDurationChanged),
+ EVENT(libvlc_MediaPreparsedChanged),
+ EVENT(libvlc_MediaFreed),
+ EVENT(libvlc_MediaStateChanged),
+
+ EVENT(libvlc_MediaPlayerPlayed),
+ EVENT(libvlc_MediaPlayerPaused),
+ EVENT(libvlc_MediaPlayerEndReached),
+ EVENT(libvlc_MediaPlayerStopped),
+ EVENT(libvlc_MediaPlayerTimeChanged),
+ EVENT(libvlc_MediaPlayerPositionChanged),
EVENT(libvlc_MediaListItemAdded),
EVENT(libvlc_MediaListWillAddItem),
EVENT(libvlc_MediaDiscovererEnded)
#undef EVENT
};
-static const char * unkwown_event_name = "Unknown Event";
+
+static const char unkwown_event_name[] = "Unknown Event";
const char * libvlc_event_type_name( libvlc_event_type_t event_type )
{
libvlc_exception_raise( p_e, "No Memory left" );
return;
}
-
+
listener->event_type = event_type;
listener->p_user_data = p_user_data;
listener->pf_callback = pf_callback;
* Remove a callback for an event.
**************************************************************************/
void libvlc_event_detach( libvlc_event_manager_t *p_event_manager,
- libvlc_event_type_t event_type,
- libvlc_callback_t pf_callback,
- void *p_user_data,
- libvlc_exception_t *p_e )
-{
- libvlc_event_detach_lock_state( p_event_manager, event_type, pf_callback,
- p_user_data, libvlc_UnLocked, p_e );
-}
-
-/**************************************************************************
- * libvlc_event_detach_no_lock (internal) :
- *
- * Remove a callback for an event.
- **************************************************************************/
-void libvlc_event_detach_lock_state( libvlc_event_manager_t *p_event_manager,
libvlc_event_type_t event_type,
libvlc_callback_t pf_callback,
void *p_user_data,
- libvlc_lock_state_t lockstate,
libvlc_exception_t *p_e )
{
libvlc_event_listeners_group_t * listeners_group;
libvlc_event_listener_t * listener;
int i, j;
- if( lockstate == libvlc_UnLocked )
- vlc_mutex_lock( &p_event_manager->event_sending_lock );
+ vlc_mutex_lock( &p_event_manager->event_sending_lock );
vlc_mutex_lock( &p_event_manager->object_lock );
for( i = 0; i < vlc_array_count(&p_event_manager->listeners_groups); i++)
{
listener->p_user_data == p_user_data )
{
/* that's our listener */
+
+ /* Mark this group as edited so that libvlc_event_send
+ * will recheck what listener to call */
+ listeners_group->b_sublistener_removed = false;
+
free( listener );
vlc_array_remove( &listeners_group->listeners, j );
vlc_mutex_unlock( &p_event_manager->object_lock );
- if( lockstate == libvlc_UnLocked )
- vlc_mutex_unlock( &p_event_manager->event_sending_lock );
+ vlc_mutex_unlock( &p_event_manager->event_sending_lock );
return;
}
}
}
}
vlc_mutex_unlock( &p_event_manager->object_lock );
- if( lockstate == libvlc_UnLocked )
- vlc_mutex_unlock( &p_event_manager->event_sending_lock );
+ vlc_mutex_unlock( &p_event_manager->event_sending_lock );
libvlc_exception_raise( p_e,
"This object event manager doesn't know about '%s,%p,%p' event observer",