#ifndef VLC_VARIABLES_H
#define VLC_VARIABLES_H 1
-#include <assert.h>
-
/**
* \file
* This file defines functions and structures for dynamic variables in vlc
VLC_EXPORT( int, __var_Type, ( vlc_object_t *, const char * ) LIBVLC_USED );
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 * ) );
#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 ** ) );
* helpers functions
*****************************************************************************/
-#ifndef NDEBUG
-/**
- * This function assert the variable is of the expected type or it
- * is not defined
- */
-static inline void __var_AssertType( vlc_object_t *p_obj, const char *psz_name,
- int i_expected )
-{
- const int i_type = __var_Type( p_obj, psz_name ) & VLC_VAR_CLASS;
- assert( i_type == 0 || i_type == (i_expected&VLC_VAR_CLASS) );
-}
-#else
-# define __var_AssertType( o, n, e ) (void)(o, n, e)
-#endif
-
/**
* Set the value of an integer variable
*
{
vlc_value_t val;
val.i_int = i;
- __var_AssertType( p_obj, psz_name, VLC_VAR_INTEGER );
- return __var_Set( p_obj, psz_name, val );
+ return var_SetChecked( p_obj, psz_name, VLC_VAR_INTEGER, val );
}
#define var_SetInteger(a,b,c) __var_SetInteger( VLC_OBJECT(a),b,c)
/**
{
vlc_value_t val;
val.b_bool = b;
- __var_AssertType( p_obj, psz_name, VLC_VAR_BOOL );
- return __var_Set( p_obj, psz_name, val );
+ return var_SetChecked( p_obj, psz_name, VLC_VAR_BOOL, val );
}
/**
{
vlc_value_t val;
val.i_time = i;
- __var_AssertType( p_obj, psz_name, VLC_VAR_TIME );
- return __var_Set( p_obj, psz_name, val );
+ return var_SetChecked( p_obj, psz_name, VLC_VAR_TIME, val );
}
/**
{
vlc_value_t val;
val.f_float = f;
- __var_AssertType( p_obj, psz_name, VLC_VAR_FLOAT );
- return __var_Set( p_obj, psz_name, val );
+ return var_SetChecked( p_obj, psz_name, VLC_VAR_FLOAT, val );
}
/**
{
vlc_value_t val;
val.psz_string = (char *)psz_string;
- __var_AssertType( p_obj, psz_name, VLC_VAR_STRING );
- return __var_Set( p_obj, psz_name, val );
+ return var_SetChecked( p_obj, psz_name, VLC_VAR_STRING, val );
}
/**
{
vlc_value_t val;
val.b_bool = true;
- __var_AssertType( p_obj, psz_name, VLC_VAR_VOID );
- return __var_Set( p_obj, psz_name, val );
+ return var_SetChecked( p_obj, psz_name, VLC_VAR_VOID, val );
}
#define var_SetVoid(a,b) __var_SetVoid( VLC_OBJECT(a),b)
LIBVLC_USED
static inline int __var_GetInteger( vlc_object_t *p_obj, const char *psz_name )
{
- vlc_value_t val;val.i_int = 0;
- __var_AssertType( p_obj, psz_name, VLC_VAR_INTEGER );
- if( !__var_Get( p_obj, psz_name, &val ) )
+ vlc_value_t val;
+ if( !var_GetChecked( p_obj, psz_name, VLC_VAR_INTEGER, &val ) )
return val.i_int;
else
return 0;
{
vlc_value_t val; val.b_bool = false;
- __var_AssertType( p_obj, psz_name, VLC_VAR_BOOL );
- if( !__var_Get( p_obj, psz_name, &val ) )
+ if( !var_GetChecked( p_obj, psz_name, VLC_VAR_BOOL, &val ) )
return val.b_bool;
else
return false;
static inline int64_t __var_GetTime( vlc_object_t *p_obj, const char *psz_name )
{
vlc_value_t val; val.i_time = 0L;
- __var_AssertType( p_obj, psz_name, VLC_VAR_TIME );
- if( !__var_Get( p_obj, psz_name, &val ) )
+ if( !var_GetChecked( p_obj, psz_name, VLC_VAR_TIME, &val ) )
return val.i_time;
else
return 0;
static inline float __var_GetFloat( vlc_object_t *p_obj, const char *psz_name )
{
vlc_value_t val; val.f_float = 0.0;
- __var_AssertType( p_obj, psz_name, VLC_VAR_FLOAT );
- if( !__var_Get( p_obj, psz_name, &val ) )
+ if( !var_GetChecked( p_obj, psz_name, VLC_VAR_FLOAT, &val ) )
return val.f_float;
else
return 0.0;
static inline char *__var_GetString( vlc_object_t *p_obj, const char *psz_name )
{
vlc_value_t val; val.psz_string = NULL;
- __var_AssertType( p_obj, psz_name, VLC_VAR_STRING );
- if( __var_Get( p_obj, psz_name, &val ) )
+ if( var_GetChecked( p_obj, psz_name, VLC_VAR_STRING, &val ) )
return NULL;
else
return val.psz_string;
static inline char *__var_GetNonEmptyString( vlc_object_t *p_obj, const char *psz_name )
{
vlc_value_t val;
- __var_AssertType( p_obj, psz_name, VLC_VAR_STRING );
- if( __var_Get( p_obj, psz_name, &val ) )
+ if( var_GetChecked( p_obj, psz_name, VLC_VAR_STRING, &val ) )
return NULL;
if( *val.psz_string )
return val.psz_string;
#include "libvlc.h"
#include "vlc_interface.h"
+#include <assert.h>
/*****************************************************************************
* Private types
return i_type;
}
-/**
- * Set a variable's value
- *
- * \param p_this The object that hold the variable
- * \param psz_name The name of the variable
- * \param val the value to set
- */
-int __var_Set( vlc_object_t *p_this, const char *psz_name, vlc_value_t val )
+int var_SetChecked( vlc_object_t *p_this, const char *psz_name,
+ int expected_type, vlc_value_t val )
{
int i_var;
variable_t *p_var;
}
p_var = &p_priv->p_vars[i_var];
+ assert( (p_var->i_type & VLC_VAR_CLASS) == 0 || expected_type == 0 ||
+ (p_var->i_type & VLC_VAR_CLASS) == expected_type );
/* Duplicate data if needed */
p_var->ops->pf_dup( &val );
return VLC_SUCCESS;
}
+
/**
- * Get a variable's value
+ * Set a variable's value
*
- * \param p_this The object that holds the variable
+ * \param p_this The object that hold the variable
* \param psz_name The name of the variable
- * \param p_val Pointer to a vlc_value_t that will hold the variable's value
- * after the function is finished
+ * \param val the value to set
*/
-int __var_Get( vlc_object_t *p_this, const char *psz_name, vlc_value_t *p_val )
+int __var_Set( vlc_object_t *p_this, const char *psz_name, vlc_value_t val )
+{
+ return var_SetChecked( p_this, psz_name, 0, val );
+}
+
+int var_GetChecked( vlc_object_t *p_this, const char *psz_name,
+ int expected_type, vlc_value_t *p_val )
{
- int i_var;
- variable_t *p_var;
vlc_object_internals_t *p_priv = vlc_internals( p_this );
+ int i_var, err = VLC_SUCCESS;
vlc_mutex_lock( &p_priv->var_lock );
i_var = Lookup( p_priv->p_vars, p_priv->i_vars, psz_name );
-
- if( i_var < 0 )
+ if( i_var >= 0 )
{
- vlc_mutex_unlock( &p_priv->var_lock );
- return VLC_ENOVAR;
- }
+ variable_t *p_var = &p_priv->p_vars[i_var];
- p_var = &p_priv->p_vars[i_var];
+ assert( (p_var->i_type & VLC_VAR_CLASS) == 0 || expected_type == 0 ||
+ (p_var->i_type & VLC_VAR_CLASS) == expected_type );
- /* Really get the variable */
- *p_val = p_var->val;
+ /* Really get the variable */
+ *p_val = p_var->val;
- /* Duplicate value if needed */
- p_var->ops->pf_dup( p_val );
+ /* Duplicate value if needed */
+ p_var->ops->pf_dup( p_val );
+ }
+ else
+ err = VLC_ENOVAR;
vlc_mutex_unlock( &p_priv->var_lock );
-
- return VLC_SUCCESS;
+ return err;
}
+/**
+ * Get a variable's value
+ *
+ * \param p_this The object that holds the variable
+ * \param psz_name The name of the variable
+ * \param p_val Pointer to a vlc_value_t that will hold the variable's value
+ * after the function is finished
+ */
+int __var_Get( vlc_object_t *p_this, const char *psz_name, vlc_value_t *p_val )
+{
+ return var_GetChecked( p_this, psz_name, 0, p_val );
+}
/**
* Register a callback in a variable