]> git.sesse.net Git - vlc/blob - include/variables.h
b63b98c29093d99b2e013fc74d341862eabd28a7
[vlc] / include / variables.h
1 /*****************************************************************************
2  * variables.h: variables handling
3  *****************************************************************************
4  * Copyright (C) 2002 VideoLAN
5  * $Id: variables.h,v 1.17 2003/09/29 15:45:19 sigmunau Exp $
6  *
7  * Authors: Samuel Hocevar <sam@zoy.org>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  * 
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
22  *****************************************************************************/
23
24 /**
25  * \defgroup variables Variables
26  *
27  * Functions for using the object variables in vlc.
28  *
29  * Vlc have a very powerful "object variable" infrastructure useful
30  * for many things.
31  *
32  * @{
33  */
34
35 typedef struct callback_entry_t callback_entry_t;
36
37 /**
38  * The structure describing a variable. 
39  * \note vlc_value_t is the common union for variable values  
40  */
41 struct variable_t
42 {
43     /** The variable's exported value */
44     vlc_value_t  val;
45
46     char *       psz_name; /**< The variable unique name */
47     uint32_t     i_hash;   /**< (almost) unique hashed value */
48     int          i_type;   /**< The type of the variable */
49
50     /** The variable display name, mainly for use by the interfaces */
51     char *       psz_text;
52
53     /** A pointer to a comparison function */
54     int      ( * pf_cmp ) ( vlc_value_t, vlc_value_t );
55     /** A pointer to a duplication function */
56     void     ( * pf_dup ) ( vlc_value_t * );
57     /** A pointer to a deallocation function */
58     void     ( * pf_free ) ( vlc_value_t * );
59
60     /** Creation count: we only destroy the variable if it reaches 0 */
61     int          i_usage;
62
63     /** If the variable has min/max/step values */
64     vlc_value_t  min, max, step;
65
66     /** Index of the default choice, if the variable is to be chosen in
67      * a list */
68     int          i_default;
69     /** List of choices */
70     vlc_list_t   choices;
71     /** List of friendly names for the choices */
72     vlc_list_t   choices_text;
73
74     /** Set to TRUE if the variable is in a callback */
75     vlc_bool_t   b_incallback;
76
77     /** Number of registered callbacks */
78     int                i_entries;
79     /** Array of registered callbacks */
80     callback_entry_t * p_entries;
81 };
82
83 /*****************************************************************************
84  * Variable types - probably very incomplete
85  *****************************************************************************/
86 #define VLC_VAR_TYPE      0x00ff
87 #define VLC_VAR_FLAGS     0xff00
88
89 /**
90  * \defgroup var_type Variable types
91  * These are the different types a vlc variable can have.
92  * @{
93  */
94 #define VLC_VAR_VOID      0x0010
95 #define VLC_VAR_BOOL      0x0020
96 #define VLC_VAR_INTEGER   0x0030
97 #define VLC_VAR_STRING    0x0040
98 #define VLC_VAR_MODULE    0x0041
99 #define VLC_VAR_FILE      0x0042
100 #define VLC_VAR_DIRECTORY 0x0043
101 #define VLC_VAR_VARIABLE  0x0044
102 #define VLC_VAR_FLOAT     0x0050
103 #define VLC_VAR_TIME      0x0060
104 #define VLC_VAR_ADDRESS   0x0070
105 #define VLC_VAR_MUTEX     0x0080
106 #define VLC_VAR_LIST      0x0090
107 /**@}*/
108 /** \defgroup var_flags Additive flags
109  * These flags are added to the type field of the variable. Most as a result of
110  * a __var_Change() call, but some may be added at creation time
111  * @{
112  */
113 #define VLC_VAR_HASCHOICE 0x0100
114 #define VLC_VAR_HASMIN    0x0200
115 #define VLC_VAR_HASMAX    0x0400
116 #define VLC_VAR_HASSTEP   0x0800
117
118 #define VLC_VAR_ISLIST    0x1000
119 #define VLC_VAR_ISCOMMAND 0x2000
120 #define VLC_VAR_ISCONFIG  0x2000
121
122 /** Creation flag */
123 #define VLC_VAR_DOINHERIT 0x8000
124 /**@}*/
125
126 /**
127  * \defgroup var_action Variable actions
128  * These are the different actions that can be used with __var_Change().
129  * The parameters given are the meaning of the two last parameters of
130  * __var_Change() when this action is being used.
131  * @{
132  */
133
134 /**
135  * Set the minimum value of this variable
136  * \param p_val The new minimum value
137  * \param p_val2 Unused
138  */
139 #define VLC_VAR_SETMIN        0x0010
140 /**
141  * Set the maximum value of this variable
142  * \param p_val The new maximum value
143  * \param p_val2 Unused
144  */
145 #define VLC_VAR_SETMAX        0x0011
146 #define VLC_VAR_SETSTEP       0x0012
147
148 /**
149  * Set the value of this variable without triggering any callbacks
150  * \param p_val The new value
151  * \param p_val2 Unused
152  */
153 #define VLC_VAR_SETVALUE      0x0013
154
155 #define VLC_VAR_SETTEXT       0x0014
156 #define VLC_VAR_GETTEXT       0x0015
157
158 #define VLC_VAR_ADDCHOICE     0x0020
159 #define VLC_VAR_DELCHOICE     0x0021
160 #define VLC_VAR_CLEARCHOICES  0x0022
161 #define VLC_VAR_SETDEFAULT    0x0023
162 #define VLC_VAR_GETCHOICES    0x0024
163 #define VLC_VAR_FREECHOICES   0x0025
164 #define VLC_VAR_GETLIST       0x0026
165 #define VLC_VAR_FREELIST      0x0027
166 #define VLC_VAR_CHOICESCOUNT  0x0028
167
168 #define VLC_VAR_INHERITVALUE  0x0030
169 /**@}*/
170
171 /*****************************************************************************
172  * Prototypes
173  *****************************************************************************/
174 VLC_EXPORT( int, __var_Create, ( vlc_object_t *, const char *, int ) );
175 VLC_EXPORT( int, __var_Destroy, ( vlc_object_t *, const char * ) );
176
177 VLC_EXPORT( int, __var_Change, ( vlc_object_t *, const char *, int, vlc_value_t *, vlc_value_t * ) );
178
179 VLC_EXPORT( int, __var_Type, ( vlc_object_t *, const char * ) );
180 VLC_EXPORT( int, __var_Set, ( vlc_object_t *, const char *, vlc_value_t ) );
181 VLC_EXPORT( int, __var_Get, ( vlc_object_t *, const char *, vlc_value_t * ) );
182
183 /**
184  * __var_Create() with automatic casting.
185  */
186 #define var_Create(a,b,c) __var_Create( VLC_OBJECT(a), b, c )
187 /**
188  * __var_Destroy() with automatic casting
189  */
190 #define var_Destroy(a,b) __var_Destroy( VLC_OBJECT(a), b )
191
192 /**
193  * __var_Change() with automatic casting
194  */
195 #define var_Change(a,b,c,d,e) __var_Change( VLC_OBJECT(a), b, c, d, e )
196
197 /**
198  * __var_Type() with automatic casting
199  */
200 #define var_Type(a,b) __var_Type( VLC_OBJECT(a), b )
201 /**
202  * __var_Set() with automatic casting
203  */
204 #define var_Set(a,b,c) __var_Set( VLC_OBJECT(a), b, c )
205 /**
206  * __var_Get() with automatic casting
207  */
208 #define var_Get(a,b,c) __var_Get( VLC_OBJECT(a), b, c )
209
210 /*****************************************************************************
211  * Variable callbacks
212  *****************************************************************************
213  * int MyCallback( vlc_object_t *p_this,
214  *                 char const *psz_variable,
215  *                 vlc_value_t oldvalue,
216  *                 vlc_value_t newvalue,
217  *                 void *p_data);
218  *****************************************************************************/
219 VLC_EXPORT( int, __var_AddCallback, ( vlc_object_t *, const char *, vlc_callback_t, void * ) );
220 VLC_EXPORT( int, __var_DelCallback, ( vlc_object_t *, const char *, vlc_callback_t, void * ) );
221
222 /**
223  * __var_AddCallback() with automatic casting
224  */
225 #define var_AddCallback(a,b,c,d) __var_AddCallback( VLC_OBJECT(a), b, c, d )
226
227 /**
228  * __var_DelCallback() with automatic casting
229  */
230 #define var_DelCallback(a,b,c,d) __var_DelCallback( VLC_OBJECT(a), b, c, d )
231
232 /*****************************************************************************
233  * helpers functions
234  *****************************************************************************/
235
236 /**
237  * Set the value of an integer variable
238  *
239  * \param p_obj The object that holds the variable
240  * \param psz_name The name of the variable
241  * \param i The new integer value of this variable
242  */
243 static inline int __var_SetInteger( vlc_object_t *p_obj, const char *psz_name, int i )
244 {
245     vlc_value_t val;
246     val.i_int = i;
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, signed long long 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  * Trigger the callbacks on a void variable
280  *
281  * \param p_obj The object that holds the variable
282  * \param psz_name The name of the variable
283  */
284 static inline int __var_SetVoid( vlc_object_t *p_obj, const char *psz_name )
285 {
286     vlc_value_t val;
287     val.b_bool = VLC_TRUE;
288     return __var_Set( p_obj, psz_name, val );
289 }
290
291 /**
292  * __var_SetInteger() with automatic casting
293  */
294 #define var_SetInteger(a,b,c)   __var_SetInteger( VLC_OBJECT(a),b,c)
295 /**
296  * __var_SetTime() with automatic casting
297  */
298 #define var_SetTime(a,b,c)      __var_SetTime( VLC_OBJECT(a),b,c)
299 /**
300  * __var_SetFloat() with automatic casting
301  */
302 #define var_SetFloat(a,b,c)     __var_SetFloat( VLC_OBJECT(a),b,c)
303 /**
304  * __var_SetVoid() with automatic casting
305  */
306 #define var_SetVoid(a,b)        __var_SetVoid( VLC_OBJECT(a),b)
307
308 /**
309  * @}
310  */
311