]> git.sesse.net Git - vlc/blob - include/vlc_variables.h
630d36d45a4d1dfa2d567c4386800235542c8226
[vlc] / include / vlc_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 /*****************************************************************************
37  * Variable types - probably very incomplete
38  *****************************************************************************/
39 #define VLC_VAR_TYPE      0x00ff
40 #define VLC_VAR_FLAGS     0xff00
41
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
45  * @{
46  */
47 #define VLC_VAR_HASCHOICE 0x0100
48 #define VLC_VAR_HASMIN    0x0200
49 #define VLC_VAR_HASMAX    0x0400
50 #define VLC_VAR_HASSTEP   0x0800
51
52 #define VLC_VAR_ISLIST    0x1000
53 #define VLC_VAR_ISCOMMAND 0x2000
54 #define VLC_VAR_ISCONFIG  0x2000
55
56 /** Creation flag */
57 #define VLC_VAR_DOINHERIT 0x8000
58 /**@}*/
59
60 /**
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.
65  * @{
66  */
67
68 /**
69  * Set the minimum value of this variable
70  * \param p_val The new minimum value
71  * \param p_val2 Unused
72  */
73 #define VLC_VAR_SETMIN              0x0010
74 /**
75  * Set the maximum value of this variable
76  * \param p_val The new maximum value
77  * \param p_val2 Unused
78  */
79 #define VLC_VAR_SETMAX              0x0011
80 #define VLC_VAR_SETSTEP             0x0012
81
82 /**
83  * Set the value of this variable without triggering any callbacks
84  * \param p_val The new value
85  * \param p_val2 Unused
86  */
87 #define VLC_VAR_SETVALUE            0x0013
88
89 #define VLC_VAR_SETTEXT             0x0014
90 #define VLC_VAR_GETTEXT             0x0015
91
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
101
102 #define VLC_VAR_INHERITVALUE        0x0030
103 #define VLC_VAR_TRIGGER_CALLBACKS   0x0035
104 /**@}*/
105
106 /*****************************************************************************
107  * Prototypes
108  *****************************************************************************/
109 VLC_EXPORT( int, __var_Create, ( vlc_object_t *, const char *, int ) );
110 VLC_EXPORT( int, __var_Destroy, ( vlc_object_t *, const char * ) );
111
112 VLC_EXPORT( int, __var_Change, ( vlc_object_t *, const char *, int, vlc_value_t *, vlc_value_t * ) );
113
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 * ) );
117
118 #define var_OptionParse(a,b) __var_OptionParse( VLC_OBJECT( a ) , b )
119 VLC_EXPORT( void, __var_OptionParse, ( vlc_object_t *, const char * ) );
120
121 /**
122  * __var_Create() with automatic casting.
123  */
124 #define var_Create(a,b,c) __var_Create( VLC_OBJECT(a), b, c )
125 /**
126  * __var_Destroy() with automatic casting
127  */
128 #define var_Destroy(a,b) __var_Destroy( VLC_OBJECT(a), b )
129
130 /**
131  * __var_Change() with automatic casting
132  */
133 #define var_Change(a,b,c,d,e) __var_Change( VLC_OBJECT(a), b, c, d, e )
134
135 /**
136  * __var_Type() with automatic casting
137  */
138 #define var_Type(a,b) __var_Type( VLC_OBJECT(a), b )
139 /**
140  * __var_Set() with automatic casting
141  */
142 #define var_Set(a,b,c) __var_Set( VLC_OBJECT(a), b, c )
143 /**
144  * __var_Get() with automatic casting
145  */
146 #define var_Get(a,b,c) __var_Get( VLC_OBJECT(a), b, c )
147
148 /*****************************************************************************
149  * Variable callbacks
150  *****************************************************************************
151  * int MyCallback( vlc_object_t *p_this,
152  *                 char const *psz_variable,
153  *                 vlc_value_t oldvalue,
154  *                 vlc_value_t newvalue,
155  *                 void *p_data);
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 * ) );
159
160 /**
161  * __var_AddCallback() with automatic casting
162  */
163 #define var_AddCallback(a,b,c,d) __var_AddCallback( VLC_OBJECT(a), b, c, d )
164
165 /**
166  * __var_DelCallback() with automatic casting
167  */
168 #define var_DelCallback(a,b,c,d) __var_DelCallback( VLC_OBJECT(a), b, c, d )
169
170 /*****************************************************************************
171  * helpers functions
172  *****************************************************************************/
173
174 /**
175  * Set the value of an integer variable
176  *
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
180  */
181 static inline int __var_SetInteger( vlc_object_t *p_obj, const char *psz_name, int i )
182 {
183     vlc_value_t val;
184     val.i_int = i;
185     return __var_Set( p_obj, psz_name, val );
186 }
187 #define var_SetInteger(a,b,c)   __var_SetInteger( VLC_OBJECT(a),b,c)
188 /**
189  * Set the value of an boolean variable
190  *
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
194  */
195 static inline int __var_SetBool( vlc_object_t *p_obj, const char *psz_name, vlc_bool_t b )
196 {
197     vlc_value_t val;
198     val.b_bool = b;
199     return __var_Set( p_obj, psz_name, val );
200 }
201
202 /**
203  * Set the value of a time variable
204  *
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
208  */
209 static inline int __var_SetTime( vlc_object_t *p_obj, const char *psz_name, int64_t i )
210 {
211     vlc_value_t val;
212     val.i_time = i;
213     return __var_Set( p_obj, psz_name, val );
214 }
215
216 /**
217  * Set the value of a float variable
218  *
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
222  */
223 static inline int __var_SetFloat( vlc_object_t *p_obj, const char *psz_name, float f )
224 {
225     vlc_value_t val;
226     val.f_float = f;
227     return __var_Set( p_obj, psz_name, val );
228 }
229
230 /**
231  * Set the value of a string variable
232  *
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
236  */
237 static inline int __var_SetString( vlc_object_t *p_obj, const char *psz_name, const char *psz_string )
238 {
239     vlc_value_t val;
240     val.psz_string = (char *)psz_string;
241     return __var_Set( p_obj, psz_name, val );
242 }
243
244 /**
245  * Trigger the callbacks on a void variable
246  *
247  * \param p_obj The object that holds the variable
248  * \param psz_name The name of the variable
249  */
250 static inline int __var_SetVoid( vlc_object_t *p_obj, const char *psz_name )
251 {
252     vlc_value_t val;
253     val.b_bool = VLC_TRUE;
254     return __var_Set( p_obj, psz_name, val );
255 }
256 #define var_SetVoid(a,b)        __var_SetVoid( VLC_OBJECT(a),b)
257
258 /**
259  * __var_SetBool() with automatic casting
260  */
261 #define var_SetBool(a,b,c)   __var_SetBool( VLC_OBJECT(a),b,c)
262
263 /**
264  * __var_SetTime() with automatic casting
265  */
266 #define var_SetTime(a,b,c)      __var_SetTime( VLC_OBJECT(a),b,c)
267 /**
268  * __var_SetFloat() with automatic casting
269  */
270 #define var_SetFloat(a,b,c)     __var_SetFloat( VLC_OBJECT(a),b,c)
271 /**
272  * __var_SetString() with automatic casting
273  */
274 #define var_SetString(a,b,c)     __var_SetString( VLC_OBJECT(a),b,c)
275
276 /**
277  * Get an integer value
278 *
279  * \param p_obj The object that holds the variable
280  * \param psz_name The name of the variable
281  */
282 static inline int __var_GetInteger( vlc_object_t *p_obj, const char *psz_name )
283 {
284     vlc_value_t val;val.i_int = 0;
285     if( !__var_Get( p_obj, psz_name, &val ) )
286         return val.i_int;
287     else
288         return 0;
289 }
290
291 /**
292  * Get a boolean value
293  *
294  * \param p_obj The object that holds the variable
295  * \param psz_name The name of the variable
296  */
297 static inline int __var_GetBool( vlc_object_t *p_obj, const char *psz_name )
298 {
299     vlc_value_t val; val.b_bool = VLC_FALSE;
300     if( !__var_Get( p_obj, psz_name, &val ) )
301         return val.b_bool;
302     else
303         return VLC_FALSE;
304 }
305
306 /**
307  * Get a time value
308  *
309  * \param p_obj The object that holds the variable
310  * \param psz_name The name of the variable
311  */
312 static inline int64_t __var_GetTime( vlc_object_t *p_obj, const char *psz_name )
313 {
314     vlc_value_t val; val.i_time = 0L;
315     if( !__var_Get( p_obj, psz_name, &val ) )
316         return val.i_time;
317     else
318         return 0;
319 }
320
321 /**
322  * Get a float value
323  *
324  * \param p_obj The object that holds the variable
325  * \param psz_name The name of the variable
326  */
327 static inline float __var_GetFloat( vlc_object_t *p_obj, const char *psz_name )
328 {
329     vlc_value_t val; val.f_float = 0.0;
330     if( !__var_Get( p_obj, psz_name, &val ) )
331         return val.f_float;
332     else
333         return 0.0;
334 }
335
336 /**
337  * Get a string value
338  *
339  * \param p_obj The object that holds the variable
340  * \param psz_name The name of the variable
341  */
342 static inline char *__var_GetString( vlc_object_t *p_obj, const char *psz_name )
343 {
344     vlc_value_t val; val.psz_string = NULL;
345     if( !__var_Get( p_obj, psz_name, &val ) )
346         return val.psz_string;
347     else
348         return strdup( "" );
349 }
350
351 /**
352  * __var_GetInteger() with automatic casting
353  */
354 #define var_GetInteger(a,b)   __var_GetInteger( VLC_OBJECT(a),b)
355 /**
356  * __var_GetBool() with automatic casting
357  */
358 #define var_GetBool(a,b)   __var_GetBool( VLC_OBJECT(a),b)
359 /**
360  * __var_GetTime() with automatic casting
361  */
362 #define var_GetTime(a,b)   __var_GetTime( VLC_OBJECT(a),b)
363 /**
364  * __var_GetFloat() with automatic casting
365  */
366 #define var_GetFloat(a,b)   __var_GetFloat( VLC_OBJECT(a),b)
367 /**
368  * __var_GetString() with automatic casting
369  */
370 #define var_GetString(a,b)   __var_GetString( VLC_OBJECT(a),b)
371
372
373
374 /**
375  * Increment an integer variable
376  * \param p_obj the object that holds the variable
377  * \param psz_name the name of the variable
378  */
379 static inline void __var_IncInteger( vlc_object_t *p_obj, const char *psz_name )
380 {
381     int i_val = __var_GetInteger( p_obj, psz_name );
382     __var_SetInteger( p_obj, psz_name, ++i_val );
383 }
384 #define var_IncInteger(a,b) __var_IncInteger( VLC_OBJECT(a), b )
385
386 /**
387  * Decrement an integer variable
388  * \param p_obj the object that holds the variable
389  * \param psz_name the name of the variable
390  */
391 static inline void __var_DecInteger( vlc_object_t *p_obj, const char *psz_name )
392 {
393     int i_val = __var_GetInteger( p_obj, psz_name );
394     __var_SetInteger( p_obj, psz_name, --i_val );
395 }
396 #define var_DecInteger(a,b) __var_DecInteger( VLC_OBJECT(a), b )
397
398 /**
399  * Create a integer variable with inherit and get its value.
400  *
401  * \param p_obj The object that holds the variable
402  * \param psz_name The name of the variable
403  */
404 static inline int __var_CreateGetInteger( vlc_object_t *p_obj, const char *psz_name )
405 {
406     vlc_value_t val;
407
408     __var_Create( p_obj, psz_name, VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
409     if( !__var_Get( p_obj, psz_name, &val ) )
410         return val.i_int;
411     else
412         return 0;
413 }
414
415 /**
416  * Create a boolean variable with inherit and get its value.
417  *
418  * \param p_obj The object that holds the variable
419  * \param psz_name The name of the variable
420  */
421 static inline int __var_CreateGetBool( vlc_object_t *p_obj, const char *psz_name )
422 {
423     vlc_value_t val;
424
425     __var_Create( p_obj, psz_name, VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
426     if( !__var_Get( p_obj, psz_name, &val ) )
427         return val.b_bool;
428     else
429         return VLC_FALSE;
430 }
431
432 /**
433  * Create a time variable with inherit and get its value.
434  *
435  * \param p_obj The object that holds the variable
436  * \param psz_name The name of the variable
437  */
438 static inline int64_t __var_CreateGetTime( vlc_object_t *p_obj, const char *psz_name )
439 {
440     vlc_value_t val;
441
442     __var_Create( p_obj, psz_name, VLC_VAR_TIME | VLC_VAR_DOINHERIT );
443     if( !__var_Get( p_obj, psz_name, &val ) )
444         return val.i_time;
445     else
446         return 0;
447 }
448
449 /**
450  * Create a float variable with inherit and get its value.
451  *
452  * \param p_obj The object that holds the variable
453  * \param psz_name The name of the variable
454  */
455 static inline float __var_CreateGetFloat( vlc_object_t *p_obj, const char *psz_name )
456 {
457     vlc_value_t val;
458
459     __var_Create( p_obj, psz_name, VLC_VAR_FLOAT | VLC_VAR_DOINHERIT );
460     if( !__var_Get( p_obj, psz_name, &val ) )
461         return val.f_float;
462     else
463         return 0.0;
464 }
465
466 /**
467  * Create a string variable with inherit and get its value.
468  *
469  * \param p_obj The object that holds the variable
470  * \param psz_name The name of the variable
471  */
472 static inline char *__var_CreateGetString( vlc_object_t *p_obj, const char *psz_name )
473 {
474     vlc_value_t val;
475
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;
479     else
480         return strdup( "" );
481 }
482
483 /**
484  * __var_CreateGetInteger() with automatic casting
485  */
486 #define var_CreateGetInteger(a,b)   __var_CreateGetInteger( VLC_OBJECT(a),b)
487 /**
488  * __var_CreateGetBool() with automatic casting
489  */
490 #define var_CreateGetBool(a,b)   __var_CreateGetBool( VLC_OBJECT(a),b)
491 /**
492  * __var_CreateGetTime() with automatic casting
493  */
494 #define var_CreateGetTime(a,b)   __var_CreateGetTime( VLC_OBJECT(a),b)
495 /**
496  * __var_CreateGetFloat() with automatic casting
497  */
498 #define var_CreateGetFloat(a,b)   __var_CreateGetFloat( VLC_OBJECT(a),b)
499 /**
500  * __var_CreateGetString() with automatic casting
501  */
502 #define var_CreateGetString(a,b)   __var_CreateGetString( VLC_OBJECT(a),b)
503
504 /**
505  * @}
506  */
507