1 /*****************************************************************************
2 * variables.h: variables handling
3 *****************************************************************************
4 * Copyright (C) 2002-2004 the VideoLAN team
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
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.
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.
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 *****************************************************************************/
26 * \defgroup variables Variables
28 * Functions for using the object variables in vlc.
30 * Vlc have a very powerful "object variable" infrastructure useful
36 /*****************************************************************************
37 * Variable types - probably very incomplete
38 *****************************************************************************/
39 #define VLC_VAR_TYPE 0x00ff
40 #define VLC_VAR_FLAGS 0xff00
42 /** \defgroup var_flags Additive flags
43 * These flags are added to the type field of the variable. Most as a result of
44 * a __var_Change() call, but some may be added at creation time
47 #define VLC_VAR_HASCHOICE 0x0100
48 #define VLC_VAR_HASMIN 0x0200
49 #define VLC_VAR_HASMAX 0x0400
50 #define VLC_VAR_HASSTEP 0x0800
52 #define VLC_VAR_ISLIST 0x1000
53 #define VLC_VAR_ISCOMMAND 0x2000
54 #define VLC_VAR_ISCONFIG 0x2000
57 #define VLC_VAR_DOINHERIT 0x8000
61 * \defgroup var_action Variable actions
62 * These are the different actions that can be used with __var_Change().
63 * The parameters given are the meaning of the two last parameters of
64 * __var_Change() when this action is being used.
69 * Set the minimum value of this variable
70 * \param p_val The new minimum value
71 * \param p_val2 Unused
73 #define VLC_VAR_SETMIN 0x0010
75 * Set the maximum value of this variable
76 * \param p_val The new maximum value
77 * \param p_val2 Unused
79 #define VLC_VAR_SETMAX 0x0011
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_ADDCHOICE 0x0020
93 #define VLC_VAR_DELCHOICE 0x0021
94 #define VLC_VAR_CLEARCHOICES 0x0022
95 #define VLC_VAR_SETDEFAULT 0x0023
96 #define VLC_VAR_GETCHOICES 0x0024
97 #define VLC_VAR_FREECHOICES 0x0025
98 #define VLC_VAR_GETLIST 0x0026
99 #define VLC_VAR_FREELIST 0x0027
100 #define VLC_VAR_CHOICESCOUNT 0x0028
102 #define VLC_VAR_INHERITVALUE 0x0030
103 #define VLC_VAR_TRIGGER_CALLBACKS 0x0035
106 /*****************************************************************************
108 *****************************************************************************/
109 VLC_EXPORT( int, __var_Create, ( vlc_object_t *, const char *, int ) );
110 VLC_EXPORT( int, __var_Destroy, ( vlc_object_t *, const char * ) );
112 VLC_EXPORT( int, __var_Change, ( vlc_object_t *, const char *, int, vlc_value_t *, vlc_value_t * ) );
114 VLC_EXPORT( int, __var_Type, ( vlc_object_t *, const char * ) );
115 VLC_EXPORT( int, __var_Set, ( vlc_object_t *, const char *, vlc_value_t ) );
116 VLC_EXPORT( int, __var_Get, ( vlc_object_t *, const char *, vlc_value_t * ) );
118 #define var_OptionParse(a,b) __var_OptionParse( VLC_OBJECT( a ) , b )
119 VLC_EXPORT( void, __var_OptionParse, ( vlc_object_t *, const char * ) );
122 * __var_Create() with automatic casting.
124 #define var_Create(a,b,c) __var_Create( VLC_OBJECT(a), b, c )
126 * __var_Destroy() with automatic casting
128 #define var_Destroy(a,b) __var_Destroy( VLC_OBJECT(a), b )
131 * __var_Change() with automatic casting
133 #define var_Change(a,b,c,d,e) __var_Change( VLC_OBJECT(a), b, c, d, e )
136 * __var_Type() with automatic casting
138 #define var_Type(a,b) __var_Type( VLC_OBJECT(a), b )
140 * __var_Set() with automatic casting
142 #define var_Set(a,b,c) __var_Set( VLC_OBJECT(a), b, c )
144 * __var_Get() with automatic casting
146 #define var_Get(a,b,c) __var_Get( VLC_OBJECT(a), b, c )
148 /*****************************************************************************
150 *****************************************************************************
151 * int MyCallback( vlc_object_t *p_this,
152 * char const *psz_variable,
153 * vlc_value_t oldvalue,
154 * vlc_value_t newvalue,
156 *****************************************************************************/
157 VLC_EXPORT( int, __var_AddCallback, ( vlc_object_t *, const char *, vlc_callback_t, void * ) );
158 VLC_EXPORT( int, __var_DelCallback, ( vlc_object_t *, const char *, vlc_callback_t, void * ) );
161 * __var_AddCallback() with automatic casting
163 #define var_AddCallback(a,b,c,d) __var_AddCallback( VLC_OBJECT(a), b, c, d )
166 * __var_DelCallback() with automatic casting
168 #define var_DelCallback(a,b,c,d) __var_DelCallback( VLC_OBJECT(a), b, c, d )
170 /*****************************************************************************
172 *****************************************************************************/
175 * Set the value of an integer variable
177 * \param p_obj The object that holds the variable
178 * \param psz_name The name of the variable
179 * \param i The new integer value of this variable
181 static inline int __var_SetInteger( vlc_object_t *p_obj, const char *psz_name, int i )
185 return __var_Set( p_obj, psz_name, val );
187 #define var_SetInteger(a,b,c) __var_SetInteger( VLC_OBJECT(a),b,c)
189 * Set the value of an boolean variable
191 * \param p_obj The object that holds the variable
192 * \param psz_name The name of the variable
193 * \param b The new boolean value of this variable
195 static inline int __var_SetBool( vlc_object_t *p_obj, const char *psz_name, vlc_bool_t b )
199 return __var_Set( p_obj, psz_name, val );
203 * Set the value of a time variable
205 * \param p_obj The object that holds the variable
206 * \param psz_name The name of the variable
207 * \param i The new time value of this variable
209 static inline int __var_SetTime( vlc_object_t *p_obj, const char *psz_name, int64_t i )
213 return __var_Set( p_obj, psz_name, val );
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_Set( p_obj, psz_name, 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_Set( p_obj, psz_name, val );
245 * Trigger the callbacks on a void variable
247 * \param p_obj The object that holds the variable
248 * \param psz_name The name of the variable
250 static inline int __var_SetVoid( vlc_object_t *p_obj, const char *psz_name )
253 val.b_bool = VLC_TRUE;
254 return __var_Set( p_obj, psz_name, val );
256 #define var_SetVoid(a,b) __var_SetVoid( VLC_OBJECT(a),b)
259 * __var_SetBool() with automatic casting
261 #define var_SetBool(a,b,c) __var_SetBool( VLC_OBJECT(a),b,c)
264 * __var_SetTime() with automatic casting
266 #define var_SetTime(a,b,c) __var_SetTime( VLC_OBJECT(a),b,c)
268 * __var_SetFloat() with automatic casting
270 #define var_SetFloat(a,b,c) __var_SetFloat( VLC_OBJECT(a),b,c)
272 * __var_SetString() with automatic casting
274 #define var_SetString(a,b,c) __var_SetString( VLC_OBJECT(a),b,c)
277 * Get an integer value
279 * \param p_obj The object that holds the variable
280 * \param psz_name The name of the variable
282 static inline int __var_GetInteger( vlc_object_t *p_obj, const char *psz_name )
284 vlc_value_t val;val.i_int = 0;
285 if( !__var_Get( p_obj, psz_name, &val ) )
292 * Get a boolean value
294 * \param p_obj The object that holds the variable
295 * \param psz_name The name of the variable
297 static inline int __var_GetBool( vlc_object_t *p_obj, const char *psz_name )
299 vlc_value_t val; val.b_bool = VLC_FALSE;
300 if( !__var_Get( p_obj, psz_name, &val ) )
309 * \param p_obj The object that holds the variable
310 * \param psz_name The name of the variable
312 static inline int64_t __var_GetTime( vlc_object_t *p_obj, const char *psz_name )
314 vlc_value_t val; val.i_time = 0L;
315 if( !__var_Get( p_obj, psz_name, &val ) )
324 * \param p_obj The object that holds the variable
325 * \param psz_name The name of the variable
327 static inline float __var_GetFloat( vlc_object_t *p_obj, const char *psz_name )
329 vlc_value_t val; val.f_float = 0.0;
330 if( !__var_Get( p_obj, psz_name, &val ) )
339 * \param p_obj The object that holds the variable
340 * \param psz_name The name of the variable
342 static inline char *__var_GetString( vlc_object_t *p_obj, const char *psz_name )
344 vlc_value_t val; val.psz_string = NULL;
345 if( !__var_Get( p_obj, psz_name, &val ) )
346 return val.psz_string;
352 * __var_GetInteger() with automatic casting
354 #define var_GetInteger(a,b) __var_GetInteger( VLC_OBJECT(a),b)
356 * __var_GetBool() with automatic casting
358 #define var_GetBool(a,b) __var_GetBool( VLC_OBJECT(a),b)
360 * __var_GetTime() with automatic casting
362 #define var_GetTime(a,b) __var_GetTime( VLC_OBJECT(a),b)
364 * __var_GetFloat() with automatic casting
366 #define var_GetFloat(a,b) __var_GetFloat( VLC_OBJECT(a),b)
368 * __var_GetString() with automatic casting
370 #define var_GetString(a,b) __var_GetString( VLC_OBJECT(a),b)
375 * Increment an integer variable
376 * \param p_obj the object that holds the variable
377 * \param psz_name the name of the variable
379 static inline void __var_IncInteger( vlc_object_t *p_obj, const char *psz_name )
381 int i_val = __var_GetInteger( p_obj, psz_name );
382 __var_SetInteger( p_obj, psz_name, ++i_val );
384 #define var_IncInteger(a,b) __var_IncInteger( VLC_OBJECT(a), b )
387 * Decrement an integer variable
388 * \param p_obj the object that holds the variable
389 * \param psz_name the name of the variable
391 static inline void __var_DecInteger( vlc_object_t *p_obj, const char *psz_name )
393 int i_val = __var_GetInteger( p_obj, psz_name );
394 __var_SetInteger( p_obj, psz_name, --i_val );
396 #define var_DecInteger(a,b) __var_DecInteger( VLC_OBJECT(a), b )
399 * Create a integer variable with inherit and get its value.
401 * \param p_obj The object that holds the variable
402 * \param psz_name The name of the variable
404 static inline int __var_CreateGetInteger( vlc_object_t *p_obj, const char *psz_name )
408 __var_Create( p_obj, psz_name, VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
409 if( !__var_Get( p_obj, psz_name, &val ) )
416 * Create a boolean variable with inherit and get its value.
418 * \param p_obj The object that holds the variable
419 * \param psz_name The name of the variable
421 static inline int __var_CreateGetBool( vlc_object_t *p_obj, const char *psz_name )
425 __var_Create( p_obj, psz_name, VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
426 if( !__var_Get( p_obj, psz_name, &val ) )
433 * Create a time variable with inherit and get its value.
435 * \param p_obj The object that holds the variable
436 * \param psz_name The name of the variable
438 static inline int64_t __var_CreateGetTime( vlc_object_t *p_obj, const char *psz_name )
442 __var_Create( p_obj, psz_name, VLC_VAR_TIME | VLC_VAR_DOINHERIT );
443 if( !__var_Get( p_obj, psz_name, &val ) )
450 * Create a float variable with inherit and get its value.
452 * \param p_obj The object that holds the variable
453 * \param psz_name The name of the variable
455 static inline float __var_CreateGetFloat( vlc_object_t *p_obj, const char *psz_name )
459 __var_Create( p_obj, psz_name, VLC_VAR_FLOAT | VLC_VAR_DOINHERIT );
460 if( !__var_Get( p_obj, psz_name, &val ) )
467 * Create a string variable with inherit and get its value.
469 * \param p_obj The object that holds the variable
470 * \param psz_name The name of the variable
472 static inline char *__var_CreateGetString( vlc_object_t *p_obj, const char *psz_name )
476 __var_Create( p_obj, psz_name, VLC_VAR_STRING | VLC_VAR_DOINHERIT );
477 if( !__var_Get( p_obj, psz_name, &val ) )
478 return val.psz_string;
484 * __var_CreateGetInteger() with automatic casting
486 #define var_CreateGetInteger(a,b) __var_CreateGetInteger( VLC_OBJECT(a),b)
488 * __var_CreateGetBool() with automatic casting
490 #define var_CreateGetBool(a,b) __var_CreateGetBool( VLC_OBJECT(a),b)
492 * __var_CreateGetTime() with automatic casting
494 #define var_CreateGetTime(a,b) __var_CreateGetTime( VLC_OBJECT(a),b)
496 * __var_CreateGetFloat() with automatic casting
498 #define var_CreateGetFloat(a,b) __var_CreateGetFloat( VLC_OBJECT(a),b)
500 * __var_CreateGetString() with automatic casting
502 #define var_CreateGetString(a,b) __var_CreateGetString( VLC_OBJECT(a),b)