]> git.sesse.net Git - vlc/blob - include/variables.h
8e658ea701563e3cbea1f16df1346e15ae8b38a7
[vlc] / include / variables.h
1 /*****************************************************************************
2  * variables.h: variables handling
3  *****************************************************************************
4  * Copyright (C) 2002 VideoLAN
5  * $Id: variables.h,v 1.20 2004/01/09 20:36:21 hartman 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_HOTKEY    0x0031
98 #define VLC_VAR_STRING    0x0040
99 #define VLC_VAR_MODULE    0x0041
100 #define VLC_VAR_FILE      0x0042
101 #define VLC_VAR_DIRECTORY 0x0043
102 #define VLC_VAR_VARIABLE  0x0044
103 #define VLC_VAR_FLOAT     0x0050
104 #define VLC_VAR_TIME      0x0060
105 #define VLC_VAR_ADDRESS   0x0070
106 #define VLC_VAR_MUTEX     0x0080
107 #define VLC_VAR_LIST      0x0090
108 /**@}*/
109 /** \defgroup var_flags Additive flags
110  * These flags are added to the type field of the variable. Most as a result of
111  * a __var_Change() call, but some may be added at creation time
112  * @{
113  */
114 #define VLC_VAR_HASCHOICE 0x0100
115 #define VLC_VAR_HASMIN    0x0200
116 #define VLC_VAR_HASMAX    0x0400
117 #define VLC_VAR_HASSTEP   0x0800
118
119 #define VLC_VAR_ISLIST    0x1000
120 #define VLC_VAR_ISCOMMAND 0x2000
121 #define VLC_VAR_ISCONFIG  0x2000
122
123 /** Creation flag */
124 #define VLC_VAR_DOINHERIT 0x8000
125 /**@}*/
126
127 /**
128  * \defgroup var_action Variable actions
129  * These are the different actions that can be used with __var_Change().
130  * The parameters given are the meaning of the two last parameters of
131  * __var_Change() when this action is being used.
132  * @{
133  */
134
135 /**
136  * Set the minimum value of this variable
137  * \param p_val The new minimum value
138  * \param p_val2 Unused
139  */
140 #define VLC_VAR_SETMIN              0x0010
141 /**
142  * Set the maximum value of this variable
143  * \param p_val The new maximum value
144  * \param p_val2 Unused
145  */
146 #define VLC_VAR_SETMAX              0x0011
147 #define VLC_VAR_SETSTEP             0x0012
148
149 /**
150  * Set the value of this variable without triggering any callbacks
151  * \param p_val The new value
152  * \param p_val2 Unused
153  */
154 #define VLC_VAR_SETVALUE            0x0013
155
156 #define VLC_VAR_SETTEXT             0x0014
157 #define VLC_VAR_GETTEXT             0x0015
158
159 #define VLC_VAR_ADDCHOICE           0x0020
160 #define VLC_VAR_DELCHOICE           0x0021
161 #define VLC_VAR_CLEARCHOICES        0x0022
162 #define VLC_VAR_SETDEFAULT          0x0023
163 #define VLC_VAR_GETCHOICES          0x0024
164 #define VLC_VAR_FREECHOICES         0x0025
165 #define VLC_VAR_GETLIST             0x0026
166 #define VLC_VAR_FREELIST            0x0027
167 #define VLC_VAR_CHOICESCOUNT        0x0028
168
169 #define VLC_VAR_INHERITVALUE        0x0030
170 #define VLC_VAR_TRIGGER_CALLBACKS   0x0035
171 /**@}*/
172
173 /*****************************************************************************
174  * Prototypes
175  *****************************************************************************/
176 VLC_EXPORT( int, __var_Create, ( vlc_object_t *, const char *, int ) );
177 VLC_EXPORT( int, __var_Destroy, ( vlc_object_t *, const char * ) );
178
179 VLC_EXPORT( int, __var_Change, ( vlc_object_t *, const char *, int, vlc_value_t *, vlc_value_t * ) );
180
181 VLC_EXPORT( int, __var_Type, ( vlc_object_t *, const char * ) );
182 VLC_EXPORT( int, __var_Set, ( vlc_object_t *, const char *, vlc_value_t ) );
183 VLC_EXPORT( int, __var_Get, ( vlc_object_t *, const char *, vlc_value_t * ) );
184
185 /**
186  * __var_Create() with automatic casting.
187  */
188 #define var_Create(a,b,c) __var_Create( VLC_OBJECT(a), b, c )
189 /**
190  * __var_Destroy() with automatic casting
191  */
192 #define var_Destroy(a,b) __var_Destroy( VLC_OBJECT(a), b )
193
194 /**
195  * __var_Change() with automatic casting
196  */
197 #define var_Change(a,b,c,d,e) __var_Change( VLC_OBJECT(a), b, c, d, e )
198
199 /**
200  * __var_Type() with automatic casting
201  */
202 #define var_Type(a,b) __var_Type( VLC_OBJECT(a), b )
203 /**
204  * __var_Set() with automatic casting
205  */
206 #define var_Set(a,b,c) __var_Set( VLC_OBJECT(a), b, c )
207 /**
208  * __var_Get() with automatic casting
209  */
210 #define var_Get(a,b,c) __var_Get( VLC_OBJECT(a), b, c )
211
212 /*****************************************************************************
213  * Variable callbacks
214  *****************************************************************************
215  * int MyCallback( vlc_object_t *p_this,
216  *                 char const *psz_variable,
217  *                 vlc_value_t oldvalue,
218  *                 vlc_value_t newvalue,
219  *                 void *p_data);
220  *****************************************************************************/
221 VLC_EXPORT( int, __var_AddCallback, ( vlc_object_t *, const char *, vlc_callback_t, void * ) );
222 VLC_EXPORT( int, __var_DelCallback, ( vlc_object_t *, const char *, vlc_callback_t, void * ) );
223
224 /**
225  * __var_AddCallback() with automatic casting
226  */
227 #define var_AddCallback(a,b,c,d) __var_AddCallback( VLC_OBJECT(a), b, c, d )
228
229 /**
230  * __var_DelCallback() with automatic casting
231  */
232 #define var_DelCallback(a,b,c,d) __var_DelCallback( VLC_OBJECT(a), b, c, d )
233
234 /*****************************************************************************
235  * helpers functions
236  *****************************************************************************/
237
238 /**
239  * Set the value of an integer variable
240  *
241  * \param p_obj The object that holds the variable
242  * \param psz_name The name of the variable
243  * \param i The new integer value of this variable
244  */
245 static inline int __var_SetInteger( vlc_object_t *p_obj, const char *psz_name, int i )
246 {
247     vlc_value_t val;
248     val.i_int = i;
249     return __var_Set( p_obj, psz_name, val );
250 }
251
252 /**
253  * Set the value of a time variable
254  *
255  * \param p_obj The object that holds the variable
256  * \param psz_name The name of the variable
257  * \param i The new time value of this variable
258  */
259 static inline int __var_SetTime( vlc_object_t *p_obj, const char *psz_name, int64_t i )
260 {
261     vlc_value_t val;
262     val.i_time = i;
263     return __var_Set( p_obj, psz_name, val );
264 }
265
266 /**
267  * Set the value of a float variable
268  *
269  * \param p_obj The object that holds the variable
270  * \param psz_name The name of the variable
271  * \param f The new float value of this variable
272  */
273 static inline int __var_SetFloat( vlc_object_t *p_obj, const char *psz_name, float f )
274 {
275     vlc_value_t val;
276     val.f_float = f;
277     return __var_Set( p_obj, psz_name, val );
278 }
279
280 /**
281  * Trigger the callbacks on a void variable
282  *
283  * \param p_obj The object that holds the variable
284  * \param psz_name The name of the variable
285  */
286 static inline int __var_SetVoid( vlc_object_t *p_obj, const char *psz_name )
287 {
288     vlc_value_t val;
289     val.b_bool = VLC_TRUE;
290     return __var_Set( p_obj, psz_name, val );
291 }
292
293 /**
294  * __var_SetInteger() with automatic casting
295  */
296 #define var_SetInteger(a,b,c)   __var_SetInteger( VLC_OBJECT(a),b,c)
297 /**
298  * __var_SetTime() with automatic casting
299  */
300 #define var_SetTime(a,b,c)      __var_SetTime( VLC_OBJECT(a),b,c)
301 /**
302  * __var_SetFloat() with automatic casting
303  */
304 #define var_SetFloat(a,b,c)     __var_SetFloat( VLC_OBJECT(a),b,c)
305 /**
306  * __var_SetVoid() with automatic casting
307  */
308 #define var_SetVoid(a,b)        __var_SetVoid( VLC_OBJECT(a),b)
309
310 /**
311  * @}
312  */
313