Commit 7e6c2325 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

var_GetAndSet: implement OR and NAND, return new value

parent 94b463ab
...@@ -117,16 +117,12 @@ ...@@ -117,16 +117,12 @@
* These are the different actions that can be used with var_GetAndSet() * These are the different actions that can be used with var_GetAndSet()
* @{ * @{
*/ */
/** enum {
* Toggle the value of this boolean VLC_VAR_BOOL_TOGGLE, /**< Invert a boolean value (param ignored) */
* \param val Unused VLC_VAR_INTEGER_ADD, /**< Add parameter to an integer value */
*/ VLC_VAR_INTEGER_OR, /**< Binary OR over an integer bits field */
#define VLC_VAR_TOGGLE_BOOL 0x0010 VLC_VAR_INTEGER_NAND,/**< Binary NAND over an integer bits field */
/** };
* Increment or decrement an integer of a given value
* \param val the value
*/
#define VLC_VAR_INTEGER_INCDEC 0x0020
/**@}*/ /**@}*/
/***************************************************************************** /*****************************************************************************
...@@ -152,8 +148,7 @@ VLC_EXPORT( int, var_Get, ( vlc_object_t *, const char *, vlc_value_t * ) ); ...@@ -152,8 +148,7 @@ 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_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_GetChecked, ( vlc_object_t *, const char *, int, vlc_value_t * ) );
VLC_EXPORT( int, var_GetAndSet, ( 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_GetAndSet(a,b,c,d) var_GetAndSet(VLC_OBJECT(a), b, c, d)
VLC_EXPORT( int, var_Inherit, ( vlc_object_t *, const char *, int, vlc_value_t * ) ); VLC_EXPORT( int, var_Inherit, ( vlc_object_t *, const char *, int, vlc_value_t * ) );
...@@ -385,11 +380,12 @@ static inline void *var_GetAddress( vlc_object_t *p_obj, const char *psz_name ) ...@@ -385,11 +380,12 @@ static inline void *var_GetAddress( vlc_object_t *p_obj, const char *psz_name )
* \param p_obj the object that holds the variable * \param p_obj the object that holds the variable
* \param psz_name the name of the variable * \param psz_name the name of the variable
*/ */
static inline void var_IncInteger( vlc_object_t *p_obj, const char *psz_name ) static inline int var_IncInteger( vlc_object_t *p_obj, const char *psz_name )
{ {
vlc_value_t val; vlc_value_t val;
val.i_int = 1; val.i_int = 1;
var_GetAndSet( p_obj, psz_name, VLC_VAR_INTEGER_INCDEC, val ); var_GetAndSet( p_obj, psz_name, VLC_VAR_INTEGER_ADD, &val );
return val.i_int;
} }
#define var_IncInteger(a,b) var_IncInteger( VLC_OBJECT(a), b ) #define var_IncInteger(a,b) var_IncInteger( VLC_OBJECT(a), b )
...@@ -398,14 +394,35 @@ static inline void var_IncInteger( vlc_object_t *p_obj, const char *psz_name ) ...@@ -398,14 +394,35 @@ static inline void var_IncInteger( vlc_object_t *p_obj, const char *psz_name )
* \param p_obj the object that holds the variable * \param p_obj the object that holds the variable
* \param psz_name the name of the variable * \param psz_name the name of the variable
*/ */
static inline void var_DecInteger( vlc_object_t *p_obj, const char *psz_name ) static inline int var_DecInteger( vlc_object_t *p_obj, const char *psz_name )
{ {
vlc_value_t val; vlc_value_t val;
val.i_int = -1; val.i_int = -1;
var_GetAndSet( p_obj, psz_name, VLC_VAR_INTEGER_INCDEC, val ); var_GetAndSet( p_obj, psz_name, VLC_VAR_INTEGER_ADD, &val );
return val.i_int;
} }
#define var_DecInteger(a,b) var_DecInteger( VLC_OBJECT(a), b ) #define var_DecInteger(a,b) var_DecInteger( VLC_OBJECT(a), b )
static inline unsigned var_OrInteger( vlc_object_t *obj, const char *name,
unsigned v )
{
vlc_value_t val;
val.i_int = v;
var_GetAndSet( obj, name, VLC_VAR_INTEGER_OR, &val );
return val.i_int;
}
#define var_OrInteger(a,b,c) var_OrInteger(VLC_OBJECT(a),b,c)
static inline unsigned var_NAndInteger( vlc_object_t *obj, const char *name,
unsigned v )
{
vlc_value_t val;
val.i_int = v;
var_GetAndSet( obj, name, VLC_VAR_INTEGER_NAND, &val );
return val.i_int;
}
#define var_NAndInteger(a,b,c) var_NAndInteger(VLC_OBJECT(a),b,c)
/** /**
* Create a integer variable with inherit and get its value. * Create a integer variable with inherit and get its value.
* *
...@@ -600,10 +617,11 @@ static inline int var_CountChoices( vlc_object_t *p_obj, const char *psz_name ) ...@@ -600,10 +617,11 @@ 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) #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 ) static inline bool var_ToggleBool( vlc_object_t *p_obj, const char *psz_name )
{ {
vlc_value_t val; vlc_value_t val;
return var_GetAndSet( p_obj, psz_name, VLC_VAR_TOGGLE_BOOL, val ); var_GetAndSet( p_obj, psz_name, VLC_VAR_BOOL_TOGGLE, &val );
return val.b_bool;
} }
#define var_ToggleBool(a,b) var_ToggleBool( VLC_OBJECT(a),b ) #define var_ToggleBool(a,b) var_ToggleBool( VLC_OBJECT(a),b )
......
...@@ -634,13 +634,14 @@ int var_Change( vlc_object_t *p_this, const char *psz_name, ...@@ -634,13 +634,14 @@ int var_Change( vlc_object_t *p_this, const char *psz_name,
* \return vlc error codes * \return vlc error codes
*/ */
int var_GetAndSet( vlc_object_t *p_this, const char *psz_name, int i_action, int var_GetAndSet( vlc_object_t *p_this, const char *psz_name, int i_action,
vlc_value_t val ) vlc_value_t *p_val )
{ {
int i_ret; int i_ret;
variable_t *p_var; variable_t *p_var;
vlc_value_t oldval; vlc_value_t oldval;
assert( p_this ); assert( p_this );
assert( p_val );
vlc_object_internals_t *p_priv = vlc_internals( p_this ); vlc_object_internals_t *p_priv = vlc_internals( p_this );
...@@ -663,13 +664,21 @@ int var_GetAndSet( vlc_object_t *p_this, const char *psz_name, int i_action, ...@@ -663,13 +664,21 @@ int var_GetAndSet( vlc_object_t *p_this, const char *psz_name, int i_action,
/* depending of the action requiered */ /* depending of the action requiered */
switch( i_action ) switch( i_action )
{ {
case VLC_VAR_TOGGLE_BOOL: case VLC_VAR_BOOL_TOGGLE:
assert( ( p_var->i_type & VLC_VAR_BOOL ) == VLC_VAR_BOOL ); assert( ( p_var->i_type & VLC_VAR_BOOL ) == VLC_VAR_BOOL );
p_var->val.b_bool = !p_var->val.b_bool; p_var->val.b_bool = !p_var->val.b_bool;
break; break;
case VLC_VAR_INTEGER_INCDEC: case VLC_VAR_INTEGER_ADD:
assert( ( p_var->i_type & VLC_VAR_INTEGER ) == VLC_VAR_INTEGER );
p_var->val.i_int += p_val->i_int;
break;
case VLC_VAR_INTEGER_OR:
assert( ( p_var->i_type & VLC_VAR_INTEGER ) == VLC_VAR_INTEGER ); assert( ( p_var->i_type & VLC_VAR_INTEGER ) == VLC_VAR_INTEGER );
p_var->val.i_int += val.i_int; p_var->val.i_int |= p_val->i_int;
break;
case VLC_VAR_INTEGER_NAND:
assert( ( p_var->i_type & VLC_VAR_INTEGER ) == VLC_VAR_INTEGER );
p_var->val.i_int &= ~p_val->i_int;
break; break;
default: default:
vlc_mutex_unlock( &p_priv->var_lock ); vlc_mutex_unlock( &p_priv->var_lock );
...@@ -678,6 +687,7 @@ int var_GetAndSet( vlc_object_t *p_this, const char *psz_name, int i_action, ...@@ -678,6 +687,7 @@ int var_GetAndSet( vlc_object_t *p_this, const char *psz_name, int i_action,
/* Check boundaries */ /* Check boundaries */
CheckValue( p_var, &p_var->val ); CheckValue( p_var, &p_var->val );
*p_val = p_var->val;
/* Deal with callbacks.*/ /* Deal with callbacks.*/
i_ret = TriggerCallback( p_this, p_var, psz_name, oldval ); i_ret = TriggerCallback( p_this, p_var, psz_name, oldval );
......
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