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