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>
This commit is contained in:
Chao Song 2023-01-17 20:52:18 +08:00 committed by Jaroslav Kysela
parent df3da091cc
commit 1350900246

View file

@ -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;
/* 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);
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);
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: