Merge svn changes up to r29455
[mplayer.git] / m_config.h
blob0c84b87569cd6558395a7a4e5bdd51dfd2ce5851
1 #ifndef MPLAYER_M_CONFIG_H
2 #define MPLAYER_M_CONFIG_H
4 /// \defgroup Config Config manager
5 ///
6 /// m_config provides an API to manipulate the config variables in MPlayer.
7 /// It makes use of the \ref Options API to provide a context stack that
8 /// allows saving and later restoring the state of all variables.
9 ///@{
11 /// \file
13 typedef struct m_config_option m_config_option_t;
14 typedef struct m_config_save_slot m_config_save_slot_t;
15 /// \ingroup ConfigProfiles
16 typedef struct m_profile m_profile_t;
17 struct m_option;
18 struct m_option_type;
20 /// Config option save slot
21 struct m_config_save_slot {
22 /// Previous level slot.
23 m_config_save_slot_t* prev;
24 /// Level at which the save was made.
25 int lvl;
26 // We have to store other datatypes in this as well,
27 // so make sure we get properly aligned addresses.
28 unsigned char data[0] __attribute__ ((aligned (8)));
31 /// Config option
32 struct m_config_option {
33 m_config_option_t* next;
34 /// Full name (ie option:subopt).
35 char* name;
36 /// Option description.
37 const struct m_option* opt;
38 /// Save slot stack.
39 m_config_save_slot_t* slots;
40 /// See \ref ConfigOptionFlags.
41 unsigned int flags;
44 /// \defgroup ConfigProfiles Config profiles
45 /// \ingroup Config
46 ///
47 /// Profiles allow to predefine some sets of options that can then
48 /// be applied later on with the internal -profile option.
49 ///
50 ///@{
52 /// Config profile
53 struct m_profile {
54 m_profile_t* next;
55 char* name;
56 char* desc;
57 int num_opts;
58 /// Option/value pair array.
59 char** opts;
62 ///@}
64 /// Config object
65 /** \ingroup Config */
66 typedef struct m_config {
67 /// Registered options.
68 /** This contains all options and suboptions.
70 m_config_option_t* opts;
71 /// Current stack level.
72 int lvl;
73 /// \ref OptionParserModes
74 int mode;
75 /// List of defined profiles.
76 m_profile_t* profiles;
77 /// Depth when recursively including profiles.
78 int profile_depth;
80 void *optstruct; // struct mpopts or other
81 } m_config_t;
83 /// \defgroup ConfigOptionFlags Config option flags
84 /// \ingroup Config
85 ///@{
87 /// Set if an option has been set at the current level.
88 #define M_CFG_OPT_SET (1<<0)
90 /// Set if another option already uses the same variable.
91 #define M_CFG_OPT_ALIAS (1<<1)
93 ///@}
95 /// Create a new config object.
96 /** \ingroup Config
98 m_config_t*
99 m_config_new(void *optstruct,
100 int includefunc(struct m_option *conf, char *filename));
102 /// Free a config object.
103 void
104 m_config_free(m_config_t* config);
106 /// Push a new context.
107 /** \param config The config object.
109 void
110 m_config_push(m_config_t* config);
112 /// Pop the current context restoring the previous context state.
113 /** \param config The config object.
115 void
116 m_config_pop(m_config_t* config);
118 /// Register some options to be used.
119 /** \param config The config object.
120 * \param args An array of \ref m_option struct.
121 * \return 1 on success, 0 on failure.
124 m_config_register_options(m_config_t *config, const struct m_option *args);
126 /// Set an option.
127 /** \param config The config object.
128 * \param arg The option's name.
129 * \param param The value of the option, can be NULL.
130 * \return See \ref OptionParserReturn.
133 m_config_set_option(m_config_t *config, char* arg, char* param);
135 /// Check if an option setting is valid.
136 /** \param config The config object.
137 * \param arg The option's name.
138 * \param param The value of the option, can be NULL.
139 * \return See \ref OptionParserReturn.
142 m_config_check_option(m_config_t *config, char* arg, char* param);
144 /// Get the option matching the given name.
145 /** \param config The config object.
146 * \param arg The option's name.
148 const struct m_option*
149 m_config_get_option(m_config_t *config, char* arg);
151 /// Print a list of all registered options.
152 /** \param config The config object.
154 void
155 m_config_print_option_list(m_config_t *config);
157 /// \addtogroup ConfigProfiles
158 ///@{
160 /// Find the profile with the given name.
161 /** \param config The config object.
162 * \param arg The profile's name.
163 * \return The profile object or NULL.
165 m_profile_t*
166 m_config_get_profile(m_config_t* config, char* name);
168 /// Get the profile with the given name, creating it if necessary.
169 /** \param config The config object.
170 * \param arg The profile's name.
171 * \return The profile object.
173 m_profile_t*
174 m_config_add_profile(m_config_t* config, char* name);
176 /// Set the description of a profile.
177 /** Used by the config file parser when defining a profile.
179 * \param p The profile object.
180 * \param arg The profile's name.
182 void
183 m_profile_set_desc(m_profile_t* p, char* desc);
185 /// Add an option to a profile.
186 /** Used by the config file parser when defining a profile.
188 * \param config The config object.
189 * \param p The profile object.
190 * \param name The option's name.
191 * \param val The option's value.
194 m_config_set_profile_option(m_config_t* config, m_profile_t* p,
195 char* name, char* val);
197 /// Enables profile usage
198 /** Used by the config file parser when loading a profile.
200 * \param config The config object.
201 * \param p The profile object.
203 void
204 m_config_set_profile(m_config_t* config, m_profile_t* p);
206 ///@}
208 ///@}
210 #endif /* MPLAYER_M_CONFIG_H */