]> git.sesse.net Git - vlc/blobdiff - src/control/core.c
For consistency, remove references to vlc from libvlc
[vlc] / src / control / core.c
index e4432e84b9ed932ab00941b11939022d3f9a4b31..6675f81219a3352c5abd70030c21cbd9b2b00ead 100644 (file)
@@ -20,7 +20,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
-
+#include <stdarg.h>
 #include <libvlc_internal.h>
 #include <vlc/libvlc.h>
 
@@ -58,53 +58,56 @@ inline char* libvlc_exception_get_message( libvlc_exception_t *p_exception )
 }
 
 inline void libvlc_exception_raise( libvlc_exception_t *p_exception,
-                                    char *psz_message )
+                                    char *psz_format, ... )
 {
+    va_list args;
+
+    /* does caller care about exceptions ? */
     if( p_exception == NULL ) return;
+
+    /* remove previous exception if it wasn't cleared */
+    if( p_exception->b_raised && p_exception->psz_message )
+    {
+        free(p_exception->psz_message);
+        p_exception->psz_message = NULL;
+    }
+
+    va_start( args, psz_format );
+    vasprintf( &p_exception->psz_message, psz_format, args );
+    va_end( args );
+
     p_exception->b_raised = 1;
-    if( psz_message )
-        p_exception->psz_message = strdup( psz_message );
 }
 
 libvlc_instance_t * libvlc_new( int argc, char **argv,
-                                libvlc_exception_t *p_exception )
+                                libvlc_exception_t *p_e )
 {
     int i_vlc_id;
     libvlc_instance_t *p_new;
-    vlc_t *p_vlc;
+    libvlc_int_t *p_libvlc_int;
 
     i_vlc_id = VLC_Create();
-    p_vlc = (vlc_t* ) vlc_current_object( i_vlc_id );
+    p_libvlc_int = (libvlc_int_t* ) vlc_current_object( i_vlc_id );
+
+    if( !p_libvlc_int ) RAISENULL( "VLC initialization failed" );
 
-    if( !p_vlc )
-    {
-        libvlc_exception_raise( p_exception, "VLC initialization failed" );
-        return NULL;
-    }
     p_new = (libvlc_instance_t *)malloc( sizeof( libvlc_instance_t ) );
+    if( !p_new ) RAISENULL( "Out of memory" );
 
     /** \todo Look for interface settings. If we don't have any, add -I dummy */
     /* Because we probably don't want a GUI by default */
 
-    if( !p_new )
-    {
-        libvlc_exception_raise( p_exception, "Out of memory" );
-        return NULL;
-    }
 
     VLC_Init( i_vlc_id, argc, argv );
 
-    p_new->p_vlc = p_vlc;
-    p_new->p_playlist = (playlist_t *)vlc_object_find( p_new->p_vlc,
+    p_new->p_libvlc_int = p_libvlc_int;
+    p_new->p_playlist = (playlist_t *)vlc_object_find( p_new->p_libvlc_int,
                                 VLC_OBJECT_PLAYLIST, FIND_CHILD );
+    p_new->p_vlm = NULL;
 
-    if( !p_new->p_playlist )
-    {
-        libvlc_exception_raise( p_exception, "Playlist creation failed" );
-        return NULL;
-    }
+    if( !p_new->p_playlist ) RAISENULL( "Playlist creation failed" );
+    
     p_new->i_vlc_id = i_vlc_id;
-
     return p_new;
 }
 
@@ -112,7 +115,12 @@ void libvlc_destroy( libvlc_instance_t *p_instance )
 {
     if( p_instance->p_playlist )
         vlc_object_release( p_instance->p_playlist );
-    vlc_object_release( p_instance->p_vlc );
+    vlc_object_release( p_instance->p_libvlc_int );
     VLC_CleanUp( p_instance->i_vlc_id );
     VLC_Destroy( p_instance->i_vlc_id );
 }
+
+int libvlc_get_vlc_id( libvlc_instance_t *p_instance )
+{
+    return p_instance->i_vlc_id;
+}