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 @@ ...@@ -2,7 +2,7 @@
* variables.h: variables handling * variables.h: variables handling
***************************************************************************** *****************************************************************************
* Copyright (C) 2002 VideoLAN * 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> * Authors: Samuel Hocevar <sam@zoy.org>
* *
...@@ -69,23 +69,26 @@ struct variable_t ...@@ -69,23 +69,26 @@ struct variable_t
#define VLC_VAR_FLAGS 0xff00 #define VLC_VAR_FLAGS 0xff00
/* Different types */ /* Different types */
#define VLC_VAR_BOOL 0x0010 #define VLC_VAR_VOID 0x0010
#define VLC_VAR_INTEGER 0x0020 #define VLC_VAR_BOOL 0x0020
#define VLC_VAR_STRING 0x0030 #define VLC_VAR_INTEGER 0x0030
#define VLC_VAR_MODULE 0x0031 #define VLC_VAR_STRING 0x0040
#define VLC_VAR_FILE 0x0032 #define VLC_VAR_MODULE 0x0041
#define VLC_VAR_FLOAT 0x0040 #define VLC_VAR_FILE 0x0042
#define VLC_VAR_TIME 0x0050 #define VLC_VAR_DIRECTORY 0x0043
#define VLC_VAR_ADDRESS 0x0060 #define VLC_VAR_FLOAT 0x0050
#define VLC_VAR_COMMAND 0x0070 #define VLC_VAR_TIME 0x0060
#define VLC_VAR_ADDRESS 0x0070
#define VLC_VAR_MUTEX 0x0080 #define VLC_VAR_MUTEX 0x0080
/* Additive flags */ /* Additive flags */
#define VLC_VAR_ISLIST 0x0100 #define VLC_VAR_HASCHOICE 0x0100
#define VLC_VAR_HASMIN 0x0200 #define VLC_VAR_HASMIN 0x0200
#define VLC_VAR_HASMAX 0x0400 #define VLC_VAR_HASMAX 0x0400
#define VLC_VAR_HASSTEP 0x0800 #define VLC_VAR_HASSTEP 0x0800
#define VLC_VAR_ISCOMMAND 0x1000
/***************************************************************************** /*****************************************************************************
* Variable actions * Variable actions
*****************************************************************************/ *****************************************************************************/
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* oss.c : OSS /dev/dsp module for vlc * oss.c : OSS /dev/dsp module for vlc
***************************************************************************** *****************************************************************************
* Copyright (C) 2000-2002 VideoLAN * 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> * Authors: Michel Kaempf <maxx@via.ecp.fr>
* Samuel Hocevar <sam@zoy.org> * Samuel Hocevar <sam@zoy.org>
...@@ -111,7 +111,7 @@ static void Probe( aout_instance_t * p_aout ) ...@@ -111,7 +111,7 @@ static void Probe( aout_instance_t * p_aout )
vlc_value_t val; vlc_value_t val;
int i_format, i_nb_channels; 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 ) if( ioctl( p_sys->i_fd, SNDCTL_DSP_RESET, NULL ) < 0 )
{ {
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* sdl.c : SDL audio output plugin for vlc * sdl.c : SDL audio output plugin for vlc
***************************************************************************** *****************************************************************************
* Copyright (C) 2000-2002 VideoLAN * 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> * Authors: Michel Kaempf <maxx@via.ecp.fr>
* Samuel Hocevar <sam@zoy.org> * Samuel Hocevar <sam@zoy.org>
...@@ -105,7 +105,7 @@ static int Open ( vlc_object_t *p_this ) ...@@ -105,7 +105,7 @@ static int Open ( vlc_object_t *p_this )
} }
if ( var_Type( p_aout, "audio-device" ) == 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. */ /* The user has selected an audio device. */
vlc_value_t val; vlc_value_t val;
...@@ -173,7 +173,7 @@ static int Open ( vlc_object_t *p_this ) ...@@ -173,7 +173,7 @@ static int Open ( vlc_object_t *p_this )
if ( var_Type( p_aout, "audio-device" ) < 0 ) if ( var_Type( p_aout, "audio-device" ) < 0 )
{ {
vlc_value_t val; 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") : val.psz_string = (obtained.channels == 2) ? N_("Stereo") :
N_("Mono"); N_("Mono");
var_Change( p_aout, "audio-device", VLC_VAR_ADDCHOICE, &val ); var_Change( p_aout, "audio-device", VLC_VAR_ADDCHOICE, &val );
...@@ -185,7 +185,7 @@ static int Open ( vlc_object_t *p_this ) ...@@ -185,7 +185,7 @@ static int Open ( vlc_object_t *p_this )
{ {
/* First launch. */ /* First launch. */
vlc_value_t val; 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"); val.psz_string = N_("Stereo");
var_Change( p_aout, "audio-device", VLC_VAR_ADDCHOICE, &val ); var_Change( p_aout, "audio-device", VLC_VAR_ADDCHOICE, &val );
val.psz_string = N_("Mono"); val.psz_string = N_("Mono");
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* rc.c : remote control stdin/stdout plugin for vlc * rc.c : remote control stdin/stdout plugin for vlc
***************************************************************************** *****************************************************************************
* Copyright (C) 2001 VideoLAN * Copyright (C) 2001 VideoLAN
* $Id: rc.c,v 1.14 2002/12/06 16:34:06 sam Exp $ * $Id: rc.c,v 1.15 2002/12/07 15:25:26 gbazin Exp $
* *
* Authors: Peter Surda <shurdeek@panorama.sth.ac.at> * Authors: Peter Surda <shurdeek@panorama.sth.ac.at>
* *
...@@ -60,12 +60,18 @@ ...@@ -60,12 +60,18 @@
static int Activate ( vlc_object_t * ); static int Activate ( vlc_object_t * );
static void Run ( intf_thread_t *p_intf ); static void Run ( intf_thread_t *p_intf );
static int Playlist ( vlc_object_t *, char *, char * ); static int Playlist ( vlc_object_t *, char const *,
static int Quit ( vlc_object_t *, char *, char * ); vlc_value_t, vlc_value_t, void * );
static int Intf ( vlc_object_t *, char *, char * ); static int Quit ( vlc_object_t *, char const *,
static int Volume ( vlc_object_t *, char *, char * ); vlc_value_t, vlc_value_t, void * );
static int VolumeMove ( vlc_object_t *, char *, char * ); static int Intf ( vlc_object_t *, char const *,
static int AudioConfig ( vlc_object_t *, char *, char * ); vlc_value_t, vlc_value_t, void * );
static int Volume ( vlc_object_t *, char const *,
vlc_value_t, vlc_value_t, void * );
static int VolumeMove ( vlc_object_t *, char const *,
vlc_value_t, vlc_value_t, void * );
static int AudioConfig ( vlc_object_t *, char const *,
vlc_value_t, vlc_value_t, void * );
/***************************************************************************** /*****************************************************************************
* Module descriptor * Module descriptor
...@@ -140,47 +146,47 @@ static void Run( intf_thread_t *p_intf ) ...@@ -140,47 +146,47 @@ static void Run( intf_thread_t *p_intf )
p_playlist = NULL; p_playlist = NULL;
/* Register commands that will be cleaned up upon object destruction */ /* Register commands that will be cleaned up upon object destruction */
var_Create( p_intf, "quit", VLC_VAR_COMMAND ); var_Create( p_intf, "quit", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
var_Set( p_intf, "quit", (vlc_value_t)(void*)Quit ); var_AddCallback( p_intf, "quit", Quit, NULL );
var_Create( p_intf, "intf", VLC_VAR_COMMAND ); var_Create( p_intf, "intf", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
var_Set( p_intf, "intf", (vlc_value_t)(void*)Intf ); var_AddCallback( p_intf, "intf", Intf, NULL );
var_Create( p_intf, "play", VLC_VAR_COMMAND ); var_Create( p_intf, "play", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
var_Set( p_intf, "play", (vlc_value_t)(void*)Playlist ); var_AddCallback( p_intf, "play", Playlist, NULL );
var_Create( p_intf, "stop", VLC_VAR_COMMAND ); var_Create( p_intf, "stop", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
var_Set( p_intf, "stop", (vlc_value_t)(void*)Playlist ); var_AddCallback( p_intf, "stop", Playlist, NULL );
var_Create( p_intf, "pause", VLC_VAR_COMMAND ); var_Create( p_intf, "pause", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
var_Set( p_intf, "pause", (vlc_value_t)(void*)Playlist ); var_AddCallback( p_intf, "pause", Playlist, NULL );
var_Create( p_intf, "seek", VLC_VAR_COMMAND ); var_Create( p_intf, "seek", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
var_Set( p_intf, "seek", (vlc_value_t)(void*)Playlist ); var_AddCallback( p_intf, "seek", Playlist, NULL );
var_Create( p_intf, "prev", VLC_VAR_COMMAND ); var_Create( p_intf, "prev", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
var_Set( p_intf, "prev", (vlc_value_t)(void*)Playlist ); var_AddCallback( p_intf, "prev", Playlist, NULL );
var_Create( p_intf, "next", VLC_VAR_COMMAND ); var_Create( p_intf, "next", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
var_Set( p_intf, "next", (vlc_value_t)(void*)Playlist ); var_AddCallback( p_intf, "next", Playlist, NULL );
var_Create( p_intf, "title", VLC_VAR_COMMAND ); var_Create( p_intf, "title", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
var_Set( p_intf, "title", (vlc_value_t)(void*)Playlist ); var_AddCallback( p_intf, "title", Playlist, NULL );
var_Create( p_intf, "title_n", VLC_VAR_COMMAND ); var_Create( p_intf, "title_n", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
var_Set( p_intf, "title_n", (vlc_value_t)(void*)Playlist ); var_AddCallback( p_intf, "title_n", Playlist, NULL );
var_Create( p_intf, "title_p", VLC_VAR_COMMAND ); var_Create( p_intf, "title_p", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
var_Set( p_intf, "title_p", (vlc_value_t)(void*)Playlist ); var_AddCallback( p_intf, "title_p", Playlist, NULL );
var_Create( p_intf, "chapter", VLC_VAR_COMMAND ); var_Create( p_intf, "chapter", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
var_Set( p_intf, "chapter", (vlc_value_t)(void*)Playlist ); var_AddCallback( p_intf, "chapter", Playlist, NULL );
var_Create( p_intf, "chapter_n", VLC_VAR_COMMAND ); var_Create( p_intf, "chapter_n", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
var_Set( p_intf, "chapter_n", (vlc_value_t)(void*)Playlist ); var_AddCallback( p_intf, "chapter_n", Playlist, NULL );
var_Create( p_intf, "chapter_p", VLC_VAR_COMMAND ); var_Create( p_intf, "chapter_p", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
var_Set( p_intf, "chapter_p", (vlc_value_t)(void*)Playlist ); var_AddCallback( p_intf, "chapter_p", Playlist, NULL );
var_Create( p_intf, "volume", VLC_VAR_COMMAND ); var_Create( p_intf, "volume", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
var_Set( p_intf, "volume", (vlc_value_t)(void*)Volume ); var_AddCallback( p_intf, "volume", Volume, NULL );
var_Create( p_intf, "volup", VLC_VAR_COMMAND ); var_Create( p_intf, "volup", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
var_Set( p_intf, "volup", (vlc_value_t)(void*)VolumeMove ); var_AddCallback( p_intf, "volup", VolumeMove, NULL );
var_Create( p_intf, "voldown", VLC_VAR_COMMAND ); var_Create( p_intf, "voldown", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
var_Set( p_intf, "voldown", (vlc_value_t)(void*)VolumeMove ); var_AddCallback( p_intf, "voldown", VolumeMove, NULL );
var_Create( p_intf, "adev", VLC_VAR_COMMAND ); var_Create( p_intf, "adev", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
var_Set( p_intf, "adev", (vlc_value_t)(void*)AudioConfig ); var_AddCallback( p_intf, "adev", AudioConfig, NULL );
var_Create( p_intf, "achan", VLC_VAR_COMMAND ); var_Create( p_intf, "achan", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
var_Set( p_intf, "achan", (vlc_value_t)(void*)AudioConfig ); var_AddCallback( p_intf, "achan", AudioConfig, NULL );
while( !p_intf->b_die ) while( !p_intf->b_die )
{ {
...@@ -292,18 +298,18 @@ static void Run( intf_thread_t *p_intf ) ...@@ -292,18 +298,18 @@ static void Run( intf_thread_t *p_intf )
} }
/* If the user typed a registered local command, try it */ /* If the user typed a registered local command, try it */
if( var_Type( p_intf, psz_cmd ) == VLC_VAR_COMMAND ) if( var_Type( p_intf, psz_cmd ) & VLC_VAR_ISCOMMAND )
{ {
vlc_value_t val; vlc_value_t val;
int i_ret; int i_ret;
val.psz_string = psz_arg; val.psz_string = psz_arg;
i_ret = var_Get( p_intf, psz_cmd, &val ); i_ret = var_Set( p_intf, psz_cmd, val );
printf( "%s: returned %i (%s)\n", printf( "%s: returned %i (%s)\n",
psz_cmd, i_ret, vlc_error( i_ret ) ); psz_cmd, i_ret, vlc_error( i_ret ) );
} }
/* Or maybe it's a global command */ /* Or maybe it's a global command */
else if( var_Type( p_intf->p_libvlc, psz_cmd ) == VLC_VAR_COMMAND ) else if( var_Type( p_intf->p_libvlc, psz_cmd ) & VLC_VAR_ISCOMMAND )
{ {
vlc_value_t val; vlc_value_t val;
int i_ret; int i_ret;
...@@ -311,7 +317,7 @@ static void Run( intf_thread_t *p_intf ) ...@@ -311,7 +317,7 @@ static void Run( intf_thread_t *p_intf )
val.psz_string = psz_arg; val.psz_string = psz_arg;
/* FIXME: it's a global command, but we should pass the /* FIXME: it's a global command, but we should pass the
* local object as an argument, not p_intf->p_libvlc. */ * local object as an argument, not p_intf->p_libvlc. */
i_ret = var_Get( p_intf->p_libvlc, psz_cmd, &val ); i_ret = var_Set( p_intf->p_libvlc, psz_cmd, val );
printf( "%s: returned %i (%s)\n", printf( "%s: returned %i (%s)\n",
psz_cmd, i_ret, vlc_error( i_ret ) ); psz_cmd, i_ret, vlc_error( i_ret ) );
} }
...@@ -431,7 +437,8 @@ static void Run( intf_thread_t *p_intf ) ...@@ -431,7 +437,8 @@ static void Run( intf_thread_t *p_intf )
} }
} }
static int Playlist( vlc_object_t *p_this, char *psz_cmd, char *psz_arg ) static int Playlist( vlc_object_t *p_this, char const *psz_cmd,
vlc_value_t oldval, vlc_value_t newval, void *p_data )
{ {
input_thread_t * p_input; input_thread_t * p_input;
playlist_t * p_playlist; playlist_t * p_playlist;
...@@ -452,7 +459,7 @@ static int Playlist( vlc_object_t *p_this, char *psz_cmd, char *psz_arg ) ...@@ -452,7 +459,7 @@ static int Playlist( vlc_object_t *p_this, char *psz_cmd, char *psz_arg )
} }
else if( !strcmp( psz_cmd, "seek" ) ) else if( !strcmp( psz_cmd, "seek" ) )
{ {
input_Seek( p_input, atoi( psz_arg ), input_Seek( p_input, atoi( newval.psz_string ),
INPUT_SEEK_SECONDS | INPUT_SEEK_SET ); INPUT_SEEK_SECONDS | INPUT_SEEK_SET );
} }
else if( !strcmp( psz_cmd, "chapter" ) || else if( !strcmp( psz_cmd, "chapter" ) ||
...@@ -463,10 +470,10 @@ static int Playlist( vlc_object_t *p_this, char *psz_cmd, char *psz_arg ) ...@@ -463,10 +470,10 @@ static int Playlist( vlc_object_t *p_this, char *psz_cmd, char *psz_arg )
if( !strcmp( psz_cmd, "chapter" ) ) if( !strcmp( psz_cmd, "chapter" ) )
{ {
if ( *psz_arg ) if ( *newval.psz_string )
{ {
/* Set. */ /* Set. */
i_chapter = atoi( psz_arg ); i_chapter = atoi( newval.psz_string );
} }
else else
{ {
...@@ -517,10 +524,10 @@ static int Playlist( vlc_object_t *p_this, char *psz_cmd, char *psz_arg ) ...@@ -517,10 +524,10 @@ static int Playlist( vlc_object_t *p_this, char *psz_cmd, char *psz_arg )
if( !strcmp( psz_cmd, "title" ) ) if( !strcmp( psz_cmd, "title" ) )
{ {
if ( *psz_arg ) if ( *newval.psz_string )
{ {
/* Set. */ /* Set. */
i_title = atoi( psz_arg ); i_title = atoi( newval.psz_string );
} }
else else
{ {
...@@ -596,18 +603,20 @@ static int Playlist( vlc_object_t *p_this, char *psz_cmd, char *psz_arg ) ...@@ -596,18 +603,20 @@ static int Playlist( vlc_object_t *p_this, char *psz_cmd, char *psz_arg )
return VLC_SUCCESS; return VLC_SUCCESS;
} }
static int Quit( vlc_object_t *p_this, char *psz_cmd, char *psz_arg ) static int Quit( vlc_object_t *p_this, char const *psz_cmd,
vlc_value_t oldval, vlc_value_t newval, void *p_data )
{ {
p_this->p_vlc->b_die = VLC_TRUE; p_this->p_vlc->b_die = VLC_TRUE;
return VLC_SUCCESS; return VLC_SUCCESS;
} }
static int Intf( vlc_object_t *p_this, char *psz_cmd, char *psz_arg ) static int Intf( vlc_object_t *p_this, char const *psz_cmd,
vlc_value_t oldval, vlc_value_t newval, void *p_data )
{ {
intf_thread_t *p_newintf; intf_thread_t *p_newintf;
char *psz_oldmodule = config_GetPsz( p_this->p_vlc, "intf" ); char *psz_oldmodule = config_GetPsz( p_this->p_vlc, "intf" );
config_PutPsz( p_this->p_vlc, "intf", psz_arg ); config_PutPsz( p_this->p_vlc, "intf", newval.psz_string );
p_newintf = intf_Create( p_this->p_vlc ); p_newintf = intf_Create( p_this->p_vlc );
config_PutPsz( p_this->p_vlc, "intf", psz_oldmodule ); config_PutPsz( p_this->p_vlc, "intf", psz_oldmodule );
...@@ -629,23 +638,18 @@ static int Intf( vlc_object_t *p_this, char *psz_cmd, char *psz_arg ) ...@@ -629,23 +638,18 @@ static int Intf( vlc_object_t *p_this, char *psz_cmd, char *psz_arg )
return VLC_SUCCESS; return VLC_SUCCESS;
} }
static int Signal( vlc_object_t *p_this, char *psz_cmd, char *psz_arg ) static int Volume( vlc_object_t *p_this, char const *psz_cmd,
{ vlc_value_t oldval, vlc_value_t newval, void *p_data )
raise( atoi(psz_arg) );
return VLC_SUCCESS;
}
static int Volume( vlc_object_t *p_this, char *psz_cmd, char *psz_arg )
{ {
aout_instance_t * p_aout; aout_instance_t * p_aout;
int i_error; int i_error;
p_aout = vlc_object_find( p_this, VLC_OBJECT_AOUT, FIND_ANYWHERE ); p_aout = vlc_object_find( p_this, VLC_OBJECT_AOUT, FIND_ANYWHERE );
if ( p_aout == NULL ) return VLC_ENOOBJ; if ( p_aout == NULL ) return VLC_ENOOBJ;
if ( *psz_arg ) if ( *newval.psz_string )
{ {
/* Set. */ /* Set. */
audio_volume_t i_volume = atoi( psz_arg ); audio_volume_t i_volume = atoi( newval.psz_string );
if ( i_volume > AOUT_VOLUME_MAX ) if ( i_volume > AOUT_VOLUME_MAX )
{ {
printf( "Volume must be in the range %d-%d\n", AOUT_VOLUME_MIN, printf( "Volume must be in the range %d-%d\n", AOUT_VOLUME_MIN,
...@@ -673,11 +677,12 @@ static int Volume( vlc_object_t *p_this, char *psz_cmd, char *psz_arg ) ...@@ -673,11 +677,12 @@ static int Volume( vlc_object_t *p_this, char *psz_cmd, char *psz_arg )
return i_error; return i_error;
} }
static int VolumeMove( vlc_object_t * p_this, char * psz_cmd, char * psz_arg ) static int VolumeMove( vlc_object_t *p_this, char const *psz_cmd,
vlc_value_t oldval, vlc_value_t newval, void *p_data )
{ {
aout_instance_t * p_aout; aout_instance_t * p_aout;
audio_volume_t i_volume; audio_volume_t i_volume;
int i_nb_steps = atoi(psz_arg); int i_nb_steps = atoi(newval.psz_string);
int i_error = VLC_SUCCESS; int i_error = VLC_SUCCESS;
if ( i_nb_steps <= 0 || i_nb_steps > (AOUT_VOLUME_MAX/AOUT_VOLUME_STEP) ) if ( i_nb_steps <= 0 || i_nb_steps > (AOUT_VOLUME_MAX/AOUT_VOLUME_STEP) )
...@@ -704,7 +709,8 @@ static int VolumeMove( vlc_object_t * p_this, char * psz_cmd, char * psz_arg ) ...@@ -704,7 +709,8 @@ static int VolumeMove( vlc_object_t * p_this, char * psz_cmd, char * psz_arg )
return i_error; return i_error;
} }
static int AudioConfig( vlc_object_t * p_this, char * psz_cmd, char * psz_arg ) static int AudioConfig( vlc_object_t *p_this, char const *psz_cmd,
vlc_value_t oldval, vlc_value_t newval, void *p_data )
{ {
aout_instance_t * p_aout; aout_instance_t * p_aout;
const char * psz_variable; const char * psz_variable;
...@@ -725,7 +731,7 @@ static int AudioConfig( vlc_object_t * p_this, char * psz_cmd, char * psz_arg ) ...@@ -725,7 +731,7 @@ static int AudioConfig( vlc_object_t * p_this, char * psz_cmd, char * psz_arg )
psz_name = "audio channels"; psz_name = "audio channels";
} }
if ( !*psz_arg ) if ( !*newval.psz_string )
{ {
/* Retrieve all registered ***. */ /* Retrieve all registered ***. */
vlc_value_t val; vlc_value_t val;
...@@ -768,7 +774,7 @@ static int AudioConfig( vlc_object_t * p_this, char * psz_cmd, char * psz_arg ) ...@@ -768,7 +774,7 @@ static int AudioConfig( vlc_object_t * p_this, char * psz_cmd, char * psz_arg )
else else
{ {
vlc_value_t val; vlc_value_t val;
val.psz_string = psz_arg; val.psz_string = newval.psz_string;
i_error = var_Set( (vlc_object_t *)p_aout, psz_variable, val ); i_error = var_Set( (vlc_object_t *)p_aout, psz_variable, val );
} }
...@@ -776,4 +782,3 @@ static int AudioConfig( vlc_object_t * p_this, char * psz_cmd, char * psz_arg ) ...@@ -776,4 +782,3 @@ static int AudioConfig( vlc_object_t * p_this, char * psz_cmd, char * psz_arg )
return i_error; return i_error;
} }
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* test4.c : Miscellaneous stress tests module for vlc * test4.c : Miscellaneous stress tests module for vlc
***************************************************************************** *****************************************************************************
* Copyright (C) 2002 VideoLAN * 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> * Authors: Samuel Hocevar <sam@zoy.org>
* *
...@@ -41,43 +41,51 @@ ...@@ -41,43 +41,51 @@
/***************************************************************************** /*****************************************************************************
* Local prototypes. * Local prototypes.
*****************************************************************************/ *****************************************************************************/
static int Foo ( 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 *, char * ); static int Callback ( vlc_object_t *, char const *,
vlc_value_t, vlc_value_t, void * );
static int MyCallback( vlc_object_t *, char const *, static int MyCallback( vlc_object_t *, char const *,
vlc_value_t, vlc_value_t, void * ); vlc_value_t, vlc_value_t, void * );
static void * MyThread ( vlc_object_t * ); 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 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. * Module descriptor.
*****************************************************************************/ *****************************************************************************/
vlc_module_begin(); vlc_module_begin();
set_description( _("Miscellaneous stress tests") ); set_description( _("Miscellaneous stress tests") );
var_Create( p_module->p_libvlc, "foo-test", VLC_VAR_COMMAND ); var_Create( p_module->p_libvlc, "foo-test",
var_Set( p_module->p_libvlc, "foo-test", (vlc_value_t)(void*)Foo ); VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
var_Create( p_module->p_libvlc, "callback-test", VLC_VAR_COMMAND ); var_AddCallback( p_module->p_libvlc, "foo-test", Foo, NULL );
var_Set( p_module->p_libvlc, "callback-test", (vlc_value_t)(void*)Callback ); var_Create( p_module->p_libvlc, "callback-test",
var_Create( p_module->p_libvlc, "stress-test", VLC_VAR_COMMAND ); VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
var_Set( p_module->p_libvlc, "stress-test", (vlc_value_t)(void*)Stress ); var_AddCallback( p_module->p_libvlc, "callback-test", Callback, NULL );
var_Create( p_module->p_libvlc, "signal", VLC_VAR_COMMAND ); var_Create( p_module->p_libvlc, "stress-test",
var_Set( p_module->p_libvlc, "signal", (vlc_value_t)(void*)Signal ); 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(); vlc_module_end();
/***************************************************************************** /*****************************************************************************
* Foo: put anything here * 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; vlc_value_t val;
int i, i_vals; int i, i_vals;
vlc_value_t *p_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"; val.psz_string = "foo";
var_Change( p_this, "honk", VLC_VAR_ADDCHOICE, &val ); 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 ) ...@@ -121,7 +129,8 @@ static int Foo( vlc_object_t *p_this, char *psz_cmd, char *psz_arg )
/***************************************************************************** /*****************************************************************************
* Callback: test callback functions * 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; int i;
char psz_var[20]; char psz_var[20];
...@@ -244,7 +253,8 @@ static void * MyThread( vlc_object_t *p_this ) ...@@ -244,7 +253,8 @@ static void * MyThread( vlc_object_t *p_this )
/***************************************************************************** /*****************************************************************************
* Stress: perform various stress tests * 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; vlc_object_t **pp_objects;
mtime_t start; mtime_t start;
...@@ -252,9 +262,9 @@ static int Stress( vlc_object_t *p_this, char *psz_cmd, char *psz_arg ) ...@@ -252,9 +262,9 @@ static int Stress( vlc_object_t *p_this, char *psz_cmd, char *psz_arg )
char * psz_blob; char * psz_blob;
int i, i_level; 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 ) if( i_level <= 0 )
{ {
i_level = 1; i_level = 1;
...@@ -426,9 +436,9 @@ static void * Dummy( vlc_object_t *p_this ) ...@@ -426,9 +436,9 @@ static void * Dummy( vlc_object_t *p_this )
/***************************************************************************** /*****************************************************************************
* Signal: send a signal to the current thread. * 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; return VLC_SUCCESS;
} }
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* output.c : internal management of output streams for the audio output * output.c : internal management of output streams for the audio output
***************************************************************************** *****************************************************************************
* Copyright (C) 2002 VideoLAN * 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> * Authors: Christophe Massiot <massiot@via.ecp.fr>
* *
...@@ -63,7 +63,7 @@ int aout_OutputNew( aout_instance_t * p_aout, ...@@ -63,7 +63,7 @@ int aout_OutputNew( aout_instance_t * p_aout,
} }
if ( var_Type( p_aout, "audio-channels" ) == 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. */ /* The user may have selected a different channels configuration. */
vlc_value_t val; vlc_value_t val;
...@@ -93,7 +93,7 @@ int aout_OutputNew( aout_instance_t * p_aout, ...@@ -93,7 +93,7 @@ int aout_OutputNew( aout_instance_t * p_aout,
{ {
/* Mono - create the audio-channels variable. */ /* Mono - create the audio-channels variable. */
vlc_value_t val; 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 ) if ( p_aout->output.output.i_original_channels & AOUT_CHAN_DUALMONO )
{ {
/* Go directly to the left channel. */ /* Go directly to the left channel. */
...@@ -118,7 +118,7 @@ int aout_OutputNew( aout_instance_t * p_aout, ...@@ -118,7 +118,7 @@ int aout_OutputNew( aout_instance_t * p_aout,
{ {
/* Stereo - create the audio-channels variable. */ /* Stereo - create the audio-channels variable. */
vlc_value_t val; 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"); val.psz_string = N_("Both");
var_Change( p_aout, "audio-channels", VLC_VAR_ADDCHOICE, &val ); var_Change( p_aout, "audio-channels", VLC_VAR_ADDCHOICE, &val );
val.psz_string = N_("Left"); val.psz_string = N_("Left");
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* objects.c: vlc_object_t handling * objects.c: vlc_object_t handling
***************************************************************************** *****************************************************************************
* Copyright (C) 2002 VideoLAN * 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> * Authors: Samuel Hocevar <sam@zoy.org>
* *
...@@ -47,7 +47,8 @@ ...@@ -47,7 +47,8 @@
/***************************************************************************** /*****************************************************************************
* Local prototypes * 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 vlc_object_t * FindObject ( vlc_object_t *, int, int );
static void DetachObject ( vlc_object_t * ); static void DetachObject ( vlc_object_t * );
...@@ -213,15 +214,12 @@ void * __vlc_object_create( vlc_object_t *p_this, int i_type ) ...@@ -213,15 +214,12 @@ void * __vlc_object_create( vlc_object_t *p_this, int i_type )
if( i_type == VLC_OBJECT_ROOT ) if( i_type == VLC_OBJECT_ROOT )
{ {
vlc_value_t val;
val.p_address = DumpCommand;
vlc_mutex_init( p_new, &structure_lock ); vlc_mutex_init( p_new, &structure_lock );
var_Create( p_new, "list", VLC_VAR_COMMAND ); var_Create( p_new, "list", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
var_Set( p_new, "list", val ); var_AddCallback( p_new, "list", DumpCommand, NULL );
var_Create( p_new, "tree", VLC_VAR_COMMAND ); var_Create( p_new, "tree", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
var_Set( p_new, "tree", val ); var_AddCallback( p_new, "tree", DumpCommand, NULL );
} }
return p_new; return p_new;
...@@ -528,16 +526,17 @@ vlc_list_t * __vlc_list_find( vlc_object_t *p_this, int i_type, int i_mode ) ...@@ -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, * vlc objects, and additional information such as their refcount, thread ID,
* etc. (command "tree"), or the same data as a simple list (command "list"). * 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' ) if( *psz_cmd == 't' )
{ {
char psz_foo[2 * MAX_DUMPSTRUCTURE_DEPTH + 1]; char psz_foo[2 * MAX_DUMPSTRUCTURE_DEPTH + 1];
vlc_object_t *p_object; 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 ) if( !p_object )
{ {
...@@ -899,4 +898,3 @@ static vlc_list_t * ListAppend( vlc_list_t *p_list, vlc_object_t *p_object ) ...@@ -899,4 +898,3 @@ static vlc_list_t * ListAppend( vlc_list_t *p_list, vlc_object_t *p_object )
return p_list; return p_list;
} }
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* variables.c: routines for object variables handling * variables.c: routines for object variables handling
***************************************************************************** *****************************************************************************
* Copyright (C) 2002 VideoLAN * 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> * 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 ) ...@@ -167,7 +167,6 @@ int __var_Create( vlc_object_t *p_this, const char *psz_name, int i_type )
/* FIXME: TODO */ /* FIXME: TODO */
break; break;
case VLC_VAR_ADDRESS: case VLC_VAR_ADDRESS:
case VLC_VAR_COMMAND:
p_var->pf_cmp = CmpAddress; p_var->pf_cmp = CmpAddress;
p_var->val.p_address = NULL; p_var->val.p_address = NULL;
break; break;
...@@ -436,7 +435,7 @@ int __var_Type( vlc_object_t *p_this, const char *psz_name ) ...@@ -436,7 +435,7 @@ int __var_Type( vlc_object_t *p_this, const char *psz_name )
if( i_var < 0 ) if( i_var < 0 )
{ {
vlc_mutex_unlock( &p_this->var_lock ); vlc_mutex_unlock( &p_this->var_lock );
return i_var; return 0;
} }
i_type = p_this->p_vars[i_var].i_type; 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 ) ...@@ -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]; 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 */ /* Really get the variable */
*p_val = p_var->val; *p_val = p_var->val;
...@@ -868,7 +843,7 @@ static int LookupInner( variable_t *p_vars, int i_count, uint32_t i_hash ) ...@@ -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 ) static void CheckValue ( variable_t *p_var, vlc_value_t *p_val )
{ {
/* Check that our variable is in the list */ /* 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; 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