1 /*****************************************************************************
2 * core.c: Core libvlc new API functions : initialization, exceptions handling
3 *****************************************************************************
4 * Copyright (C) 2005 the VideoLAN team
7 * Authors: Clément Stenac <zorglub@videolan.org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 #include <libvlc_internal.h>
25 #include <vlc/libvlc.h>
29 /*************************************************************************
31 *************************************************************************/
32 inline void libvlc_exception_init( libvlc_exception_t *p_exception )
34 p_exception->b_raised = 0;
35 p_exception->psz_message = NULL;
38 void libvlc_exception_clear( libvlc_exception_t *p_exception )
40 if( p_exception->psz_message )
41 free( p_exception->psz_message );
42 p_exception->psz_message = NULL;
43 p_exception->b_raised = 0;
46 inline int libvlc_exception_raised( libvlc_exception_t *p_exception )
48 return p_exception->b_raised;
51 inline char* libvlc_exception_get_message( libvlc_exception_t *p_exception )
53 if( p_exception->b_raised == 1 && p_exception->psz_message )
55 return p_exception->psz_message;
60 inline void libvlc_exception_raise( libvlc_exception_t *p_exception,
61 char *psz_format, ... )
65 /* does caller care about exceptions ? */
66 if( p_exception == NULL ) return;
68 /* remove previous exception if it wasn't cleared */
69 if( p_exception->b_raised && p_exception->psz_message )
71 free(p_exception->psz_message);
72 p_exception->psz_message = NULL;
75 va_start( args, psz_format );
76 vasprintf( &p_exception->psz_message, psz_format, args );
79 p_exception->b_raised = 1;
82 libvlc_instance_t * libvlc_new( int argc, char **argv,
83 libvlc_exception_t *p_e )
85 libvlc_instance_t *p_new;
87 libvlc_int_t *p_libvlc_int = libvlc_InternalCreate();
88 if( !p_libvlc_int ) RAISENULL( "VLC initialization failed" );
90 p_new = (libvlc_instance_t *)malloc( sizeof( libvlc_instance_t ) );
91 if( !p_new ) RAISENULL( "Out of memory" );
93 /** \todo Look for interface settings. If we don't have any, add -I dummy */
94 /* Because we probably don't want a GUI by default */
96 if( libvlc_InternalInit( p_libvlc_int, argc, argv ) )
97 RAISENULL( "VLC initialization failed" );
99 p_new->p_libvlc_int = p_libvlc_int;
104 void libvlc_destroy( libvlc_instance_t *p_instance )
106 libvlc_InternalCleanup( p_instance->p_libvlc_int );
107 libvlc_InternalDestroy( p_instance->p_libvlc_int, VLC_FALSE );
110 int libvlc_get_vlc_id( libvlc_instance_t *p_instance )
112 return p_instance->p_libvlc_int->i_object_id;