Commit 0d62cd7d authored by Gildas Bazin's avatar Gildas Bazin

* ALL: a few updates to the variables API:
  - got rid of the VLC_VAR_COMMAND variable type and introduced the VLC_VAR_ISCOMMAND flag
instead. This simplifies things and avoid the strange command variables behaviour. Command
variables will now trigger their callback on var_Set() like any other variables (look in
modules/control/rc/rc.c for an example).
  - Renamed the VLC_VAR_ISLIST flag into VLC_VAR_HASCHOICE.
  - Added a new VLC_VAR_VOID variable type. This can be useful in conjunction with
VLC_VAR_ISCOMMAND for instance.
parent ead83c79
......@@ -2,7 +2,7 @@
* variables.h: variables handling
*****************************************************************************
* Copyright (C) 2002 VideoLAN
* $Id: variables.h,v 1.8 2002/11/11 14:39:11 sam Exp $
* $Id: variables.h,v 1.9 2002/12/07 15:25:26 gbazin Exp $
*
* Authors: Samuel Hocevar <sam@zoy.org>
*
......@@ -69,23 +69,26 @@ struct variable_t
#define VLC_VAR_FLAGS 0xff00
/* Different types */
#define VLC_VAR_BOOL 0x0010
#define VLC_VAR_INTEGER 0x0020
#define VLC_VAR_STRING 0x0030
#define VLC_VAR_MODULE 0x0031
#define VLC_VAR_FILE 0x0032
#define VLC_VAR_FLOAT 0x0040
#define VLC_VAR_TIME 0x0050
#define VLC_VAR_ADDRESS 0x0060
#define VLC_VAR_COMMAND 0x0070
#define VLC_VAR_VOID 0x0010
#define VLC_VAR_BOOL 0x0020
#define VLC_VAR_INTEGER 0x0030
#define VLC_VAR_STRING 0x0040
#define VLC_VAR_MODULE 0x0041
#define VLC_VAR_FILE 0x0042
#define VLC_VAR_DIRECTORY 0x0043
#define VLC_VAR_FLOAT 0x0050
#define VLC_VAR_TIME 0x0060
#define VLC_VAR_ADDRESS 0x0070
#define VLC_VAR_MUTEX 0x0080
/* Additive flags */
#define VLC_VAR_ISLIST 0x0100
#define VLC_VAR_HASCHOICE 0x0100
#define VLC_VAR_HASMIN 0x0200
#define VLC_VAR_HASMAX 0x0400
#define VLC_VAR_HASSTEP 0x0800
#define VLC_VAR_ISCOMMAND 0x1000
/*****************************************************************************
* Variable actions
*****************************************************************************/
......
......@@ -2,7 +2,7 @@
* oss.c : OSS /dev/dsp module for vlc
*****************************************************************************
* Copyright (C) 2000-2002 VideoLAN
* $Id: oss.c,v 1.35 2002/12/06 16:34:04 sam Exp $
* $Id: oss.c,v 1.36 2002/12/07 15:25:26 gbazin Exp $
*
* Authors: Michel Kaempf <maxx@via.ecp.fr>
* Samuel Hocevar <sam@zoy.org>
......@@ -111,7 +111,7 @@ static void Probe( aout_instance_t * p_aout )
vlc_value_t val;
int i_format, i_nb_channels;
var_Create( p_aout, "audio-device", VLC_VAR_STRING | VLC_VAR_ISLIST );
var_Create( p_aout, "audio-device", VLC_VAR_STRING | VLC_VAR_HASCHOICE );
if( ioctl( p_sys->i_fd, SNDCTL_DSP_RESET, NULL ) < 0 )
{
......
......@@ -2,7 +2,7 @@
* sdl.c : SDL audio output plugin for vlc
*****************************************************************************
* Copyright (C) 2000-2002 VideoLAN
* $Id: sdl.c,v 1.15 2002/11/14 22:38:47 massiot Exp $
* $Id: sdl.c,v 1.16 2002/12/07 15:25:26 gbazin Exp $
*
* Authors: Michel Kaempf <maxx@via.ecp.fr>
* Samuel Hocevar <sam@zoy.org>
......@@ -105,7 +105,7 @@ static int Open ( vlc_object_t *p_this )
}
if ( var_Type( p_aout, "audio-device" ) ==
(VLC_VAR_STRING | VLC_VAR_ISLIST) )
(VLC_VAR_STRING | VLC_VAR_HASCHOICE) )
{
/* The user has selected an audio device. */
vlc_value_t val;
......@@ -173,7 +173,7 @@ static int Open ( vlc_object_t *p_this )
if ( var_Type( p_aout, "audio-device" ) < 0 )
{
vlc_value_t val;
var_Create( p_aout, "audio-device", VLC_VAR_STRING | VLC_VAR_ISLIST );
var_Create( p_aout, "audio-device", VLC_VAR_STRING | VLC_VAR_HASCHOICE );
val.psz_string = (obtained.channels == 2) ? N_("Stereo") :
N_("Mono");
var_Change( p_aout, "audio-device", VLC_VAR_ADDCHOICE, &val );
......@@ -185,7 +185,7 @@ static int Open ( vlc_object_t *p_this )
{
/* First launch. */
vlc_value_t val;
var_Create( p_aout, "audio-device", VLC_VAR_STRING | VLC_VAR_ISLIST );
var_Create( p_aout, "audio-device", VLC_VAR_STRING | VLC_VAR_HASCHOICE );
val.psz_string = N_("Stereo");
var_Change( p_aout, "audio-device", VLC_VAR_ADDCHOICE, &val );
val.psz_string = N_("Mono");
......
This diff is collapsed.
......@@ -2,7 +2,7 @@
* test4.c : Miscellaneous stress tests module for vlc
*****************************************************************************
* Copyright (C) 2002 VideoLAN
* $Id: test4.c,v 1.4 2002/11/10 18:04:22 sam Exp $
* $Id: test4.c,v 1.5 2002/12/07 15:25:26 gbazin Exp $
*
* Authors: Samuel Hocevar <sam@zoy.org>
*
......@@ -41,43 +41,51 @@
/*****************************************************************************
* Local prototypes.
*****************************************************************************/
static int Foo ( vlc_object_t *, char *, char * );
static int Callback ( vlc_object_t *, char *, char * );
static int Foo ( vlc_object_t *, char const *,
vlc_value_t, vlc_value_t, void * );
static int Callback ( vlc_object_t *, char const *,
vlc_value_t, vlc_value_t, void * );
static int MyCallback( vlc_object_t *, char const *,
vlc_value_t, vlc_value_t, void * );
static void * MyThread ( vlc_object_t * );
static int Stress ( vlc_object_t *, char *, char * );
static int Stress ( vlc_object_t *, char const *,
vlc_value_t, vlc_value_t, void * );
static void * Dummy ( vlc_object_t * );
static int Signal ( vlc_object_t *, char *, char * );
static int Signal ( vlc_object_t *, char const *,
vlc_value_t, vlc_value_t, void * );
/*****************************************************************************
* Module descriptor.
*****************************************************************************/
vlc_module_begin();
set_description( _("Miscellaneous stress tests") );
var_Create( p_module->p_libvlc, "foo-test", VLC_VAR_COMMAND );
var_Set( p_module->p_libvlc, "foo-test", (vlc_value_t)(void*)Foo );
var_Create( p_module->p_libvlc, "callback-test", VLC_VAR_COMMAND );
var_Set( p_module->p_libvlc, "callback-test", (vlc_value_t)(void*)Callback );
var_Create( p_module->p_libvlc, "stress-test", VLC_VAR_COMMAND );
var_Set( p_module->p_libvlc, "stress-test", (vlc_value_t)(void*)Stress );
var_Create( p_module->p_libvlc, "signal", VLC_VAR_COMMAND );
var_Set( p_module->p_libvlc, "signal", (vlc_value_t)(void*)Signal );
var_Create( p_module->p_libvlc, "foo-test",
VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
var_AddCallback( p_module->p_libvlc, "foo-test", Foo, NULL );
var_Create( p_module->p_libvlc, "callback-test",
VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
var_AddCallback( p_module->p_libvlc, "callback-test", Callback, NULL );
var_Create( p_module->p_libvlc, "stress-test",
VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
var_AddCallback( p_module->p_libvlc, "stress-test", Stress, NULL );
var_Create( p_module->p_libvlc, "signal",
VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
var_AddCallback( p_module->p_libvlc, "signal", Signal, NULL );
vlc_module_end();
/*****************************************************************************
* Foo: put anything here
*****************************************************************************/
static int Foo( vlc_object_t *p_this, char *psz_cmd, char *psz_arg )
static int Foo( vlc_object_t *p_this, char const *psz_cmd,
vlc_value_t oldval, vlc_value_t newval, void *p_data )
{
vlc_value_t val;
int i, i_vals;
vlc_value_t *p_vals;
var_Create( p_this, "honk", VLC_VAR_STRING | VLC_VAR_ISLIST );
var_Create( p_this, "honk", VLC_VAR_STRING | VLC_VAR_HASCHOICE );
val.psz_string = "foo";
var_Change( p_this, "honk", VLC_VAR_ADDCHOICE, &val );
......@@ -121,7 +129,8 @@ static int Foo( vlc_object_t *p_this, char *psz_cmd, char *psz_arg )
/*****************************************************************************
* Callback: test callback functions
*****************************************************************************/
static int Callback( vlc_object_t *p_this, char *psz_cmd, char *psz_arg )
static int Callback( vlc_object_t *p_this, char const *psz_cmd,
vlc_value_t oldval, vlc_value_t newval, void *p_data )
{
int i;
char psz_var[20];
......@@ -244,7 +253,8 @@ static void * MyThread( vlc_object_t *p_this )
/*****************************************************************************
* Stress: perform various stress tests
*****************************************************************************/
static int Stress( vlc_object_t *p_this, char *psz_cmd, char *psz_arg )
static int Stress( vlc_object_t *p_this, char const *psz_cmd,
vlc_value_t oldval, vlc_value_t newval, void *p_data )
{
vlc_object_t **pp_objects;
mtime_t start;
......@@ -252,9 +262,9 @@ static int Stress( vlc_object_t *p_this, char *psz_cmd, char *psz_arg )
char * psz_blob;
int i, i_level;
if( *psz_arg )
if( *newval.psz_string )
{
i_level = atoi( psz_arg );
i_level = atoi( newval.psz_string );
if( i_level <= 0 )
{
i_level = 1;
......@@ -426,9 +436,9 @@ static void * Dummy( vlc_object_t *p_this )
/*****************************************************************************
* Signal: send a signal to the current thread.
*****************************************************************************/
static int Signal( vlc_object_t *p_this, char *psz_cmd, char *psz_arg )
static int Signal( vlc_object_t *p_this, char const *psz_cmd,
vlc_value_t oldval, vlc_value_t newval, void *p_data )
{
raise( atoi(psz_arg) );
raise( atoi(newval.psz_string) );
return VLC_SUCCESS;
}
......@@ -2,7 +2,7 @@
* output.c : internal management of output streams for the audio output
*****************************************************************************
* Copyright (C) 2002 VideoLAN
* $Id: output.c,v 1.25 2002/12/06 10:10:39 sam Exp $
* $Id: output.c,v 1.26 2002/12/07 15:25:27 gbazin Exp $
*
* Authors: Christophe Massiot <massiot@via.ecp.fr>
*
......@@ -63,7 +63,7 @@ int aout_OutputNew( aout_instance_t * p_aout,
}
if ( var_Type( p_aout, "audio-channels" ) ==
(VLC_VAR_STRING | VLC_VAR_ISLIST) )
(VLC_VAR_STRING | VLC_VAR_HASCHOICE) )
{
/* The user may have selected a different channels configuration. */
vlc_value_t val;
......@@ -93,7 +93,7 @@ int aout_OutputNew( aout_instance_t * p_aout,
{
/* Mono - create the audio-channels variable. */
vlc_value_t val;
var_Create( p_aout, "audio-channels", VLC_VAR_STRING | VLC_VAR_ISLIST );
var_Create( p_aout, "audio-channels", VLC_VAR_STRING | VLC_VAR_HASCHOICE );
if ( p_aout->output.output.i_original_channels & AOUT_CHAN_DUALMONO )
{
/* Go directly to the left channel. */
......@@ -118,7 +118,7 @@ int aout_OutputNew( aout_instance_t * p_aout,
{
/* Stereo - create the audio-channels variable. */
vlc_value_t val;
var_Create( p_aout, "audio-channels", VLC_VAR_STRING | VLC_VAR_ISLIST );
var_Create( p_aout, "audio-channels", VLC_VAR_STRING | VLC_VAR_HASCHOICE );
val.psz_string = N_("Both");
var_Change( p_aout, "audio-channels", VLC_VAR_ADDCHOICE, &val );
val.psz_string = N_("Left");
......
......@@ -2,7 +2,7 @@
* objects.c: vlc_object_t handling
*****************************************************************************
* Copyright (C) 2002 VideoLAN
* $Id: objects.c,v 1.30 2002/12/06 10:10:39 sam Exp $
* $Id: objects.c,v 1.31 2002/12/07 15:25:27 gbazin Exp $
*
* Authors: Samuel Hocevar <sam@zoy.org>
*
......@@ -47,7 +47,8 @@
/*****************************************************************************
* Local prototypes
*****************************************************************************/
static int DumpCommand( vlc_object_t *, char *, char * );
static int DumpCommand( vlc_object_t *, char const *,
vlc_value_t, vlc_value_t, void * );
static vlc_object_t * FindObject ( vlc_object_t *, int, int );
static void DetachObject ( vlc_object_t * );
......@@ -213,15 +214,12 @@ void * __vlc_object_create( vlc_object_t *p_this, int i_type )
if( i_type == VLC_OBJECT_ROOT )
{
vlc_value_t val;
val.p_address = DumpCommand;
vlc_mutex_init( p_new, &structure_lock );
var_Create( p_new, "list", VLC_VAR_COMMAND );
var_Set( p_new, "list", val );
var_Create( p_new, "tree", VLC_VAR_COMMAND );
var_Set( p_new, "tree", val );
var_Create( p_new, "list", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
var_AddCallback( p_new, "list", DumpCommand, NULL );
var_Create( p_new, "tree", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
var_AddCallback( p_new, "tree", DumpCommand, NULL );
}
return p_new;
......@@ -528,16 +526,17 @@ vlc_list_t * __vlc_list_find( vlc_object_t *p_this, int i_type, int i_mode )
* vlc objects, and additional information such as their refcount, thread ID,
* etc. (command "tree"), or the same data as a simple list (command "list").
*****************************************************************************/
static int DumpCommand( vlc_object_t *p_this, char *psz_cmd, char *psz_arg )
static int DumpCommand( vlc_object_t *p_this, char const *psz_cmd,
vlc_value_t oldval, vlc_value_t newval, void *p_data )
{
if( *psz_cmd == 't' )
{
char psz_foo[2 * MAX_DUMPSTRUCTURE_DEPTH + 1];
vlc_object_t *p_object;
if( *psz_arg )
if( *newval.psz_string )
{
p_object = vlc_object_get( p_this, atoi(psz_arg) );
p_object = vlc_object_get( p_this, atoi(newval.psz_string) );
if( !p_object )
{
......@@ -899,4 +898,3 @@ static vlc_list_t * ListAppend( vlc_list_t *p_list, vlc_object_t *p_object )
return p_list;
}
......@@ -2,7 +2,7 @@
* variables.c: routines for object variables handling
*****************************************************************************
* Copyright (C) 2002 VideoLAN
* $Id: variables.c,v 1.14 2002/12/06 10:10:40 sam Exp $
* $Id: variables.c,v 1.15 2002/12/07 15:25:27 gbazin Exp $
*
* Authors: Samuel Hocevar <sam@zoy.org>
*
......@@ -167,7 +167,6 @@ int __var_Create( vlc_object_t *p_this, const char *psz_name, int i_type )
/* FIXME: TODO */
break;
case VLC_VAR_ADDRESS:
case VLC_VAR_COMMAND:
p_var->pf_cmp = CmpAddress;
p_var->val.p_address = NULL;
break;
......@@ -436,7 +435,7 @@ int __var_Type( vlc_object_t *p_this, const char *psz_name )
if( i_var < 0 )
{
vlc_mutex_unlock( &p_this->var_lock );
return i_var;
return 0;
}
i_type = p_this->p_vars[i_var].i_type;
......@@ -542,30 +541,6 @@ int __var_Get( vlc_object_t *p_this, const char *psz_name, vlc_value_t *p_val )
p_var = &p_this->p_vars[i_var];
/* Some variables trigger special behaviour. */
switch( p_var->i_type & VLC_VAR_TYPE )
{
case VLC_VAR_COMMAND:
if( p_var->val.p_address )
{
/* We need to save data before releasing the lock */
int i_ret;
int (*pf_command) (vlc_object_t *, char *, char *) =
p_var->val.p_address;
char *psz_cmd = strdup( p_var->psz_name );
char *psz_arg = strdup( p_val->psz_string );
vlc_mutex_unlock( &p_this->var_lock );
i_ret = pf_command( p_this, psz_cmd, psz_arg );
free( psz_cmd );
free( psz_arg );
return i_ret;
}
break;
}
/* Really get the variable */
*p_val = p_var->val;
......@@ -868,7 +843,7 @@ static int LookupInner( variable_t *p_vars, int i_count, uint32_t i_hash )
static void CheckValue ( variable_t *p_var, vlc_value_t *p_val )
{
/* Check that our variable is in the list */
if( p_var->i_type & VLC_VAR_ISLIST && p_var->i_choices )
if( p_var->i_type & VLC_VAR_HASCHOICE && p_var->i_choices )
{
int i;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment