Commit 6c2286c2 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

Remove some exceptions in media_list

parent 67875950
...@@ -103,12 +103,10 @@ VLC_PUBLIC_API libvlc_media_t * ...@@ -103,12 +103,10 @@ VLC_PUBLIC_API libvlc_media_t *
* *
* \param p_ml a media list instance * \param p_ml a media list instance
* \param p_mi a media instance * \param p_mi a media instance
* \param p_e initialized exception object * \return 0 on success, -1 if the media list is read-only
*/ */
VLC_PUBLIC_API void VLC_PUBLIC_API int
libvlc_media_list_add_media( libvlc_media_list_t *, libvlc_media_list_add_media( libvlc_media_list_t *, libvlc_media_t * );
libvlc_media_t *,
libvlc_exception_t * );
/** /**
* Insert media instance in media list on a position * Insert media instance in media list on a position
...@@ -117,24 +115,22 @@ VLC_PUBLIC_API void ...@@ -117,24 +115,22 @@ VLC_PUBLIC_API void
* \param p_ml a media list instance * \param p_ml a media list instance
* \param p_mi a media instance * \param p_mi a media instance
* \param i_pos position in array where to insert * \param i_pos position in array where to insert
* \param p_e initialized exception object * \return 0 on success, -1 if the media list si read-only
*/ */
VLC_PUBLIC_API void VLC_PUBLIC_API int
libvlc_media_list_insert_media( libvlc_media_list_t *, libvlc_media_list_insert_media( libvlc_media_list_t *,
libvlc_media_t *, libvlc_media_t *, int );
int,
libvlc_exception_t * );
/** /**
* Remove media instance from media list on a position * Remove media instance from media list on a position
* The libvlc_media_list_lock should be held upon entering this function. * The libvlc_media_list_lock should be held upon entering this function.
* *
* \param p_ml a media list instance * \param p_ml a media list instance
* \param i_pos position in array where to insert * \param i_pos position in array where to insert
* \param p_e initialized exception object * \return 0 on success, -1 if the list is read-only or the item was not found
*/ */
VLC_PUBLIC_API void VLC_PUBLIC_API int
libvlc_media_list_remove_index( libvlc_media_list_t *, int, libvlc_media_list_remove_index( libvlc_media_list_t *, int );
libvlc_exception_t * );
/** /**
* Get count on media list items * Get count on media list items
...@@ -152,12 +148,12 @@ VLC_PUBLIC_API int ...@@ -152,12 +148,12 @@ VLC_PUBLIC_API int
* *
* \param p_ml a media list instance * \param p_ml a media list instance
* \param i_pos position in array where to insert * \param i_pos position in array where to insert
* \param p_e initialized exception object * \return media instance at position i_pos, or NULL if not found.
* \return media instance at position i_pos and libvlc_media_retain() has been called to increase the refcount on this object. * In case of success, libvlc_media_retain() is called to increase the refcount
* on the media.
*/ */
VLC_PUBLIC_API libvlc_media_t * VLC_PUBLIC_API libvlc_media_t *
libvlc_media_list_item_at_index( libvlc_media_list_t *, int, libvlc_media_list_item_at_index( libvlc_media_list_t *, int );
libvlc_exception_t * );
/** /**
* Find index position of List media instance in media list. * Find index position of List media instance in media list.
* Warning: the function will return the first matched position. * Warning: the function will return the first matched position.
......
...@@ -106,7 +106,7 @@ static void input_item_subitem_added( const vlc_event_t *p_event, ...@@ -106,7 +106,7 @@ static void input_item_subitem_added( const vlc_event_t *p_event,
} }
if( p_md->p_subitems ) if( p_md->p_subitems )
{ {
libvlc_media_list_add_media( p_md->p_subitems, p_md_child, NULL ); libvlc_media_list_add_media( p_md->p_subitems, p_md_child );
} }
/* Construct the event */ /* Construct the event */
......
...@@ -118,10 +118,10 @@ static void services_discovery_item_removed( const vlc_event_t * p_event, ...@@ -118,10 +118,10 @@ static void services_discovery_item_removed( const vlc_event_t * p_event,
libvlc_media_list_lock( p_mdis->p_mlist ); libvlc_media_list_lock( p_mdis->p_mlist );
for( i = 0; i < count; i++ ) for( i = 0; i < count; i++ )
{ {
p_md = libvlc_media_list_item_at_index( p_mdis->p_mlist, i, NULL ); p_md = libvlc_media_list_item_at_index( p_mdis->p_mlist, i );
if( p_md->p_input_item == p_item ) if( p_md->p_input_item == p_item )
{ {
_libvlc_media_list_remove_index( p_mdis->p_mlist, i, NULL ); _libvlc_media_list_remove_index( p_mdis->p_mlist, i );
break; break;
} }
} }
......
...@@ -124,21 +124,17 @@ notify_item_deletion( libvlc_media_list_t * p_mlist, ...@@ -124,21 +124,17 @@ notify_item_deletion( libvlc_media_list_t * p_mlist,
/************************************************************************** /**************************************************************************
* static mlist_is_writable (private) * static mlist_is_writable (private)
*
* Raise exception and return 0 when the media_list instance is read-only,
* or else return 1.
**************************************************************************/ **************************************************************************/
static inline static inline
int mlist_is_writable( libvlc_media_list_t *p_mlist, libvlc_exception_t *p_e ) bool mlist_is_writable( libvlc_media_list_t *p_mlist )
{ {
if( !p_mlist||p_mlist->b_read_only ) if( !p_mlist||p_mlist->b_read_only )
{ {
/* We are read-only from user side */ /* We are read-only from user side */
libvlc_exception_raise( p_e );
libvlc_printerr( "Attempt to write a read-only media list" ); libvlc_printerr( "Attempt to write a read-only media list" );
return 0; return false;
} }
return 1; return true;
} }
/* /*
...@@ -273,9 +269,11 @@ libvlc_media_list_add_file_content( libvlc_media_list_t * p_mlist, ...@@ -273,9 +269,11 @@ libvlc_media_list_add_file_content( libvlc_media_list_t * p_mlist,
return; return;
} }
libvlc_media_list_add_media( p_mlist, p_md, p_e ); if( libvlc_media_list_add_media( p_mlist, p_md ) )
if( libvlc_exception_raised( p_e ) ) {
libvlc_exception_raise( p_e );
return; return;
}
input_Read( p_mlist->p_libvlc_instance->p_libvlc_int, p_input_item ); input_Read( p_mlist->p_libvlc_instance->p_libvlc_int, p_input_item );
...@@ -334,13 +332,13 @@ int libvlc_media_list_count( libvlc_media_list_t * p_mlist ) ...@@ -334,13 +332,13 @@ int libvlc_media_list_count( libvlc_media_list_t * p_mlist )
* *
* Lock should be held when entering. * Lock should be held when entering.
**************************************************************************/ **************************************************************************/
void libvlc_media_list_add_media( int libvlc_media_list_add_media( libvlc_media_list_t * p_mlist,
libvlc_media_list_t * p_mlist, libvlc_media_t * p_md )
libvlc_media_t * p_md,
libvlc_exception_t * p_e )
{ {
if( mlist_is_writable(p_mlist,p_e) ) if( !mlist_is_writable(p_mlist) )
return -1;
_libvlc_media_list_add_media( p_mlist, p_md ); _libvlc_media_list_add_media( p_mlist, p_md );
return 0;
} }
/* LibVLC internal version */ /* LibVLC internal version */
...@@ -361,14 +359,14 @@ void _libvlc_media_list_add_media( libvlc_media_list_t * p_mlist, ...@@ -361,14 +359,14 @@ void _libvlc_media_list_add_media( libvlc_media_list_t * p_mlist,
* *
* Lock should be hold when entering. * Lock should be hold when entering.
**************************************************************************/ **************************************************************************/
void libvlc_media_list_insert_media( int libvlc_media_list_insert_media( libvlc_media_list_t * p_mlist,
libvlc_media_list_t * p_mlist,
libvlc_media_t * p_md, libvlc_media_t * p_md,
int index, int index )
libvlc_exception_t * p_e )
{ {
if( mlist_is_writable(p_mlist,p_e) ) if( !mlist_is_writable(p_mlist) )
return -1;
_libvlc_media_list_insert_media( p_mlist, p_md, index ); _libvlc_media_list_insert_media( p_mlist, p_md, index );
return 0;
} }
/* LibVLC internal version */ /* LibVLC internal version */
...@@ -389,26 +387,24 @@ void _libvlc_media_list_insert_media( ...@@ -389,26 +387,24 @@ void _libvlc_media_list_insert_media(
* *
* Lock should be held when entering. * Lock should be held when entering.
**************************************************************************/ **************************************************************************/
void libvlc_media_list_remove_index( libvlc_media_list_t * p_mlist, int libvlc_media_list_remove_index( libvlc_media_list_t * p_mlist,
int index, int index )
libvlc_exception_t * p_e )
{ {
if( mlist_is_writable(p_mlist,p_e) ) if( !mlist_is_writable(p_mlist) )
_libvlc_media_list_remove_index( p_mlist, index, p_e ); return -1;
return _libvlc_media_list_remove_index( p_mlist, index );
} }
/* LibVLC internal version */ /* LibVLC internal version */
void _libvlc_media_list_remove_index( libvlc_media_list_t * p_mlist, int _libvlc_media_list_remove_index( libvlc_media_list_t * p_mlist,
int index, int index )
libvlc_exception_t * p_e )
{ {
libvlc_media_t * p_md; libvlc_media_t * p_md;
if( index < 0 || index >= vlc_array_count( &p_mlist->items )) if( index < 0 || index >= vlc_array_count( &p_mlist->items ))
{ {
libvlc_exception_raise( p_e );
libvlc_printerr( "Index out of bounds" ); libvlc_printerr( "Index out of bounds" );
return; return -1;
} }
p_md = vlc_array_item_at_index( &p_mlist->items, index ); p_md = vlc_array_item_at_index( &p_mlist->items, index );
...@@ -418,6 +414,7 @@ void _libvlc_media_list_remove_index( libvlc_media_list_t * p_mlist, ...@@ -418,6 +414,7 @@ void _libvlc_media_list_remove_index( libvlc_media_list_t * p_mlist,
notify_item_deletion( p_mlist, p_md, index, EventDidHappen ); notify_item_deletion( p_mlist, p_md, index, EventDidHappen );
libvlc_media_release( p_md ); libvlc_media_release( p_md );
return 0;
} }
/************************************************************************** /**************************************************************************
...@@ -427,14 +424,12 @@ void _libvlc_media_list_remove_index( libvlc_media_list_t * p_mlist, ...@@ -427,14 +424,12 @@ void _libvlc_media_list_remove_index( libvlc_media_list_t * p_mlist,
**************************************************************************/ **************************************************************************/
libvlc_media_t * libvlc_media_t *
libvlc_media_list_item_at_index( libvlc_media_list_t * p_mlist, libvlc_media_list_item_at_index( libvlc_media_list_t * p_mlist,
int index, int index )
libvlc_exception_t * p_e )
{ {
libvlc_media_t * p_md; libvlc_media_t * p_md;
if( index < 0 || index >= vlc_array_count( &p_mlist->items )) if( index < 0 || index >= vlc_array_count( &p_mlist->items ))
{ {
libvlc_exception_raise( p_e );
libvlc_printerr( "Index out of bounds" ); libvlc_printerr( "Index out of bounds" );
return NULL; return NULL;
} }
......
...@@ -64,8 +64,7 @@ void _libvlc_media_list_insert_media( ...@@ -64,8 +64,7 @@ void _libvlc_media_list_insert_media(
libvlc_media_list_t * p_mlist, libvlc_media_list_t * p_mlist,
libvlc_media_t * p_md, int index ); libvlc_media_t * p_md, int index );
void _libvlc_media_list_remove_index( int _libvlc_media_list_remove_index(
libvlc_media_list_t * p_mlist, int index, libvlc_media_list_t * p_mlist, int index );
libvlc_exception_t * p_e );
#endif #endif
...@@ -122,7 +122,7 @@ get_path_rec( const libvlc_media_list_path_t path, libvlc_media_list_t * p_curre ...@@ -122,7 +122,7 @@ get_path_rec( const libvlc_media_list_path_t path, libvlc_media_list_t * p_curre
count = libvlc_media_list_count( p_current_mlist ); count = libvlc_media_list_count( p_current_mlist );
for( i = 0; i < count; i++ ) for( i = 0; i < count; i++ )
{ {
libvlc_media_t * p_md = libvlc_media_list_item_at_index( p_current_mlist, i, NULL ); libvlc_media_t * p_md = libvlc_media_list_item_at_index( p_current_mlist, i );
if( p_md == p_searched_md ) if( p_md == p_searched_md )
return libvlc_media_list_path_copy_by_appending( path, i ); /* Found! */ return libvlc_media_list_path_copy_by_appending( path, i ); /* Found! */
...@@ -167,7 +167,7 @@ libvlc_media_list_item_at_path( libvlc_media_list_t * p_mlist, const libvlc_medi ...@@ -167,7 +167,7 @@ libvlc_media_list_item_at_path( libvlc_media_list_t * p_mlist, const libvlc_medi
int i; int i;
for( i = 0; path[i] != -1; i++ ) for( i = 0; path[i] != -1; i++ )
{ {
p_md = libvlc_media_list_item_at_index( p_current_mlist, path[i], NULL ); p_md = libvlc_media_list_item_at_index( p_current_mlist, path[i] );
if( p_current_mlist != p_mlist ) if( p_current_mlist != p_mlist )
libvlc_media_list_release( p_current_mlist ); libvlc_media_list_release( p_current_mlist );
...@@ -209,7 +209,7 @@ libvlc_media_list_parentlist_at_path( libvlc_media_list_t * p_mlist, const libvl ...@@ -209,7 +209,7 @@ libvlc_media_list_parentlist_at_path( libvlc_media_list_t * p_mlist, const libvl
return p_current_mlist; return p_current_mlist;
} }
p_md = libvlc_media_list_item_at_index( p_current_mlist, path[i], NULL ); p_md = libvlc_media_list_item_at_index( p_current_mlist, path[i] );
p_current_mlist = libvlc_media_subitems( p_md ); p_current_mlist = libvlc_media_subitems( p_md );
libvlc_media_release( p_md ); libvlc_media_release( p_md );
......
...@@ -28,6 +28,7 @@ static void test_media_list (const char ** argv, int argc) ...@@ -28,6 +28,7 @@ static void test_media_list (const char ** argv, int argc)
libvlc_instance_t *vlc; libvlc_instance_t *vlc;
libvlc_media_t *md1, *md2, *md3, *md4; libvlc_media_t *md1, *md2, *md3, *md4;
libvlc_media_list_t *ml; libvlc_media_list_t *ml;
int ret;
log ("Testing media_list\n"); log ("Testing media_list\n");
...@@ -45,30 +46,30 @@ static void test_media_list (const char ** argv, int argc) ...@@ -45,30 +46,30 @@ static void test_media_list (const char ** argv, int argc)
md3 = libvlc_media_new (vlc, "/dev/null"); md3 = libvlc_media_new (vlc, "/dev/null");
assert (md3 != NULL); assert (md3 != NULL);
libvlc_media_list_add_media (ml, md1, &ex); ret = libvlc_media_list_add_media (ml, md1);
catch (); assert (!ret);
libvlc_media_list_add_media (ml, md2, &ex); ret = libvlc_media_list_add_media (ml, md2);
catch (); assert (!ret);
assert( libvlc_media_list_count (ml) == 2 ); assert( libvlc_media_list_count (ml) == 2 );
assert( libvlc_media_list_index_of_item (ml, md1) == 0 ); assert( libvlc_media_list_index_of_item (ml, md1) == 0 );
assert( libvlc_media_list_index_of_item (ml, md2) == 1 ); assert( libvlc_media_list_index_of_item (ml, md2) == 1 );
libvlc_media_list_remove_index (ml, 0, &ex); /* removing first item */ ret = libvlc_media_list_remove_index (ml, 0); /* removing first item */
catch (); assert (!ret);
/* test if second item was moved on first place */ /* test if second item was moved on first place */
assert( libvlc_media_list_index_of_item (ml, md2) == 0 ); assert( libvlc_media_list_index_of_item (ml, md2) == 0 );
libvlc_media_list_add_media (ml, md1, &ex); /* add 2 items */ ret = libvlc_media_list_add_media (ml, md1); /* add 2 items */
catch (); assert (!ret);
libvlc_media_list_add_media (ml, md1, &ex); ret = libvlc_media_list_add_media (ml, md1);
catch (); assert (!ret);
/* there should be 3 pieces */ /* there should be 3 pieces */
assert( libvlc_media_list_count (ml) == 3 ); assert( libvlc_media_list_count (ml) == 3 );
libvlc_media_list_insert_media (ml, md3, 2, &ex); ret = libvlc_media_list_insert_media (ml, md3, 2);
catch (); assert (!ret);
/* there should be 4 pieces */ /* there should be 4 pieces */
assert( libvlc_media_list_count (ml) == 4 ); assert( libvlc_media_list_count (ml) == 4 );
...@@ -77,33 +78,31 @@ static void test_media_list (const char ** argv, int argc) ...@@ -77,33 +78,31 @@ static void test_media_list (const char ** argv, int argc)
assert( libvlc_media_list_index_of_item (ml, md3) == 2 ); assert( libvlc_media_list_index_of_item (ml, md3) == 2 );
/* test right returning descriptor*/ /* test right returning descriptor*/
assert ( libvlc_media_list_item_at_index (ml, 0, &ex) == md2 ); assert ( libvlc_media_list_item_at_index (ml, 0) == md2 );
catch ();
assert ( libvlc_media_list_item_at_index (ml, 2, &ex) == md3 ); assert ( libvlc_media_list_item_at_index (ml, 2) == md3 );
catch ();
/* test if give exceptions, when it should */ /* test if give exceptions, when it should */
/* have 4 items, so index 4 should give exception */ /* have 4 items, so index 4 should give exception */
libvlc_media_list_remove_index (ml, 4, &ex); ret = libvlc_media_list_remove_index (ml, 4);
assert (have_exception ()); assert (ret == -1);
libvlc_media_list_remove_index (ml, 100, &ex); ret = libvlc_media_list_remove_index (ml, 100);
assert (have_exception ()); assert (ret == -1);
libvlc_media_list_remove_index (ml, -1, &ex); ret = libvlc_media_list_remove_index (ml, -1);
assert (have_exception ()); assert (ret == -1);
/* getting non valid items */ /* getting non valid items */
libvlc_media_t * p_non_exist = libvlc_media_t * p_non_exist =
libvlc_media_list_item_at_index (ml, 4, &ex); libvlc_media_list_item_at_index (ml, 4);
assert (have_exception ()); assert (p_non_exist == NULL);
p_non_exist = libvlc_media_list_item_at_index (ml, 100, &ex); p_non_exist = libvlc_media_list_item_at_index (ml, 100);
assert (have_exception ()); assert (p_non_exist == NULL);
p_non_exist = libvlc_media_list_item_at_index (ml, -1, &ex); p_non_exist = libvlc_media_list_item_at_index (ml, -1);
assert (have_exception ()); assert (p_non_exist == NULL);
md4 = libvlc_media_new (vlc, "/dev/null"); md4 = libvlc_media_new (vlc, "/dev/null");
assert (md4 != NULL); assert (md4 != NULL);
......
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