]> git.sesse.net Git - vlc/blob - src/interface/interface.c
GGI fonctionnel. N'oubliez pas de d�finit GII_INPUT.
[vlc] / src / interface / interface.c
1 /*******************************************************************************
2  * interface.c: interface access for other threads
3  * (c)1998 VideoLAN
4  *******************************************************************************
5  * This library provides basic functions for threads to interact with user
6  * interface, such as command line.
7  *******************************************************************************/
8
9 /*******************************************************************************
10  * Preamble
11  *******************************************************************************/
12 #include <errno.h>
13 #include <stdio.h>
14 #include <stdlib.h>
15 #include <string.h>
16 #include <sys/types.h>
17 #include <sys/uio.h>                                        /* for input.h */
18
19 #include "config.h"
20 #include "common.h"
21 #include "mtime.h"
22 #include "vlc_thread.h"
23 #include "input.h"
24 #include "intf_msg.h"
25 #include "interface.h"
26 #include "intf_cmd.h"
27 #include "intf_console.h"
28 #include "main.h"
29
30 #include "intf_sys.h"
31
32
33 /*******************************************************************************
34  * intf_Create: prepare interface before main loop
35  *******************************************************************************
36  * This function opens output devices and create specific interfaces. It send
37  * it's own error messages.
38  *******************************************************************************/
39 intf_thread_t* intf_Create( void )
40 {    
41     intf_thread_t *p_intf;                                        
42
43     /* Allocate structure */
44     p_intf = malloc( sizeof( intf_thread_t ) );
45     if( !p_intf )
46     {
47         intf_ErrMsg("error: %s\n", strerror( ENOMEM ) );        
48         return( NULL );
49     }
50
51     /* Initialize structure */
52     p_intf->b_die =     0;    
53     p_intf->p_vout =    NULL;
54     p_intf->p_input =   NULL;   
55
56     /* Start interfaces */
57     p_intf->p_console = intf_ConsoleCreate();
58     if( p_intf->p_console == NULL )
59     {
60         intf_ErrMsg("error: can't create control console\n");
61         free( p_intf );
62         return( NULL );
63     }
64     if( intf_SysCreate( p_intf ) )
65     {
66         intf_ErrMsg("error: can't create interface\n");
67         intf_ConsoleDestroy( p_intf->p_console );
68         free( p_intf );
69         return( NULL );
70     }   
71
72     intf_Msg("Interface initialized\n");    
73     return( p_intf );
74 }
75
76 /*******************************************************************************
77  * intf_Run
78  *******************************************************************************
79  * Initialization script and main interface loop.
80  *******************************************************************************/
81 void intf_Run( intf_thread_t *p_intf )
82
83     /* Execute the initialization script - if a positive number is returned, 
84      * the script could be executed but failed */
85     if( intf_ExecScript( main_GetPszVariable( INTF_INIT_SCRIPT_VAR, INTF_INIT_SCRIPT_DEFAULT ) ) > 0 )
86     {
87         intf_ErrMsg("warning: error(s) during startup script\n");
88     }
89
90     /* Main loop */
91     while(!p_intf->b_die)
92     {
93         /* Flush waiting messages */
94         intf_FlushMsg();
95
96         /* Manage specific interface */
97         intf_SysManage( p_intf );
98
99         /* Sleep to avoid using all CPU - since some interfaces needs to access 
100          * keyboard events, a 100ms delay is a good compromise */
101         msleep( INTF_IDLE_SLEEP );
102     }
103 }
104
105 /*******************************************************************************
106  * intf_Destroy: clean interface after main loop
107  *******************************************************************************
108  * This function destroys specific interfaces and close output devices.
109  *******************************************************************************/
110 void intf_Destroy( intf_thread_t *p_intf )
111 {
112     /* Destroy interfaces */
113     intf_SysDestroy( p_intf );
114     intf_ConsoleDestroy( p_intf->p_console );
115
116     /* Free structure */
117     free( p_intf );
118 }
119
120 /*******************************************************************************
121  * intf_SelectInput: change input stream
122  *******************************************************************************
123  * Kill existing input, if any, and try to open a new one. If p_cfg is NULL,
124  * no new input will be openned.
125  *******************************************************************************/
126 int intf_SelectInput( intf_thread_t * p_intf, input_cfg_t *p_cfg )
127 {
128     intf_DbgMsg("0x%x\n", p_intf );
129     
130     /* Kill existing input, if any */
131     if( p_intf->p_input != NULL )
132     {        
133         input_DestroyThread( p_intf->p_input /*??, NULL*/ );
134         p_intf->p_input = NULL;        
135     }
136     
137     /* Open new one */
138     if( p_cfg != NULL )
139     {        
140         p_intf->p_input = input_CreateThread( p_cfg /*??, NULL*/ );    
141     }
142     
143     return( (p_cfg != NULL) && (p_intf->p_input == NULL) );    
144 }
145
146