]> git.sesse.net Git - vlc/blobdiff - src/control/media_list.c
Use var_Inherit* instead of var_CreateGet*.
[vlc] / src / control / media_list.c
index 914c12c7c51943648005643c3ea07fcf1cbdea00..08271247a3ceca66c8f9a946777741ae7bcbf5a6 100644 (file)
@@ -124,21 +124,17 @@ notify_item_deletion( libvlc_media_list_t * p_mlist,
 
 /**************************************************************************
  *       static mlist_is_writable (private)
- *
- * Raise exception and return 0 when the media_list instance is read-only,
- * or else return 1.
  **************************************************************************/
 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 )
     {
         /* We are read-only from user side */
-        libvlc_exception_raise( p_e );
         libvlc_printerr( "Attempt to write a read-only media list" );
-        return 0;
+        return false;
     }
-    return 1;
+    return true;
 }
 
 /*
@@ -187,6 +183,7 @@ libvlc_media_list_new( libvlc_instance_t * p_inst )
     vlc_mutex_init( &p_mlist->refcount_lock ); // FIXME: spinlock?
 
     vlc_array_init( &p_mlist->items );
+    assert( p_mlist->items.i_count == 0 );
     p_mlist->i_refcount = 1;
     p_mlist->p_md = NULL;
 
@@ -246,10 +243,9 @@ void libvlc_media_list_retain( libvlc_media_list_t * p_mlist )
 /**************************************************************************
  *       add_file_content (Public)
  **************************************************************************/
-void
+int
 libvlc_media_list_add_file_content( libvlc_media_list_t * p_mlist,
-                                    const char * psz_uri,
-                                    libvlc_exception_t * p_e )
+                                    const char * psz_uri )
 {
     input_item_t * p_input_item;
     libvlc_media_t * p_md;
@@ -260,28 +256,27 @@ libvlc_media_list_add_file_content( libvlc_media_list_t * p_mlist,
 
     if( !p_input_item )
     {
-        libvlc_exception_raise( p_e );
         libvlc_printerr( "Not enough memory" );
-        return;
+        return -1;
     }
 
-    p_md = libvlc_media_new_from_input_item(
-            p_mlist->p_libvlc_instance,
-            p_input_item, p_e );
-
+    p_md = libvlc_media_new_from_input_item( p_mlist->p_libvlc_instance,
+                                             p_input_item );
     if( !p_md )
     {
         vlc_gc_decref( p_input_item );
-        return;
+        return -1;
     }
 
-    libvlc_media_list_add_media( p_mlist, p_md, p_e );
-    if( libvlc_exception_raised( p_e ) )
-        return;
+    if( libvlc_media_list_add_media( p_mlist, p_md ) )
+    {
+#warning Missing error handling!
+        /* printerr and leaks */
+        return -1;
+    }
 
     input_Read( p_mlist->p_libvlc_instance->p_libvlc_int, p_input_item );
-
-    return;
+    return 0;
 }
 
 /**************************************************************************
@@ -336,13 +331,13 @@ int libvlc_media_list_count( libvlc_media_list_t * p_mlist )
  *
  * Lock should be held when entering.
  **************************************************************************/
-void libvlc_media_list_add_media(
-                                   libvlc_media_list_t * p_mlist,
-                                   libvlc_media_t * p_md,
-                                   libvlc_exception_t * p_e )
+int libvlc_media_list_add_media( libvlc_media_list_t * p_mlist,
+                                 libvlc_media_t * p_md )
 {
-    if( mlist_is_writable(p_mlist,p_e) )
-        _libvlc_media_list_add_media( p_mlist, p_md );
+    if( !mlist_is_writable(p_mlist) )
+        return -1;
+    _libvlc_media_list_add_media( p_mlist, p_md );
+    return 0;
 }
 
 /* LibVLC internal version */
@@ -363,14 +358,14 @@ void _libvlc_media_list_add_media( libvlc_media_list_t * p_mlist,
  *
  * Lock should be hold when entering.
  **************************************************************************/
-void libvlc_media_list_insert_media(
-                                   libvlc_media_list_t * p_mlist,
-                                   libvlc_media_t * p_md,
-                                   int index,
-                                   libvlc_exception_t * p_e )
+int libvlc_media_list_insert_media( libvlc_media_list_t * p_mlist,
+                                    libvlc_media_t * p_md,
+                                    int index )
 {
-    if( mlist_is_writable(p_mlist,p_e) )
-        _libvlc_media_list_insert_media( p_mlist, p_md, index );
+    if( !mlist_is_writable(p_mlist) )
+        return -1;
+    _libvlc_media_list_insert_media( p_mlist, p_md, index );
+    return 0;
 }
 
 /* LibVLC internal version */
@@ -391,26 +386,24 @@ void _libvlc_media_list_insert_media(
  *
  * Lock should be held when entering.
  **************************************************************************/
-void libvlc_media_list_remove_index( libvlc_media_list_t * p_mlist,
-                                     int index,
-                                     libvlc_exception_t * p_e )
+int libvlc_media_list_remove_index( libvlc_media_list_t * p_mlist,
+                                     int index )
 {
-    if( mlist_is_writable(p_mlist,p_e) )
-        _libvlc_media_list_remove_index( p_mlist, index, p_e );
+    if( !mlist_is_writable(p_mlist) )
+        return -1;
+    return _libvlc_media_list_remove_index( p_mlist, index );
 }
 
 /* LibVLC internal version */
-void _libvlc_media_list_remove_index( libvlc_media_list_t * p_mlist,
-                                     int index,
-                                     libvlc_exception_t * p_e )
+int _libvlc_media_list_remove_index( libvlc_media_list_t * p_mlist,
+                                     int index )
 {
     libvlc_media_t * p_md;
 
     if( index < 0 || index >= vlc_array_count( &p_mlist->items ))
     {
-        libvlc_exception_raise( p_e );
         libvlc_printerr( "Index out of bounds" );
-        return;
+        return -1;
     }
 
     p_md = vlc_array_item_at_index( &p_mlist->items, index );
@@ -420,6 +413,7 @@ void _libvlc_media_list_remove_index( libvlc_media_list_t * p_mlist,
     notify_item_deletion( p_mlist, p_md, index, EventDidHappen );
 
     libvlc_media_release( p_md );
+    return 0;
 }
 
 /**************************************************************************
@@ -429,14 +423,12 @@ void _libvlc_media_list_remove_index( libvlc_media_list_t * p_mlist,
  **************************************************************************/
 libvlc_media_t *
 libvlc_media_list_item_at_index( libvlc_media_list_t * p_mlist,
-                                 int index,
-                                 libvlc_exception_t * p_e )
+                                 int index )
 {
     libvlc_media_t * p_md;
 
     if( index < 0 || index >= vlc_array_count( &p_mlist->items ))
     {
-        libvlc_exception_raise( p_e );
         libvlc_printerr( "Index out of bounds" );
         return NULL;
     }