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 *******************************************************************************/
16 #include <sys/types.h>
17 #include <sys/uio.h> /* for input.h */
22 #include "vlc_thread.h"
25 #include "interface.h"
27 #include "intf_console.h"
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 )
41 intf_thread_t *p_intf;
43 /* Allocate structure */
44 p_intf = malloc( sizeof( intf_thread_t ) );
47 intf_ErrMsg("error: %s\n", strerror( ENOMEM ) );
51 /* Initialize structure */
53 p_intf->p_vout = NULL;
54 p_intf->p_input = NULL;
56 /* Start interfaces */
57 p_intf->p_console = intf_ConsoleCreate();
58 if( p_intf->p_console == NULL )
60 intf_ErrMsg("error: can't create control console\n");
64 if( intf_SysCreate( p_intf ) )
66 intf_ErrMsg("error: can't create interface\n");
67 intf_ConsoleDestroy( p_intf->p_console );
72 intf_Msg("Interface initialized\n");
76 /*******************************************************************************
78 *******************************************************************************
79 * Initialization script and main interface loop.
80 *******************************************************************************/
81 void intf_Run( intf_thread_t *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("warning: error(s) during startup 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 );
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 )
112 /* Destroy interfaces */
113 intf_SysDestroy( p_intf );
114 intf_ConsoleDestroy( p_intf->p_console );
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 )
128 intf_DbgMsg("0x%x\n", p_intf );
130 /* Kill existing input, if any */
131 if( p_intf->p_input != NULL )
133 input_DestroyThread( p_intf->p_input /*??, NULL*/ );
134 p_intf->p_input = NULL;
140 p_intf->p_input = input_CreateThread( p_cfg /*??, NULL*/ );
143 return( (p_cfg != NULL) && (p_intf->p_input == NULL) );