1 /*******************************************************************************
2 * interface.c: interface access for other threads
4 *******************************************************************************
5 * This library provides basic functions for threads to interact with user
6 * interface, such as command line.
7 *******************************************************************************/
9 /*******************************************************************************
11 *******************************************************************************/
15 #include <sys/uio.h> /* for input.h */
20 #include "vlc_thread.h"
23 #include "interface.h"
25 #include "intf_console.h"
31 /*******************************************************************************
32 * intf_Create: prepare interface before main loop
33 *******************************************************************************
34 * This function opens output devices and create specific interfaces. It send
35 * it's own error messages.
36 *******************************************************************************/
37 intf_thread_t* intf_Create( void )
39 intf_thread_t *p_intf;
41 /* Allocate structure */
42 p_intf = malloc( sizeof( intf_thread_t ) );
49 intf_DbgMsg( "0x%x\n", p_intf );
51 /* Initialize structure */
52 p_intf->p_vout = NULL;
53 p_intf->p_input = NULL;
55 /* Start interfaces */
56 p_intf->p_console = intf_ConsoleCreate();
57 if( p_intf->p_console == NULL )
59 intf_ErrMsg("intf error: can't create control console\n");
63 if( intf_SysCreate( p_intf ) )
65 intf_ErrMsg("intf error: can't create interface\n");
66 intf_ConsoleDestroy( p_intf->p_console );
74 /*******************************************************************************
76 *******************************************************************************
77 * Initialization script and main interface loop.
78 *******************************************************************************/
79 void intf_Run( intf_thread_t *p_intf )
81 intf_DbgMsg("0x%x begin\n", p_intf );
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 )
87 intf_ErrMsg("intf error: error during initialization script\n");
93 /* Flush waiting messages */
96 /* Manage specific interface */
97 intf_SysManage( p_intf );
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 );
104 intf_DbgMsg("0x%x end\n", p_intf );
107 /*******************************************************************************
108 * intf_Destroy: clean interface after main loop
109 *******************************************************************************
110 * This function destroys specific interfaces and close output devices.
111 *******************************************************************************/
112 void intf_Destroy( intf_thread_t *p_intf )
114 intf_DbgMsg("0x%x\n", p_intf );
116 /* Destroy interfaces */
117 intf_SysDestroy( p_intf );
118 intf_ConsoleDestroy( p_intf->p_console );
124 /*******************************************************************************
125 * intf_SelectInput: change input stream
126 *******************************************************************************
127 * Kill existing input, if any, and try to open a new one. If p_cfg is NULL,
128 * no new input will be openned.
129 *******************************************************************************/
130 int intf_SelectInput( intf_thread_t * p_intf, input_cfg_t *p_cfg )
132 intf_DbgMsg("0x%x\n", p_intf );
134 /* Kill existing input, if any */
135 if( p_intf->p_input != NULL )
137 input_DestroyThread( p_intf->p_input /*??, NULL*/ );
138 p_intf->p_input = NULL;
144 p_intf->p_input = input_CreateThread( p_cfg /*??, NULL*/ );
147 return( (p_cfg != NULL) && (p_intf->p_input == NULL) );