mirror of
https://github.com/alsa-project/alsa-lib.git
synced 2025-10-29 05:40:25 -04:00
Added snd_config_imake_* functions.
This commit is contained in:
parent
7cf4ef131d
commit
f9756e6efd
4 changed files with 120 additions and 64 deletions
|
|
@ -96,6 +96,11 @@ int snd_config_make_string(snd_config_t **config, const char *key);
|
|||
int snd_config_make_pointer(snd_config_t **config, const char *key);
|
||||
int snd_config_make_compound(snd_config_t **config, const char *key, int join);
|
||||
|
||||
int snd_config_imake_integer(snd_config_t **config, const char *key, const long value);
|
||||
int snd_config_imake_real(snd_config_t **config, const char *key, const double value);
|
||||
int snd_config_imake_string(snd_config_t **config, const char *key, const char *ascii);
|
||||
int snd_config_imake_pointer(snd_config_t **config, const char *key, const void *ptr);
|
||||
|
||||
snd_config_type_t snd_config_get_type(snd_config_t *config);
|
||||
|
||||
int snd_config_set_id(snd_config_t *config, const char *id);
|
||||
|
|
|
|||
110
src/conf.c
110
src/conf.c
|
|
@ -1586,6 +1586,88 @@ int snd_config_make_compound(snd_config_t **config, const char *id,
|
|||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Build an integer config node and use given initial value
|
||||
* \param config Returned config node handle pointer
|
||||
* \param id Node id
|
||||
* \param value Initial value
|
||||
* \return 0 on success otherwise a negative error code
|
||||
*/
|
||||
int snd_config_imake_integer(snd_config_t **config, const char *id, const long value)
|
||||
{
|
||||
int err;
|
||||
|
||||
err = snd_config_make(config, id, SND_CONFIG_TYPE_INTEGER);
|
||||
if (err < 0)
|
||||
return err;
|
||||
(*config)->u.integer = value;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Build a real config node and use given initial value
|
||||
* \param config Returned config node handle pointer
|
||||
* \param id Node id
|
||||
* \param value Initial value
|
||||
* \return 0 on success otherwise a negative error code
|
||||
*/
|
||||
int snd_config_imake_real(snd_config_t **config, const char *id, const double value)
|
||||
{
|
||||
int err;
|
||||
|
||||
err = snd_config_make(config, id, SND_CONFIG_TYPE_REAL);
|
||||
if (err < 0)
|
||||
return err;
|
||||
(*config)->u.real = value;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Build a string config node and use given initial value
|
||||
* \param config Returned config node handle pointer
|
||||
* \param id Node id
|
||||
* \param value Initial value
|
||||
* \return 0 on success otherwise a negative error code
|
||||
*/
|
||||
int snd_config_imake_string(snd_config_t **config, const char *id, const char *value)
|
||||
{
|
||||
int err;
|
||||
snd_config_t *tmp;
|
||||
|
||||
err = snd_config_make(&tmp, id, SND_CONFIG_TYPE_STRING);
|
||||
if (err < 0)
|
||||
return err;
|
||||
if (value) {
|
||||
tmp->u.string = strdup(value);
|
||||
if (!tmp->u.string) {
|
||||
snd_config_delete(tmp);
|
||||
return -ENOMEM;
|
||||
}
|
||||
} else {
|
||||
tmp->u.string = NULL;
|
||||
}
|
||||
*config = tmp;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Build a pointer config node and use given initial value
|
||||
* \param config Returned config node handle pointer
|
||||
* \param id Node id
|
||||
* \param value Initial value
|
||||
* \return 0 on success otherwise a negative error code
|
||||
*/
|
||||
int snd_config_imake_pointer(snd_config_t **config, const char *id, const void *value)
|
||||
{
|
||||
int err;
|
||||
|
||||
err = snd_config_make(config, id, SND_CONFIG_TYPE_POINTER);
|
||||
if (err < 0)
|
||||
return err;
|
||||
(*config)->u.ptr = value;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Change the value of an integer config node
|
||||
* \param config Config node handle
|
||||
|
|
@ -1629,9 +1711,13 @@ int snd_config_set_string(snd_config_t *config, const char *value)
|
|||
return -EINVAL;
|
||||
if (config->u.string)
|
||||
free(config->u.string);
|
||||
if (value) {
|
||||
config->u.string = strdup(value);
|
||||
if (!config->u.string)
|
||||
return -ENOMEM;
|
||||
} else {
|
||||
config->u.string = NULL;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -2394,10 +2480,9 @@ int snd_config_hook_load_for_all_cards(snd_config_t *root, snd_config_t *config,
|
|||
err = snd_determine_driver(card, &fdriver);
|
||||
if (err < 0)
|
||||
return err;
|
||||
err = snd_config_make_string(&private_data, "string");
|
||||
err = snd_config_imake_string(&private_data, "string", fdriver);
|
||||
if (err < 0)
|
||||
goto __err;
|
||||
snd_config_set_string(private_data, fdriver);
|
||||
if (snd_config_search(root, fdriver, &n) >= 0) {
|
||||
if (snd_config_get_string(n, &driver) < 0)
|
||||
continue;
|
||||
|
|
@ -2763,23 +2848,21 @@ static int _snd_config_expand(snd_config_t *src,
|
|||
case SND_CONFIG_TYPE_INTEGER:
|
||||
{
|
||||
long v;
|
||||
err = snd_config_make(dst, id, type);
|
||||
if (err < 0)
|
||||
return err;
|
||||
err = snd_config_get_integer(src, &v);
|
||||
assert(err >= 0);
|
||||
snd_config_set_integer(*dst, v);
|
||||
err = snd_config_imake_integer(dst, id, v);
|
||||
if (err < 0)
|
||||
return err;
|
||||
break;
|
||||
}
|
||||
case SND_CONFIG_TYPE_REAL:
|
||||
{
|
||||
double v;
|
||||
err = snd_config_make(dst, id, type);
|
||||
if (err < 0)
|
||||
return err;
|
||||
err = snd_config_get_real(src, &v);
|
||||
assert(err >= 0);
|
||||
snd_config_set_real(*dst, v);
|
||||
err = snd_config_imake_real(dst, id, v);
|
||||
if (err < 0)
|
||||
return err;
|
||||
break;
|
||||
}
|
||||
case SND_CONFIG_TYPE_STRING:
|
||||
|
|
@ -2801,14 +2884,9 @@ static int _snd_config_expand(snd_config_t *src,
|
|||
return err;
|
||||
}
|
||||
} else {
|
||||
err = snd_config_make(dst, id, type);
|
||||
err = snd_config_imake_string(dst, id, s);
|
||||
if (err < 0)
|
||||
return err;
|
||||
err = snd_config_set_string(*dst, s);
|
||||
if (err < 0) {
|
||||
snd_config_delete(*dst);
|
||||
return err;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -283,11 +283,8 @@ int snd_func_getenv(snd_config_t **dst, snd_config_t *root, snd_config_t *src,
|
|||
if (err >= 0) {
|
||||
const char *id;
|
||||
err = snd_config_get_id(src, &id);
|
||||
if (err >= 0) {
|
||||
err = snd_config_make_string(dst, id);
|
||||
if (err >= 0)
|
||||
snd_config_set_string(*dst, res);
|
||||
}
|
||||
err = snd_config_imake_string(dst, id, res);
|
||||
free(res);
|
||||
}
|
||||
__error:
|
||||
|
|
@ -336,10 +333,9 @@ int snd_func_igetenv(snd_config_t **dst, snd_config_t *root, snd_config_t *src,
|
|||
err = snd_config_get_id(src, &id);
|
||||
if (err < 0)
|
||||
return err;
|
||||
err = snd_config_make_integer(dst, id);
|
||||
err = snd_config_imake_integer(dst, id, v);
|
||||
if (err < 0)
|
||||
return err;
|
||||
snd_config_set_integer(*dst, v);
|
||||
return 0;
|
||||
}
|
||||
#ifndef DOC_HIDDEN
|
||||
|
|
@ -424,11 +420,8 @@ int snd_func_concat(snd_config_t **dst, snd_config_t *root, snd_config_t *src,
|
|||
goto __error;
|
||||
}
|
||||
err = snd_config_get_id(src, &id);
|
||||
if (err >= 0) {
|
||||
err = snd_config_make_string(dst, id);
|
||||
if (err >= 0)
|
||||
snd_config_set_string(*dst, res);
|
||||
}
|
||||
err = snd_config_imake_string(dst, id, res);
|
||||
free(res);
|
||||
__error:
|
||||
return err;
|
||||
|
|
@ -461,10 +454,7 @@ int snd_func_datadir(snd_config_t **dst, snd_config_t *root ATTRIBUTE_UNUSED,
|
|||
err = snd_config_get_id(src, &id);
|
||||
if (err < 0)
|
||||
return err;
|
||||
err = snd_config_make_string(dst, id);
|
||||
if (err >= 0)
|
||||
err = snd_config_set_string(*dst, DATADIR "/alsa");
|
||||
return err;
|
||||
return snd_config_imake_string(dst, id, DATADIR "/alsa");
|
||||
}
|
||||
#ifndef DOC_HIDDEN
|
||||
SND_DLSYM_BUILD_VERSION(snd_func_datadir, SND_CONFIG_DLSYM_VERSION_EVALUATE);
|
||||
|
|
@ -527,11 +517,8 @@ int snd_func_private_string(snd_config_t **dst, snd_config_t *root ATTRIBUTE_UNU
|
|||
return err;
|
||||
}
|
||||
err = snd_config_get_id(src, &id);
|
||||
if (err >= 0) {
|
||||
err = snd_config_make_string(dst, id);
|
||||
if (err >= 0)
|
||||
err = snd_config_set_string(*dst, str);
|
||||
}
|
||||
err = snd_config_imake_string(dst, id, str);
|
||||
return err;
|
||||
}
|
||||
#ifndef DOC_HIDDEN
|
||||
|
|
@ -609,11 +596,8 @@ int snd_func_private_card_driver(snd_config_t **dst, snd_config_t *root ATTRIBUT
|
|||
if ((err = snd_determine_driver(card, &driver)) < 0)
|
||||
return err;
|
||||
err = snd_config_get_id(src, &id);
|
||||
if (err >= 0) {
|
||||
err = snd_config_make_string(dst, id);
|
||||
if (err >= 0)
|
||||
err = snd_config_set_string(*dst, driver);
|
||||
}
|
||||
err = snd_config_imake_string(dst, id, driver);
|
||||
free(driver);
|
||||
return err;
|
||||
}
|
||||
|
|
@ -667,10 +651,9 @@ int snd_func_card_driver(snd_config_t **dst, snd_config_t *root, snd_config_t *s
|
|||
return v;
|
||||
}
|
||||
free(str);
|
||||
err = snd_config_make_integer(&val, "card");
|
||||
err = snd_config_imake_integer(&val, "card", v);
|
||||
if (err < 0)
|
||||
return err;
|
||||
snd_config_set_integer(val, v);
|
||||
err = snd_func_private_card_driver(dst, root, src, val);
|
||||
snd_config_delete(val);
|
||||
return err;
|
||||
|
|
@ -738,11 +721,8 @@ int snd_func_card_id(snd_config_t **dst, snd_config_t *root, snd_config_t *src,
|
|||
goto __error;
|
||||
}
|
||||
err = snd_config_get_id(src, &id);
|
||||
if (err >= 0) {
|
||||
err = snd_config_make_string(dst, id);
|
||||
if (err >= 0)
|
||||
err = snd_config_set_string(*dst, res);
|
||||
}
|
||||
err = snd_config_imake_string(dst, id, res);
|
||||
free(res);
|
||||
__error:
|
||||
if (ctl)
|
||||
|
|
@ -836,11 +816,8 @@ int snd_func_pcm_id(snd_config_t **dst, snd_config_t *root, snd_config_t *src, v
|
|||
goto __error;
|
||||
}
|
||||
err = snd_config_get_id(src, &id);
|
||||
if (err >= 0) {
|
||||
err = snd_config_make_string(dst, id);
|
||||
if (err >= 0)
|
||||
err = snd_config_set_string(*dst, snd_pcm_info_get_id(info));
|
||||
}
|
||||
err = snd_config_imake_string(dst, id, snd_pcm_info_get_id(info));
|
||||
__error:
|
||||
if (ctl)
|
||||
snd_ctl_close(ctl);
|
||||
|
|
@ -893,11 +870,8 @@ int snd_func_private_pcm_subdevice(snd_config_t **dst, snd_config_t *root ATTRIB
|
|||
return err;
|
||||
}
|
||||
err = snd_config_get_id(src, &id);
|
||||
if (err >= 0) {
|
||||
err = snd_config_make_integer(dst, id);
|
||||
if (err >= 0)
|
||||
err = snd_config_set_integer(*dst, snd_pcm_info_get_subdevice(info));
|
||||
}
|
||||
err = snd_config_imake_integer(dst, id, snd_pcm_info_get_subdevice(info));
|
||||
return err;
|
||||
}
|
||||
#ifndef DOC_HIDDEN
|
||||
|
|
|
|||
|
|
@ -650,10 +650,9 @@ int _snd_pcm_hook_ctl_elems_install(snd_pcm_t *pcm, snd_config_t *conf)
|
|||
SNDERR("Cannot open CTL %s", ctl_name);
|
||||
return err;
|
||||
}
|
||||
err = snd_config_make_pointer(&pcm_conf, "pcm_handle");
|
||||
err = snd_config_imake_pointer(&pcm_conf, "pcm_handle", pcm);
|
||||
if (err < 0)
|
||||
goto _err;
|
||||
snd_config_set_pointer(pcm_conf, pcm);
|
||||
err = snd_sctl_build(&sctl, ctl, conf, pcm_conf, 0);
|
||||
if (err < 0)
|
||||
goto _err;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue