diff options
author | Chao Song <chao.song@linux.intel.com> | 2023-01-17 20:52:18 +0800 |
---|---|---|
committer | Jaroslav Kysela <perex@perex.cz> | 2023-01-24 09:45:45 +0100 |
commit | 1350900246e0462b584331be0df24e177e7b25be (patch) | |
tree | 3ada40cc7a2c7111c75b2f7992fa2880dd30c4bf | |
parent | df3da091cc753bc55365fc20ce92aade3f32b387 (diff) | |
download | alsa-utils-1350900246e0462b584331be0df24e177e7b25be.tar.gz |
topology: pre-processor: support to include conf block with IncludeByKey
Currently, The IncludeByKey mechanism only supports conditionally
including a topology conf file. Even if we only
want to conditionally include a small conf block, we have
to use a conf file and in the end we will have a lot of
trivial conf files that only contain a single conf blocks.
This patch extends the use of IncludeByKey ito support including conf
blocks conditionally. For example, the block below will include the route
conditionally based on the variable definition COPIER_ROUTE.
Define {
COPIER_ROUTE 1
}
IncludeByKey.COPIER_ROUTE {
"1" {
Object.Base.route.11 {
source copier.module.8.2
sink copier.module.17.2
}
}
}
Fixes: https://github.com/alsa-project/alsa-utils/pull/187
Signed-off-by: Chao Song <chao.song@linux.intel.com>
Co-authored-by: Jaroslav Kysela <perex@perex.cz>
Signed-off-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
-rw-r--r-- | topology/pre-processor.c | 57 |
1 files changed, 34 insertions, 23 deletions
diff --git a/topology/pre-processor.c b/topology/pre-processor.c index dfe3ad6..38bb87b 100644 --- a/topology/pre-processor.c +++ b/topology/pre-processor.c @@ -504,30 +504,39 @@ static int pre_process_include_conf(struct tplg_pre_processor *tplg_pp, snd_conf if (ret) continue; - /* regex matched. now include the conf file */ - ret = snd_config_get_string(n, &filename); - if (ret < 0) - goto err; - - if (filename && filename[0] != '/') - full_path = tplg_snprintf("%s/%s", tplg_pp->inc_path, filename); - else - full_path = tplg_snprintf("%s", filename); - - ret = snd_input_stdio_open(&in, full_path, "r"); - if (ret < 0) { - fprintf(stderr, "Unable to open included conf file %s\n", full_path); + /* regex matched. now include or use the configuration */ + if (snd_config_get_type(n) == SND_CONFIG_TYPE_COMPOUND) { + /* configuration block */ + ret = snd_config_merge(*new, n, 0); + if (ret < 0) { + fprintf(stderr, "Unable to merge key '%s'\n", value); + goto err; + } + } else { + ret = snd_config_get_string(n, &filename); + if (ret < 0) + goto err; + + if (filename && filename[0] != '/') + full_path = tplg_snprintf("%s/%s", tplg_pp->inc_path, filename); + else + full_path = tplg_snprintf("%s", filename); + + ret = snd_input_stdio_open(&in, full_path, "r"); + if (ret < 0) { + fprintf(stderr, "Unable to open included conf file %s\n", full_path); + free(full_path); + goto err; + } free(full_path); - goto err; - } - free(full_path); - /* load config */ - ret = snd_config_load(*new, in); - snd_input_close(in); - if (ret < 0) { - fprintf(stderr, "Unable to load included configuration\n"); - goto err; + /* load config */ + ret = snd_config_load(*new, in); + snd_input_close(in); + if (ret < 0) { + fprintf(stderr, "Unable to load included configuration\n"); + goto err; + } } /* forcefully overwrite with defines from the command line */ @@ -538,7 +547,9 @@ static int pre_process_include_conf(struct tplg_pre_processor *tplg_pp, snd_conf } /* recursively process any nested includes */ - return pre_process_includes(tplg_pp, *new); + ret = pre_process_includes(tplg_pp, *new); + if (ret < 0) + goto err; } err: |