1 /*****************************************************************************
2 * intf_ncurses.c: ncurses interface
3 *****************************************************************************
4 * Copyright (C) 2001 VideoLAN
6 * Authors: Samuel Hocevar <sam@zoy.org>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
21 *****************************************************************************/
23 #define MODULE_NAME ncurses
24 #include "modules_inner.h"
26 /*****************************************************************************
28 *****************************************************************************/
31 #include <errno.h> /* ENOMEM */
32 #include <stdlib.h> /* free() */
33 #include <string.h> /* strerror() */
45 #include "stream_control.h"
46 #include "input_ext-intf.h"
49 #include "interface.h"
53 /*****************************************************************************
54 * intf_sys_t: description and status of ncurses interface
55 *****************************************************************************/
56 typedef struct intf_sys_s
59 vlc_mutex_t change_lock; /* the change lock */
63 /*****************************************************************************
65 *****************************************************************************/
66 static int intf_Probe ( probedata_t *p_data );
67 static int intf_Open ( intf_thread_t *p_intf );
68 static void intf_Close ( intf_thread_t *p_intf );
69 static void intf_Run ( intf_thread_t *p_intf );
71 /*****************************************************************************
72 * Functions exported as capabilities. They are declared as static so that
73 * we don't pollute the namespace too much.
74 *****************************************************************************/
75 void _M( intf_getfunctions )( function_list_t * p_function_list )
77 p_function_list->pf_probe = intf_Probe;
78 p_function_list->functions.intf.pf_open = intf_Open;
79 p_function_list->functions.intf.pf_close = intf_Close;
80 p_function_list->functions.intf.pf_run = intf_Run;
83 /*****************************************************************************
84 * intf_Probe: probe the interface and return a score
85 *****************************************************************************
86 * This function tries to initialize ncurses and returns a score to the
87 * plugin manager so that it can select the best plugin.
88 *****************************************************************************/
89 static int intf_Probe( probedata_t *p_data )
91 if( TestMethod( INTF_METHOD_VAR, "ncurses" ) )
99 /*****************************************************************************
100 * intf_Open: initialize and create window
101 *****************************************************************************/
102 static int intf_Open( intf_thread_t *p_intf )
104 /* Allocate instance and initialize some members */
105 p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
106 if( p_intf->p_sys == NULL )
108 intf_ErrMsg("error: %s", strerror(ENOMEM));
112 /* Initialize the curses library */
115 /* Don't do NL -> CR/NL */
118 /* Take input chars one at a time */
127 /*****************************************************************************
128 * intf_Close: destroy interface window
129 *****************************************************************************/
130 static void intf_Close( intf_thread_t *p_intf )
132 /* Close the ncurses interface */
135 /* Destroy structure */
136 free( p_intf->p_sys );
139 /*****************************************************************************
140 * intf_Run: ncurses thread
141 *****************************************************************************/
142 static void intf_Run( intf_thread_t *p_intf )
144 while( !p_intf->b_die )
146 p_intf->pf_manage( p_intf );
148 msleep( INTF_IDLE_SLEEP );
152 /* following functions are local */