1 /*****************************************************************************
2 * interface.c: interface access for other threads
3 * This library provides basic functions for threads to interact with user
4 * interface, such as command line.
5 *****************************************************************************
6 * Copyright (C) 1998-2007 VLC authors and VideoLAN
9 * Authors: Vincent Seguin <seguin@via.ecp.fr>
11 * This program is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU Lesser General Public License as published by
13 * the Free Software Foundation; either version 2.1 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License for more details.
21 * You should have received a copy of the GNU Lesser General Public License
22 * along with this program; if not, write to the Free Software Foundation,
23 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
24 *****************************************************************************/
28 * This file contains functions related to interface management
32 /*****************************************************************************
34 *****************************************************************************/
45 #include <vlc_common.h>
46 #include <vlc_modules.h>
47 #include <vlc_interface.h>
51 #include "../lib/libvlc_internal.h"
54 static int AddIntfCallback( vlc_object_t *, char const *,
55 vlc_value_t , vlc_value_t , void * );
57 static vlc_mutex_t lock = VLC_STATIC_MUTEX;
61 * Create and start an interface.
63 * @param p_this the calling vlc_object_t
64 * @param chain configuration chain string
65 * @return VLC_SUCCESS or an error code
67 int intf_Create( vlc_object_t *p_this, const char *chain )
69 libvlc_int_t *p_libvlc = p_this->p_libvlc;
70 intf_thread_t * p_intf;
72 /* Allocate structure */
73 p_intf = vlc_custom_create( p_libvlc, sizeof( *p_intf ), "interface" );
77 /* Variable used for interface spawning */
78 vlc_value_t val, text;
79 var_Create( p_intf, "intf-add", VLC_VAR_STRING |
80 VLC_VAR_HASCHOICE | VLC_VAR_ISCOMMAND );
81 text.psz_string = _("Add Interface");
82 var_Change( p_intf, "intf-add", VLC_VAR_SETTEXT, &text, NULL );
83 #if !defined(_WIN32) && defined(HAVE_ISATTY)
87 val.psz_string = (char *)"rc";
88 text.psz_string = (char *)_("Console");
89 var_Change( p_intf, "intf-add", VLC_VAR_ADDCHOICE, &val, &text );
91 val.psz_string = (char *)"telnet";
92 text.psz_string = (char *)_("Telnet");
93 var_Change( p_intf, "intf-add", VLC_VAR_ADDCHOICE, &val, &text );
94 val.psz_string = (char *)"http";
95 text.psz_string = (char *)_("Web");
96 var_Change( p_intf, "intf-add", VLC_VAR_ADDCHOICE, &val, &text );
97 val.psz_string = (char *)"logger";
98 text.psz_string = (char *)_("Debug logging");
99 var_Change( p_intf, "intf-add", VLC_VAR_ADDCHOICE, &val, &text );
100 val.psz_string = (char *)"gestures";
101 text.psz_string = (char *)_("Mouse Gestures");
102 var_Change( p_intf, "intf-add", VLC_VAR_ADDCHOICE, &val, &text );
104 var_AddCallback( p_intf, "intf-add", AddIntfCallback, NULL );
106 /* Attach interface to LibVLC */
108 /* Choose the best module */
109 p_intf->p_cfg = NULL;
110 char *psz_parser = *chain == '$'
111 ? var_CreateGetString(p_intf, chain+1)
114 char *psz_tmp = config_ChainCreate( &module, &p_intf->p_cfg,
118 p_intf->p_module = module_need( p_intf, "interface", module, true );
120 if( p_intf->p_module == NULL )
122 msg_Err( p_intf, "no suitable interface module" );
126 vlc_mutex_lock( &lock );
127 p_intf->p_next = libvlc_priv( p_libvlc )->p_intf;
128 libvlc_priv( p_libvlc )->p_intf = p_intf;
129 vlc_mutex_unlock( &lock );
134 if( p_intf->p_module )
135 module_unneed( p_intf, p_intf->p_module );
136 config_ChainDestroy( p_intf->p_cfg );
137 vlc_object_release( p_intf );
143 * Stops and destroys all interfaces
144 * @param p_libvlc the LibVLC instance
146 void intf_DestroyAll( libvlc_int_t *p_libvlc )
148 intf_thread_t *p_intf;
150 vlc_mutex_lock( &lock );
151 p_intf = libvlc_priv( p_libvlc )->p_intf;
153 libvlc_priv( p_libvlc )->p_intf = NULL;
155 vlc_mutex_unlock( &lock );
157 /* Cleanup the interfaces */
158 while( p_intf != NULL )
160 intf_thread_t *p_next = p_intf->p_next;
162 module_unneed( p_intf, p_intf->p_module );
163 config_ChainDestroy( p_intf->p_cfg );
164 vlc_object_release( p_intf );
169 /* Following functions are local */
171 static int AddIntfCallback( vlc_object_t *p_this, char const *psz_cmd,
172 vlc_value_t oldval, vlc_value_t newval, void *p_data )
174 (void)psz_cmd; (void)oldval; (void)p_data;
177 /* Try to create the interface */
178 if( asprintf( &psz_intf, "%s,none", newval.psz_string ) == -1 )
181 int ret = intf_Create( VLC_OBJECT(p_this->p_libvlc), psz_intf );
184 msg_Err( p_this, "interface \"%s\" initialization failed",