m_config: implement m_config_new in terms of m_config_simple

Also change m_config_simple() such that you need to register options
using m_config_register_options().
This commit is contained in:
wm4 2012-08-04 11:33:24 +02:00
parent 37c03f2c81
commit 6031b8e22c
3 changed files with 14 additions and 18 deletions

View File

@ -175,8 +175,9 @@ static int vo_preinit(struct vo *vo, char *arg)
if (vo->driver->privsize)
vo->priv = talloc_zero_size(vo, vo->driver->privsize);
if (vo->driver->options) {
struct m_config *cfg = m_config_simple(vo->driver->options, vo->priv);
struct m_config *cfg = m_config_simple(vo->priv);
talloc_steal(vo->priv, cfg);
m_config_register_options(cfg, vo->driver->options);
char n[50];
int l = snprintf(n, sizeof(n), "vo/%s", vo->driver->info->short_name);
assert(l < sizeof(n));

View File

@ -182,11 +182,19 @@ static int config_destroy(void *p)
return 0;
}
struct m_config *m_config_simple(void *optstruct)
{
struct m_config *config = talloc_struct(NULL, struct m_config, {
.optstruct = optstruct,
});
talloc_set_destructor(config, config_destroy);
return config;
}
struct m_config *m_config_new(void *optstruct,
int includefunc(struct m_config *conf,
char *filename))
{
struct m_config *config;
static const struct m_option ref_opts[] = {
{ "profile", NULL, CONF_TYPE_STRING_LIST, CONF_NOSAVE, 0, 0, NULL },
{ "show-profile", show_profile, CONF_TYPE_PRINT_FUNC, CONF_NOCFG },
@ -194,8 +202,8 @@ struct m_config *m_config_new(void *optstruct,
{ NULL }
};
config = talloc_zero(NULL, struct m_config);
talloc_set_destructor(config, config_destroy);
struct m_config *config = m_config_simple(optstruct);
struct m_option *self_opts = talloc_memdup(config, ref_opts,
sizeof(ref_opts));
for (int i = 1; self_opts[i].name; i++)
@ -209,22 +217,10 @@ struct m_config *m_config_new(void *optstruct,
m_config_add_option(config, p, NULL, NULL);
config->includefunc = includefunc;
}
config->optstruct = optstruct;
return config;
}
struct m_config *m_config_simple(const struct m_option *options,
void *optstruct)
{
struct m_config *config = talloc_struct(NULL, struct m_config, {
.optstruct = optstruct,
});
talloc_set_destructor(config, config_destroy);
m_config_register_options(config, options);
return config;
}
void m_config_free(struct m_config *config)
{
talloc_free(config);

View File

@ -102,8 +102,7 @@ struct m_config *
m_config_new(void *optstruct,
int includefunc(struct m_config *conf, char *filename));
struct m_config *m_config_simple(const struct m_option *options,
void *optstruct);
struct m_config *m_config_simple(void *optstruct);
// Free a config object.
void m_config_free(struct m_config *config);