]> git.sesse.net Git - vlc/blob - include/configuration.h
* ./include/configuration.h: renamed MODULE_CONFIG_* macros into
[vlc] / include / configuration.h
1 /*****************************************************************************
2  * configuration.h : configuration management module
3  * This file describes the programming interface for the configuration module.
4  * It includes functions allowing to declare, get or set configuration options.
5  *****************************************************************************
6  * Copyright (C) 1999, 2000 VideoLAN
7  * $Id: configuration.h,v 1.14 2002/06/11 09:44:21 gbazin Exp $
8  *
9  * Authors: Gildas Bazin <gbazin@netcourrier.com>
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  * 
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
24  *****************************************************************************/
25
26 /*****************************************************************************
27  * Macros used to build the configuration structure.
28  *****************************************************************************/
29
30 /* Configuration hint types */
31 #define CONFIG_HINT_END                     0x0001  /* End of config */
32 #define CONFIG_HINT_CATEGORY                0x0002  /* Start of new category */
33 #define CONFIG_HINT_SUBCATEGORY             0x0003  /* Start of sub-category */
34 #define CONFIG_HINT_SUBCATEGORY_END         0x0004  /* End of sub-category */
35 #define CONFIG_HINT_USAGE                   0x0005  /* Usage information */
36
37 #define CONFIG_HINT                         0x000F
38
39 /* Configuration item types */
40 #define CONFIG_ITEM_STRING                  0x0010  /* String option */
41 #define CONFIG_ITEM_FILE                    0x0020  /* File option */
42 #define CONFIG_ITEM_MODULE                  0x0030  /* Module option */
43 #define CONFIG_ITEM_INTEGER                 0x0040  /* Integer option */
44 #define CONFIG_ITEM_BOOL                    0x0050  /* Bool option */
45 #define CONFIG_ITEM_FLOAT                   0x0060  /* Float option */
46
47 #define CONFIG_ITEM                         0x00F0
48
49 struct module_config_s
50 {
51     int          i_type;                               /* Configuration type */
52     char        *psz_name;                                    /* Option name */
53     char         i_short;                      /* Optional short option name */
54     char        *psz_text;      /* Short comment on the configuration option */
55     char        *psz_longtext;   /* Long comment on the configuration option */
56     char        *psz_value;                                  /* Option value */
57     int          i_value;                                    /* Option value */
58     float        f_value;                                    /* Option value */
59
60     /* Function to call when commiting a change */
61     void ( * pf_callback ) ( vlc_object_t * );
62
63     char       **ppsz_list;        /* List of possible values for the option */
64
65     vlc_mutex_t *p_lock;            /* Lock to use when modifying the config */
66     vlc_bool_t   b_dirty;          /* Dirty flag to indicate a config change */
67 };
68
69 /*****************************************************************************
70  * Prototypes - these methods are used to get, set or manipulate configuration
71  * data.
72  *****************************************************************************/
73 VLC_EXPORT( int,    __config_GetInt,   (vlc_object_t *, const char *) );
74 VLC_EXPORT( void,   __config_PutInt,   (vlc_object_t *, const char *, int) );
75 VLC_EXPORT( float,  __config_GetFloat, (vlc_object_t *, const char *) );
76 VLC_EXPORT( void,   __config_PutFloat, (vlc_object_t *, const char *, float) );
77 VLC_EXPORT( char *, __config_GetPsz,   (vlc_object_t *, const char *) );
78 VLC_EXPORT( void,   __config_PutPsz,   (vlc_object_t *, const char *, char *) );
79
80 VLC_EXPORT( int,    __config_LoadCmdLine,  ( vlc_object_t *, int *, char *[], vlc_bool_t ) );
81 VLC_EXPORT( char *,   config_GetHomeDir,     ( void ) );
82 VLC_EXPORT( int,    __config_LoadConfigFile, ( vlc_object_t *, const char * ) );
83 VLC_EXPORT( int,    __config_SaveConfigFile, ( vlc_object_t *, const char * ) );
84 VLC_EXPORT( module_config_t *, config_FindConfig,( vlc_object_t *, const char *psz_name ) );
85
86 VLC_EXPORT( void, config_Duplicate, ( module_t *, module_config_t * ) );
87             void  config_Free       ( module_t * );
88
89 VLC_EXPORT( void, config_SetCallbacks, ( module_config_t *, module_config_t * ) );
90 VLC_EXPORT( void, config_UnsetCallbacks, ( module_config_t * ) );
91
92 #define config_GetInt(a,b) __config_GetInt(CAST_TO_VLC_OBJECT(a),b)
93 #define config_PutInt(a,b,c) __config_PutInt(CAST_TO_VLC_OBJECT(a),b,c)
94 #define config_GetFloat(a,b) __config_GetFloat(CAST_TO_VLC_OBJECT(a),b)
95 #define config_PutFloat(a,b,c) __config_PutFloat(CAST_TO_VLC_OBJECT(a),b,c)
96 #define config_GetPsz(a,b) __config_GetPsz(CAST_TO_VLC_OBJECT(a),b)
97 #define config_PutPsz(a,b,c) __config_PutPsz(CAST_TO_VLC_OBJECT(a),b,c)
98
99 #define config_LoadCmdLine(a,b,c,d) __config_LoadCmdLine(CAST_TO_VLC_OBJECT(a),b,c,d)
100 #define config_LoadConfigFile(a,b) __config_LoadConfigFile(CAST_TO_VLC_OBJECT(a),b)
101 #define config_SaveConfigFile(a,b) __config_SaveConfigFile(CAST_TO_VLC_OBJECT(a),b)
102
103 /*****************************************************************************
104  * Macros used to build the configuration structure.
105  *
106  * Note that internally we support only 3 types of config data: int , float
107  *   and string.
108  *   The other types declared here just map to one of these 3 basic types but
109  *   have the advantage of also providing very good hints to a configuration
110  *   interface so as to make it more user friendly.
111  * The configuration structure also includes category hints. These hints can
112  *   provide a configuration interface with some very useful data and again
113  *   allow for a more user friendly interface.
114  *****************************************************************************/
115
116 #define MODULE_CONFIG_START \
117     static module_config_t p_config[] = {
118 #define MODULE_CONFIG_STOP \
119     { CONFIG_HINT_END, NULL, '\0' } };
120
121 #define ADD_CATEGORY_HINT( text, longtext ) \
122     { CONFIG_HINT_CATEGORY, NULL, '\0', text, longtext },
123 #define ADD_SUBCATEGORY_HINT( text, longtext ) \
124     { CONFIG_HINT_SUBCATEGORY, NULL, '\0', text, longtext },
125 #define END_SUBCATEGORY_HINT \
126     { CONFIG_HINT_SUBCATEGORY_END, NULL, '\0' },
127 #define ADD_USAGE_HINT( text ) \
128     { CONFIG_HINT_USAGE, NULL, '\0', text },
129
130 #define ADD_STRING( name, psz_value, p_callback, text, longtext ) \
131     { CONFIG_ITEM_STRING, name, '\0', text, longtext, psz_value, 0, 0, \
132       p_callback },
133 #define ADD_STRING_FROM_LIST( name, psz_value, ppsz_list, p_callback, text, \
134       longtext ) \
135     { CONFIG_ITEM_STRING, name, '\0', text, longtext, psz_value, 0, 0, \
136       p_callback, ppsz_list },
137 #define ADD_FILE( name, psz_value, p_callback, text, longtext ) \
138     { CONFIG_ITEM_FILE, name, '\0', text, longtext, psz_value, 0, 0, \
139       p_callback },
140 #define ADD_MODULE( name, i_caps, psz_value, p_callback, text, longtext ) \
141     { CONFIG_ITEM_MODULE, name, '\0', text, longtext, psz_value, i_caps, 0, \
142       p_callback },
143 #define ADD_INTEGER( name, i_value, p_callback, text, longtext ) \
144     { CONFIG_ITEM_INTEGER, name, '\0', text, longtext, NULL, i_value, 0, \
145       p_callback },
146 #define ADD_FLOAT( name, f_value, p_callback, text, longtext ) \
147     { CONFIG_ITEM_FLOAT, name, '\0', text, longtext, NULL, 0, f_value, \
148       p_callback },
149 #define ADD_BOOL( name, b_value, p_callback, text, longtext ) \
150     { CONFIG_ITEM_BOOL, name, '\0', text, longtext, NULL, b_value, 0, \
151       p_callback },
152
153 /* These should be seldom used. They were added just to provide easy shortcuts
154  * for the command line interface */
155 #define ADD_STRING_WITH_SHORT( name, ch, psz_value, p_callback, text, ltext ) \
156     { CONFIG_ITEM_STRING, name, ch, text, ltext, psz_value, 0, 0, \
157       p_callback },
158 #define ADD_FILE_WITH_SHORT( name, ch, psz_value, p_callback, text, ltext ) \
159     { CONFIG_ITEM_FILE, name, ch, text, ltext, psz_value, 0, 0, \
160       p_callback },
161 #define ADD_MODULE_WITH_SHORT( name, ch, i_capability, psz_value, p_callback, \
162     text, ltext) \
163     { CONFIG_ITEM_MODULE, name, ch, text, ltext, psz_value, i_capability, 0, \
164       p_callback },
165 #define ADD_INTEGER_WITH_SHORT( name, ch, i_value, p_callback, text, ltext ) \
166     { CONFIG_ITEM_INTEGER, name, ch, text, ltext, NULL, i_value, 0, \
167       p_callback },
168 #define ADD_FLOAT_WITH_SHORT( name, ch, f_value, p_callback, text, ltext ) \
169     { CONFIG_ITEM_FLOAT, name, ch, text, ltext, NULL, 0, f_value, \
170       p_callback },
171 #define ADD_BOOL_WITH_SHORT( name, ch, b_value, p_callback, text, ltext ) \
172     { CONFIG_ITEM_BOOL, name, ch, text, ltext, NULL, b_value, 0, \
173       p_callback },