]> git.sesse.net Git - vlc/blob - src/misc/exit.c
decoder: remove unnecessary special case
[vlc] / src / misc / exit.c
1 /*****************************************************************************
2  * exit.c: LibVLC termination event
3  *****************************************************************************
4  * Copyright (C) 2009-2010 VLC authors and VideoLAN
5  *
6  * This program is free software; you can redistribute it and/or modify it
7  * under the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation; either version 2.1 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with this program; if not, write to the Free Software Foundation,
18  * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
19  *****************************************************************************/
20
21 #ifdef HAVE_CONFIG_H
22 # include "config.h"
23 #endif
24
25 #include <vlc_common.h>
26 #include <vlc_interface.h>
27 #include "libvlc.h"
28 #include "../lib/libvlc_internal.h"
29
30 void vlc_ExitInit( vlc_exit_t *exit )
31 {
32     vlc_mutex_init( &exit->lock );
33     exit->handler = NULL;
34     exit->opaque = NULL;
35 }
36
37 void vlc_ExitDestroy( vlc_exit_t *exit )
38 {
39     vlc_mutex_destroy( &exit->lock );
40 }
41
42
43 /**
44  * Registers a callback for the LibVLC exit event.
45  */
46 void libvlc_SetExitHandler( libvlc_int_t *p_libvlc, void (*handler) (void *),
47                             void *opaque )
48 {
49     vlc_exit_t *exit = &libvlc_priv( p_libvlc )->exit;
50
51     vlc_mutex_lock( &exit->lock );
52     exit->handler = handler;
53     exit->opaque = opaque;
54     vlc_mutex_unlock( &exit->lock );
55 }
56
57 /**
58  * Posts an exit signal to LibVLC instance.
59  * This function should only be called on behalf of the user.
60  */
61 void libvlc_Quit( libvlc_int_t *p_libvlc )
62 {
63     vlc_exit_t *exit = &libvlc_priv( p_libvlc )->exit;
64
65     msg_Dbg( p_libvlc, "exiting" );
66     vlc_mutex_lock( &exit->lock );
67     if( exit->handler != NULL )
68         exit->handler( exit->opaque );
69     else
70         msg_Dbg( p_libvlc, "no exit handler" );
71     vlc_mutex_unlock( &exit->lock );
72 }