1 /*****************************************************************************
2 * vlc_variables.h: variables handling
3 *****************************************************************************
4 * Copyright (C) 2002-2004 VLC authors and VideoLAN
7 * Authors: Samuel Hocevar <sam@zoy.org>
8 * Gildas Bazin <gbazin@netcourrier.com>
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.
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.
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 *****************************************************************************/
25 #ifndef VLC_VARIABLES_H
26 #define VLC_VARIABLES_H 1
29 * \defgroup variables Variables
32 * VLC object variables and callbacks
36 * VLC object variables and callbacks interface
39 #define VLC_VAR_TYPE 0x00ff
40 #define VLC_VAR_CLASS 0x00f0
41 #define VLC_VAR_FLAGS 0xff00
44 * \defgroup var_type Variable types
45 * These are the different types a vlc variable can have.
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
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
62 #define VLC_VAR_HASCHOICE 0x0100
63 #define VLC_VAR_HASMIN 0x0200
64 #define VLC_VAR_HASMAX 0x0400
65 #define VLC_VAR_HASSTEP 0x0800
67 #define VLC_VAR_ISCOMMAND 0x2000
70 /* If the variable is not found on the current module
71 search all parents and finally module config until found */
72 #define VLC_VAR_DOINHERIT 0x8000
76 * \defgroup var_action Variable actions
77 * These are the different actions that can be used with var_Change().
78 * The parameters given are the meaning of the two last parameters of
79 * var_Change() when this action is being used.
84 * Set the minimum value of this variable
85 * \param p_val The new minimum value
86 * \param p_val2 Unused
88 #define VLC_VAR_SETMIN 0x0010
90 * Set the maximum value of this variable
91 * \param p_val The new maximum value
92 * \param p_val2 Unused
94 #define VLC_VAR_SETMAX 0x0011
95 #define VLC_VAR_SETSTEP 0x0012
98 * Set the value of this variable without triggering any callbacks
99 * \param p_val The new value
100 * \param p_val2 Unused
102 #define VLC_VAR_SETVALUE 0x0013
104 #define VLC_VAR_SETTEXT 0x0014
105 #define VLC_VAR_GETTEXT 0x0015
107 #define VLC_VAR_GETMIN 0x0016
108 #define VLC_VAR_GETMAX 0x0017
109 #define VLC_VAR_GETSTEP 0x0018
111 #define VLC_VAR_ADDCHOICE 0x0020
112 #define VLC_VAR_DELCHOICE 0x0021
113 #define VLC_VAR_CLEARCHOICES 0x0022
114 #define VLC_VAR_SETDEFAULT 0x0023
115 #define VLC_VAR_GETCHOICES 0x0024
117 #define VLC_VAR_CHOICESCOUNT 0x0026
121 /** \defgroup var_GetAndSet Variable actions
122 * These are the different actions that can be used with var_GetAndSet()
126 VLC_VAR_BOOL_TOGGLE
, /**< Invert a boolean value (param ignored) */
127 VLC_VAR_INTEGER_ADD
, /**< Add parameter to an integer value */
128 VLC_VAR_INTEGER_OR
, /**< Binary OR over an integer bits field */
129 VLC_VAR_INTEGER_NAND
,/**< Binary NAND over an integer bits field */
133 /*****************************************************************************
135 *****************************************************************************/
136 VLC_API
int var_Create( vlc_object_t
*, const char *, int );
137 #define var_Create(a,b,c) var_Create( VLC_OBJECT(a), b, c )
139 VLC_API
void var_Destroy( vlc_object_t
*, const char * );
140 #define var_Destroy(a,b) var_Destroy( VLC_OBJECT(a), b )
142 VLC_API
int var_Change( vlc_object_t
*, const char *, int, vlc_value_t
*, vlc_value_t
* );
143 #define var_Change(a,b,c,d,e) var_Change( VLC_OBJECT(a), b, c, d, e )
145 VLC_API
int var_Type( vlc_object_t
*, const char * ) VLC_USED
;
146 #define var_Type(a,b) var_Type( VLC_OBJECT(a), b )
148 VLC_API
int var_Set( vlc_object_t
*, const char *, vlc_value_t
);
149 #define var_Set(a,b,c) var_Set( VLC_OBJECT(a), b, c )
151 VLC_API
int var_Get( vlc_object_t
*, const char *, vlc_value_t
* );
152 #define var_Get(a,b,c) var_Get( VLC_OBJECT(a), b, c )
154 VLC_API
int var_SetChecked( vlc_object_t
*, const char *, int, vlc_value_t
);
155 #define var_SetChecked(o,n,t,v) var_SetChecked(VLC_OBJECT(o),n,t,v)
156 VLC_API
int var_GetChecked( vlc_object_t
*, const char *, int, vlc_value_t
* );
157 #define var_GetChecked(o,n,t,v) var_GetChecked(VLC_OBJECT(o),n,t,v)
158 VLC_API
int var_GetAndSet( vlc_object_t
*, const char *, int, vlc_value_t
* );
160 VLC_API
int var_Inherit( vlc_object_t
*, const char *, int, vlc_value_t
* );
162 VLC_API
void var_FreeList( vlc_value_t
*, vlc_value_t
* );
165 /*****************************************************************************
167 *****************************************************************************
168 * int MyCallback( vlc_object_t *p_this,
169 * char const *psz_variable,
170 * vlc_value_t oldvalue,
171 * vlc_value_t newvalue,
173 *****************************************************************************/
174 VLC_API
int var_AddCallback( vlc_object_t
*, const char *, vlc_callback_t
, void * );
175 VLC_API
int var_DelCallback( vlc_object_t
*, const char *, vlc_callback_t
, void * );
176 VLC_API
int var_TriggerCallback( vlc_object_t
*, const char * );
178 VLC_API
int var_AddListCallback( vlc_object_t
*, const char *, vlc_list_callback_t
, void * );
179 VLC_API
int var_DelListCallback( vlc_object_t
*, const char *, vlc_list_callback_t
, void * );
181 #define var_AddCallback(a,b,c,d) var_AddCallback( VLC_OBJECT(a), b, c, d )
182 #define var_DelCallback(a,b,c,d) var_DelCallback( VLC_OBJECT(a), b, c, d )
183 #define var_TriggerCallback(a,b) var_TriggerCallback( VLC_OBJECT(a), b )
185 #define var_AddListCallback(a,b,c,d) var_AddListCallback( VLC_OBJECT(a), b, c, d )
186 #define var_DelListCallback(a,b,c,d) var_DelListCallback( VLC_OBJECT(a), b, c, d )
188 /*****************************************************************************
190 *****************************************************************************/
193 * Set the value of an integer variable
195 * \param p_obj The object that holds the variable
196 * \param psz_name The name of the variable
197 * \param i The new integer value of this variable
199 static inline int var_SetInteger( vlc_object_t
*p_obj
, const char *psz_name
,
204 return var_SetChecked( p_obj
, psz_name
, VLC_VAR_INTEGER
, val
);
208 * Set the value of an boolean variable
210 * \param p_obj The object that holds the variable
211 * \param psz_name The name of the variable
212 * \param b The new boolean value of this variable
214 static inline int var_SetBool( vlc_object_t
*p_obj
, const char *psz_name
, bool b
)
218 return var_SetChecked( p_obj
, psz_name
, VLC_VAR_BOOL
, val
);
221 static inline int var_SetCoords( vlc_object_t
*obj
, const char *name
,
222 int32_t x
, int32_t y
)
227 return var_SetChecked (obj
, name
, VLC_VAR_COORDS
, val
);
229 #define var_SetCoords(o,n,x,y) var_SetCoords(VLC_OBJECT(o),n,x,y)
232 * Set the value of a float variable
234 * \param p_obj The object that holds the variable
235 * \param psz_name The name of the variable
236 * \param f The new float value of this variable
238 static inline int var_SetFloat( vlc_object_t
*p_obj
, const char *psz_name
, float f
)
242 return var_SetChecked( p_obj
, psz_name
, VLC_VAR_FLOAT
, val
);
246 * Set the value of a string variable
248 * \param p_obj The object that holds the variable
249 * \param psz_name The name of the variable
250 * \param psz_string The new string value of this variable
252 static inline int var_SetString( vlc_object_t
*p_obj
, const char *psz_name
, const char *psz_string
)
255 val
.psz_string
= (char *)psz_string
;
256 return var_SetChecked( p_obj
, psz_name
, VLC_VAR_STRING
, val
);
260 * Set the value of a pointer variable
262 * \param p_obj The object that holds the variable
263 * \param psz_name The name of the variable
264 * \param ptr The new pointer value of this variable
267 int var_SetAddress( vlc_object_t
*p_obj
, const char *psz_name
, void *ptr
)
271 return var_SetChecked( p_obj
, psz_name
, VLC_VAR_ADDRESS
, val
);
274 #define var_SetInteger(a,b,c) var_SetInteger( VLC_OBJECT(a),b,c)
275 #define var_SetBool(a,b,c) var_SetBool( VLC_OBJECT(a),b,c)
276 #define var_SetFloat(a,b,c) var_SetFloat( VLC_OBJECT(a),b,c)
277 #define var_SetString(a,b,c) var_SetString( VLC_OBJECT(a),b,c)
278 #define var_SetAddress(o, n, p) var_SetAddress(VLC_OBJECT(o), n, p)
282 * Get an integer value
284 * \param p_obj The object that holds the variable
285 * \param psz_name The name of the variable
288 static inline int64_t var_GetInteger( vlc_object_t
*p_obj
, const char *psz_name
)
291 if( !var_GetChecked( p_obj
, psz_name
, VLC_VAR_INTEGER
, &val
) )
298 * Get a boolean value
300 * \param p_obj The object that holds the variable
301 * \param psz_name The name of the variable
304 static inline bool var_GetBool( vlc_object_t
*p_obj
, const char *psz_name
)
306 vlc_value_t val
; val
.b_bool
= false;
308 if( !var_GetChecked( p_obj
, psz_name
, VLC_VAR_BOOL
, &val
) )
314 static inline void var_GetCoords( vlc_object_t
*obj
, const char *name
,
315 int32_t *px
, int32_t *py
)
319 if (likely(!var_GetChecked (obj
, name
, VLC_VAR_COORDS
, &val
)))
327 #define var_GetCoords(o,n,x,y) var_GetCoords(VLC_OBJECT(o),n,x,y)
332 * \param p_obj The object that holds the variable
333 * \param psz_name The name of the variable
336 static inline float var_GetFloat( vlc_object_t
*p_obj
, const char *psz_name
)
338 vlc_value_t val
; val
.f_float
= 0.0;
339 if( !var_GetChecked( p_obj
, psz_name
, VLC_VAR_FLOAT
, &val
) )
348 * \param p_obj The object that holds the variable
349 * \param psz_name The name of the variable
352 static inline char *var_GetString( vlc_object_t
*p_obj
, const char *psz_name
)
354 vlc_value_t val
; val
.psz_string
= NULL
;
355 if( var_GetChecked( p_obj
, psz_name
, VLC_VAR_STRING
, &val
) )
358 return val
.psz_string
;
362 static inline char *var_GetNonEmptyString( vlc_object_t
*p_obj
, const char *psz_name
)
365 if( var_GetChecked( p_obj
, psz_name
, VLC_VAR_STRING
, &val
) )
367 if( val
.psz_string
&& *val
.psz_string
)
368 return val
.psz_string
;
369 free( val
.psz_string
);
374 static inline void *var_GetAddress( vlc_object_t
*p_obj
, const char *psz_name
)
377 if( var_GetChecked( p_obj
, psz_name
, VLC_VAR_ADDRESS
, &val
) )
380 return val
.p_address
;
384 * Increment an integer variable
385 * \param p_obj the object that holds the variable
386 * \param psz_name the name of the variable
388 static inline int64_t var_IncInteger( vlc_object_t
*p_obj
, const char *psz_name
)
392 if( var_GetAndSet( p_obj
, psz_name
, VLC_VAR_INTEGER_ADD
, &val
) )
396 #define var_IncInteger(a,b) var_IncInteger( VLC_OBJECT(a), b )
399 * Decrement an integer variable
400 * \param p_obj the object that holds the variable
401 * \param psz_name the name of the variable
403 static inline int64_t var_DecInteger( vlc_object_t
*p_obj
, const char *psz_name
)
407 if( var_GetAndSet( p_obj
, psz_name
, VLC_VAR_INTEGER_ADD
, &val
) )
411 #define var_DecInteger(a,b) var_DecInteger( VLC_OBJECT(a), b )
413 static inline uint64_t var_OrInteger( vlc_object_t
*obj
, const char *name
,
418 if( var_GetAndSet( obj
, name
, VLC_VAR_INTEGER_OR
, &val
) )
422 #define var_OrInteger(a,b,c) var_OrInteger(VLC_OBJECT(a),b,c)
424 static inline uint64_t var_NAndInteger( vlc_object_t
*obj
, const char *name
,
429 if( var_GetAndSet( obj
, name
, VLC_VAR_INTEGER_NAND
, &val
) )
433 #define var_NAndInteger(a,b,c) var_NAndInteger(VLC_OBJECT(a),b,c)
436 * Create a integer variable with inherit and get its value.
438 * \param p_obj The object that holds the variable
439 * \param psz_name The name of the variable
442 static inline int64_t var_CreateGetInteger( vlc_object_t
*p_obj
, const char *psz_name
)
444 var_Create( p_obj
, psz_name
, VLC_VAR_INTEGER
| VLC_VAR_DOINHERIT
);
445 return var_GetInteger( p_obj
, psz_name
);
449 * Create a boolean variable with inherit and get its value.
451 * \param p_obj The object that holds the variable
452 * \param psz_name The name of the variable
455 static inline bool var_CreateGetBool( vlc_object_t
*p_obj
, const char *psz_name
)
457 var_Create( p_obj
, psz_name
, VLC_VAR_BOOL
| VLC_VAR_DOINHERIT
);
458 return var_GetBool( p_obj
, psz_name
);
462 * Create a float variable with inherit and get its value.
464 * \param p_obj The object that holds the variable
465 * \param psz_name The name of the variable
468 static inline float var_CreateGetFloat( vlc_object_t
*p_obj
, const char *psz_name
)
470 var_Create( p_obj
, psz_name
, VLC_VAR_FLOAT
| VLC_VAR_DOINHERIT
);
471 return var_GetFloat( p_obj
, psz_name
);
475 * Create a string variable with inherit and get its value.
477 * \param p_obj The object that holds the variable
478 * \param psz_name The name of the variable
481 static inline char *var_CreateGetString( vlc_object_t
*p_obj
,
482 const char *psz_name
)
484 var_Create( p_obj
, psz_name
, VLC_VAR_STRING
| VLC_VAR_DOINHERIT
);
485 return var_GetString( p_obj
, psz_name
);
489 static inline char *var_CreateGetNonEmptyString( vlc_object_t
*p_obj
,
490 const char *psz_name
)
492 var_Create( p_obj
, psz_name
, VLC_VAR_STRING
| VLC_VAR_DOINHERIT
);
493 return var_GetNonEmptyString( p_obj
, psz_name
);
497 * Create an address variable with inherit and get its value.
499 * \param p_obj The object that holds the variable
500 * \param psz_name The name of the variable
503 static inline void *var_CreateGetAddress( vlc_object_t
*p_obj
,
504 const char *psz_name
)
506 var_Create( p_obj
, psz_name
, VLC_VAR_ADDRESS
| VLC_VAR_DOINHERIT
);
507 return var_GetAddress( p_obj
, psz_name
);
510 #define var_CreateGetInteger(a,b) var_CreateGetInteger( VLC_OBJECT(a),b)
511 #define var_CreateGetBool(a,b) var_CreateGetBool( VLC_OBJECT(a),b)
512 #define var_CreateGetFloat(a,b) var_CreateGetFloat( VLC_OBJECT(a),b)
513 #define var_CreateGetString(a,b) var_CreateGetString( VLC_OBJECT(a),b)
514 #define var_CreateGetNonEmptyString(a,b) var_CreateGetNonEmptyString( VLC_OBJECT(a),b)
515 #define var_CreateGetAddress(a,b) var_CreateGetAddress( VLC_OBJECT(a),b)
518 * Create a integer command variable with inherit and get its value.
520 * \param p_obj The object that holds the variable
521 * \param psz_name The name of the variable
524 static inline int64_t var_CreateGetIntegerCommand( vlc_object_t
*p_obj
, const char *psz_name
)
526 var_Create( p_obj
, psz_name
, VLC_VAR_INTEGER
| VLC_VAR_DOINHERIT
527 | VLC_VAR_ISCOMMAND
);
528 return var_GetInteger( p_obj
, psz_name
);
532 * Create a boolean command variable with inherit and get its value.
534 * \param p_obj The object that holds the variable
535 * \param psz_name The name of the variable
538 static inline bool var_CreateGetBoolCommand( vlc_object_t
*p_obj
, const char *psz_name
)
540 var_Create( p_obj
, psz_name
, VLC_VAR_BOOL
| VLC_VAR_DOINHERIT
541 | VLC_VAR_ISCOMMAND
);
542 return var_GetBool( p_obj
, psz_name
);
546 * Create a float command variable with inherit and get its value.
548 * \param p_obj The object that holds the variable
549 * \param psz_name The name of the variable
552 static inline float var_CreateGetFloatCommand( vlc_object_t
*p_obj
, const char *psz_name
)
554 var_Create( p_obj
, psz_name
, VLC_VAR_FLOAT
| VLC_VAR_DOINHERIT
555 | VLC_VAR_ISCOMMAND
);
556 return var_GetFloat( p_obj
, psz_name
);
560 * Create a string command variable with inherit and get its value.
562 * \param p_obj The object that holds the variable
563 * \param psz_name The name of the variable
566 static inline char *var_CreateGetStringCommand( vlc_object_t
*p_obj
,
567 const char *psz_name
)
569 var_Create( p_obj
, psz_name
, VLC_VAR_STRING
| VLC_VAR_DOINHERIT
570 | VLC_VAR_ISCOMMAND
);
571 return var_GetString( p_obj
, psz_name
);
575 static inline char *var_CreateGetNonEmptyStringCommand( vlc_object_t
*p_obj
,
576 const char *psz_name
)
578 var_Create( p_obj
, psz_name
, VLC_VAR_STRING
| VLC_VAR_DOINHERIT
579 | VLC_VAR_ISCOMMAND
);
580 return var_GetNonEmptyString( p_obj
, psz_name
);
583 #define var_CreateGetIntegerCommand(a,b) var_CreateGetIntegerCommand( VLC_OBJECT(a),b)
584 #define var_CreateGetBoolCommand(a,b) var_CreateGetBoolCommand( VLC_OBJECT(a),b)
585 #define var_CreateGetFloatCommand(a,b) var_CreateGetFloatCommand( VLC_OBJECT(a),b)
586 #define var_CreateGetStringCommand(a,b) var_CreateGetStringCommand( VLC_OBJECT(a),b)
587 #define var_CreateGetNonEmptyStringCommand(a,b) var_CreateGetNonEmptyStringCommand( VLC_OBJECT(a),b)
590 static inline int var_CountChoices( vlc_object_t
*p_obj
, const char *psz_name
)
593 if( var_Change( p_obj
, psz_name
, VLC_VAR_CHOICESCOUNT
, &count
, NULL
) )
597 #define var_CountChoices(a,b) var_CountChoices( VLC_OBJECT(a),b)
600 static inline bool var_ToggleBool( vlc_object_t
*p_obj
, const char *psz_name
)
603 if( var_GetAndSet( p_obj
, psz_name
, VLC_VAR_BOOL_TOGGLE
, &val
) )
607 #define var_ToggleBool(a,b) var_ToggleBool( VLC_OBJECT(a),b )
611 static inline bool var_InheritBool( vlc_object_t
*obj
, const char *name
)
615 if( var_Inherit( obj
, name
, VLC_VAR_BOOL
, &val
) )
619 #define var_InheritBool(o, n) var_InheritBool(VLC_OBJECT(o), n)
622 static inline int64_t var_InheritInteger( vlc_object_t
*obj
, const char *name
)
626 if( var_Inherit( obj
, name
, VLC_VAR_INTEGER
, &val
) )
630 #define var_InheritInteger(o, n) var_InheritInteger(VLC_OBJECT(o), n)
633 static inline float var_InheritFloat( vlc_object_t
*obj
, const char *name
)
637 if( var_Inherit( obj
, name
, VLC_VAR_FLOAT
, &val
) )
641 #define var_InheritFloat(o, n) var_InheritFloat(VLC_OBJECT(o), n)
644 static inline char *var_InheritString( vlc_object_t
*obj
, const char *name
)
648 if( var_Inherit( obj
, name
, VLC_VAR_STRING
, &val
) )
649 val
.psz_string
= NULL
;
650 else if( val
.psz_string
&& !*val
.psz_string
)
652 free( val
.psz_string
);
653 val
.psz_string
= NULL
;
655 return val
.psz_string
;
657 #define var_InheritString(o, n) var_InheritString(VLC_OBJECT(o), n)
660 static inline void *var_InheritAddress( vlc_object_t
*obj
, const char *name
)
664 if( var_Inherit( obj
, name
, VLC_VAR_ADDRESS
, &val
) )
665 val
.p_address
= NULL
;
666 return val
.p_address
;
668 #define var_InheritAddress(o, n) var_InheritAddress(VLC_OBJECT(o), n)
670 VLC_API
int var_InheritURational( vlc_object_t
*, unsigned *num
, unsigned *den
, const char *var
);
671 #define var_InheritURational(a,b,c,d) var_InheritURational(VLC_OBJECT(a), b, c, d)
673 #define var_GetInteger(a,b) var_GetInteger( VLC_OBJECT(a),b)
674 #define var_GetBool(a,b) var_GetBool( VLC_OBJECT(a),b)
675 #define var_GetFloat(a,b) var_GetFloat( VLC_OBJECT(a),b)
676 #define var_GetString(a,b) var_GetString( VLC_OBJECT(a),b)
677 #define var_GetNonEmptyString(a,b) var_GetNonEmptyString( VLC_OBJECT(a),b)
678 #define var_GetAddress(a,b) var_GetAddress( VLC_OBJECT(a),b)
680 VLC_API
int var_LocationParse(vlc_object_t
*, const char *mrl
, const char *prefix
);
681 #define var_LocationParse(o, m, p) var_LocationParse(VLC_OBJECT(o), m, p)
686 #endif /* _VLC_VARIABLES_H */