]> git.sesse.net Git - vlc/blob - src/control/core.c
Merge 0.8.5-api changes
[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., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
22  *****************************************************************************/
23
24 #include <libvlc_internal.h>
25 #include <vlc/libvlc.h>
26
27 #include <vlc/intf.h>
28
29 vlc_t * vlc_current_object( int );
30
31 /*************************************************************************
32  * Exceptions handling
33  *************************************************************************/
34 inline void libvlc_exception_init( libvlc_exception_t *p_exception )
35 {
36     p_exception->b_raised = 0;
37     p_exception->psz_message = NULL;
38 }
39
40 inline int libvlc_exception_raised( libvlc_exception_t *p_exception )
41 {
42     return p_exception->b_raised;
43 }
44
45 inline char* libvlc_exception_get_message( libvlc_exception_t *p_exception )
46 {
47     if( p_exception->b_raised == 1 && p_exception->psz_message )
48     {
49         return p_exception->psz_message;
50     }
51     return NULL;
52 }
53
54 inline void libvlc_exception_raise( libvlc_exception_t *p_exception,
55                                     char *psz_message )
56 {
57     if( p_exception == NULL ) return;
58     p_exception->b_raised = 1;
59     p_exception->psz_message = strdup( psz_message );
60 }
61
62
63 libvlc_instance_t * libvlc_new( int argc, char **argv,
64                                 libvlc_exception_t *p_exception )
65 {
66     int i_vlc_id;
67     libvlc_instance_t *p_new;
68     vlc_t *p_vlc;
69
70     i_vlc_id = VLC_Create();
71     p_vlc = (vlc_t* ) vlc_current_object( i_vlc_id );
72
73     if( !p_vlc )
74     {
75         libvlc_exception_raise( p_exception, "VLC initialization failed" );
76         return NULL;
77     }
78     p_new = (libvlc_instance_t *)malloc( sizeof( libvlc_instance_t ) );
79
80     /** \todo Look for interface settings. If we don't have any, add -I dummy */
81     /* Because we probably don't want a GUI by default */
82
83     if( !p_new )
84     {
85         libvlc_exception_raise( p_exception, "Out of memory" );
86         return NULL;
87     }
88
89     VLC_Init( i_vlc_id, argc, argv );
90
91     p_new->p_vlc = p_vlc;
92     p_new->p_playlist = (playlist_t *)vlc_object_find( p_new->p_vlc,
93                                 VLC_OBJECT_PLAYLIST, FIND_CHILD );
94
95     if( !p_new->p_playlist )
96     {
97         libvlc_exception_raise( p_exception, "Playlist creation failed" );
98         return NULL;
99     }
100     p_new->i_vlc_id = i_vlc_id;
101
102     return p_new;
103 }
104
105 void libvlc_destroy( libvlc_instance_t *p_instance )
106 {
107     if( p_instance->p_playlist )
108         vlc_object_release( p_instance->p_playlist );
109     vlc_object_release( p_instance->p_vlc );
110     VLC_CleanUp( p_instance->i_vlc_id );
111     VLC_Destroy( p_instance->i_vlc_id );
112 }