]> git.sesse.net Git - vlc/commitdiff
variables: add a Get and Set function. This function can be only used (for the
authorRémi Duraffort <ivoire@videolan.org>
Mon, 27 Jul 2009 06:00:53 +0000 (08:00 +0200)
committerRémi Duraffort <ivoire@videolan.org>
Mon, 27 Jul 2009 07:06:33 +0000 (09:06 +0200)
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).

include/vlc_variables.h
src/libvlccore.sym
src/misc/variables.c

index 0efe910d03641ca2f69a3152b2e3bb5c1f24afd5..aaada0d133d4135187827c2f7f20ef7a4067efbd 100644 (file)
 #define VLC_VAR_SETISCOMMAND        0x0040
 /**@}*/
 
 #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
  *****************************************************************************/
 /*****************************************************************************
  * 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_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 ** ) );
 
 #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_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
 
 /*****************************************************************************
  * 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)
 
  */
 #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 )
 /**
  * @}
  */
 /**
  * @}
  */
index 357f4ecfc95aad67f7b0e17af8be4f5c448b3706..affea306c77a88c2b95bb3c436622f221336897d 100644 (file)
@@ -437,6 +437,7 @@ __var_DelCallback
 __var_Destroy
 var_FreeList
 __var_Get
 __var_Destroy
 var_FreeList
 __var_Get
+__var_GetAndSet
 var_GetChecked
 __var_Set
 var_SetChecked
 var_GetChecked
 __var_Set
 var_SetChecked
index 864089baf9658b0cc1b5d84cede9943c635fae52..c3f29714ea73b861e16fd74bccb78aa9122632d0 100644 (file)
@@ -662,6 +662,66 @@ int __var_Change( vlc_object_t *p_this, const char *psz_name,
     return VLC_SUCCESS;
 }
 
     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
  *
 /**
  * Request a variable's type
  *