]> git.sesse.net Git - vlc/blob - src/control/core.c
Removes trailing spaces. Removes tabs.
[vlc] / src / control / core.c
1 /*****************************************************************************
2  * core.c: Core libvlc new API functions : initialization, exceptions handling
3  *****************************************************************************
4  * Copyright (C) 2005 the VideoLAN team
5  * $Id$
6  *
7  * Authors: ClĂ©ment Stenac <zorglub@videolan.org>
8  *
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.
13  *
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.
18  *
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  *****************************************************************************/
23 #include <stdarg.h>
24 #include "libvlc_internal.h"
25 #include <vlc/libvlc.h>
26
27 #include <vlc_interface.h>
28
29 /*************************************************************************
30  * Exceptions handling
31  *************************************************************************/
32 void libvlc_exception_init( libvlc_exception_t *p_exception )
33 {
34     p_exception->b_raised = 0;
35     p_exception->psz_message = NULL;
36 }
37
38 void libvlc_exception_clear( libvlc_exception_t *p_exception )
39 {
40     if( p_exception->psz_message )
41         free( p_exception->psz_message );
42     p_exception->psz_message = NULL;
43     p_exception->b_raised = 0;
44 }
45
46 int libvlc_exception_raised( libvlc_exception_t *p_exception )
47 {
48     return (NULL != p_exception) && p_exception->b_raised;
49 }
50
51 char *libvlc_exception_get_message( libvlc_exception_t *p_exception )
52 {
53     if( p_exception->b_raised == 1 && p_exception->psz_message )
54     {
55         return p_exception->psz_message;
56     }
57     return NULL;
58 }
59
60 void libvlc_exception_raise( libvlc_exception_t *p_exception,
61                                            const char *psz_format, ... )
62 {
63     va_list args;
64
65     /* does caller care about exceptions ? */
66     if( p_exception == NULL ) return;
67
68     /* remove previous exception if it wasn't cleared */
69     if( p_exception->b_raised && p_exception->psz_message )
70         free(p_exception->psz_message);
71
72     va_start( args, psz_format );
73     if( vasprintf( &p_exception->psz_message, psz_format, args ) == -1)
74         p_exception->psz_message = NULL;
75     va_end( args );
76
77     p_exception->b_raised = 1;
78 }
79
80 libvlc_instance_t * libvlc_new( int argc, char **argv,
81                                 libvlc_exception_t *p_e )
82 {
83     libvlc_instance_t *p_new;
84
85     libvlc_int_t *p_libvlc_int = libvlc_InternalCreate();
86     if( !p_libvlc_int ) RAISENULL( "VLC initialization failed" );
87
88     p_new = (libvlc_instance_t *)malloc( sizeof( libvlc_instance_t ) );
89     if( !p_new ) RAISENULL( "Out of memory" );
90
91     /** \todo Look for interface settings. If we don't have any, add -I dummy */
92     /* Because we probably don't want a GUI by default */
93
94     if( libvlc_InternalInit( p_libvlc_int, argc, argv ) )
95         RAISENULL( "VLC initialization failed" );
96
97     p_new->p_libvlc_int = p_libvlc_int;
98     p_new->p_vlm = NULL;
99     p_new->b_playlist_locked = 0;
100     p_new->p_callback_list = NULL;
101     vlc_mutex_init(p_libvlc_int, &p_new->instance_lock);
102     vlc_mutex_init(p_libvlc_int, &p_new->event_callback_lock);
103  
104     libvlc_event_init(p_new, p_e);
105
106     return p_new;
107 }
108
109 void libvlc_destroy( libvlc_instance_t *p_instance, libvlc_exception_t *p_e )
110 {
111     libvlc_event_fini( p_instance, p_e );
112     vlc_mutex_destroy( &p_instance->instance_lock );
113     vlc_mutex_destroy( &p_instance->event_callback_lock);
114     libvlc_InternalCleanup( p_instance->p_libvlc_int );
115     libvlc_InternalDestroy( p_instance->p_libvlc_int, VLC_FALSE );
116     free( p_instance );
117 }
118
119 int libvlc_get_vlc_id( libvlc_instance_t *p_instance )
120 {
121     return p_instance->p_libvlc_int->i_object_id;
122 }