]> git.sesse.net Git - vlc/blob - include/variables.h
Start of meta engine stuff. src/input/input.c needs to be fixed a bit. I'll finish...
[vlc] / include / 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 /**
26  * \defgroup variables Variables
27  *
28  * Functions for using the object variables in vlc.
29  *
30  * Vlc have a very powerful "object variable" infrastructure useful
31  * for many things.
32  *
33  * @{
34  */
35
36 typedef struct callback_entry_t callback_entry_t;
37
38 /**
39  * The structure describing a variable.
40  * \note vlc_value_t is the common union for variable values
41  */
42 struct variable_t
43 {
44     /** The variable's exported value */
45     vlc_value_t  val;
46
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 */
50
51     /** The variable display name, mainly for use by the interfaces */
52     char *       psz_text;
53
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 * );
60
61     /** Creation count: we only destroy the variable if it reaches 0 */
62     int          i_usage;
63
64     /** If the variable has min/max/step values */
65     vlc_value_t  min, max, step;
66
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;
74
75     /** Set to TRUE if the variable is in a callback */
76     vlc_bool_t   b_incallback;
77
78     /** Number of registered callbacks */
79     int                i_entries;
80     /** Array of registered callbacks */
81     callback_entry_t * p_entries;
82 };
83
84 /*****************************************************************************
85  * Variable types - probably very incomplete
86  *****************************************************************************/
87 #define VLC_VAR_TYPE      0x00ff
88 #define VLC_VAR_FLAGS     0xff00
89
90 /** \defgroup var_flags Additive flags
91  * These flags are added to the type field of the variable. Most as a result of
92  * a __var_Change() call, but some may be added at creation time
93  * @{
94  */
95 #define VLC_VAR_HASCHOICE 0x0100
96 #define VLC_VAR_HASMIN    0x0200
97 #define VLC_VAR_HASMAX    0x0400
98 #define VLC_VAR_HASSTEP   0x0800
99
100 #define VLC_VAR_ISLIST    0x1000
101 #define VLC_VAR_ISCOMMAND 0x2000
102 #define VLC_VAR_ISCONFIG  0x2000
103
104 /** Creation flag */
105 #define VLC_VAR_DOINHERIT 0x8000
106 /**@}*/
107
108 /**
109  * \defgroup var_action Variable actions
110  * These are the different actions that can be used with __var_Change().
111  * The parameters given are the meaning of the two last parameters of
112  * __var_Change() when this action is being used.
113  * @{
114  */
115
116 /**
117  * Set the minimum value of this variable
118  * \param p_val The new minimum value
119  * \param p_val2 Unused
120  */
121 #define VLC_VAR_SETMIN              0x0010
122 /**
123  * Set the maximum value of this variable
124  * \param p_val The new maximum value
125  * \param p_val2 Unused
126  */
127 #define VLC_VAR_SETMAX              0x0011
128 #define VLC_VAR_SETSTEP             0x0012
129
130 /**
131  * Set the value of this variable without triggering any callbacks
132  * \param p_val The new value
133  * \param p_val2 Unused
134  */
135 #define VLC_VAR_SETVALUE            0x0013
136
137 #define VLC_VAR_SETTEXT             0x0014
138 #define VLC_VAR_GETTEXT             0x0015
139
140 #define VLC_VAR_ADDCHOICE           0x0020
141 #define VLC_VAR_DELCHOICE           0x0021
142 #define VLC_VAR_CLEARCHOICES        0x0022
143 #define VLC_VAR_SETDEFAULT          0x0023
144 #define VLC_VAR_GETCHOICES          0x0024
145 #define VLC_VAR_FREECHOICES         0x0025
146 #define VLC_VAR_GETLIST             0x0026
147 #define VLC_VAR_FREELIST            0x0027
148 #define VLC_VAR_CHOICESCOUNT        0x0028
149
150 #define VLC_VAR_INHERITVALUE        0x0030
151 #define VLC_VAR_TRIGGER_CALLBACKS   0x0035
152 /**@}*/
153
154 /*****************************************************************************
155  * Prototypes
156  *****************************************************************************/
157 VLC_EXPORT( int, __var_Create, ( vlc_object_t *, const char *, int ) );
158 VLC_EXPORT( int, __var_Destroy, ( vlc_object_t *, const char * ) );
159
160 VLC_EXPORT( int, __var_Change, ( vlc_object_t *, const char *, int, vlc_value_t *, vlc_value_t * ) );
161
162 VLC_EXPORT( int, __var_Type, ( vlc_object_t *, const char * ) );
163 VLC_EXPORT( int, __var_Set, ( vlc_object_t *, const char *, vlc_value_t ) );
164 VLC_EXPORT( int, __var_Get, ( vlc_object_t *, const char *, vlc_value_t * ) );
165
166 #define var_OptionParse(a,b) __var_OptionParse( VLC_OBJECT( a ) , b )
167 VLC_EXPORT( void, __var_OptionParse, ( vlc_object_t *, const char * ) );
168
169 /**
170  * __var_Create() with automatic casting.
171  */
172 #define var_Create(a,b,c) __var_Create( VLC_OBJECT(a), b, c )
173 /**
174  * __var_Destroy() with automatic casting
175  */
176 #define var_Destroy(a,b) __var_Destroy( VLC_OBJECT(a), b )
177
178 /**
179  * __var_Change() with automatic casting
180  */
181 #define var_Change(a,b,c,d,e) __var_Change( VLC_OBJECT(a), b, c, d, e )
182
183 /**
184  * __var_Type() with automatic casting
185  */
186 #define var_Type(a,b) __var_Type( VLC_OBJECT(a), b )
187 /**
188  * __var_Set() with automatic casting
189  */
190 #define var_Set(a,b,c) __var_Set( VLC_OBJECT(a), b, c )
191 /**
192  * __var_Get() with automatic casting
193  */
194 #define var_Get(a,b,c) __var_Get( VLC_OBJECT(a), b, c )
195
196 /*****************************************************************************
197  * Variable callbacks
198  *****************************************************************************
199  * int MyCallback( vlc_object_t *p_this,
200  *                 char const *psz_variable,
201  *                 vlc_value_t oldvalue,
202  *                 vlc_value_t newvalue,
203  *                 void *p_data);
204  *****************************************************************************/
205 VLC_EXPORT( int, __var_AddCallback, ( vlc_object_t *, const char *, vlc_callback_t, void * ) );
206 VLC_EXPORT( int, __var_DelCallback, ( vlc_object_t *, const char *, vlc_callback_t, void * ) );
207
208 /**
209  * __var_AddCallback() with automatic casting
210  */
211 #define var_AddCallback(a,b,c,d) __var_AddCallback( VLC_OBJECT(a), b, c, d )
212
213 /**
214  * __var_DelCallback() with automatic casting
215  */
216 #define var_DelCallback(a,b,c,d) __var_DelCallback( VLC_OBJECT(a), b, c, d )
217
218 /*****************************************************************************
219  * helpers functions
220  *****************************************************************************/
221
222 /**
223  * Set the value of an integer variable
224  *
225  * \param p_obj The object that holds the variable
226  * \param psz_name The name of the variable
227  * \param i The new integer value of this variable
228  */
229 static inline int __var_SetInteger( vlc_object_t *p_obj, const char *psz_name, int i )
230 {
231     vlc_value_t val;
232     val.i_int = i;
233     return __var_Set( p_obj, psz_name, val );
234 }
235 #define var_SetInteger(a,b,c)   __var_SetInteger( VLC_OBJECT(a),b,c)
236 /**
237  * Set the value of an boolean variable
238  *
239  * \param p_obj The object that holds the variable
240  * \param psz_name The name of the variable
241  * \param b The new boolean value of this variable
242  */
243 static inline int __var_SetBool( vlc_object_t *p_obj, const char *psz_name, vlc_bool_t b )
244 {
245     vlc_value_t val;
246     val.b_bool = b;
247     return __var_Set( p_obj, psz_name, val );
248 }
249
250 /**
251  * Set the value of a time variable
252  *
253  * \param p_obj The object that holds the variable
254  * \param psz_name The name of the variable
255  * \param i The new time value of this variable
256  */
257 static inline int __var_SetTime( vlc_object_t *p_obj, const char *psz_name, int64_t i )
258 {
259     vlc_value_t val;
260     val.i_time = i;
261     return __var_Set( p_obj, psz_name, val );
262 }
263
264 /**
265  * Set the value of a float variable
266  *
267  * \param p_obj The object that holds the variable
268  * \param psz_name The name of the variable
269  * \param f The new float value of this variable
270  */
271 static inline int __var_SetFloat( vlc_object_t *p_obj, const char *psz_name, float f )
272 {
273     vlc_value_t val;
274     val.f_float = f;
275     return __var_Set( p_obj, psz_name, val );
276 }
277
278 /**
279  * Set the value of a string variable
280  *
281  * \param p_obj The object that holds the variable
282  * \param psz_name The name of the variable
283  * \param psz_string The new string value of this variable
284  */
285 static inline int __var_SetString( vlc_object_t *p_obj, const char *psz_name, char *psz_string )
286 {
287     vlc_value_t val;
288     val.psz_string = psz_string;
289     return __var_Set( p_obj, psz_name, val );
290 }
291
292 /**
293  * Trigger the callbacks on a void variable
294  *
295  * \param p_obj The object that holds the variable
296  * \param psz_name The name of the variable
297  */
298 static inline int __var_SetVoid( vlc_object_t *p_obj, const char *psz_name )
299 {
300     vlc_value_t val;
301     val.b_bool = VLC_TRUE;
302     return __var_Set( p_obj, psz_name, val );
303 }
304 #define var_SetVoid(a,b)        __var_SetVoid( VLC_OBJECT(a),b)
305
306 /**
307  * __var_SetBool() with automatic casting
308  */
309 #define var_SetBool(a,b,c)   __var_SetBool( VLC_OBJECT(a),b,c)
310
311 /**
312  * __var_SetTime() with automatic casting
313  */
314 #define var_SetTime(a,b,c)      __var_SetTime( VLC_OBJECT(a),b,c)
315 /**
316  * __var_SetFloat() with automatic casting
317  */
318 #define var_SetFloat(a,b,c)     __var_SetFloat( VLC_OBJECT(a),b,c)
319 /**
320  * __var_SetString() with automatic casting
321  */
322 #define var_SetString(a,b,c)     __var_SetString( VLC_OBJECT(a),b,c)
323
324 /**
325  * Get an integer value
326 *
327  * \param p_obj The object that holds the variable
328  * \param psz_name The name of the variable
329  */
330 static inline int __var_GetInteger( vlc_object_t *p_obj, const char *psz_name )
331 {
332     vlc_value_t val;val.i_int = 0;
333     if( !__var_Get( p_obj, psz_name, &val ) )
334         return val.i_int;
335     else
336         return 0;
337 }
338
339 /**
340  * Get a boolean value
341  *
342  * \param p_obj The object that holds the variable
343  * \param psz_name The name of the variable
344  */
345 static inline int __var_GetBool( vlc_object_t *p_obj, const char *psz_name )
346 {
347     vlc_value_t val; val.b_bool = VLC_FALSE;
348     if( !__var_Get( p_obj, psz_name, &val ) )
349         return val.b_bool;
350     else
351         return VLC_FALSE;
352 }
353
354 /**
355  * Get a time value
356  *
357  * \param p_obj The object that holds the variable
358  * \param psz_name The name of the variable
359  */
360 static inline int64_t __var_GetTime( vlc_object_t *p_obj, const char *psz_name )
361 {
362     vlc_value_t val; val.i_time = 0L;
363     if( !__var_Get( p_obj, psz_name, &val ) )
364         return val.i_time;
365     else
366         return 0;
367 }
368
369 /**
370  * Get a float value
371  *
372  * \param p_obj The object that holds the variable
373  * \param psz_name The name of the variable
374  */
375 static inline float __var_GetFloat( vlc_object_t *p_obj, const char *psz_name )
376 {
377     vlc_value_t val; val.f_float = 0.0;
378     if( !__var_Get( p_obj, psz_name, &val ) )
379         return val.f_float;
380     else
381         return 0.0;
382 }
383
384 /**
385  * Get a string value
386  *
387  * \param p_obj The object that holds the variable
388  * \param psz_name The name of the variable
389  */
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_Get( p_obj, psz_name, &val ) )
394         return val.psz_string;
395     else
396         return strdup( "" );
397 }
398
399 /**
400  * __var_GetInteger() with automatic casting
401  */
402 #define var_GetInteger(a,b)   __var_GetInteger( VLC_OBJECT(a),b)
403 /**
404  * __var_GetBool() with automatic casting
405  */
406 #define var_GetBool(a,b)   __var_GetBool( VLC_OBJECT(a),b)
407 /**
408  * __var_GetTime() with automatic casting
409  */
410 #define var_GetTime(a,b)   __var_GetTime( VLC_OBJECT(a),b)
411 /**
412  * __var_GetFloat() with automatic casting
413  */
414 #define var_GetFloat(a,b)   __var_GetFloat( VLC_OBJECT(a),b)
415 /**
416  * __var_GetString() with automatic casting
417  */
418 #define var_GetString(a,b)   __var_GetString( VLC_OBJECT(a),b)
419
420
421
422 /**
423  * Increment an integer variable
424  * \param p_obj the object that holds the variable
425  * \param psz_name the name of the variable
426  */
427 static inline void __var_IncInteger( vlc_object_t *p_obj, const char *psz_name )
428 {
429     int i_val = __var_GetInteger( p_obj, psz_name );
430     __var_SetInteger( p_obj, psz_name, ++i_val );
431 }
432 #define var_IncInteger(a,b) __var_IncInteger( VLC_OBJECT(a), b )
433
434 /**
435  * Decrement an integer variable
436  * \param p_obj the object that holds the variable
437  * \param psz_name the name of the variable
438  */
439 static inline void __var_DecInteger( vlc_object_t *p_obj, const char *psz_name )
440 {
441     int i_val = __var_GetInteger( p_obj, psz_name );
442     __var_SetInteger( p_obj, psz_name, --i_val );
443 }
444 #define var_DecInteger(a,b) __var_DecInteger( VLC_OBJECT(a), b )
445
446 /**
447  * Create a integer variable with inherit and get its value.
448  *
449  * \param p_obj The object that holds the variable
450  * \param psz_name The name of the variable
451  */
452 static inline int __var_CreateGetInteger( vlc_object_t *p_obj, const char *psz_name )
453 {
454     vlc_value_t val;
455
456     __var_Create( p_obj, psz_name, VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
457     if( !__var_Get( p_obj, psz_name, &val ) )
458         return val.i_int;
459     else
460         return 0;
461 }
462
463 /**
464  * Create a boolean variable with inherit and get its value.
465  *
466  * \param p_obj The object that holds the variable
467  * \param psz_name The name of the variable
468  */
469 static inline int __var_CreateGetBool( vlc_object_t *p_obj, const char *psz_name )
470 {
471     vlc_value_t val;
472
473     __var_Create( p_obj, psz_name, VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
474     if( !__var_Get( p_obj, psz_name, &val ) )
475         return val.b_bool;
476     else
477         return VLC_FALSE;
478 }
479
480 /**
481  * Create a time variable with inherit and get its value.
482  *
483  * \param p_obj The object that holds the variable
484  * \param psz_name The name of the variable
485  */
486 static inline int64_t __var_CreateGetTime( vlc_object_t *p_obj, const char *psz_name )
487 {
488     vlc_value_t val;
489
490     __var_Create( p_obj, psz_name, VLC_VAR_TIME | VLC_VAR_DOINHERIT );
491     if( !__var_Get( p_obj, psz_name, &val ) )
492         return val.i_time;
493     else
494         return 0;
495 }
496
497 /**
498  * Create a float variable with inherit and get its value.
499  *
500  * \param p_obj The object that holds the variable
501  * \param psz_name The name of the variable
502  */
503 static inline float __var_CreateGetFloat( vlc_object_t *p_obj, const char *psz_name )
504 {
505     vlc_value_t val;
506
507     __var_Create( p_obj, psz_name, VLC_VAR_FLOAT | VLC_VAR_DOINHERIT );
508     if( !__var_Get( p_obj, psz_name, &val ) )
509         return val.f_float;
510     else
511         return 0.0;
512 }
513
514 /**
515  * Create a string variable with inherit and get its value.
516  *
517  * \param p_obj The object that holds the variable
518  * \param psz_name The name of the variable
519  */
520 static inline char *__var_CreateGetString( vlc_object_t *p_obj, const char *psz_name )
521 {
522     vlc_value_t val;
523
524     __var_Create( p_obj, psz_name, VLC_VAR_STRING | VLC_VAR_DOINHERIT );
525     if( !__var_Get( p_obj, psz_name, &val ) )
526         return val.psz_string;
527     else
528         return strdup( "" );
529 }
530
531 /**
532  * __var_CreateGetInteger() with automatic casting
533  */
534 #define var_CreateGetInteger(a,b)   __var_CreateGetInteger( VLC_OBJECT(a),b)
535 /**
536  * __var_CreateGetBool() with automatic casting
537  */
538 #define var_CreateGetBool(a,b)   __var_CreateGetBool( VLC_OBJECT(a),b)
539 /**
540  * __var_CreateGetTime() with automatic casting
541  */
542 #define var_CreateGetTime(a,b)   __var_CreateGetTime( VLC_OBJECT(a),b)
543 /**
544  * __var_CreateGetFloat() with automatic casting
545  */
546 #define var_CreateGetFloat(a,b)   __var_CreateGetFloat( VLC_OBJECT(a),b)
547 /**
548  * __var_CreateGetString() with automatic casting
549  */
550 #define var_CreateGetString(a,b)   __var_CreateGetString( VLC_OBJECT(a),b)
551
552 /**
553  * @}
554  */
555