mirror of
https://github.com/alsa-project/alsa-lib.git
synced 2025-11-06 13:29:59 -05:00
ucm: configuration - implement in-place Include
An example:
Include {
File "Inc.conf"
Before.SectionDevice "Mic"
}
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
This commit is contained in:
parent
14636be4a8
commit
3edfebc522
6 changed files with 375 additions and 168 deletions
|
|
@ -347,103 +347,6 @@ static void config_dump(snd_config_t *cfg)
|
|||
}
|
||||
#endif
|
||||
|
||||
static int compound_merge(const char *id,
|
||||
snd_config_t *dst, snd_config_t *src,
|
||||
snd_config_t *before, snd_config_t *after)
|
||||
{
|
||||
snd_config_iterator_t i, next;
|
||||
snd_config_t *n, *_before = NULL, *_after = NULL;
|
||||
const char *s;
|
||||
char tmpid[32];
|
||||
int err, array, idx;
|
||||
|
||||
if (snd_config_get_type(src) != SND_CONFIG_TYPE_COMPOUND) {
|
||||
uc_error("compound type expected for If True/False block");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (before) {
|
||||
err = get_string(before, id, &s);
|
||||
if (err < 0 && err != -ENOENT)
|
||||
return err;
|
||||
if (err == 0) {
|
||||
err = snd_config_search(dst, s, &_before);
|
||||
if (err < 0 && err != -ENOENT)
|
||||
return err;
|
||||
}
|
||||
}
|
||||
if (after) {
|
||||
err = get_string(after, id, &s);
|
||||
if (err < 0 && err != -ENOENT)
|
||||
return err;
|
||||
if (err == 0) {
|
||||
err = snd_config_search(dst, s, &_after);
|
||||
if (err < 0 && err != -ENOENT)
|
||||
return err;
|
||||
}
|
||||
}
|
||||
|
||||
if (_before && _after) {
|
||||
uc_error("defined both before and after identifiers in the If block");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
array = snd_config_is_array(dst);
|
||||
if (array < 0) {
|
||||
uc_error("destination configuration node is not a compound");
|
||||
return array;
|
||||
}
|
||||
if (array && snd_config_is_array(src) <= 0) {
|
||||
uc_error("source configuration node is not an array");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
idx = 0;
|
||||
snd_config_for_each(i, next, src) {
|
||||
n = snd_config_iterator_entry(i);
|
||||
err = snd_config_remove(n);
|
||||
if (err < 0)
|
||||
return err;
|
||||
/* for array, use a temporary non-clashing identifier */
|
||||
if (array > 0) {
|
||||
snprintf(tmpid, sizeof(tmpid), "_tmp_%d", idx++);
|
||||
err = snd_config_set_id(n, tmpid);
|
||||
if (err < 0)
|
||||
return err;
|
||||
}
|
||||
if (_before) {
|
||||
err = snd_config_add_before(_before, n);
|
||||
if (err < 0)
|
||||
return err;
|
||||
_before = NULL;
|
||||
_after = n;
|
||||
} else if (_after) {
|
||||
err = snd_config_add_after(_after, n);
|
||||
if (err < 0)
|
||||
return err;
|
||||
_after = n;
|
||||
} else {
|
||||
err = snd_config_add(dst, n);
|
||||
if (err < 0)
|
||||
return err;
|
||||
}
|
||||
}
|
||||
|
||||
/* set new indexes for the final array */
|
||||
if (array > 0) {
|
||||
idx = 0;
|
||||
snd_config_for_each(i, next, dst) {
|
||||
n = snd_config_iterator_entry(i);
|
||||
snprintf(tmpid, sizeof(tmpid), "%d", idx++);
|
||||
err = snd_config_set_id(n, tmpid);
|
||||
if (err < 0)
|
||||
return err;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* put back the result from all conditions to the parent
|
||||
*/
|
||||
|
|
@ -451,9 +354,8 @@ int uc_mgr_evaluate_condition(snd_use_case_mgr_t *uc_mgr,
|
|||
snd_config_t *parent,
|
||||
snd_config_t *cond)
|
||||
{
|
||||
snd_config_iterator_t i, i2, next, next2;
|
||||
snd_config_t *a, *n, *n2, *parent2, *before, *after;
|
||||
const char *id;
|
||||
snd_config_iterator_t i, next;
|
||||
snd_config_t *a, *n, *before, *after;
|
||||
int err;
|
||||
|
||||
if (uc_mgr->conf_format < 2) {
|
||||
|
|
@ -474,38 +376,13 @@ int uc_mgr_evaluate_condition(snd_use_case_mgr_t *uc_mgr,
|
|||
return err;
|
||||
if (a == NULL)
|
||||
continue;
|
||||
err = snd_config_search(a, "If", &n2);
|
||||
if (err < 0 && err != -ENOENT) {
|
||||
uc_error("If block error (If)");
|
||||
return -EINVAL;
|
||||
} else if (err == 0) {
|
||||
err = uc_mgr_evaluate_condition(uc_mgr, a, n2);
|
||||
if (err < 0)
|
||||
return err;
|
||||
snd_config_delete(n2);
|
||||
}
|
||||
snd_config_for_each(i2, next2, a) {
|
||||
n2 = snd_config_iterator_entry(i2);
|
||||
err = snd_config_remove(n2);
|
||||
if (err < 0)
|
||||
return err;
|
||||
err = snd_config_get_id(n2, &id);
|
||||
if (err < 0) {
|
||||
__add:
|
||||
err = snd_config_add(parent, n2);
|
||||
if (err < 0)
|
||||
return err;
|
||||
continue;
|
||||
} else {
|
||||
err = snd_config_search(parent, id, &parent2);
|
||||
if (err == -ENOENT)
|
||||
goto __add;
|
||||
err = compound_merge(id, parent2, n2, before, after);
|
||||
if (err < 0)
|
||||
return err;
|
||||
}
|
||||
snd_config_delete(n2);
|
||||
}
|
||||
err = uc_mgr_evaluate_inplace(uc_mgr, a);
|
||||
if (err < 0)
|
||||
return err;
|
||||
err = uc_mgr_config_tree_merge(parent, a, before, after);
|
||||
if (err < 0)
|
||||
return err;
|
||||
snd_config_delete(a);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue