Commit 556953c4 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

libvlc_event_manager: remove exceptions

parent 6b53f6b7
...@@ -294,13 +294,12 @@ typedef void ( *libvlc_callback_t )( const libvlc_event_t *, void * ); ...@@ -294,13 +294,12 @@ typedef void ( *libvlc_callback_t )( const libvlc_event_t *, void * );
* \param i_event_type the desired event to which we want to listen * \param i_event_type the desired event to which we want to listen
* \param f_callback the function to call when i_event_type occurs * \param f_callback the function to call when i_event_type occurs
* \param user_data user provided data to carry with the event * \param user_data user provided data to carry with the event
* \param p_e an initialized exception pointer * \return 0 on success, ENOMEM on error
*/ */
VLC_PUBLIC_API void libvlc_event_attach( libvlc_event_manager_t *p_event_manager, VLC_PUBLIC_API int libvlc_event_attach( libvlc_event_manager_t *p_event_manager,
libvlc_event_type_t i_event_type, libvlc_event_type_t i_event_type,
libvlc_callback_t f_callback, libvlc_callback_t f_callback,
void *user_data, void *user_data );
libvlc_exception_t *p_e );
/** /**
* Unregister an event notification. * Unregister an event notification.
......
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
#include "libvlc_internal.h" #include "libvlc_internal.h"
#include "event_internal.h" #include "event_internal.h"
#include <assert.h> #include <assert.h>
#include <errno.h>
typedef struct libvlc_event_listeners_group_t typedef struct libvlc_event_listeners_group_t
{ {
...@@ -67,15 +68,13 @@ group_contains_listener( libvlc_event_listeners_group_t * group, ...@@ -67,15 +68,13 @@ group_contains_listener( libvlc_event_listeners_group_t * group,
* Init an object's event manager. * Init an object's event manager.
**************************************************************************/ **************************************************************************/
libvlc_event_manager_t * libvlc_event_manager_t *
libvlc_event_manager_new( void * p_obj, libvlc_instance_t * p_libvlc_inst, libvlc_event_manager_new( void * p_obj, libvlc_instance_t * p_libvlc_inst )
libvlc_exception_t *p_e )
{ {
libvlc_event_manager_t * p_em; libvlc_event_manager_t * p_em;
p_em = malloc(sizeof( libvlc_event_manager_t )); p_em = malloc(sizeof( libvlc_event_manager_t ));
if( !p_em ) if( !p_em )
{ {
libvlc_exception_raise( p_e );
libvlc_printerr( "Not enough memory" ); libvlc_printerr( "Not enough memory" );
return NULL; return NULL;
} }
...@@ -129,18 +128,10 @@ void libvlc_event_manager_release( libvlc_event_manager_t * p_em ) ...@@ -129,18 +128,10 @@ void libvlc_event_manager_release( libvlc_event_manager_t * p_em )
**************************************************************************/ **************************************************************************/
void libvlc_event_manager_register_event_type( void libvlc_event_manager_register_event_type(
libvlc_event_manager_t * p_em, libvlc_event_manager_t * p_em,
libvlc_event_type_t event_type, libvlc_event_type_t event_type )
libvlc_exception_t * p_e )
{ {
libvlc_event_listeners_group_t * listeners_group; libvlc_event_listeners_group_t * listeners_group;
listeners_group = malloc(sizeof(libvlc_event_listeners_group_t)); listeners_group = xmalloc(sizeof(libvlc_event_listeners_group_t));
if( !listeners_group )
{
libvlc_exception_raise( p_e );
libvlc_printerr( "Not enough memory" );
return;
}
listeners_group->event_type = event_type; listeners_group->event_type = event_type;
vlc_array_init( &listeners_group->listeners ); vlc_array_init( &listeners_group->listeners );
...@@ -276,24 +267,18 @@ const char * libvlc_event_type_name( libvlc_event_type_t event_type ) ...@@ -276,24 +267,18 @@ const char * libvlc_event_type_name( libvlc_event_type_t event_type )
* Add a callback for an event. * Add a callback for an event.
**************************************************************************/ **************************************************************************/
static static
void event_attach( libvlc_event_manager_t * p_event_manager, int event_attach( libvlc_event_manager_t * p_event_manager,
libvlc_event_type_t event_type, libvlc_event_type_t event_type,
libvlc_callback_t pf_callback, libvlc_callback_t pf_callback, void *p_user_data,
void *p_user_data, bool is_asynchronous )
bool is_asynchronous,
libvlc_exception_t *p_e )
{ {
libvlc_event_listeners_group_t * listeners_group; libvlc_event_listeners_group_t * listeners_group;
libvlc_event_listener_t * listener; libvlc_event_listener_t * listener;
int i; int i;
listener = malloc(sizeof(libvlc_event_listener_t)); listener = malloc(sizeof(libvlc_event_listener_t));
if( !listener ) if( unlikely(listener == NULL) )
{ return ENOMEM;
libvlc_exception_raise( p_e );
libvlc_printerr( "Not enough memory" );
return;
}
listener->event_type = event_type; listener->event_type = event_type;
listener->p_user_data = p_user_data; listener->p_user_data = p_user_data;
...@@ -308,7 +293,7 @@ void event_attach( libvlc_event_manager_t * p_event_manager, ...@@ -308,7 +293,7 @@ void event_attach( libvlc_event_manager_t * p_event_manager,
{ {
vlc_array_append( &listeners_group->listeners, listener ); vlc_array_append( &listeners_group->listeners, listener );
vlc_mutex_unlock( &p_event_manager->object_lock ); vlc_mutex_unlock( &p_event_manager->object_lock );
return; return 0;
} }
} }
vlc_mutex_unlock( &p_event_manager->object_lock ); vlc_mutex_unlock( &p_event_manager->object_lock );
...@@ -324,13 +309,13 @@ void event_attach( libvlc_event_manager_t * p_event_manager, ...@@ -324,13 +309,13 @@ void event_attach( libvlc_event_manager_t * p_event_manager,
* *
* Add a callback for an event. * Add a callback for an event.
**************************************************************************/ **************************************************************************/
void libvlc_event_attach( libvlc_event_manager_t * p_event_manager, int libvlc_event_attach( libvlc_event_manager_t * p_event_manager,
libvlc_event_type_t event_type, libvlc_event_type_t event_type,
libvlc_callback_t pf_callback, libvlc_callback_t pf_callback,
void *p_user_data, void *p_user_data )
libvlc_exception_t *p_e )
{ {
event_attach(p_event_manager, event_type, pf_callback, p_user_data, false /* synchronous */, p_e); return event_attach(p_event_manager, event_type, pf_callback, p_user_data,
false /* synchronous */);
} }
/************************************************************************** /**************************************************************************
...@@ -341,10 +326,10 @@ void libvlc_event_attach( libvlc_event_manager_t * p_event_manager, ...@@ -341,10 +326,10 @@ void libvlc_event_attach( libvlc_event_manager_t * p_event_manager,
void libvlc_event_attach_async( libvlc_event_manager_t * p_event_manager, void libvlc_event_attach_async( libvlc_event_manager_t * p_event_manager,
libvlc_event_type_t event_type, libvlc_event_type_t event_type,
libvlc_callback_t pf_callback, libvlc_callback_t pf_callback,
void *p_user_data, void *p_user_data )
libvlc_exception_t *p_e )
{ {
event_attach(p_event_manager, event_type, pf_callback, p_user_data, true /* asynchronous */, p_e); event_attach(p_event_manager, event_type, pf_callback, p_user_data,
true /* asynchronous */);
} }
/************************************************************************** /**************************************************************************
......
...@@ -178,16 +178,16 @@ libvlc_media_list_hierarchical_view( libvlc_media_list_t * p_mlist, ...@@ -178,16 +178,16 @@ libvlc_media_list_hierarchical_view( libvlc_media_list_t * p_mlist,
libvlc_media_list_lock( p_mlist ); libvlc_media_list_lock( p_mlist );
libvlc_event_attach( p_mlv->p_mlist->p_event_manager, libvlc_event_attach( p_mlv->p_mlist->p_event_manager,
libvlc_MediaListItemAdded, libvlc_MediaListItemAdded,
media_list_item_added, p_mlv, NULL ); media_list_item_added, p_mlv );
libvlc_event_attach( p_mlv->p_mlist->p_event_manager, libvlc_event_attach( p_mlv->p_mlist->p_event_manager,
libvlc_MediaListWillAddItem, libvlc_MediaListWillAddItem,
media_list_will_add_item, p_mlv, NULL ); media_list_will_add_item, p_mlv );
libvlc_event_attach( p_mlv->p_mlist->p_event_manager, libvlc_event_attach( p_mlv->p_mlist->p_event_manager,
libvlc_MediaListItemDeleted, libvlc_MediaListItemDeleted,
media_list_item_deleted, p_mlv, NULL ); media_list_item_deleted, p_mlv );
libvlc_event_attach( p_mlv->p_mlist->p_event_manager, libvlc_event_attach( p_mlv->p_mlist->p_event_manager,
libvlc_MediaListWillDeleteItem, libvlc_MediaListWillDeleteItem,
media_list_will_delete_item, p_mlv, NULL ); media_list_will_delete_item, p_mlv );
libvlc_media_list_unlock( p_mlist ); libvlc_media_list_unlock( p_mlist );
return p_mlv; return p_mlv;
} }
...@@ -208,7 +208,7 @@ media_list_item_added( const libvlc_event_t * p_event, void * user_data ) ...@@ -208,7 +208,7 @@ media_list_item_added( const libvlc_event_t * p_event, void * user_data )
if( index >= 0) if( index >= 0)
libvlc_media_list_view_item_added( p_mlv, p_md, index ); libvlc_media_list_view_item_added( p_mlv, p_md, index );
libvlc_event_attach( p_md->p_event_manager, libvlc_MediaSubItemAdded, libvlc_event_attach( p_md->p_event_manager, libvlc_MediaSubItemAdded,
items_subitems_added, p_mlv, NULL ); items_subitems_added, p_mlv );
} }
static void static void
...@@ -298,16 +298,16 @@ libvlc_media_list_hierarchical_node_view( libvlc_media_list_t * p_mlist, ...@@ -298,16 +298,16 @@ libvlc_media_list_hierarchical_node_view( libvlc_media_list_t * p_mlist,
libvlc_media_list_lock( p_mlist ); libvlc_media_list_lock( p_mlist );
libvlc_event_attach( p_mlv->p_mlist->p_event_manager, libvlc_event_attach( p_mlv->p_mlist->p_event_manager,
libvlc_MediaListItemAdded, libvlc_MediaListItemAdded,
media_list_item_added, p_mlv, NULL ); media_list_item_added, p_mlv );
libvlc_event_attach( p_mlv->p_mlist->p_event_manager, libvlc_event_attach( p_mlv->p_mlist->p_event_manager,
libvlc_MediaListWillAddItem, libvlc_MediaListWillAddItem,
media_list_will_add_item, p_mlv, NULL ); media_list_will_add_item, p_mlv );
libvlc_event_attach( p_mlv->p_mlist->p_event_manager, libvlc_event_attach( p_mlv->p_mlist->p_event_manager,
libvlc_MediaListItemDeleted, libvlc_MediaListItemDeleted,
media_list_item_deleted, p_mlv, NULL ); media_list_item_deleted, p_mlv );
libvlc_event_attach( p_mlv->p_mlist->p_event_manager, libvlc_event_attach( p_mlv->p_mlist->p_event_manager,
libvlc_MediaListWillDeleteItem, libvlc_MediaListWillDeleteItem,
media_list_will_delete_item, p_mlv, NULL ); media_list_will_delete_item, p_mlv );
libvlc_media_list_unlock( p_mlist ); libvlc_media_list_unlock( p_mlist );
return p_mlv; return p_mlv;
} }
...@@ -81,16 +81,14 @@ void libvlc_deinit_threads (void); ...@@ -81,16 +81,14 @@ void libvlc_deinit_threads (void);
/* Events */ /* Events */
libvlc_event_manager_t * libvlc_event_manager_new( libvlc_event_manager_t * libvlc_event_manager_new(
void * p_obj, libvlc_instance_t * p_libvlc_inst, void * p_obj, libvlc_instance_t * p_libvlc_inst );
libvlc_exception_t *p_e );
void libvlc_event_manager_release( void libvlc_event_manager_release(
libvlc_event_manager_t * p_em ); libvlc_event_manager_t * p_em );
void libvlc_event_manager_register_event_type( void libvlc_event_manager_register_event_type(
libvlc_event_manager_t * p_em, libvlc_event_manager_t * p_em,
libvlc_event_type_t event_type, libvlc_event_type_t event_type );
libvlc_exception_t * p_e );
void libvlc_event_send( void libvlc_event_send(
libvlc_event_manager_t * p_em, libvlc_event_manager_t * p_em,
...@@ -99,8 +97,7 @@ void libvlc_event_send( ...@@ -99,8 +97,7 @@ void libvlc_event_send(
void libvlc_event_attach_async( libvlc_event_manager_t * p_event_manager, void libvlc_event_attach_async( libvlc_event_manager_t * p_event_manager,
libvlc_event_type_t event_type, libvlc_event_type_t event_type,
libvlc_callback_t pf_callback, libvlc_callback_t pf_callback,
void *p_user_data, void *p_user_data );
libvlc_exception_t *p_e );
/* Exception shorcuts */ /* Exception shorcuts */
......
...@@ -270,17 +270,22 @@ libvlc_media_t * libvlc_media_new_from_input_item( ...@@ -270,17 +270,22 @@ libvlc_media_t * libvlc_media_new_from_input_item(
* It can give a bunch of item to read. */ * It can give a bunch of item to read. */
p_md->p_subitems = NULL; p_md->p_subitems = NULL;
p_md->p_event_manager = libvlc_event_manager_new( p_md, p_instance, p_e ); p_md->p_event_manager = libvlc_event_manager_new( p_md, p_instance );
if( unlikely(p_md->p_event_manager == NULL) )
{
free(p_md);
return NULL;
}
libvlc_event_manager_register_event_type( p_md->p_event_manager, libvlc_event_manager_register_event_type( p_md->p_event_manager,
libvlc_MediaMetaChanged, p_e ); libvlc_MediaMetaChanged );
libvlc_event_manager_register_event_type( p_md->p_event_manager, libvlc_event_manager_register_event_type( p_md->p_event_manager,
libvlc_MediaSubItemAdded, p_e ); libvlc_MediaSubItemAdded );
libvlc_event_manager_register_event_type( p_md->p_event_manager, libvlc_event_manager_register_event_type( p_md->p_event_manager,
libvlc_MediaFreed, p_e ); libvlc_MediaFreed );
libvlc_event_manager_register_event_type( p_md->p_event_manager, libvlc_event_manager_register_event_type( p_md->p_event_manager,
libvlc_MediaDurationChanged, p_e ); libvlc_MediaDurationChanged );
libvlc_event_manager_register_event_type( p_md->p_event_manager, libvlc_event_manager_register_event_type( p_md->p_event_manager,
libvlc_MediaStateChanged, p_e ); libvlc_MediaStateChanged );
vlc_gc_incref( p_md->p_input_item ); vlc_gc_incref( p_md->p_input_item );
......
...@@ -190,13 +190,17 @@ libvlc_media_discoverer_new_from_name( libvlc_instance_t * p_inst, ...@@ -190,13 +190,17 @@ libvlc_media_discoverer_new_from_name( libvlc_instance_t * p_inst,
vlc_dictionary_init( &p_mdis->catname_to_submedialist, 0 ); vlc_dictionary_init( &p_mdis->catname_to_submedialist, 0 );
p_mdis->p_event_manager = libvlc_event_manager_new( p_mdis, p_mdis->p_event_manager = libvlc_event_manager_new( p_mdis, p_inst );
p_inst, NULL ); if( unlikely(p_mdis->p_event_manager == NULL) )
{
free( p_mdis );
return NULL;
}
libvlc_event_manager_register_event_type( p_mdis->p_event_manager, libvlc_event_manager_register_event_type( p_mdis->p_event_manager,
libvlc_MediaDiscovererStarted, NULL ); libvlc_MediaDiscovererStarted );
libvlc_event_manager_register_event_type( p_mdis->p_event_manager, libvlc_event_manager_register_event_type( p_mdis->p_event_manager,
libvlc_MediaDiscovererEnded, NULL ); libvlc_MediaDiscovererEnded );
p_mdis->p_sd = vlc_sd_Create( (vlc_object_t*)p_inst->p_libvlc_int ); p_mdis->p_sd = vlc_sd_Create( (vlc_object_t*)p_inst->p_libvlc_int );
......
...@@ -71,7 +71,12 @@ libvlc_media_library_new( libvlc_instance_t * p_inst, ...@@ -71,7 +71,12 @@ libvlc_media_library_new( libvlc_instance_t * p_inst,
p_mlib->i_refcount = 1; p_mlib->i_refcount = 1;
p_mlib->p_mlist = NULL; p_mlib->p_mlist = NULL;
p_mlib->p_event_manager = libvlc_event_manager_new( p_mlib, p_inst, p_e ); p_mlib->p_event_manager = libvlc_event_manager_new( p_mlib, p_inst );
if( unlikely(p_mlib->p_event_manager == NULL) )
{
free(p_mlib);
return NULL;
}
return p_mlib; return p_mlib;
} }
......
...@@ -157,31 +157,32 @@ libvlc_media_list_new( libvlc_instance_t * p_inst, ...@@ -157,31 +157,32 @@ libvlc_media_list_new( libvlc_instance_t * p_inst,
libvlc_media_list_t * p_mlist; libvlc_media_list_t * p_mlist;
p_mlist = malloc(sizeof(libvlc_media_list_t)); p_mlist = malloc(sizeof(libvlc_media_list_t));
if( !p_mlist ) if( unlikely(p_mlist == NULL) )
{
libvlc_printerr( "Not enough memory" );
return NULL; return NULL;
}
p_mlist->p_libvlc_instance = p_inst; p_mlist->p_libvlc_instance = p_inst;
p_mlist->p_event_manager = libvlc_event_manager_new( p_mlist, p_inst, p_e ); p_mlist->p_event_manager = libvlc_event_manager_new( p_mlist, p_inst );
if( unlikely(p_mlist->p_event_manager == NULL) )
{
free(p_mlist);
return NULL;
}
/* Code for that one should be handled in flat_media_list.c */ /* Code for that one should be handled in flat_media_list.c */
p_mlist->p_flat_mlist = NULL; p_mlist->p_flat_mlist = NULL;
p_mlist->b_read_only = false; p_mlist->b_read_only = false;
libvlc_event_manager_register_event_type( p_mlist->p_event_manager, libvlc_event_manager_register_event_type( p_mlist->p_event_manager,
libvlc_MediaListItemAdded, p_e ); libvlc_MediaListItemAdded );
libvlc_event_manager_register_event_type( p_mlist->p_event_manager, libvlc_event_manager_register_event_type( p_mlist->p_event_manager,
libvlc_MediaListWillAddItem, p_e ); libvlc_MediaListWillAddItem );
libvlc_event_manager_register_event_type( p_mlist->p_event_manager, libvlc_event_manager_register_event_type( p_mlist->p_event_manager,
libvlc_MediaListItemDeleted, p_e ); libvlc_MediaListItemDeleted );
libvlc_event_manager_register_event_type( p_mlist->p_event_manager, libvlc_event_manager_register_event_type( p_mlist->p_event_manager,
libvlc_MediaListWillDeleteItem, p_e ); libvlc_MediaListWillDeleteItem );
if( libvlc_exception_raised( p_e ) )
{
libvlc_event_manager_release( p_mlist->p_event_manager );
free( p_mlist );
return NULL;
}
vlc_mutex_init( &p_mlist->object_lock ); vlc_mutex_init( &p_mlist->object_lock );
vlc_mutex_init( &p_mlist->refcount_lock ); // FIXME: spinlock? vlc_mutex_init( &p_mlist->refcount_lock ); // FIXME: spinlock?
......
...@@ -358,7 +358,7 @@ static void ...@@ -358,7 +358,7 @@ static void
install_playlist_observer(libvlc_media_list_player_t * p_mlp) install_playlist_observer(libvlc_media_list_player_t * p_mlp)
{ {
assert_locked(p_mlp); assert_locked(p_mlp);
libvlc_event_attach(mlist_em(p_mlp), libvlc_MediaListItemDeleted, mlist_item_deleted, p_mlp, NULL); libvlc_event_attach(mlist_em(p_mlp), libvlc_MediaListItemDeleted, mlist_item_deleted, p_mlp);
} }
/************************************************************************** /**************************************************************************
...@@ -379,7 +379,7 @@ static void ...@@ -379,7 +379,7 @@ static void
install_media_player_observer(libvlc_media_list_player_t * p_mlp) install_media_player_observer(libvlc_media_list_player_t * p_mlp)
{ {
assert_locked(p_mlp); assert_locked(p_mlp);
libvlc_event_attach_async(mplayer_em(p_mlp), libvlc_MediaPlayerEndReached, media_player_reached_end, p_mlp, NULL); libvlc_event_attach_async(mplayer_em(p_mlp), libvlc_MediaPlayerEndReached, media_player_reached_end, p_mlp);
} }
...@@ -459,16 +459,25 @@ libvlc_media_list_player_new(libvlc_instance_t * p_instance, libvlc_exception_t ...@@ -459,16 +459,25 @@ libvlc_media_list_player_new(libvlc_instance_t * p_instance, libvlc_exception_t
(void)p_e; (void)p_e;
libvlc_media_list_player_t * p_mlp; libvlc_media_list_player_t * p_mlp;
p_mlp = calloc( 1, sizeof(libvlc_media_list_player_t) ); p_mlp = calloc( 1, sizeof(libvlc_media_list_player_t) );
if (!p_mlp) if (unlikely(p_mlp == NULL))
{
libvlc_printerr("Not enough memory");
return NULL; return NULL;
}
p_mlp->p_event_manager = libvlc_event_manager_new(p_mlp, p_instance);
if (unlikely(p_mlp->p_event_manager == NULL))
{
free (p_mlp);
return NULL;
}
libvlc_retain(p_instance); libvlc_retain(p_instance);
p_mlp->p_libvlc_instance = p_instance; p_mlp->p_libvlc_instance = p_instance;
p_mlp->i_refcount = 1; p_mlp->i_refcount = 1;
vlc_mutex_init(&p_mlp->object_lock); vlc_mutex_init(&p_mlp->object_lock);
vlc_mutex_init(&p_mlp->mp_callback_lock); vlc_mutex_init(&p_mlp->mp_callback_lock);
p_mlp->p_event_manager = libvlc_event_manager_new(p_mlp, p_instance, p_e); libvlc_event_manager_register_event_type(p_mlp->p_event_manager, libvlc_MediaListPlayerNextItemSet);
libvlc_event_manager_register_event_type(p_mlp->p_event_manager, libvlc_MediaListPlayerNextItemSet, p_e);
p_mlp->e_playback_mode = libvlc_playback_mode_default; p_mlp->e_playback_mode = libvlc_playback_mode_default;
return p_mlp; return p_mlp;
......
...@@ -82,10 +82,10 @@ install_md_listener( libvlc_media_list_view_t * p_mlv, ...@@ -82,10 +82,10 @@ install_md_listener( libvlc_media_list_view_t * p_mlv,
} }
libvlc_event_attach( p_mlist->p_event_manager, libvlc_event_attach( p_mlist->p_event_manager,
libvlc_MediaListItemAdded, libvlc_MediaListItemAdded,
media_list_item_added, p_mlv, NULL ); media_list_item_added, p_mlv );
libvlc_event_attach( p_mlist->p_event_manager, libvlc_event_attach( p_mlist->p_event_manager,
libvlc_MediaListItemDeleted, libvlc_MediaListItemDeleted,
media_list_item_removed, p_mlv, NULL ); media_list_item_removed, p_mlv );
libvlc_media_list_unlock( p_mlist ); libvlc_media_list_unlock( p_mlist );
libvlc_media_list_release( p_mlist ); libvlc_media_list_release( p_mlist );
} }
...@@ -94,7 +94,7 @@ install_md_listener( libvlc_media_list_view_t * p_mlv, ...@@ -94,7 +94,7 @@ install_md_listener( libvlc_media_list_view_t * p_mlv,
/* No mlist, wait for a subitem added event */ /* No mlist, wait for a subitem added event */
libvlc_event_attach( p_md->p_event_manager, libvlc_event_attach( p_md->p_event_manager,
libvlc_MediaSubItemAdded, libvlc_MediaSubItemAdded,
media_list_subitem_added, p_mlv, NULL ); media_list_subitem_added, p_mlv );
} }
} }
...@@ -167,10 +167,10 @@ media_list_subitem_added( const libvlc_event_t * p_event, void * p_user_data ) ...@@ -167,10 +167,10 @@ media_list_subitem_added( const libvlc_event_t * p_event, void * p_user_data )
libvlc_event_attach( p_mlist->p_event_manager, libvlc_event_attach( p_mlist->p_event_manager,
libvlc_MediaListItemAdded, libvlc_MediaListItemAdded,
media_list_item_added, p_mlv, NULL ); media_list_item_added, p_mlv );
libvlc_event_attach( p_mlist->p_event_manager, libvlc_event_attach( p_mlist->p_event_manager,
libvlc_MediaListItemDeleted, libvlc_MediaListItemDeleted,
media_list_item_removed, p_mlv, NULL ); media_list_item_removed, p_mlv );
libvlc_media_list_unlock( p_mlist ); libvlc_media_list_unlock( p_mlist );
libvlc_media_list_release( p_mlist ); libvlc_media_list_release( p_mlist );
} }
...@@ -199,10 +199,10 @@ libvlc_media_list_view_set_ml_notification_callback( ...@@ -199,10 +199,10 @@ libvlc_media_list_view_set_ml_notification_callback(
p_mlv->pf_ml_item_removed = item_removed; p_mlv->pf_ml_item_removed = item_removed;
libvlc_event_attach( p_mlv->p_mlist->p_event_manager, libvlc_event_attach( p_mlv->p_mlist->p_event_manager,
libvlc_MediaListItemAdded, libvlc_MediaListItemAdded,
media_list_item_added, p_mlv, NULL ); media_list_item_added, p_mlv );
libvlc_event_attach( p_mlv->p_mlist->p_event_manager, libvlc_event_attach( p_mlv->p_mlist->p_event_manager,
libvlc_MediaListItemDeleted, libvlc_MediaListItemDeleted,
media_list_item_removed, p_mlv, NULL ); media_list_item_removed, p_mlv );
int i, count = libvlc_media_list_count( p_mlv->p_mlist ); int i, count = libvlc_media_list_count( p_mlv->p_mlist );
for( i = 0; i < count; i++) for( i = 0; i < count; i++)
{ {
...@@ -308,21 +308,29 @@ libvlc_media_list_view_new( libvlc_media_list_t * p_mlist, ...@@ -308,21 +308,29 @@ libvlc_media_list_view_new( libvlc_media_list_t * p_mlist,
{ {
libvlc_media_list_view_t * p_mlv; libvlc_media_list_view_t * p_mlv;
p_mlv = calloc( 1, sizeof(libvlc_media_list_view_t) ); p_mlv = calloc( 1, sizeof(libvlc_media_list_view_t) );
if( !p_mlv ) if( unlikely(p_mlv == NULL) )
{
libvlc_printerr( "Not enough memory" );
return NULL; return NULL;
}
p_mlv->p_libvlc_instance = p_mlist->p_libvlc_instance; p_mlv->p_libvlc_instance = p_mlist->p_libvlc_instance;
p_mlv->p_event_manager = libvlc_event_manager_new( p_mlist, p_mlv->p_event_manager = libvlc_event_manager_new( p_mlist,
p_mlv->p_libvlc_instance, p_e ); p_mlv->p_libvlc_instance );
if( unlikely(p_mlv->p_event_manager == NULL) )
{
free(p_mlv);
return NULL;
}
libvlc_event_manager_register_event_type( p_mlv->p_event_manager, libvlc_event_manager_register_event_type( p_mlv->p_event_manager,
libvlc_MediaListViewItemAdded, p_e ); libvlc_MediaListViewItemAdded );
libvlc_event_manager_register_event_type( p_mlv->p_event_manager, libvlc_event_manager_register_event_type( p_mlv->p_event_manager,
libvlc_MediaListViewWillAddItem, p_e ); libvlc_MediaListViewWillAddItem );
libvlc_event_manager_register_event_type( p_mlv->p_event_manager, libvlc_event_manager_register_event_type( p_mlv->p_event_manager,
libvlc_MediaListViewItemDeleted, p_e ); libvlc_MediaListViewItemDeleted );
libvlc_event_manager_register_event_type( p_mlv->p_event_manager, libvlc_event_manager_register_event_type( p_mlv->p_event_manager,
libvlc_MediaListViewWillDeleteItem, p_e ); libvlc_MediaListViewWillDeleteItem );
libvlc_media_list_retain( p_mlist ); libvlc_media_list_retain( p_mlist );
p_mlv->p_mlist = p_mlist; p_mlv->p_mlist = p_mlist;
......
...@@ -67,7 +67,7 @@ static void libvlc_media_player_destroy( libvlc_media_player_t *p_mi ); ...@@ -67,7 +67,7 @@ static void libvlc_media_player_destroy( libvlc_media_player_t *p_mi );
#define register_event(a, b) __register_event(a, libvlc_MediaPlayer ## b) #define register_event(a, b) __register_event(a, libvlc_MediaPlayer ## b)
static inline void __register_event(libvlc_media_player_t *mp, libvlc_event_type_t type) static inline void __register_event(libvlc_media_player_t *mp, libvlc_event_type_t type)
{ {
libvlc_event_manager_register_event_type(mp->p_event_manager, type, NULL); libvlc_event_manager_register_event_type(mp->p_event_manager, type);
} }
static inline void lock(libvlc_media_player_t *mp) static inline void lock(libvlc_media_player_t *mp)
...@@ -361,14 +361,13 @@ libvlc_media_player_new( libvlc_instance_t *instance, libvlc_exception_t *e ) ...@@ -361,14 +361,13 @@ libvlc_media_player_new( libvlc_instance_t *instance, libvlc_exception_t *e )
mp->p_input_thread = NULL; mp->p_input_thread = NULL;
mp->p_input_resource = NULL; mp->p_input_resource = NULL;
mp->i_refcount = 1; mp->i_refcount = 1;
vlc_mutex_init(&mp->object_lock); mp->p_event_manager = libvlc_event_manager_new(mp, instance);
mp->p_event_manager = libvlc_event_manager_new(mp, instance, e); if (unlikely(mp->p_event_manager == NULL))
if (libvlc_exception_raised(e))
{ {
vlc_mutex_destroy(&mp->object_lock);
free(mp); free(mp);
return NULL; return NULL;
} }
vlc_mutex_init(&mp->object_lock);
register_event(mp, NothingSpecial); register_event(mp, NothingSpecial);
register_event(mp, Opening); register_event(mp, Opening);
......
...@@ -125,41 +125,42 @@ static int libvlc_vlm_init( libvlc_instance_t *p_instance, ...@@ -125,41 +125,42 @@ static int libvlc_vlm_init( libvlc_instance_t *p_instance,
if( !p_instance->libvlc_vlm.p_event_manager ) if( !p_instance->libvlc_vlm.p_event_manager )
{ {
p_instance->libvlc_vlm.p_event_manager = p_instance->libvlc_vlm.p_event_manager =
libvlc_event_manager_new( p_instance->libvlc_vlm.p_vlm, libvlc_event_manager_new( p_instance->libvlc_vlm.p_vlm, p_instance );
p_instance, p_exception ); if( unlikely(p_instance->libvlc_vlm.p_event_manager == NULL) )
return VLC_ENOMEM;
libvlc_event_manager_register_event_type( libvlc_event_manager_register_event_type(
p_instance->libvlc_vlm.p_event_manager, p_instance->libvlc_vlm.p_event_manager,
libvlc_VlmMediaAdded, NULL ); libvlc_VlmMediaAdded );
libvlc_event_manager_register_event_type( libvlc_event_manager_register_event_type(
p_instance->libvlc_vlm.p_event_manager, p_instance->libvlc_vlm.p_event_manager,
libvlc_VlmMediaRemoved, NULL ); libvlc_VlmMediaRemoved );
libvlc_event_manager_register_event_type( libvlc_event_manager_register_event_type(
p_instance->libvlc_vlm.p_event_manager, p_instance->libvlc_vlm.p_event_manager,
libvlc_VlmMediaChanged, NULL ); libvlc_VlmMediaChanged );
libvlc_event_manager_register_event_type( libvlc_event_manager_register_event_type(
p_instance->libvlc_vlm.p_event_manager, p_instance->libvlc_vlm.p_event_manager,
libvlc_VlmMediaInstanceStarted, NULL ); libvlc_VlmMediaInstanceStarted );
libvlc_event_manager_register_event_type( libvlc_event_manager_register_event_type(
p_instance->libvlc_vlm.p_event_manager, p_instance->libvlc_vlm.p_event_manager,
libvlc_VlmMediaInstanceStopped, NULL ); libvlc_VlmMediaInstanceStopped );
libvlc_event_manager_register_event_type( libvlc_event_manager_register_event_type(
p_instance->libvlc_vlm.p_event_manager, p_instance->libvlc_vlm.p_event_manager,
libvlc_VlmMediaInstanceStatusInit, NULL ); libvlc_VlmMediaInstanceStatusInit );
libvlc_event_manager_register_event_type( libvlc_event_manager_register_event_type(
p_instance->libvlc_vlm.p_event_manager, p_instance->libvlc_vlm.p_event_manager,
libvlc_VlmMediaInstanceStatusOpening, NULL ); libvlc_VlmMediaInstanceStatusOpening );
libvlc_event_manager_register_event_type( libvlc_event_manager_register_event_type(
p_instance->libvlc_vlm.p_event_manager, p_instance->libvlc_vlm.p_event_manager,
libvlc_VlmMediaInstanceStatusPlaying, NULL ); libvlc_VlmMediaInstanceStatusPlaying );
libvlc_event_manager_register_event_type( libvlc_event_manager_register_event_type(
p_instance->libvlc_vlm.p_event_manager, p_instance->libvlc_vlm.p_event_manager,
libvlc_VlmMediaInstanceStatusPause, NULL ); libvlc_VlmMediaInstanceStatusPause );
libvlc_event_manager_register_event_type( libvlc_event_manager_register_event_type(
p_instance->libvlc_vlm.p_event_manager, p_instance->libvlc_vlm.p_event_manager,
libvlc_VlmMediaInstanceStatusEnd, NULL ); libvlc_VlmMediaInstanceStatusEnd );
libvlc_event_manager_register_event_type( libvlc_event_manager_register_event_type(
p_instance->libvlc_vlm.p_event_manager, p_instance->libvlc_vlm.p_event_manager,
libvlc_VlmMediaInstanceStatusError, NULL ); libvlc_VlmMediaInstanceStatusError );
} }
if( !p_instance->libvlc_vlm.p_vlm ) if( !p_instance->libvlc_vlm.p_vlm )
......
...@@ -70,7 +70,7 @@ static void test_events (const char ** argv, int argc) ...@@ -70,7 +70,7 @@ static void test_events (const char ** argv, int argc)
libvlc_MediaPlayerTimeChanged, libvlc_MediaPlayerTimeChanged,
libvlc_MediaPlayerPositionChanged, libvlc_MediaPlayerPositionChanged,
}; };
int i, mi_events_len = sizeof(mi_events)/sizeof(*mi_events); int mi_events_len = sizeof(mi_events)/sizeof(*mi_events);
log ("Testing events\n"); log ("Testing events\n");
...@@ -85,14 +85,18 @@ static void test_events (const char ** argv, int argc) ...@@ -85,14 +85,18 @@ static void test_events (const char ** argv, int argc)
log ("+ Testing attaching to Media Instance\n"); log ("+ Testing attaching to Media Instance\n");
for (i = 0; i < mi_events_len; i++) { for (int i = 0; i < mi_events_len; i++) {
libvlc_event_attach (em, mi_events[i], test_events_dummy_callback, &callback_was_called, &ex); int ret;
catch ();
ret = libvlc_event_attach (em, mi_events[i],
test_events_dummy_callback,
&callback_was_called);
assert(ret == 0);
} }
log ("+ Testing event reception\n"); log ("+ Testing event reception\n");
for (i = 0; i < mi_events_len; i++) for (int i = 0; i < mi_events_len; i++)
test_event_type_reception (em, mi_events[i], &callback_was_called); test_event_type_reception (em, mi_events[i], &callback_was_called);
log ("+ Testing event detaching while in the event callback\n"); log ("+ Testing event detaching while in the event callback\n");
...@@ -103,8 +107,10 @@ static void test_events (const char ** argv, int argc) ...@@ -103,8 +107,10 @@ static void test_events (const char ** argv, int argc)
libvlc_event_detach (em, mi_events[mi_events_len-1], test_events_dummy_callback, &callback_was_called); libvlc_event_detach (em, mi_events[mi_events_len-1], test_events_dummy_callback, &callback_was_called);
libvlc_event_attach (em, mi_events[mi_events_len-1], test_events_callback_and_detach, &callback_was_called, &ex); int val = libvlc_event_attach (em, mi_events[mi_events_len-1],
catch (); test_events_callback_and_detach,
&callback_was_called);
assert (val == 0);
libvlc_event_send (em, &event); libvlc_event_send (em, &event);
assert( callback_was_called ); assert( callback_was_called );
...@@ -115,7 +121,7 @@ static void test_events (const char ** argv, int argc) ...@@ -115,7 +121,7 @@ static void test_events (const char ** argv, int argc)
log ("+ Testing regular detach()\n"); log ("+ Testing regular detach()\n");
for (i = 0; i < mi_events_len - 1; i++) for (int i = 0; i < mi_events_len - 1; i++)
libvlc_event_detach (em, mi_events[i], test_events_dummy_callback, &callback_was_called); libvlc_event_detach (em, mi_events[i], test_events_dummy_callback, &callback_was_called);
libvlc_media_player_release (mi); libvlc_media_player_release (mi);
......
...@@ -142,8 +142,9 @@ static void test_media_list_player_items_queue(const char** argv, int argc) ...@@ -142,8 +142,9 @@ static void test_media_list_player_items_queue(const char** argv, int argc)
libvlc_media_list_player_set_media_list (mlp, ml); libvlc_media_list_player_set_media_list (mlp, ml);
libvlc_event_manager_t * em = libvlc_media_list_player_event_manager(mlp); libvlc_event_manager_t * em = libvlc_media_list_player_event_manager(mlp);
libvlc_event_attach(em, libvlc_MediaListPlayerNextItemSet, check_items_order_callback, &check, &ex); int val = libvlc_event_attach(em, libvlc_MediaListPlayerNextItemSet,
catch (); check_items_order_callback, &check);
assert(val == 0);
libvlc_media_list_player_play(mlp, &ex); libvlc_media_list_player_play(mlp, &ex);
catch (); catch ();
......
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