* modules/codec/dvbsub.c: bug fix in the encoder.
[vlc.git] / include / variables.h
blobde6f94ec90c166ea2e46c1496c3c003455db4260
1 /*****************************************************************************
2 * variables.h: variables handling
3 *****************************************************************************
4 * Copyright (C) 2002-2004 VideoLAN
5 * $Id$
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., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
23 *****************************************************************************/
25 /**
26 * \defgroup variables Variables
28 * Functions for using the object variables in vlc.
30 * Vlc have a very powerful "object variable" infrastructure useful
31 * for many things.
33 * @{
36 typedef struct callback_entry_t callback_entry_t;
38 /**
39 * The structure describing a variable.
40 * \note vlc_value_t is the common union for variable values
42 struct variable_t
44 /** The variable's exported value */
45 vlc_value_t val;
47 char * psz_name; /**< The variable unique name */
48 uint32_t i_hash; /**< (almost) unique hashed value */
49 int i_type; /**< The type of the variable */
51 /** The variable display name, mainly for use by the interfaces */
52 char * psz_text;
54 /** A pointer to a comparison function */
55 int ( * pf_cmp ) ( vlc_value_t, vlc_value_t );
56 /** A pointer to a duplication function */
57 void ( * pf_dup ) ( vlc_value_t * );
58 /** A pointer to a deallocation function */
59 void ( * pf_free ) ( vlc_value_t * );
61 /** Creation count: we only destroy the variable if it reaches 0 */
62 int i_usage;
64 /** If the variable has min/max/step values */
65 vlc_value_t min, max, step;
67 /** Index of the default choice, if the variable is to be chosen in
68 * a list */
69 int i_default;
70 /** List of choices */
71 vlc_list_t choices;
72 /** List of friendly names for the choices */
73 vlc_list_t choices_text;
75 /** Set to TRUE if the variable is in a callback */
76 vlc_bool_t b_incallback;
78 /** Number of registered callbacks */
79 int i_entries;
80 /** Array of registered callbacks */
81 callback_entry_t * p_entries;
84 /*****************************************************************************
85 * Variable types - probably very incomplete
86 *****************************************************************************/
87 #define VLC_VAR_TYPE 0x00ff
88 #define VLC_VAR_FLAGS 0xff00
90 /**
91 * \defgroup var_type Variable types
92 * These are the different types a vlc variable can have.
93 * @{
95 #define VLC_VAR_VOID 0x0010
96 #define VLC_VAR_BOOL 0x0020
97 #define VLC_VAR_INTEGER 0x0030
98 #define VLC_VAR_HOTKEY 0x0031
99 #define VLC_VAR_STRING 0x0040
100 #define VLC_VAR_MODULE 0x0041
101 #define VLC_VAR_FILE 0x0042
102 #define VLC_VAR_DIRECTORY 0x0043
103 #define VLC_VAR_VARIABLE 0x0044
104 #define VLC_VAR_FLOAT 0x0050
105 #define VLC_VAR_TIME 0x0060
106 #define VLC_VAR_ADDRESS 0x0070
107 #define VLC_VAR_MUTEX 0x0080
108 #define VLC_VAR_LIST 0x0090
109 /**@}*/
110 /** \defgroup var_flags Additive flags
111 * These flags are added to the type field of the variable. Most as a result of
112 * a __var_Change() call, but some may be added at creation time
113 * @{
115 #define VLC_VAR_HASCHOICE 0x0100
116 #define VLC_VAR_HASMIN 0x0200
117 #define VLC_VAR_HASMAX 0x0400
118 #define VLC_VAR_HASSTEP 0x0800
120 #define VLC_VAR_ISLIST 0x1000
121 #define VLC_VAR_ISCOMMAND 0x2000
122 #define VLC_VAR_ISCONFIG 0x2000
124 /** Creation flag */
125 #define VLC_VAR_DOINHERIT 0x8000
126 /**@}*/
129 * \defgroup var_action Variable actions
130 * These are the different actions that can be used with __var_Change().
131 * The parameters given are the meaning of the two last parameters of
132 * __var_Change() when this action is being used.
133 * @{
137 * Set the minimum value of this variable
138 * \param p_val The new minimum value
139 * \param p_val2 Unused
141 #define VLC_VAR_SETMIN 0x0010
143 * Set the maximum value of this variable
144 * \param p_val The new maximum value
145 * \param p_val2 Unused
147 #define VLC_VAR_SETMAX 0x0011
148 #define VLC_VAR_SETSTEP 0x0012
151 * Set the value of this variable without triggering any callbacks
152 * \param p_val The new value
153 * \param p_val2 Unused
155 #define VLC_VAR_SETVALUE 0x0013
157 #define VLC_VAR_SETTEXT 0x0014
158 #define VLC_VAR_GETTEXT 0x0015
160 #define VLC_VAR_ADDCHOICE 0x0020
161 #define VLC_VAR_DELCHOICE 0x0021
162 #define VLC_VAR_CLEARCHOICES 0x0022
163 #define VLC_VAR_SETDEFAULT 0x0023
164 #define VLC_VAR_GETCHOICES 0x0024
165 #define VLC_VAR_FREECHOICES 0x0025
166 #define VLC_VAR_GETLIST 0x0026
167 #define VLC_VAR_FREELIST 0x0027
168 #define VLC_VAR_CHOICESCOUNT 0x0028
170 #define VLC_VAR_INHERITVALUE 0x0030
171 #define VLC_VAR_TRIGGER_CALLBACKS 0x0035
172 /**@}*/
174 /*****************************************************************************
175 * Prototypes
176 *****************************************************************************/
177 VLC_EXPORT( int, __var_Create, ( vlc_object_t *, const char *, int ) );
178 VLC_EXPORT( int, __var_Destroy, ( vlc_object_t *, const char * ) );
180 VLC_EXPORT( int, __var_Change, ( vlc_object_t *, const char *, int, vlc_value_t *, vlc_value_t * ) );
182 VLC_EXPORT( int, __var_Type, ( vlc_object_t *, const char * ) );
183 VLC_EXPORT( int, __var_Set, ( vlc_object_t *, const char *, vlc_value_t ) );
184 VLC_EXPORT( int, __var_Get, ( vlc_object_t *, const char *, vlc_value_t * ) );
187 * __var_Create() with automatic casting.
189 #define var_Create(a,b,c) __var_Create( VLC_OBJECT(a), b, c )
191 * __var_Destroy() with automatic casting
193 #define var_Destroy(a,b) __var_Destroy( VLC_OBJECT(a), b )
196 * __var_Change() with automatic casting
198 #define var_Change(a,b,c,d,e) __var_Change( VLC_OBJECT(a), b, c, d, e )
201 * __var_Type() with automatic casting
203 #define var_Type(a,b) __var_Type( VLC_OBJECT(a), b )
205 * __var_Set() with automatic casting
207 #define var_Set(a,b,c) __var_Set( VLC_OBJECT(a), b, c )
209 * __var_Get() with automatic casting
211 #define var_Get(a,b,c) __var_Get( VLC_OBJECT(a), b, c )
213 /*****************************************************************************
214 * Variable callbacks
215 *****************************************************************************
216 * int MyCallback( vlc_object_t *p_this,
217 * char const *psz_variable,
218 * vlc_value_t oldvalue,
219 * vlc_value_t newvalue,
220 * void *p_data);
221 *****************************************************************************/
222 VLC_EXPORT( int, __var_AddCallback, ( vlc_object_t *, const char *, vlc_callback_t, void * ) );
223 VLC_EXPORT( int, __var_DelCallback, ( vlc_object_t *, const char *, vlc_callback_t, void * ) );
226 * __var_AddCallback() with automatic casting
228 #define var_AddCallback(a,b,c,d) __var_AddCallback( VLC_OBJECT(a), b, c, d )
231 * __var_DelCallback() with automatic casting
233 #define var_DelCallback(a,b,c,d) __var_DelCallback( VLC_OBJECT(a), b, c, d )
235 /*****************************************************************************
236 * helpers functions
237 *****************************************************************************/
240 * Set the value of an integer variable
242 * \param p_obj The object that holds the variable
243 * \param psz_name The name of the variable
244 * \param i The new integer value of this variable
246 static inline int __var_SetInteger( vlc_object_t *p_obj, const char *psz_name, int i )
248 vlc_value_t val;
249 val.i_int = i;
250 return __var_Set( p_obj, psz_name, val );
254 * Set the value of an boolean variable
256 * \param p_obj The object that holds the variable
257 * \param psz_name The name of the variable
258 * \param b The new boolean value of this variable
260 static inline int __var_SetBool( vlc_object_t *p_obj, const char *psz_name, vlc_bool_t b )
262 vlc_value_t val;
263 val.b_bool = b;
264 return __var_Set( p_obj, psz_name, val );
268 * Set the value of a time variable
270 * \param p_obj The object that holds the variable
271 * \param psz_name The name of the variable
272 * \param i The new time value of this variable
274 static inline int __var_SetTime( vlc_object_t *p_obj, const char *psz_name, int64_t i )
276 vlc_value_t val;
277 val.i_time = i;
278 return __var_Set( p_obj, psz_name, val );
282 * Set the value of a float variable
284 * \param p_obj The object that holds the variable
285 * \param psz_name The name of the variable
286 * \param f The new float value of this variable
288 static inline int __var_SetFloat( vlc_object_t *p_obj, const char *psz_name, float f )
290 vlc_value_t val;
291 val.f_float = f;
292 return __var_Set( p_obj, psz_name, val );
296 * Set the value of a string variable
298 * \param p_obj The object that holds the variable
299 * \param psz_name The name of the variable
300 * \param psz_string The new string value of this variable
302 static inline int __var_SetString( vlc_object_t *p_obj, const char *psz_name, char *psz_string )
304 vlc_value_t val;
305 val.psz_string = psz_string;
306 return __var_Set( p_obj, psz_name, val );
310 * Trigger the callbacks on a void variable
312 * \param p_obj The object that holds the variable
313 * \param psz_name The name of the variable
315 static inline int __var_SetVoid( vlc_object_t *p_obj, const char *psz_name )
317 vlc_value_t val;
318 val.b_bool = VLC_TRUE;
319 return __var_Set( p_obj, psz_name, val );
323 * __var_SetInteger() with automatic casting
325 #define var_SetInteger(a,b,c) __var_SetInteger( VLC_OBJECT(a),b,c)
327 * __var_SetBool() with automatic casting
329 #define var_SetBool(a,b,c) __var_SetBool( VLC_OBJECT(a),b,c)
332 * __var_SetTime() with automatic casting
334 #define var_SetTime(a,b,c) __var_SetTime( VLC_OBJECT(a),b,c)
336 * __var_SetFloat() with automatic casting
338 #define var_SetFloat(a,b,c) __var_SetFloat( VLC_OBJECT(a),b,c)
340 * __var_SetString() with automatic casting
342 #define var_SetString(a,b,c) __var_SetString( VLC_OBJECT(a),b,c)
344 * __var_SetVoid() with automatic casting
346 #define var_SetVoid(a,b) __var_SetVoid( VLC_OBJECT(a),b)
349 * Get a integer value
351 * \param p_obj The object that holds the variable
352 * \param psz_name The name of the variable
354 static inline int __var_GetInteger( vlc_object_t *p_obj, const char *psz_name )
356 vlc_value_t val;
357 if( !__var_Get( p_obj, psz_name, &val ) )
358 return val.i_int;
359 else
360 return 0;
364 * Get a boolean value
366 * \param p_obj The object that holds the variable
367 * \param psz_name The name of the variable
369 static inline int __var_GetBool( vlc_object_t *p_obj, const char *psz_name )
371 vlc_value_t val;
372 if( !__var_Get( p_obj, psz_name, &val ) )
373 return val.b_bool;
374 else
375 return VLC_FALSE;
379 * Get a time value
381 * \param p_obj The object that holds the variable
382 * \param psz_name The name of the variable
384 static inline int64_t __var_GetTime( vlc_object_t *p_obj, const char *psz_name )
386 vlc_value_t val;
387 if( !__var_Get( p_obj, psz_name, &val ) )
388 return val.i_time;
389 else
390 return 0;
394 * Get a float value
396 * \param p_obj The object that holds the variable
397 * \param psz_name The name of the variable
399 static inline float __var_GetFloat( vlc_object_t *p_obj, const char *psz_name )
401 vlc_value_t val;
402 if( !__var_Get( p_obj, psz_name, &val ) )
403 return val.f_float;
404 else
405 return 0.0;
409 * Get a string value
411 * \param p_obj The object that holds the variable
412 * \param psz_name The name of the variable
414 static inline char *__var_GetString( vlc_object_t *p_obj, const char *psz_name )
416 vlc_value_t val;
417 if( !__var_Get( p_obj, psz_name, &val ) )
418 return val.psz_string;
419 else
420 return strdup( "" );
424 * __var_GetInteger() with automatic casting
426 #define var_GetInteger(a,b) __var_GetInteger( VLC_OBJECT(a),b)
428 * __var_GetBool() with automatic casting
430 #define var_GetBool(a,b) __var_GetBool( VLC_OBJECT(a),b)
432 * __var_GetTime() with automatic casting
434 #define var_GetTime(a,b) __var_GetTime( VLC_OBJECT(a),b)
436 * __var_GetFloat() with automatic casting
438 #define var_GetFloat(a,b) __var_GetFloat( VLC_OBJECT(a),b)
440 * __var_GetString() with automatic casting
442 #define var_GetString(a,b) __var_GetString( VLC_OBJECT(a),b)
446 * Create a integer variable with inherit and get its value.
448 * \param p_obj The object that holds the variable
449 * \param psz_name The name of the variable
451 static inline int __var_CreateGetInteger( vlc_object_t *p_obj, const char *psz_name )
453 vlc_value_t val;
455 __var_Create( p_obj, psz_name, VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
456 if( !__var_Get( p_obj, psz_name, &val ) )
457 return val.i_int;
458 else
459 return 0;
463 * Create a boolean variable with inherit and get its value.
465 * \param p_obj The object that holds the variable
466 * \param psz_name The name of the variable
468 static inline int __var_CreateGetBool( vlc_object_t *p_obj, const char *psz_name )
470 vlc_value_t val;
472 __var_Create( p_obj, psz_name, VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
473 if( !__var_Get( p_obj, psz_name, &val ) )
474 return val.b_bool;
475 else
476 return VLC_FALSE;
480 * Create a time variable with inherit and get its value.
482 * \param p_obj The object that holds the variable
483 * \param psz_name The name of the variable
485 static inline int64_t __var_CreateGetTime( vlc_object_t *p_obj, const char *psz_name )
487 vlc_value_t val;
489 __var_Create( p_obj, psz_name, VLC_VAR_TIME | VLC_VAR_DOINHERIT );
490 if( !__var_Get( p_obj, psz_name, &val ) )
491 return val.i_time;
492 else
493 return 0;
497 * Create a float 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
502 static inline float __var_CreateGetFloat( vlc_object_t *p_obj, const char *psz_name )
504 vlc_value_t val;
506 __var_Create( p_obj, psz_name, VLC_VAR_FLOAT | VLC_VAR_DOINHERIT );
507 if( !__var_Get( p_obj, psz_name, &val ) )
508 return val.f_float;
509 else
510 return 0.0;
514 * Create a string variable with inherit and get its value.
516 * \param p_obj The object that holds the variable
517 * \param psz_name The name of the variable
519 static inline char *__var_CreateGetString( vlc_object_t *p_obj, const char *psz_name )
521 vlc_value_t val;
523 __var_Create( p_obj, psz_name, VLC_VAR_STRING | VLC_VAR_DOINHERIT );
524 if( !__var_Get( p_obj, psz_name, &val ) )
525 return val.psz_string;
526 else
527 return strdup( "" );
531 * __var_CreateGetInteger() with automatic casting
533 #define var_CreateGetInteger(a,b) __var_CreateGetInteger( VLC_OBJECT(a),b)
535 * __var_CreateGetBool() with automatic casting
537 #define var_CreateGetBool(a,b) __var_CreateGetBool( VLC_OBJECT(a),b)
539 * __var_CreateGetTime() with automatic casting
541 #define var_CreateGetTime(a,b) __var_CreateGetTime( VLC_OBJECT(a),b)
543 * __var_CreateGetFloat() with automatic casting
545 #define var_CreateGetFloat(a,b) __var_CreateGetFloat( VLC_OBJECT(a),b)
547 * __var_CreateGetString() with automatic casting
549 #define var_CreateGetString(a,b) __var_CreateGetString( VLC_OBJECT(a),b)
552 * @}