Commit 1bc0945e authored by ivoire's avatar ivoire
Browse files

variables: add a Get and Set function. This function can be only used (for the

moment) to toggle a boolean with the variable lock taken (which is not the case
when doing a var_SetBool(!var_GetBool)).
This function is also two times faster (only one lookup).
parent 98094e9e
......@@ -115,6 +115,17 @@
#define VLC_VAR_SETISCOMMAND 0x0040
/**@}*/
/** \defgroup var_GetAndSet Variable actions
* These are the different actions that can be used with __var_GetAndSet()
* @{
*/
/**
* Toggle the value of this boolean
* \param val Unused
*/
#define VLC_VAR_TOGGLE_BOOL 0x0010
/**@}*/
/*****************************************************************************
* Prototypes
*****************************************************************************/
......@@ -128,6 +139,7 @@ VLC_EXPORT( int, __var_Set, ( vlc_object_t *, const char *, vlc_value_t ) );
VLC_EXPORT( int, __var_Get, ( vlc_object_t *, const char *, vlc_value_t * ) );
VLC_EXPORT( int, var_SetChecked, ( vlc_object_t *, const char *, int, vlc_value_t ) );
VLC_EXPORT( int, var_GetChecked, ( vlc_object_t *, const char *, int, vlc_value_t * ) );
VLC_EXPORT( int, __var_GetAndSet, ( vlc_object_t *, const char *, int, vlc_value_t ) );
#define var_Command(a,b,c,d,e) __var_Command( VLC_OBJECT( a ), b, c, d, e )
VLC_EXPORT( int, __var_Command, ( vlc_object_t *, const char *, const char *, const char *, char ** ) );
......@@ -160,6 +172,10 @@ VLC_EXPORT( void, var_FreeList, ( vlc_value_t *, vlc_value_t * ) );
* __var_Get() with automatic casting
*/
#define var_Get(a,b,c) __var_Get( VLC_OBJECT(a), b, c )
/**
* __var_GetAndSet() with automatic casting
*/
#define var_GetAndSet(a,b,c,d) __var_GetAndSet(VLC_OBJECT(a), b, c, d)
/*****************************************************************************
* Variable callbacks
......@@ -654,6 +670,16 @@ static inline int __var_CountChoices( vlc_object_t *p_obj, const char *psz_name
*/
#define var_CountChoices(a,b) __var_CountChoices( VLC_OBJECT(a),b)
static inline int __var_ToggleBool( vlc_object_t *p_obj, const char *psz_name )
{
vlc_value_t val;
return __var_GetAndSet( p_obj, psz_name, VLC_VAR_TOGGLE_BOOL, val );
}
/**
* __var_ToggleBool() with automatic casting
*/
#define var_ToggleBool(a,b) __var_ToggleBool( VLC_OBJECT(a),b )
/**
* @}
*/
......
......@@ -437,6 +437,7 @@ __var_DelCallback
__var_Destroy
var_FreeList
__var_Get
__var_GetAndSet
var_GetChecked
__var_Set
var_SetChecked
......
......@@ -662,6 +662,66 @@ int __var_Change( vlc_object_t *p_this, const char *psz_name,
return VLC_SUCCESS;
}
/**
* Perform a Get and Set on a variable
*
* \param p_this: The object that hold the variable
* \param psz_name: the name of the variable
* \param i_action: the action to perform
* \param p_val: The action parameter
* \return vlc error codes
*/
int __var_GetAndSet( vlc_object_t *p_this, const char *psz_name, int i_action,
vlc_value_t val )
{
int i_var;
int i_ret = VLC_SUCCESS;
variable_t *p_var;
vlc_value_t oldval;
vlc_object_internals_t *p_priv = vlc_internals( p_this );
vlc_mutex_lock( &p_priv->var_lock );
i_var = GetUnused( p_this, psz_name );
if( i_var < 0 )
{
vlc_mutex_unlock( &p_priv->var_lock );
return i_var;
}
p_var = &p_priv->p_vars[i_var];
/* Duplicated data if needed */
//p_var->ops->pf_dup( &val );
/* Backup needed stuff */
oldval = p_var->val;
/* depending of the action requiered */
switch( i_action )
{
case VLC_VAR_TOGGLE_BOOL:
assert( ( p_var->i_type & VLC_VAR_BOOL ) == VLC_VAR_BOOL );
p_var->val.b_bool = !p_var->val.b_bool;
break;
default:
vlc_mutex_unlock( &p_priv->var_lock );
return VLC_EGENERIC;
}
/* Check boundaries */
CheckValue( p_var, &p_var->val );
/* Del with callbacks.*/
if( p_var->i_entries )
i_ret = TriggerCallback( p_this, p_var, psz_name, oldval, p_var->val );
vlc_mutex_unlock( &p_priv->var_lock );
return i_ret;
}
/**
* Request a variable's type
*
......
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