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
64 #define VLC_VAR_ISCOMMAND 0x2000
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
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.
80 #define VLC_VAR_SETSTEP 0x0012
83 * Set the value of this variable without triggering any callbacks
84 * \param p_val The new value
85 * \param p_val2 Unused
87 #define VLC_VAR_SETVALUE 0x0013
89 #define VLC_VAR_SETTEXT 0x0014
90 #define VLC_VAR_GETTEXT 0x0015
92 #define VLC_VAR_GETMIN 0x0016
93 #define VLC_VAR_GETMAX 0x0017
94 #define VLC_VAR_GETSTEP 0x0018
96 #define VLC_VAR_ADDCHOICE 0x0020
97 #define VLC_VAR_DELCHOICE 0x0021
98 #define VLC_VAR_CLEARCHOICES 0x0022
99 #define VLC_VAR_GETCHOICES 0x0024
101 #define VLC_VAR_CHOICESCOUNT 0x0026
102 #define VLC_VAR_SETMINMAX 0x0027
106 /** \defgroup var_GetAndSet Variable actions
107 * These are the different actions that can be used with var_GetAndSet()
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 */
118 /*****************************************************************************
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 )
124 VLC_API
void var_Destroy( vlc_object_t
*, const char * );
125 #define var_Destroy(a,b) var_Destroy( VLC_OBJECT(a), b )
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 )
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 )
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 )
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 )
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
* );
145 VLC_API
int var_Inherit( vlc_object_t
*, const char *, int, vlc_value_t
* );
147 VLC_API
void var_FreeList( vlc_value_t
*, vlc_value_t
* );
150 /*****************************************************************************
152 *****************************************************************************
153 * int MyCallback( vlc_object_t *p_this,
154 * char const *psz_variable,
155 * vlc_value_t oldvalue,
156 * vlc_value_t newvalue,
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 * );
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 * );
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 )
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 )
173 /*****************************************************************************
175 *****************************************************************************/
178 * Set the value of an integer variable
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
184 static inline int var_SetInteger( vlc_object_t
*p_obj
, const char *psz_name
,
189 return var_SetChecked( p_obj
, psz_name
, VLC_VAR_INTEGER
, val
);
193 * Set the value of an boolean variable
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
199 static inline int var_SetBool( vlc_object_t
*p_obj
, const char *psz_name
, bool b
)
203 return var_SetChecked( p_obj
, psz_name
, VLC_VAR_BOOL
, val
);
206 static inline int var_SetCoords( vlc_object_t
*obj
, const char *name
,
207 int32_t x
, int32_t y
)
212 return var_SetChecked (obj
, name
, VLC_VAR_COORDS
, val
);
214 #define var_SetCoords(o,n,x,y) var_SetCoords(VLC_OBJECT(o),n,x,y)
217 * Set the value of a float variable
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
223 static inline int var_SetFloat( vlc_object_t
*p_obj
, const char *psz_name
, float f
)
227 return var_SetChecked( p_obj
, psz_name
, VLC_VAR_FLOAT
, val
);
231 * Set the value of a string variable
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
237 static inline int var_SetString( vlc_object_t
*p_obj
, const char *psz_name
, const char *psz_string
)
240 val
.psz_string
= (char *)psz_string
;
241 return var_SetChecked( p_obj
, psz_name
, VLC_VAR_STRING
, val
);
245 * Set the value of a pointer variable
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
252 int var_SetAddress( vlc_object_t
*p_obj
, const char *psz_name
, void *ptr
)
256 return var_SetChecked( p_obj
, psz_name
, VLC_VAR_ADDRESS
, val
);
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)
267 * Get an integer value
269 * \param p_obj The object that holds the variable
270 * \param psz_name The name of the variable
273 static inline int64_t var_GetInteger( vlc_object_t
*p_obj
, const char *psz_name
)
276 if( !var_GetChecked( p_obj
, psz_name
, VLC_VAR_INTEGER
, &val
) )
283 * Get a boolean value
285 * \param p_obj The object that holds the variable
286 * \param psz_name The name of the variable
289 static inline bool var_GetBool( vlc_object_t
*p_obj
, const char *psz_name
)
291 vlc_value_t val
; val
.b_bool
= false;
293 if( !var_GetChecked( p_obj
, psz_name
, VLC_VAR_BOOL
, &val
) )
299 static inline void var_GetCoords( vlc_object_t
*obj
, const char *name
,
300 int32_t *px
, int32_t *py
)
304 if (likely(!var_GetChecked (obj
, name
, VLC_VAR_COORDS
, &val
)))
312 #define var_GetCoords(o,n,x,y) var_GetCoords(VLC_OBJECT(o),n,x,y)
317 * \param p_obj The object that holds the variable
318 * \param psz_name The name of the variable
321 static inline float var_GetFloat( vlc_object_t
*p_obj
, const char *psz_name
)
323 vlc_value_t val
; val
.f_float
= 0.0;
324 if( !var_GetChecked( p_obj
, psz_name
, VLC_VAR_FLOAT
, &val
) )
333 * \param p_obj The object that holds the variable
334 * \param psz_name The name of the variable
337 static inline char *var_GetString( vlc_object_t
*p_obj
, const char *psz_name
)
339 vlc_value_t val
; val
.psz_string
= NULL
;
340 if( var_GetChecked( p_obj
, psz_name
, VLC_VAR_STRING
, &val
) )
343 return val
.psz_string
;
347 static inline char *var_GetNonEmptyString( vlc_object_t
*p_obj
, const char *psz_name
)
350 if( var_GetChecked( p_obj
, psz_name
, VLC_VAR_STRING
, &val
) )
352 if( val
.psz_string
&& *val
.psz_string
)
353 return val
.psz_string
;
354 free( val
.psz_string
);
359 static inline void *var_GetAddress( vlc_object_t
*p_obj
, const char *psz_name
)
362 if( var_GetChecked( p_obj
, psz_name
, VLC_VAR_ADDRESS
, &val
) )
365 return val
.p_address
;
369 * Increment an integer variable
370 * \param p_obj the object that holds the variable
371 * \param psz_name the name of the variable
373 static inline int64_t var_IncInteger( vlc_object_t
*p_obj
, const char *psz_name
)
377 if( var_GetAndSet( p_obj
, psz_name
, VLC_VAR_INTEGER_ADD
, &val
) )
381 #define var_IncInteger(a,b) var_IncInteger( VLC_OBJECT(a), b )
384 * Decrement 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_DecInteger( 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_DecInteger(a,b) var_DecInteger( VLC_OBJECT(a), b )
398 static inline uint64_t var_OrInteger( vlc_object_t
*obj
, const char *name
,
403 if( var_GetAndSet( obj
, name
, VLC_VAR_INTEGER_OR
, &val
) )
407 #define var_OrInteger(a,b,c) var_OrInteger(VLC_OBJECT(a),b,c)
409 static inline uint64_t var_NAndInteger( vlc_object_t
*obj
, const char *name
,
414 if( var_GetAndSet( obj
, name
, VLC_VAR_INTEGER_NAND
, &val
) )
418 #define var_NAndInteger(a,b,c) var_NAndInteger(VLC_OBJECT(a),b,c)
421 * Create a integer variable with inherit and get its value.
423 * \param p_obj The object that holds the variable
424 * \param psz_name The name of the variable
427 static inline int64_t var_CreateGetInteger( vlc_object_t
*p_obj
, const char *psz_name
)
429 var_Create( p_obj
, psz_name
, VLC_VAR_INTEGER
| VLC_VAR_DOINHERIT
);
430 return var_GetInteger( p_obj
, psz_name
);
434 * Create a boolean variable with inherit and get its value.
436 * \param p_obj The object that holds the variable
437 * \param psz_name The name of the variable
440 static inline bool var_CreateGetBool( vlc_object_t
*p_obj
, const char *psz_name
)
442 var_Create( p_obj
, psz_name
, VLC_VAR_BOOL
| VLC_VAR_DOINHERIT
);
443 return var_GetBool( p_obj
, psz_name
);
447 * Create a float variable with inherit and get its value.
449 * \param p_obj The object that holds the variable
450 * \param psz_name The name of the variable
453 static inline float var_CreateGetFloat( vlc_object_t
*p_obj
, const char *psz_name
)
455 var_Create( p_obj
, psz_name
, VLC_VAR_FLOAT
| VLC_VAR_DOINHERIT
);
456 return var_GetFloat( p_obj
, psz_name
);
460 * Create a string variable with inherit and get its value.
462 * \param p_obj The object that holds the variable
463 * \param psz_name The name of the variable
466 static inline char *var_CreateGetString( vlc_object_t
*p_obj
,
467 const char *psz_name
)
469 var_Create( p_obj
, psz_name
, VLC_VAR_STRING
| VLC_VAR_DOINHERIT
);
470 return var_GetString( p_obj
, psz_name
);
474 static inline char *var_CreateGetNonEmptyString( vlc_object_t
*p_obj
,
475 const char *psz_name
)
477 var_Create( p_obj
, psz_name
, VLC_VAR_STRING
| VLC_VAR_DOINHERIT
);
478 return var_GetNonEmptyString( p_obj
, psz_name
);
482 * Create an address variable with inherit and get its value.
484 * \param p_obj The object that holds the variable
485 * \param psz_name The name of the variable
488 static inline void *var_CreateGetAddress( vlc_object_t
*p_obj
,
489 const char *psz_name
)
491 var_Create( p_obj
, psz_name
, VLC_VAR_ADDRESS
| VLC_VAR_DOINHERIT
);
492 return var_GetAddress( p_obj
, psz_name
);
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)
503 * Create a integer command variable with inherit and get its value.
505 * \param p_obj The object that holds the variable
506 * \param psz_name The name of the variable
509 static inline int64_t var_CreateGetIntegerCommand( vlc_object_t
*p_obj
, const char *psz_name
)
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
);
517 * Create a boolean command variable with inherit and get its value.
519 * \param p_obj The object that holds the variable
520 * \param psz_name The name of the variable
523 static inline bool var_CreateGetBoolCommand( vlc_object_t
*p_obj
, const char *psz_name
)
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
);
531 * Create a float command variable with inherit and get its value.
533 * \param p_obj The object that holds the variable
534 * \param psz_name The name of the variable
537 static inline float var_CreateGetFloatCommand( vlc_object_t
*p_obj
, const char *psz_name
)
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
);
545 * Create a string command variable with inherit and get its value.
547 * \param p_obj The object that holds the variable
548 * \param psz_name The name of the variable
551 static inline char *var_CreateGetStringCommand( vlc_object_t
*p_obj
,
552 const char *psz_name
)
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
);
560 static inline char *var_CreateGetNonEmptyStringCommand( vlc_object_t
*p_obj
,
561 const char *psz_name
)
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
);
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)
575 static inline int var_CountChoices( vlc_object_t
*p_obj
, const char *psz_name
)
578 if( var_Change( p_obj
, psz_name
, VLC_VAR_CHOICESCOUNT
, &count
, NULL
) )
582 #define var_CountChoices(a,b) var_CountChoices( VLC_OBJECT(a),b)
585 static inline bool var_ToggleBool( vlc_object_t
*p_obj
, const char *psz_name
)
588 if( var_GetAndSet( p_obj
, psz_name
, VLC_VAR_BOOL_TOGGLE
, &val
) )
592 #define var_ToggleBool(a,b) var_ToggleBool( VLC_OBJECT(a),b )
596 static inline bool var_InheritBool( vlc_object_t
*obj
, const char *name
)
600 if( var_Inherit( obj
, name
, VLC_VAR_BOOL
, &val
) )
604 #define var_InheritBool(o, n) var_InheritBool(VLC_OBJECT(o), n)
607 static inline int64_t var_InheritInteger( vlc_object_t
*obj
, const char *name
)
611 if( var_Inherit( obj
, name
, VLC_VAR_INTEGER
, &val
) )
615 #define var_InheritInteger(o, n) var_InheritInteger(VLC_OBJECT(o), n)
618 static inline float var_InheritFloat( vlc_object_t
*obj
, const char *name
)
622 if( var_Inherit( obj
, name
, VLC_VAR_FLOAT
, &val
) )
626 #define var_InheritFloat(o, n) var_InheritFloat(VLC_OBJECT(o), n)
629 static inline char *var_InheritString( vlc_object_t
*obj
, const char *name
)
633 if( var_Inherit( obj
, name
, VLC_VAR_STRING
, &val
) )
634 val
.psz_string
= NULL
;
635 else if( val
.psz_string
&& !*val
.psz_string
)
637 free( val
.psz_string
);
638 val
.psz_string
= NULL
;
640 return val
.psz_string
;
642 #define var_InheritString(o, n) var_InheritString(VLC_OBJECT(o), n)
645 static inline void *var_InheritAddress( vlc_object_t
*obj
, const char *name
)
649 if( var_Inherit( obj
, name
, VLC_VAR_ADDRESS
, &val
) )
650 val
.p_address
= NULL
;
651 return val
.p_address
;
653 #define var_InheritAddress(o, n) var_InheritAddress(VLC_OBJECT(o), n)
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)
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)
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)
671 #endif /* _VLC_VARIABLES_H */