vlc_variables.h

Go to the documentation of this file.
00001 /*****************************************************************************
00002  * vlc_variables.h: variables handling
00003  *****************************************************************************
00004  * Copyright (C) 2002-2004 VLC authors and VideoLAN
00005  * $Id: e5885876f1508c2689b21179faf2218b907e09ec $
00006  *
00007  * Authors: Samuel Hocevar <sam@zoy.org>
00008  *          Gildas Bazin <gbazin@netcourrier.com>
00009  *
00010  * This program is free software; you can redistribute it and/or modify it
00011  * under the terms of the GNU Lesser General Public License as published by
00012  * the Free Software Foundation; either version 2.1 of the License, or
00013  * (at your option) any later version.
00014  *
00015  * This program is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00018  * GNU Lesser General Public License for more details.
00019  *
00020  * You should have received a copy of the GNU Lesser General Public License
00021  * along with this program; if not, write to the Free Software Foundation,
00022  * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
00023  *****************************************************************************/
00024 
00025 #ifndef VLC_VARIABLES_H
00026 #define VLC_VARIABLES_H 1
00027 
00028 /**
00029  * \file
00030  * This file defines functions and structures for dynamic variables in vlc
00031  */
00032 
00033 /**
00034  * \defgroup variables Variables
00035  *
00036  * Functions for using the object variables in vlc.
00037  *
00038  * Vlc have a very powerful "object variable" infrastructure useful
00039  * for many things.
00040  *
00041  * @{
00042  */
00043 
00044 #define VLC_VAR_TYPE      0x00ff
00045 #define VLC_VAR_CLASS     0x00f0
00046 #define VLC_VAR_FLAGS     0xff00
00047 
00048 /**
00049  * \defgroup var_type Variable types
00050  * These are the different types a vlc variable can have.
00051  * @{
00052  */
00053 #define VLC_VAR_VOID      0x0010
00054 #define VLC_VAR_BOOL      0x0020
00055 #define VLC_VAR_INTEGER   0x0030
00056 #define VLC_VAR_HOTKEY    0x0031
00057 #define VLC_VAR_STRING    0x0040
00058 #define VLC_VAR_VARIABLE  0x0044
00059 #define VLC_VAR_FLOAT     0x0050
00060 #define VLC_VAR_TIME      0x0060
00061 #define VLC_VAR_ADDRESS   0x0070
00062 #define VLC_VAR_COORDS    0x00A0
00063 /**@}*/
00064 
00065 /** \defgroup var_flags Additive flags
00066  * These flags are added to the type field of the variable. Most as a result of
00067  * a var_Change() call, but some may be added at creation time
00068  * @{
00069  */
00070 #define VLC_VAR_HASCHOICE 0x0100
00071 #define VLC_VAR_HASMIN    0x0200
00072 #define VLC_VAR_HASMAX    0x0400
00073 #define VLC_VAR_HASSTEP   0x0800
00074 
00075 #define VLC_VAR_ISCOMMAND 0x2000
00076 
00077 /** Creation flag */
00078 /* If the variable is not found on the current module
00079    search all parents and finally module config until found */
00080 #define VLC_VAR_DOINHERIT 0x8000
00081 /**@}*/
00082 
00083 /**
00084  * \defgroup var_action Variable actions
00085  * These are the different actions that can be used with var_Change().
00086  * The parameters given are the meaning of the two last parameters of
00087  * var_Change() when this action is being used.
00088  * @{
00089  */
00090 
00091 /**
00092  * Set the minimum value of this variable
00093  * \param p_val The new minimum value
00094  * \param p_val2 Unused
00095  */
00096 #define VLC_VAR_SETMIN              0x0010
00097 /**
00098  * Set the maximum value of this variable
00099  * \param p_val The new maximum value
00100  * \param p_val2 Unused
00101  */
00102 #define VLC_VAR_SETMAX              0x0011
00103 #define VLC_VAR_SETSTEP             0x0012
00104 
00105 /**
00106  * Set the value of this variable without triggering any callbacks
00107  * \param p_val The new value
00108  * \param p_val2 Unused
00109  */
00110 #define VLC_VAR_SETVALUE            0x0013
00111 
00112 #define VLC_VAR_SETTEXT             0x0014
00113 #define VLC_VAR_GETTEXT             0x0015
00114 
00115 #define VLC_VAR_GETMIN              0x0016
00116 #define VLC_VAR_GETMAX              0x0017
00117 #define VLC_VAR_GETSTEP             0x0018
00118 
00119 #define VLC_VAR_ADDCHOICE           0x0020
00120 #define VLC_VAR_DELCHOICE           0x0021
00121 #define VLC_VAR_CLEARCHOICES        0x0022
00122 #define VLC_VAR_SETDEFAULT          0x0023
00123 #define VLC_VAR_GETCHOICES          0x0024
00124 #define VLC_VAR_GETLIST             0x0025
00125 #define VLC_VAR_CHOICESCOUNT        0x0026
00126 
00127 #define VLC_VAR_SETISCOMMAND        0x0040
00128 /**@}*/
00129 
00130 /** \defgroup var_GetAndSet Variable actions
00131  * These are the different actions that can be used with var_GetAndSet()
00132  * @{
00133  */
00134 enum {
00135     VLC_VAR_BOOL_TOGGLE, /**< Invert a boolean value (param ignored) */
00136     VLC_VAR_INTEGER_ADD, /**< Add parameter to an integer value */
00137     VLC_VAR_INTEGER_OR,  /**< Binary OR over an integer bits field */
00138     VLC_VAR_INTEGER_NAND,/**< Binary NAND over an integer bits field */
00139 };
00140 /**@}*/
00141 
00142 /*****************************************************************************
00143  * Prototypes
00144  *****************************************************************************/
00145 VLC_API int var_Create( vlc_object_t *, const char *, int );
00146 #define var_Create(a,b,c) var_Create( VLC_OBJECT(a), b, c )
00147 
00148 VLC_API int var_Destroy( vlc_object_t *, const char * );
00149 #define var_Destroy(a,b) var_Destroy( VLC_OBJECT(a), b )
00150 
00151 VLC_API int var_Change( vlc_object_t *, const char *, int, vlc_value_t *, vlc_value_t * );
00152 #define var_Change(a,b,c,d,e) var_Change( VLC_OBJECT(a), b, c, d, e )
00153 
00154 VLC_API int var_Type( vlc_object_t *, const char * ) VLC_USED;
00155 #define var_Type(a,b) var_Type( VLC_OBJECT(a), b )
00156 
00157 VLC_API int var_Set( vlc_object_t *, const char *, vlc_value_t );
00158 #define var_Set(a,b,c) var_Set( VLC_OBJECT(a), b, c )
00159 
00160 VLC_API int var_Get( vlc_object_t *, const char *, vlc_value_t * );
00161 #define var_Get(a,b,c) var_Get( VLC_OBJECT(a), b, c )
00162 
00163 VLC_API int var_SetChecked( vlc_object_t *, const char *, int, vlc_value_t );
00164 #define var_SetChecked(o,n,t,v) var_SetChecked(VLC_OBJECT(o),n,t,v)
00165 VLC_API int var_GetChecked( vlc_object_t *, const char *, int, vlc_value_t * );
00166 #define var_GetChecked(o,n,t,v) var_GetChecked(VLC_OBJECT(o),n,t,v)
00167 VLC_API int var_GetAndSet( vlc_object_t *, const char *, int, vlc_value_t * );
00168 
00169 VLC_API int var_Inherit( vlc_object_t *, const char *, int, vlc_value_t * );
00170 
00171 VLC_API int var_Command( vlc_object_t *, const char *, const char *, const char *, char ** );
00172 #define var_Command(a,b,c,d,e) var_Command( VLC_OBJECT( a ), b, c, d, e )
00173 
00174 VLC_API void var_FreeList( vlc_value_t *, vlc_value_t * );
00175 
00176 
00177 /*****************************************************************************
00178  * Variable callbacks
00179  *****************************************************************************
00180  * int MyCallback( vlc_object_t *p_this,
00181  *                 char const *psz_variable,
00182  *                 vlc_value_t oldvalue,
00183  *                 vlc_value_t newvalue,
00184  *                 void *p_data);
00185  *****************************************************************************/
00186 VLC_API int var_AddCallback( vlc_object_t *, const char *, vlc_callback_t, void * );
00187 VLC_API int var_DelCallback( vlc_object_t *, const char *, vlc_callback_t, void * );
00188 VLC_API int var_TriggerCallback( vlc_object_t *, const char * );
00189 
00190 #define var_AddCallback(a,b,c,d) var_AddCallback( VLC_OBJECT(a), b, c, d )
00191 #define var_DelCallback(a,b,c,d) var_DelCallback( VLC_OBJECT(a), b, c, d )
00192 #define var_TriggerCallback(a,b) var_TriggerCallback( VLC_OBJECT(a), b )
00193 
00194 /*****************************************************************************
00195  * helpers functions
00196  *****************************************************************************/
00197 
00198 /**
00199  * Set the value of an integer variable
00200  *
00201  * \param p_obj The object that holds the variable
00202  * \param psz_name The name of the variable
00203  * \param i The new integer value of this variable
00204  */
00205 static inline int var_SetInteger( vlc_object_t *p_obj, const char *psz_name,
00206                                   int64_t i )
00207 {
00208     vlc_value_t val;
00209     val.i_int = i;
00210     return var_SetChecked( p_obj, psz_name, VLC_VAR_INTEGER, val );
00211 }
00212 
00213 /**
00214  * Set the value of an boolean variable
00215  *
00216  * \param p_obj The object that holds the variable
00217  * \param psz_name The name of the variable
00218  * \param b The new boolean value of this variable
00219  */
00220 static inline int var_SetBool( vlc_object_t *p_obj, const char *psz_name, bool b )
00221 {
00222     vlc_value_t val;
00223     val.b_bool = b;
00224     return var_SetChecked( p_obj, psz_name, VLC_VAR_BOOL, val );
00225 }
00226 
00227 /**
00228  * Set the value of a time variable
00229  *
00230  * \param p_obj The object that holds the variable
00231  * \param psz_name The name of the variable
00232  * \param i The new time value of this variable
00233  */
00234 static inline int var_SetTime( vlc_object_t *p_obj, const char *psz_name, int64_t i )
00235 {
00236     vlc_value_t val;
00237     val.i_time = i;
00238     return var_SetChecked( p_obj, psz_name, VLC_VAR_TIME, val );
00239 }
00240 
00241 static inline int var_SetCoords( vlc_object_t *obj, const char *name,
00242                                  int32_t x, int32_t y )
00243 {
00244     vlc_value_t val;
00245     val.coords.x = x;
00246     val.coords.y = y;
00247     return var_SetChecked (obj, name, VLC_VAR_COORDS, val);
00248 }
00249 #define var_SetCoords(o,n,x,y) var_SetCoords(VLC_OBJECT(o),n,x,y)
00250 
00251 /**
00252  * Set the value of a float variable
00253  *
00254  * \param p_obj The object that holds the variable
00255  * \param psz_name The name of the variable
00256  * \param f The new float value of this variable
00257  */
00258 static inline int var_SetFloat( vlc_object_t *p_obj, const char *psz_name, float f )
00259 {
00260     vlc_value_t val;
00261     val.f_float = f;
00262     return var_SetChecked( p_obj, psz_name, VLC_VAR_FLOAT, val );
00263 }
00264 
00265 /**
00266  * Set the value of a string variable
00267  *
00268  * \param p_obj The object that holds the variable
00269  * \param psz_name The name of the variable
00270  * \param psz_string The new string value of this variable
00271  */
00272 static inline int var_SetString( vlc_object_t *p_obj, const char *psz_name, const char *psz_string )
00273 {
00274     vlc_value_t val;
00275     val.psz_string = (char *)psz_string;
00276     return var_SetChecked( p_obj, psz_name, VLC_VAR_STRING, val );
00277 }
00278 
00279 /**
00280  * Set the value of a pointer variable
00281  *
00282  * \param p_obj The object that holds the variable
00283  * \param psz_name The name of the variable
00284  * \param ptr The new pointer value of this variable
00285  */
00286 static inline
00287 int var_SetAddress( vlc_object_t *p_obj, const char *psz_name, void *ptr )
00288 {
00289     vlc_value_t val;
00290     val.p_address = ptr;
00291     return var_SetChecked( p_obj, psz_name, VLC_VAR_ADDRESS, val );
00292 }
00293 
00294 #define var_SetInteger(a,b,c)   var_SetInteger( VLC_OBJECT(a),b,c)
00295 #define var_SetBool(a,b,c)      var_SetBool( VLC_OBJECT(a),b,c)
00296 #define var_SetTime(a,b,c)      var_SetTime( VLC_OBJECT(a),b,c)
00297 #define var_SetFloat(a,b,c)     var_SetFloat( VLC_OBJECT(a),b,c)
00298 #define var_SetString(a,b,c)    var_SetString( VLC_OBJECT(a),b,c)
00299 #define var_SetAddress(o, n, p) var_SetAddress(VLC_OBJECT(o), n, p)
00300 
00301 
00302 /**
00303  * Get an integer value
00304 *
00305  * \param p_obj The object that holds the variable
00306  * \param psz_name The name of the variable
00307  */
00308 VLC_USED
00309 static inline int64_t var_GetInteger( vlc_object_t *p_obj, const char *psz_name )
00310 {
00311     vlc_value_t val;
00312     if( !var_GetChecked( p_obj, psz_name, VLC_VAR_INTEGER, &val ) )
00313         return val.i_int;
00314     else
00315         return 0;
00316 }
00317 
00318 /**
00319  * Get a boolean value
00320  *
00321  * \param p_obj The object that holds the variable
00322  * \param psz_name The name of the variable
00323  */
00324 VLC_USED
00325 static inline bool var_GetBool( vlc_object_t *p_obj, const char *psz_name )
00326 {
00327     vlc_value_t val; val.b_bool = false;
00328 
00329     if( !var_GetChecked( p_obj, psz_name, VLC_VAR_BOOL, &val ) )
00330         return val.b_bool;
00331     else
00332         return false;
00333 }
00334 
00335 /**
00336  * Get a time value
00337  *
00338  * \param p_obj The object that holds the variable
00339  * \param psz_name The name of the variable
00340  */
00341 VLC_USED
00342 static inline int64_t var_GetTime( vlc_object_t *p_obj, const char *psz_name )
00343 {
00344     vlc_value_t val; val.i_time = 0L;
00345     if( !var_GetChecked( p_obj, psz_name, VLC_VAR_TIME, &val ) )
00346         return val.i_time;
00347     else
00348         return 0;
00349 }
00350 
00351 static inline void var_GetCoords( vlc_object_t *obj, const char *name,
00352                                   int32_t *px, int32_t *py )
00353 {
00354     vlc_value_t val;
00355 
00356     if (likely(!var_GetChecked (obj, name, VLC_VAR_COORDS, &val)))
00357     {
00358         *px = val.coords.x;
00359         *py = val.coords.y;
00360     }
00361     else
00362         *px = *py = 0;
00363 }
00364 #define var_GetCoords(o,n,x,y) var_GetCoords(VLC_OBJECT(o),n,x,y)
00365 
00366 /**
00367  * Get a float value
00368  *
00369  * \param p_obj The object that holds the variable
00370  * \param psz_name The name of the variable
00371  */
00372 VLC_USED
00373 static inline float var_GetFloat( vlc_object_t *p_obj, const char *psz_name )
00374 {
00375     vlc_value_t val; val.f_float = 0.0;
00376     if( !var_GetChecked( p_obj, psz_name, VLC_VAR_FLOAT, &val ) )
00377         return val.f_float;
00378     else
00379         return 0.0;
00380 }
00381 
00382 /**
00383  * Get a string value
00384  *
00385  * \param p_obj The object that holds the variable
00386  * \param psz_name The name of the variable
00387  */
00388 VLC_USED VLC_MALLOC
00389 static inline char *var_GetString( vlc_object_t *p_obj, const char *psz_name )
00390 {
00391     vlc_value_t val; val.psz_string = NULL;
00392     if( var_GetChecked( p_obj, psz_name, VLC_VAR_STRING, &val ) )
00393         return NULL;
00394     else
00395         return val.psz_string;
00396 }
00397 
00398 VLC_USED VLC_MALLOC
00399 static inline char *var_GetNonEmptyString( vlc_object_t *p_obj, const char *psz_name )
00400 {
00401     vlc_value_t val;
00402     if( var_GetChecked( p_obj, psz_name, VLC_VAR_STRING, &val ) )
00403         return NULL;
00404     if( val.psz_string && *val.psz_string )
00405         return val.psz_string;
00406     free( val.psz_string );
00407     return NULL;
00408 }
00409 
00410 VLC_USED
00411 static inline void *var_GetAddress( vlc_object_t *p_obj, const char *psz_name )
00412 {
00413     vlc_value_t val;
00414     if( var_GetChecked( p_obj, psz_name, VLC_VAR_ADDRESS, &val ) )
00415         return NULL;
00416     else
00417         return val.p_address;
00418 }
00419 
00420 /**
00421  * Increment an integer variable
00422  * \param p_obj the object that holds the variable
00423  * \param psz_name the name of the variable
00424  */
00425 static inline int64_t var_IncInteger( vlc_object_t *p_obj, const char *psz_name )
00426 {
00427     vlc_value_t val;
00428     val.i_int = 1;
00429     var_GetAndSet( p_obj, psz_name, VLC_VAR_INTEGER_ADD, &val );
00430     return val.i_int;
00431 }
00432 #define var_IncInteger(a,b) var_IncInteger( VLC_OBJECT(a), b )
00433 
00434 /**
00435  * Decrement an integer variable
00436  * \param p_obj the object that holds the variable
00437  * \param psz_name the name of the variable
00438  */
00439 static inline int64_t var_DecInteger( vlc_object_t *p_obj, const char *psz_name )
00440 {
00441     vlc_value_t val;
00442     val.i_int = -1;
00443     var_GetAndSet( p_obj, psz_name, VLC_VAR_INTEGER_ADD, &val );
00444     return val.i_int;
00445 }
00446 #define var_DecInteger(a,b) var_DecInteger( VLC_OBJECT(a), b )
00447 
00448 static inline uint64_t var_OrInteger( vlc_object_t *obj, const char *name,
00449                                       unsigned v )
00450 {
00451     vlc_value_t val;
00452     val.i_int = v;
00453     var_GetAndSet( obj, name, VLC_VAR_INTEGER_OR, &val );
00454     return val.i_int;
00455 }
00456 #define var_OrInteger(a,b,c) var_OrInteger(VLC_OBJECT(a),b,c)
00457 
00458 static inline uint64_t var_NAndInteger( vlc_object_t *obj, const char *name,
00459                                         unsigned v )
00460 {
00461     vlc_value_t val;
00462     val.i_int = v;
00463     var_GetAndSet( obj, name, VLC_VAR_INTEGER_NAND, &val );
00464     return val.i_int;
00465 }
00466 #define var_NAndInteger(a,b,c) var_NAndInteger(VLC_OBJECT(a),b,c)
00467 
00468 /**
00469  * Create a integer variable with inherit and get its value.
00470  *
00471  * \param p_obj The object that holds the variable
00472  * \param psz_name The name of the variable
00473  */
00474 VLC_USED
00475 static inline int64_t var_CreateGetInteger( vlc_object_t *p_obj, const char *psz_name )
00476 {
00477     var_Create( p_obj, psz_name, VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
00478     return var_GetInteger( p_obj, psz_name );
00479 }
00480 
00481 /**
00482  * Create a boolean variable with inherit and get its value.
00483  *
00484  * \param p_obj The object that holds the variable
00485  * \param psz_name The name of the variable
00486  */
00487 VLC_USED
00488 static inline bool var_CreateGetBool( vlc_object_t *p_obj, const char *psz_name )
00489 {
00490     var_Create( p_obj, psz_name, VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
00491     return var_GetBool( p_obj, psz_name );
00492 }
00493 
00494 /**
00495  * Create a time variable with inherit and get its value.
00496  *
00497  * \param p_obj The object that holds the variable
00498  * \param psz_name The name of the variable
00499  */
00500 VLC_USED
00501 static inline int64_t var_CreateGetTime( vlc_object_t *p_obj, const char *psz_name )
00502 {
00503     var_Create( p_obj, psz_name, VLC_VAR_TIME | VLC_VAR_DOINHERIT );
00504     return var_GetTime( p_obj, psz_name );
00505 }
00506 
00507 /**
00508  * Create a float variable with inherit and get its value.
00509  *
00510  * \param p_obj The object that holds the variable
00511  * \param psz_name The name of the variable
00512  */
00513 VLC_USED
00514 static inline float var_CreateGetFloat( vlc_object_t *p_obj, const char *psz_name )
00515 {
00516     var_Create( p_obj, psz_name, VLC_VAR_FLOAT | VLC_VAR_DOINHERIT );
00517     return var_GetFloat( p_obj, psz_name );
00518 }
00519 
00520 /**
00521  * Create a string variable with inherit and get its value.
00522  *
00523  * \param p_obj The object that holds the variable
00524  * \param psz_name The name of the variable
00525  */
00526 VLC_USED VLC_MALLOC
00527 static inline char *var_CreateGetString( vlc_object_t *p_obj,
00528                                            const char *psz_name )
00529 {
00530     var_Create( p_obj, psz_name, VLC_VAR_STRING | VLC_VAR_DOINHERIT );
00531     return var_GetString( p_obj, psz_name );
00532 }
00533 
00534 VLC_USED VLC_MALLOC
00535 static inline char *var_CreateGetNonEmptyString( vlc_object_t *p_obj,
00536                                                    const char *psz_name )
00537 {
00538     var_Create( p_obj, psz_name, VLC_VAR_STRING | VLC_VAR_DOINHERIT );
00539     return var_GetNonEmptyString( p_obj, psz_name );
00540 }
00541 
00542 /**
00543  * Create an address variable with inherit and get its value.
00544  *
00545  * \param p_obj The object that holds the variable
00546  * \param psz_name The name of the variable
00547  */
00548 VLC_USED
00549 static inline void *var_CreateGetAddress( vlc_object_t *p_obj,
00550                                            const char *psz_name )
00551 {
00552     var_Create( p_obj, psz_name, VLC_VAR_ADDRESS | VLC_VAR_DOINHERIT );
00553     return var_GetAddress( p_obj, psz_name );
00554 }
00555 
00556 #define var_CreateGetInteger(a,b)   var_CreateGetInteger( VLC_OBJECT(a),b)
00557 #define var_CreateGetBool(a,b)   var_CreateGetBool( VLC_OBJECT(a),b)
00558 #define var_CreateGetTime(a,b)   var_CreateGetTime( VLC_OBJECT(a),b)
00559 #define var_CreateGetFloat(a,b)   var_CreateGetFloat( VLC_OBJECT(a),b)
00560 #define var_CreateGetString(a,b)   var_CreateGetString( VLC_OBJECT(a),b)
00561 #define var_CreateGetNonEmptyString(a,b)   var_CreateGetNonEmptyString( VLC_OBJECT(a),b)
00562 #define var_CreateGetAddress(a,b)  var_CreateGetAddress( VLC_OBJECT(a),b)
00563 
00564 /**
00565  * Create a integer command variable with inherit and get its value.
00566  *
00567  * \param p_obj The object that holds the variable
00568  * \param psz_name The name of the variable
00569  */
00570 VLC_USED
00571 static inline int64_t var_CreateGetIntegerCommand( vlc_object_t *p_obj, const char *psz_name )
00572 {
00573     var_Create( p_obj, psz_name, VLC_VAR_INTEGER | VLC_VAR_DOINHERIT
00574                                    | VLC_VAR_ISCOMMAND );
00575     return var_GetInteger( p_obj, psz_name );
00576 }
00577 
00578 /**
00579  * Create a boolean command variable with inherit and get its value.
00580  *
00581  * \param p_obj The object that holds the variable
00582  * \param psz_name The name of the variable
00583  */
00584 VLC_USED
00585 static inline bool var_CreateGetBoolCommand( vlc_object_t *p_obj, const char *psz_name )
00586 {
00587     var_Create( p_obj, psz_name, VLC_VAR_BOOL | VLC_VAR_DOINHERIT
00588                                    | VLC_VAR_ISCOMMAND );
00589     return var_GetBool( p_obj, psz_name );
00590 }
00591 
00592 /**
00593  * Create a time command variable with inherit and get its value.
00594  *
00595  * \param p_obj The object that holds the variable
00596  * \param psz_name The name of the variable
00597  */
00598 VLC_USED
00599 static inline int64_t var_CreateGetTimeCommand( vlc_object_t *p_obj, const char *psz_name )
00600 {
00601     var_Create( p_obj, psz_name, VLC_VAR_TIME | VLC_VAR_DOINHERIT
00602                                    | VLC_VAR_ISCOMMAND );
00603     return var_GetTime( p_obj, psz_name );
00604 }
00605 
00606 /**
00607  * Create a float command variable with inherit and get its value.
00608  *
00609  * \param p_obj The object that holds the variable
00610  * \param psz_name The name of the variable
00611  */
00612 VLC_USED
00613 static inline float var_CreateGetFloatCommand( vlc_object_t *p_obj, const char *psz_name )
00614 {
00615     var_Create( p_obj, psz_name, VLC_VAR_FLOAT | VLC_VAR_DOINHERIT
00616                                    | VLC_VAR_ISCOMMAND );
00617     return var_GetFloat( p_obj, psz_name );
00618 }
00619 
00620 /**
00621  * Create a string command variable with inherit and get its value.
00622  *
00623  * \param p_obj The object that holds the variable
00624  * \param psz_name The name of the variable
00625  */
00626 VLC_USED VLC_MALLOC
00627 static inline char *var_CreateGetStringCommand( vlc_object_t *p_obj,
00628                                            const char *psz_name )
00629 {
00630     var_Create( p_obj, psz_name, VLC_VAR_STRING | VLC_VAR_DOINHERIT
00631                                    | VLC_VAR_ISCOMMAND );
00632     return var_GetString( p_obj, psz_name );
00633 }
00634 
00635 VLC_USED VLC_MALLOC
00636 static inline char *var_CreateGetNonEmptyStringCommand( vlc_object_t *p_obj,
00637                                                    const char *psz_name )
00638 {
00639     var_Create( p_obj, psz_name, VLC_VAR_STRING | VLC_VAR_DOINHERIT
00640                                    | VLC_VAR_ISCOMMAND );
00641     return var_GetNonEmptyString( p_obj, psz_name );
00642 }
00643 
00644 #define var_CreateGetIntegerCommand(a,b)   var_CreateGetIntegerCommand( VLC_OBJECT(a),b)
00645 #define var_CreateGetBoolCommand(a,b)   var_CreateGetBoolCommand( VLC_OBJECT(a),b)
00646 #define var_CreateGetTimeCommand(a,b)   var_CreateGetTimeCommand( VLC_OBJECT(a),b)
00647 #define var_CreateGetFloatCommand(a,b)   var_CreateGetFloatCommand( VLC_OBJECT(a),b)
00648 #define var_CreateGetStringCommand(a,b)   var_CreateGetStringCommand( VLC_OBJECT(a),b)
00649 #define var_CreateGetNonEmptyStringCommand(a,b)   var_CreateGetNonEmptyStringCommand( VLC_OBJECT(a),b)
00650 
00651 VLC_USED
00652 static inline int var_CountChoices( vlc_object_t *p_obj, const char *psz_name )
00653 {
00654     vlc_value_t count;
00655     if( var_Change( p_obj, psz_name, VLC_VAR_CHOICESCOUNT, &count, NULL ) )
00656         return 0;
00657     return count.i_int;
00658 }
00659 #define var_CountChoices(a,b) var_CountChoices( VLC_OBJECT(a),b)
00660 
00661 
00662 static inline bool var_ToggleBool( vlc_object_t *p_obj, const char *psz_name )
00663 {
00664     vlc_value_t val;
00665     var_GetAndSet( p_obj, psz_name, VLC_VAR_BOOL_TOGGLE, &val );
00666     return val.b_bool;
00667 }
00668 #define var_ToggleBool(a,b) var_ToggleBool( VLC_OBJECT(a),b )
00669 
00670 
00671 VLC_USED
00672 static inline bool var_InheritBool( vlc_object_t *obj, const char *name )
00673 {
00674     vlc_value_t val;
00675 
00676     if( var_Inherit( obj, name, VLC_VAR_BOOL, &val ) )
00677         val.b_bool = false;
00678     return val.b_bool;
00679 }
00680 #define var_InheritBool(o, n) var_InheritBool(VLC_OBJECT(o), n)
00681 
00682 VLC_USED
00683 static inline int64_t var_InheritInteger( vlc_object_t *obj, const char *name )
00684 {
00685     vlc_value_t val;
00686 
00687     if( var_Inherit( obj, name, VLC_VAR_INTEGER, &val ) )
00688         val.i_int = 0;
00689     return val.i_int;
00690 }
00691 #define var_InheritInteger(o, n) var_InheritInteger(VLC_OBJECT(o), n)
00692 
00693 VLC_USED
00694 static inline float var_InheritFloat( vlc_object_t *obj, const char *name )
00695 {
00696     vlc_value_t val;
00697 
00698     if( var_Inherit( obj, name, VLC_VAR_FLOAT, &val ) )
00699         val.f_float = 0.;
00700     return val.f_float;
00701 }
00702 #define var_InheritFloat(o, n) var_InheritFloat(VLC_OBJECT(o), n)
00703 
00704 VLC_USED VLC_MALLOC
00705 static inline char *var_InheritString( vlc_object_t *obj, const char *name )
00706 {
00707     vlc_value_t val;
00708 
00709     if( var_Inherit( obj, name, VLC_VAR_STRING, &val ) )
00710         val.psz_string = NULL;
00711     else if( val.psz_string && !*val.psz_string )
00712     {
00713         free( val.psz_string );
00714         val.psz_string = NULL;
00715     }
00716     return val.psz_string;
00717 }
00718 #define var_InheritString(o, n) var_InheritString(VLC_OBJECT(o), n)
00719 
00720 VLC_USED
00721 static inline mtime_t var_InheritTime( vlc_object_t *obj, const char *name )
00722 {
00723     vlc_value_t val;
00724 
00725     if( var_Inherit( obj, name, VLC_VAR_TIME, &val ) )
00726         val.i_time = 0;
00727     return val.i_time;
00728 }
00729 #define var_InheritTime(o, n) var_InheritTime(VLC_OBJECT(o), n)
00730 
00731 VLC_USED
00732 static inline void *var_InheritAddress( vlc_object_t *obj, const char *name )
00733 {
00734     vlc_value_t val;
00735 
00736     if( var_Inherit( obj, name, VLC_VAR_ADDRESS, &val ) )
00737         val.p_address = NULL;
00738     return val.p_address;
00739 }
00740 #define var_InheritAddress(o, n) var_InheritAddress(VLC_OBJECT(o), n)
00741 
00742 VLC_API int var_InheritURational( vlc_object_t *, unsigned *num, unsigned *den, const char *var );
00743 #define var_InheritURational(a,b,c,d) var_InheritURational(VLC_OBJECT(a), b, c, d)
00744 
00745 #define var_GetInteger(a,b)   var_GetInteger( VLC_OBJECT(a),b)
00746 #define var_GetBool(a,b)   var_GetBool( VLC_OBJECT(a),b)
00747 #define var_GetTime(a,b)   var_GetTime( VLC_OBJECT(a),b)
00748 #define var_GetFloat(a,b)   var_GetFloat( VLC_OBJECT(a),b)
00749 #define var_GetString(a,b)   var_GetString( VLC_OBJECT(a),b)
00750 #define var_GetNonEmptyString(a,b)   var_GetNonEmptyString( VLC_OBJECT(a),b)
00751 #define var_GetAddress(a,b)  var_GetAddress( VLC_OBJECT(a),b)
00752 
00753 VLC_API int var_LocationParse(vlc_object_t *, const char *mrl, const char *prefix);
00754 #define var_LocationParse(o, m, p) var_LocationParse(VLC_OBJECT(o), m, p)
00755 
00756 /**
00757  * @}
00758  */
00759 #endif /*  _VLC_VARIABLES_H */
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines