| 1 | /***************************************************************************** |
| 2 | * vlc_variables.h: variables handling |
| 3 | ***************************************************************************** |
| 4 | * Copyright (C) 2002-2004 VLC authors and VideoLAN |
| 5 | * $Id: 83752b171f82c86164142a6254f513fc9cb7a324 $ |
| 6 | * |
| 7 | * Authors: Samuel Hocevar <sam@zoy.org> |
| 8 | * Gildas Bazin <gbazin@netcourrier.com> |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify it |
| 11 | * under the terms of the GNU Lesser General Public License as published by |
| 12 | * the Free Software Foundation; either version 2.1 of the License, or |
| 13 | * (at your option) any later version. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | * GNU Lesser General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU Lesser General Public License |
| 21 | * along with this program; if not, write to the Free Software Foundation, |
| 22 | * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. |
| 23 | *****************************************************************************/ |
| 24 | |
| 25 | #ifndef VLC_VARIABLES_H |
| 26 | #define VLC_VARIABLES_H 1 |
| 27 | |
| 28 | /** |
| 29 | * \defgroup variables Variables |
| 30 | * \ingroup vlc_object |
| 31 | * |
| 32 | * VLC object variables and callbacks |
| 33 | * |
| 34 | * @{ |
| 35 | * \file |
| 36 | * VLC object variables and callbacks interface |
| 37 | */ |
| 38 | |
| 39 | #define VLC_VAR_TYPE 0x00ff |
| 40 | #define VLC_VAR_CLASS 0x00f0 |
| 41 | #define VLC_VAR_FLAGS 0xff00 |
| 42 | |
| 43 | /** |
| 44 | * \defgroup var_type Variable types |
| 45 | * These are the different types a vlc variable can have. |
| 46 | * @{ |
| 47 | */ |
| 48 | #define VLC_VAR_VOID 0x0010 |
| 49 | #define VLC_VAR_BOOL 0x0020 |
| 50 | #define VLC_VAR_INTEGER 0x0030 |
| 51 | #define VLC_VAR_STRING 0x0040 |
| 52 | #define VLC_VAR_FLOAT 0x0050 |
| 53 | #define VLC_VAR_ADDRESS 0x0070 |
| 54 | #define VLC_VAR_COORDS 0x00A0 |
| 55 | /**@}*/ |
| 56 | |
| 57 | /** \defgroup var_flags Additive flags |
| 58 | * These flags are added to the type field of the variable. Most as a result of |
| 59 | * a var_Change() call, but some may be added at creation time |
| 60 | * @{ |
| 61 | */ |
| 62 | #define VLC_VAR_HASCHOICE 0x0100 |
| 63 | |
| 64 | #define VLC_VAR_ISCOMMAND 0x2000 |
| 65 | |
| 66 | /** Creation flag */ |
| 67 | /* If the variable is not found on the current module |
| 68 | search all parents and finally module config until found */ |
| 69 | #define VLC_VAR_DOINHERIT 0x8000 |
| 70 | /**@}*/ |
| 71 | |
| 72 | /** |
| 73 | * \defgroup var_action Variable actions |
| 74 | * These are the different actions that can be used with var_Change(). |
| 75 | * The parameters given are the meaning of the two last parameters of |
| 76 | * var_Change() when this action is being used. |
| 77 | * @{ |
| 78 | */ |
| 79 | |
| 80 | #define VLC_VAR_SETSTEP 0x0012 |
| 81 | |
| 82 | /** |
| 83 | * Set the value of this variable without triggering any callbacks |
| 84 | * \param p_val The new value |
| 85 | * \param p_val2 Unused |
| 86 | */ |
| 87 | #define VLC_VAR_SETVALUE 0x0013 |
| 88 | |
| 89 | #define VLC_VAR_SETTEXT 0x0014 |
| 90 | #define VLC_VAR_GETTEXT 0x0015 |
| 91 | |
| 92 | #define VLC_VAR_GETMIN 0x0016 |
| 93 | #define VLC_VAR_GETMAX 0x0017 |
| 94 | #define VLC_VAR_GETSTEP 0x0018 |
| 95 | |
| 96 | #define VLC_VAR_ADDCHOICE 0x0020 |
| 97 | #define VLC_VAR_DELCHOICE 0x0021 |
| 98 | #define VLC_VAR_CLEARCHOICES 0x0022 |
| 99 | #define VLC_VAR_GETCHOICES 0x0024 |
| 100 | |
| 101 | #define VLC_VAR_CHOICESCOUNT 0x0026 |
| 102 | #define VLC_VAR_SETMINMAX 0x0027 |
| 103 | |
| 104 | /**@}*/ |
| 105 | |
| 106 | /** \defgroup var_GetAndSet Variable actions |
| 107 | * These are the different actions that can be used with var_GetAndSet() |
| 108 | * @{ |
| 109 | */ |
| 110 | enum { |
| 111 | VLC_VAR_BOOL_TOGGLE, /**< Invert a boolean value (param ignored) */ |
| 112 | VLC_VAR_INTEGER_ADD, /**< Add parameter to an integer value */ |
| 113 | VLC_VAR_INTEGER_OR, /**< Binary OR over an integer bits field */ |
| 114 | VLC_VAR_INTEGER_NAND,/**< Binary NAND over an integer bits field */ |
| 115 | }; |
| 116 | /**@}*/ |
| 117 | |
| 118 | /***************************************************************************** |
| 119 | * Prototypes |
| 120 | *****************************************************************************/ |
| 121 | VLC_API int var_Create( vlc_object_t *, const char *, int ); |
| 122 | #define var_Create(a,b,c) var_Create( VLC_OBJECT(a), b, c ) |
| 123 | |
| 124 | VLC_API void var_Destroy( vlc_object_t *, const char * ); |
| 125 | #define var_Destroy(a,b) var_Destroy( VLC_OBJECT(a), b ) |
| 126 | |
| 127 | VLC_API int var_Change( vlc_object_t *, const char *, int, vlc_value_t *, vlc_value_t * ); |
| 128 | #define var_Change(a,b,c,d,e) var_Change( VLC_OBJECT(a), b, c, d, e ) |
| 129 | |
| 130 | VLC_API int var_Type( vlc_object_t *, const char * ) VLC_USED; |
| 131 | #define var_Type(a,b) var_Type( VLC_OBJECT(a), b ) |
| 132 | |
| 133 | VLC_API int var_Set( vlc_object_t *, const char *, vlc_value_t ); |
| 134 | #define var_Set(a,b,c) var_Set( VLC_OBJECT(a), b, c ) |
| 135 | |
| 136 | VLC_API int var_Get( vlc_object_t *, const char *, vlc_value_t * ); |
| 137 | #define var_Get(a,b,c) var_Get( VLC_OBJECT(a), b, c ) |
| 138 | |
| 139 | VLC_API int var_SetChecked( vlc_object_t *, const char *, int, vlc_value_t ); |
| 140 | #define var_SetChecked(o,n,t,v) var_SetChecked(VLC_OBJECT(o),n,t,v) |
| 141 | VLC_API int var_GetChecked( vlc_object_t *, const char *, int, vlc_value_t * ); |
| 142 | #define var_GetChecked(o,n,t,v) var_GetChecked(VLC_OBJECT(o),n,t,v) |
| 143 | VLC_API int var_GetAndSet( vlc_object_t *, const char *, int, vlc_value_t * ); |
| 144 | |
| 145 | VLC_API int var_Inherit( vlc_object_t *, const char *, int, vlc_value_t * ); |
| 146 | |
| 147 | VLC_API void var_FreeList( vlc_value_t *, vlc_value_t * ); |
| 148 | |
| 149 | |
| 150 | /***************************************************************************** |
| 151 | * Variable callbacks |
| 152 | ***************************************************************************** |
| 153 | * int MyCallback( vlc_object_t *p_this, |
| 154 | * char const *psz_variable, |
| 155 | * vlc_value_t oldvalue, |
| 156 | * vlc_value_t newvalue, |
| 157 | * void *p_data); |
| 158 | *****************************************************************************/ |
| 159 | VLC_API void var_AddCallback( vlc_object_t *, const char *, vlc_callback_t, void * ); |
| 160 | VLC_API void var_DelCallback( vlc_object_t *, const char *, vlc_callback_t, void * ); |
| 161 | VLC_API void var_TriggerCallback( vlc_object_t *, const char * ); |
| 162 | |
| 163 | VLC_API void var_AddListCallback( vlc_object_t *, const char *, vlc_list_callback_t, void * ); |
| 164 | VLC_API void var_DelListCallback( vlc_object_t *, const char *, vlc_list_callback_t, void * ); |
| 165 | |
| 166 | #define var_AddCallback(a,b,c,d) var_AddCallback( VLC_OBJECT(a), b, c, d ) |
| 167 | #define var_DelCallback(a,b,c,d) var_DelCallback( VLC_OBJECT(a), b, c, d ) |
| 168 | #define var_TriggerCallback(a,b) var_TriggerCallback( VLC_OBJECT(a), b ) |
| 169 | |
| 170 | #define var_AddListCallback(a,b,c,d) var_AddListCallback( VLC_OBJECT(a), b, c, d ) |
| 171 | #define var_DelListCallback(a,b,c,d) var_DelListCallback( VLC_OBJECT(a), b, c, d ) |
| 172 | |
| 173 | /***************************************************************************** |
| 174 | * helpers functions |
| 175 | *****************************************************************************/ |
| 176 | |
| 177 | /** |
| 178 | * Set the value of an integer variable |
| 179 | * |
| 180 | * \param p_obj The object that holds the variable |
| 181 | * \param psz_name The name of the variable |
| 182 | * \param i The new integer value of this variable |
| 183 | */ |
| 184 | static inline int var_SetInteger( vlc_object_t *p_obj, const char *psz_name, |
| 185 | int64_t i ) |
| 186 | { |
| 187 | vlc_value_t val; |
| 188 | val.i_int = i; |
| 189 | return var_SetChecked( p_obj, psz_name, VLC_VAR_INTEGER, val ); |
| 190 | } |
| 191 | |
| 192 | /** |
| 193 | * Set the value of an boolean variable |
| 194 | * |
| 195 | * \param p_obj The object that holds the variable |
| 196 | * \param psz_name The name of the variable |
| 197 | * \param b The new boolean value of this variable |
| 198 | */ |
| 199 | static inline int var_SetBool( vlc_object_t *p_obj, const char *psz_name, bool b ) |
| 200 | { |
| 201 | vlc_value_t val; |
| 202 | val.b_bool = b; |
| 203 | return var_SetChecked( p_obj, psz_name, VLC_VAR_BOOL, val ); |
| 204 | } |
| 205 | |
| 206 | static inline int var_SetCoords( vlc_object_t *obj, const char *name, |
| 207 | int32_t x, int32_t y ) |
| 208 | { |
| 209 | vlc_value_t val; |
| 210 | val.coords.x = x; |
| 211 | val.coords.y = y; |
| 212 | return var_SetChecked (obj, name, VLC_VAR_COORDS, val); |
| 213 | } |
| 214 | #define var_SetCoords(o,n,x,y) var_SetCoords(VLC_OBJECT(o),n,x,y) |
| 215 | |
| 216 | /** |
| 217 | * Set the value of a float variable |
| 218 | * |
| 219 | * \param p_obj The object that holds the variable |
| 220 | * \param psz_name The name of the variable |
| 221 | * \param f The new float value of this variable |
| 222 | */ |
| 223 | static inline int var_SetFloat( vlc_object_t *p_obj, const char *psz_name, float f ) |
| 224 | { |
| 225 | vlc_value_t val; |
| 226 | val.f_float = f; |
| 227 | return var_SetChecked( p_obj, psz_name, VLC_VAR_FLOAT, val ); |
| 228 | } |
| 229 | |
| 230 | /** |
| 231 | * Set the value of a string variable |
| 232 | * |
| 233 | * \param p_obj The object that holds the variable |
| 234 | * \param psz_name The name of the variable |
| 235 | * \param psz_string The new string value of this variable |
| 236 | */ |
| 237 | static inline int var_SetString( vlc_object_t *p_obj, const char *psz_name, const char *psz_string ) |
| 238 | { |
| 239 | vlc_value_t val; |
| 240 | val.psz_string = (char *)psz_string; |
| 241 | return var_SetChecked( p_obj, psz_name, VLC_VAR_STRING, val ); |
| 242 | } |
| 243 | |
| 244 | /** |
| 245 | * Set the value of a pointer variable |
| 246 | * |
| 247 | * \param p_obj The object that holds the variable |
| 248 | * \param psz_name The name of the variable |
| 249 | * \param ptr The new pointer value of this variable |
| 250 | */ |
| 251 | static inline |
| 252 | int var_SetAddress( vlc_object_t *p_obj, const char *psz_name, void *ptr ) |
| 253 | { |
| 254 | vlc_value_t val; |
| 255 | val.p_address = ptr; |
| 256 | return var_SetChecked( p_obj, psz_name, VLC_VAR_ADDRESS, val ); |
| 257 | } |
| 258 | |
| 259 | #define var_SetInteger(a,b,c) var_SetInteger( VLC_OBJECT(a),b,c) |
| 260 | #define var_SetBool(a,b,c) var_SetBool( VLC_OBJECT(a),b,c) |
| 261 | #define var_SetFloat(a,b,c) var_SetFloat( VLC_OBJECT(a),b,c) |
| 262 | #define var_SetString(a,b,c) var_SetString( VLC_OBJECT(a),b,c) |
| 263 | #define var_SetAddress(o, n, p) var_SetAddress(VLC_OBJECT(o), n, p) |
| 264 | |
| 265 | |
| 266 | /** |
| 267 | * Get an integer value |
| 268 | * |
| 269 | * \param p_obj The object that holds the variable |
| 270 | * \param psz_name The name of the variable |
| 271 | */ |
| 272 | VLC_USED |
| 273 | static inline int64_t var_GetInteger( vlc_object_t *p_obj, const char *psz_name ) |
| 274 | { |
| 275 | vlc_value_t val; |
| 276 | if( !var_GetChecked( p_obj, psz_name, VLC_VAR_INTEGER, &val ) ) |
| 277 | return val.i_int; |
| 278 | else |
| 279 | return 0; |
| 280 | } |
| 281 | |
| 282 | /** |
| 283 | * Get a boolean value |
| 284 | * |
| 285 | * \param p_obj The object that holds the variable |
| 286 | * \param psz_name The name of the variable |
| 287 | */ |
| 288 | VLC_USED |
| 289 | static inline bool var_GetBool( vlc_object_t *p_obj, const char *psz_name ) |
| 290 | { |
| 291 | vlc_value_t val; val.b_bool = false; |
| 292 | |
| 293 | if( !var_GetChecked( p_obj, psz_name, VLC_VAR_BOOL, &val ) ) |
| 294 | return val.b_bool; |
| 295 | else |
| 296 | return false; |
| 297 | } |
| 298 | |
| 299 | static inline void var_GetCoords( vlc_object_t *obj, const char *name, |
| 300 | int32_t *px, int32_t *py ) |
| 301 | { |
| 302 | vlc_value_t val; |
| 303 | |
| 304 | if (likely(!var_GetChecked (obj, name, VLC_VAR_COORDS, &val))) |
| 305 | { |
| 306 | *px = val.coords.x; |
| 307 | *py = val.coords.y; |
| 308 | } |
| 309 | else |
| 310 | *px = *py = 0; |
| 311 | } |
| 312 | #define var_GetCoords(o,n,x,y) var_GetCoords(VLC_OBJECT(o),n,x,y) |
| 313 | |
| 314 | /** |
| 315 | * Get a float value |
| 316 | * |
| 317 | * \param p_obj The object that holds the variable |
| 318 | * \param psz_name The name of the variable |
| 319 | */ |
| 320 | VLC_USED |
| 321 | static inline float var_GetFloat( vlc_object_t *p_obj, const char *psz_name ) |
| 322 | { |
| 323 | vlc_value_t val; val.f_float = 0.0; |
| 324 | if( !var_GetChecked( p_obj, psz_name, VLC_VAR_FLOAT, &val ) ) |
| 325 | return val.f_float; |
| 326 | else |
| 327 | return 0.0; |
| 328 | } |
| 329 | |
| 330 | /** |
| 331 | * Get a string value |
| 332 | * |
| 333 | * \param p_obj The object that holds the variable |
| 334 | * \param psz_name The name of the variable |
| 335 | */ |
| 336 | VLC_USED VLC_MALLOC |
| 337 | static inline char *var_GetString( vlc_object_t *p_obj, const char *psz_name ) |
| 338 | { |
| 339 | vlc_value_t val; val.psz_string = NULL; |
| 340 | if( var_GetChecked( p_obj, psz_name, VLC_VAR_STRING, &val ) ) |
| 341 | return NULL; |
| 342 | else |
| 343 | return val.psz_string; |
| 344 | } |
| 345 | |
| 346 | VLC_USED VLC_MALLOC |
| 347 | static inline char *var_GetNonEmptyString( vlc_object_t *p_obj, const char *psz_name ) |
| 348 | { |
| 349 | vlc_value_t val; |
| 350 | if( var_GetChecked( p_obj, psz_name, VLC_VAR_STRING, &val ) ) |
| 351 | return NULL; |
| 352 | if( val.psz_string && *val.psz_string ) |
| 353 | return val.psz_string; |
| 354 | free( ptr: val.psz_string ); |
| 355 | return NULL; |
| 356 | } |
| 357 | |
| 358 | VLC_USED |
| 359 | static inline void *var_GetAddress( vlc_object_t *p_obj, const char *psz_name ) |
| 360 | { |
| 361 | vlc_value_t val; |
| 362 | if( var_GetChecked( p_obj, psz_name, VLC_VAR_ADDRESS, &val ) ) |
| 363 | return NULL; |
| 364 | else |
| 365 | return val.p_address; |
| 366 | } |
| 367 | |
| 368 | /** |
| 369 | * Increment an integer variable |
| 370 | * \param p_obj the object that holds the variable |
| 371 | * \param psz_name the name of the variable |
| 372 | */ |
| 373 | static inline int64_t var_IncInteger( vlc_object_t *p_obj, const char *psz_name ) |
| 374 | { |
| 375 | vlc_value_t val; |
| 376 | val.i_int = 1; |
| 377 | if( var_GetAndSet( p_obj, psz_name, VLC_VAR_INTEGER_ADD, &val ) ) |
| 378 | return 0; |
| 379 | return val.i_int; |
| 380 | } |
| 381 | #define var_IncInteger(a,b) var_IncInteger( VLC_OBJECT(a), b ) |
| 382 | |
| 383 | /** |
| 384 | * Decrement an integer variable |
| 385 | * \param p_obj the object that holds the variable |
| 386 | * \param psz_name the name of the variable |
| 387 | */ |
| 388 | static inline int64_t var_DecInteger( vlc_object_t *p_obj, const char *psz_name ) |
| 389 | { |
| 390 | vlc_value_t val; |
| 391 | val.i_int = -1; |
| 392 | if( var_GetAndSet( p_obj, psz_name, VLC_VAR_INTEGER_ADD, &val ) ) |
| 393 | return 0; |
| 394 | return val.i_int; |
| 395 | } |
| 396 | #define var_DecInteger(a,b) var_DecInteger( VLC_OBJECT(a), b ) |
| 397 | |
| 398 | static inline uint64_t var_OrInteger( vlc_object_t *obj, const char *name, |
| 399 | unsigned v ) |
| 400 | { |
| 401 | vlc_value_t val; |
| 402 | val.i_int = v; |
| 403 | if( var_GetAndSet( obj, name, VLC_VAR_INTEGER_OR, &val ) ) |
| 404 | return 0; |
| 405 | return val.i_int; |
| 406 | } |
| 407 | #define var_OrInteger(a,b,c) var_OrInteger(VLC_OBJECT(a),b,c) |
| 408 | |
| 409 | static inline uint64_t var_NAndInteger( vlc_object_t *obj, const char *name, |
| 410 | unsigned v ) |
| 411 | { |
| 412 | vlc_value_t val; |
| 413 | val.i_int = v; |
| 414 | if( var_GetAndSet( obj, name, VLC_VAR_INTEGER_NAND, &val ) ) |
| 415 | return 0; |
| 416 | return val.i_int; |
| 417 | } |
| 418 | #define var_NAndInteger(a,b,c) var_NAndInteger(VLC_OBJECT(a),b,c) |
| 419 | |
| 420 | /** |
| 421 | * Create a integer variable with inherit and get its value. |
| 422 | * |
| 423 | * \param p_obj The object that holds the variable |
| 424 | * \param psz_name The name of the variable |
| 425 | */ |
| 426 | VLC_USED |
| 427 | static inline int64_t var_CreateGetInteger( vlc_object_t *p_obj, const char *psz_name ) |
| 428 | { |
| 429 | var_Create( p_obj, psz_name, VLC_VAR_INTEGER | VLC_VAR_DOINHERIT ); |
| 430 | return var_GetInteger( p_obj, psz_name ); |
| 431 | } |
| 432 | |
| 433 | /** |
| 434 | * Create a boolean variable with inherit and get its value. |
| 435 | * |
| 436 | * \param p_obj The object that holds the variable |
| 437 | * \param psz_name The name of the variable |
| 438 | */ |
| 439 | VLC_USED |
| 440 | static inline bool var_CreateGetBool( vlc_object_t *p_obj, const char *psz_name ) |
| 441 | { |
| 442 | var_Create( p_obj, psz_name, VLC_VAR_BOOL | VLC_VAR_DOINHERIT ); |
| 443 | return var_GetBool( p_obj, psz_name ); |
| 444 | } |
| 445 | |
| 446 | /** |
| 447 | * Create a float variable with inherit and get its value. |
| 448 | * |
| 449 | * \param p_obj The object that holds the variable |
| 450 | * \param psz_name The name of the variable |
| 451 | */ |
| 452 | VLC_USED |
| 453 | static inline float var_CreateGetFloat( vlc_object_t *p_obj, const char *psz_name ) |
| 454 | { |
| 455 | var_Create( p_obj, psz_name, VLC_VAR_FLOAT | VLC_VAR_DOINHERIT ); |
| 456 | return var_GetFloat( p_obj, psz_name ); |
| 457 | } |
| 458 | |
| 459 | /** |
| 460 | * Create a string variable with inherit and get its value. |
| 461 | * |
| 462 | * \param p_obj The object that holds the variable |
| 463 | * \param psz_name The name of the variable |
| 464 | */ |
| 465 | VLC_USED VLC_MALLOC |
| 466 | static inline char *var_CreateGetString( vlc_object_t *p_obj, |
| 467 | const char *psz_name ) |
| 468 | { |
| 469 | var_Create( p_obj, psz_name, VLC_VAR_STRING | VLC_VAR_DOINHERIT ); |
| 470 | return var_GetString( p_obj, psz_name ); |
| 471 | } |
| 472 | |
| 473 | VLC_USED VLC_MALLOC |
| 474 | static inline char *var_CreateGetNonEmptyString( vlc_object_t *p_obj, |
| 475 | const char *psz_name ) |
| 476 | { |
| 477 | var_Create( p_obj, psz_name, VLC_VAR_STRING | VLC_VAR_DOINHERIT ); |
| 478 | return var_GetNonEmptyString( p_obj, psz_name ); |
| 479 | } |
| 480 | |
| 481 | /** |
| 482 | * Create an address variable with inherit and get its value. |
| 483 | * |
| 484 | * \param p_obj The object that holds the variable |
| 485 | * \param psz_name The name of the variable |
| 486 | */ |
| 487 | VLC_USED |
| 488 | static inline void *var_CreateGetAddress( vlc_object_t *p_obj, |
| 489 | const char *psz_name ) |
| 490 | { |
| 491 | var_Create( p_obj, psz_name, VLC_VAR_ADDRESS | VLC_VAR_DOINHERIT ); |
| 492 | return var_GetAddress( p_obj, psz_name ); |
| 493 | } |
| 494 | |
| 495 | #define var_CreateGetInteger(a,b) var_CreateGetInteger( VLC_OBJECT(a),b) |
| 496 | #define var_CreateGetBool(a,b) var_CreateGetBool( VLC_OBJECT(a),b) |
| 497 | #define var_CreateGetFloat(a,b) var_CreateGetFloat( VLC_OBJECT(a),b) |
| 498 | #define var_CreateGetString(a,b) var_CreateGetString( VLC_OBJECT(a),b) |
| 499 | #define var_CreateGetNonEmptyString(a,b) var_CreateGetNonEmptyString( VLC_OBJECT(a),b) |
| 500 | #define var_CreateGetAddress(a,b) var_CreateGetAddress( VLC_OBJECT(a),b) |
| 501 | |
| 502 | /** |
| 503 | * Create a integer command variable with inherit and get its value. |
| 504 | * |
| 505 | * \param p_obj The object that holds the variable |
| 506 | * \param psz_name The name of the variable |
| 507 | */ |
| 508 | VLC_USED |
| 509 | static inline int64_t var_CreateGetIntegerCommand( vlc_object_t *p_obj, const char *psz_name ) |
| 510 | { |
| 511 | var_Create( p_obj, psz_name, VLC_VAR_INTEGER | VLC_VAR_DOINHERIT |
| 512 | | VLC_VAR_ISCOMMAND ); |
| 513 | return var_GetInteger( p_obj, psz_name ); |
| 514 | } |
| 515 | |
| 516 | /** |
| 517 | * Create a boolean command variable with inherit and get its value. |
| 518 | * |
| 519 | * \param p_obj The object that holds the variable |
| 520 | * \param psz_name The name of the variable |
| 521 | */ |
| 522 | VLC_USED |
| 523 | static inline bool var_CreateGetBoolCommand( vlc_object_t *p_obj, const char *psz_name ) |
| 524 | { |
| 525 | var_Create( p_obj, psz_name, VLC_VAR_BOOL | VLC_VAR_DOINHERIT |
| 526 | | VLC_VAR_ISCOMMAND ); |
| 527 | return var_GetBool( p_obj, psz_name ); |
| 528 | } |
| 529 | |
| 530 | /** |
| 531 | * Create a float command variable with inherit and get its value. |
| 532 | * |
| 533 | * \param p_obj The object that holds the variable |
| 534 | * \param psz_name The name of the variable |
| 535 | */ |
| 536 | VLC_USED |
| 537 | static inline float var_CreateGetFloatCommand( vlc_object_t *p_obj, const char *psz_name ) |
| 538 | { |
| 539 | var_Create( p_obj, psz_name, VLC_VAR_FLOAT | VLC_VAR_DOINHERIT |
| 540 | | VLC_VAR_ISCOMMAND ); |
| 541 | return var_GetFloat( p_obj, psz_name ); |
| 542 | } |
| 543 | |
| 544 | /** |
| 545 | * Create a string command variable with inherit and get its value. |
| 546 | * |
| 547 | * \param p_obj The object that holds the variable |
| 548 | * \param psz_name The name of the variable |
| 549 | */ |
| 550 | VLC_USED VLC_MALLOC |
| 551 | static inline char *var_CreateGetStringCommand( vlc_object_t *p_obj, |
| 552 | const char *psz_name ) |
| 553 | { |
| 554 | var_Create( p_obj, psz_name, VLC_VAR_STRING | VLC_VAR_DOINHERIT |
| 555 | | VLC_VAR_ISCOMMAND ); |
| 556 | return var_GetString( p_obj, psz_name ); |
| 557 | } |
| 558 | |
| 559 | VLC_USED VLC_MALLOC |
| 560 | static inline char *var_CreateGetNonEmptyStringCommand( vlc_object_t *p_obj, |
| 561 | const char *psz_name ) |
| 562 | { |
| 563 | var_Create( p_obj, psz_name, VLC_VAR_STRING | VLC_VAR_DOINHERIT |
| 564 | | VLC_VAR_ISCOMMAND ); |
| 565 | return var_GetNonEmptyString( p_obj, psz_name ); |
| 566 | } |
| 567 | |
| 568 | #define var_CreateGetIntegerCommand(a,b) var_CreateGetIntegerCommand( VLC_OBJECT(a),b) |
| 569 | #define var_CreateGetBoolCommand(a,b) var_CreateGetBoolCommand( VLC_OBJECT(a),b) |
| 570 | #define var_CreateGetFloatCommand(a,b) var_CreateGetFloatCommand( VLC_OBJECT(a),b) |
| 571 | #define var_CreateGetStringCommand(a,b) var_CreateGetStringCommand( VLC_OBJECT(a),b) |
| 572 | #define var_CreateGetNonEmptyStringCommand(a,b) var_CreateGetNonEmptyStringCommand( VLC_OBJECT(a),b) |
| 573 | |
| 574 | VLC_USED |
| 575 | static inline int var_CountChoices( vlc_object_t *p_obj, const char *psz_name ) |
| 576 | { |
| 577 | vlc_value_t count; |
| 578 | if( var_Change( p_obj, psz_name, VLC_VAR_CHOICESCOUNT, &count, NULL ) ) |
| 579 | return 0; |
| 580 | return count.i_int; |
| 581 | } |
| 582 | #define var_CountChoices(a,b) var_CountChoices( VLC_OBJECT(a),b) |
| 583 | |
| 584 | |
| 585 | static inline bool var_ToggleBool( vlc_object_t *p_obj, const char *psz_name ) |
| 586 | { |
| 587 | vlc_value_t val; |
| 588 | if( var_GetAndSet( p_obj, psz_name, VLC_VAR_BOOL_TOGGLE, &val ) ) |
| 589 | return false; |
| 590 | return val.b_bool; |
| 591 | } |
| 592 | #define var_ToggleBool(a,b) var_ToggleBool( VLC_OBJECT(a),b ) |
| 593 | |
| 594 | |
| 595 | VLC_USED |
| 596 | static inline bool var_InheritBool( vlc_object_t *obj, const char *name ) |
| 597 | { |
| 598 | vlc_value_t val; |
| 599 | |
| 600 | if( var_Inherit( obj, name, VLC_VAR_BOOL, &val ) ) |
| 601 | val.b_bool = false; |
| 602 | return val.b_bool; |
| 603 | } |
| 604 | #define var_InheritBool(o, n) var_InheritBool(VLC_OBJECT(o), n) |
| 605 | |
| 606 | VLC_USED |
| 607 | static inline int64_t var_InheritInteger( vlc_object_t *obj, const char *name ) |
| 608 | { |
| 609 | vlc_value_t val; |
| 610 | |
| 611 | if( var_Inherit( obj, name, VLC_VAR_INTEGER, &val ) ) |
| 612 | val.i_int = 0; |
| 613 | return val.i_int; |
| 614 | } |
| 615 | #define var_InheritInteger(o, n) var_InheritInteger(VLC_OBJECT(o), n) |
| 616 | |
| 617 | VLC_USED |
| 618 | static inline float var_InheritFloat( vlc_object_t *obj, const char *name ) |
| 619 | { |
| 620 | vlc_value_t val; |
| 621 | |
| 622 | if( var_Inherit( obj, name, VLC_VAR_FLOAT, &val ) ) |
| 623 | val.f_float = 0.; |
| 624 | return val.f_float; |
| 625 | } |
| 626 | #define var_InheritFloat(o, n) var_InheritFloat(VLC_OBJECT(o), n) |
| 627 | |
| 628 | VLC_USED VLC_MALLOC |
| 629 | static inline char *var_InheritString( vlc_object_t *obj, const char *name ) |
| 630 | { |
| 631 | vlc_value_t val; |
| 632 | |
| 633 | if( var_Inherit( obj, name, VLC_VAR_STRING, &val ) ) |
| 634 | val.psz_string = NULL; |
| 635 | else if( val.psz_string && !*val.psz_string ) |
| 636 | { |
| 637 | free( ptr: val.psz_string ); |
| 638 | val.psz_string = NULL; |
| 639 | } |
| 640 | return val.psz_string; |
| 641 | } |
| 642 | #define var_InheritString(o, n) var_InheritString(VLC_OBJECT(o), n) |
| 643 | |
| 644 | VLC_USED |
| 645 | static inline void *var_InheritAddress( vlc_object_t *obj, const char *name ) |
| 646 | { |
| 647 | vlc_value_t val; |
| 648 | |
| 649 | if( var_Inherit( obj, name, VLC_VAR_ADDRESS, &val ) ) |
| 650 | val.p_address = NULL; |
| 651 | return val.p_address; |
| 652 | } |
| 653 | #define var_InheritAddress(o, n) var_InheritAddress(VLC_OBJECT(o), n) |
| 654 | |
| 655 | VLC_API int var_InheritURational( vlc_object_t *, unsigned *num, unsigned *den, const char *var ); |
| 656 | #define var_InheritURational(a,b,c,d) var_InheritURational(VLC_OBJECT(a), b, c, d) |
| 657 | |
| 658 | #define var_GetInteger(a,b) var_GetInteger( VLC_OBJECT(a),b) |
| 659 | #define var_GetBool(a,b) var_GetBool( VLC_OBJECT(a),b) |
| 660 | #define var_GetFloat(a,b) var_GetFloat( VLC_OBJECT(a),b) |
| 661 | #define var_GetString(a,b) var_GetString( VLC_OBJECT(a),b) |
| 662 | #define var_GetNonEmptyString(a,b) var_GetNonEmptyString( VLC_OBJECT(a),b) |
| 663 | #define var_GetAddress(a,b) var_GetAddress( VLC_OBJECT(a),b) |
| 664 | |
| 665 | VLC_API int var_LocationParse(vlc_object_t *, const char *mrl, const char *prefix); |
| 666 | #define var_LocationParse(o, m, p) var_LocationParse(VLC_OBJECT(o), m, p) |
| 667 | |
| 668 | /** |
| 669 | * @} |
| 670 | */ |
| 671 | #endif /* _VLC_VARIABLES_H */ |
| 672 | |