Skip to content

Commit

Permalink
topology: Expand attribute references inside $[] expressions
Browse files Browse the repository at this point in the history
Properly expand referred object attributes inside $[] expression. This
allows for example this simplified case:

Define {
       CHANNELS 2
       BIT_DEPTH 16
}

Object.Base.foo {
	channels	$CHANNELS
	sample_bits	$BIT_DEPTH
	frame_bits	"$[$channels * $sample_bits]"
}

Closes: #250
Reported-by: Seppo Ingalsuo <[email protected]>
Signed-off-by: Jyri Sarha <[email protected]>
Signed-off-by: Jaroslav Kysela <[email protected]>
  • Loading branch information
Jyri Sarha authored and perexg committed Jan 24, 2024
1 parent 6eb1eb5 commit 0029ab7
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion topology/pre-process-object.c
Original file line number Diff line number Diff line change
Expand Up @@ -1603,6 +1603,7 @@ pre_process_object_variables_expand_fcn(snd_config_t **dst, const char *str, voi
snd_config_t *object_cfg = tplg_pp->current_obj_cfg;
snd_config_t *conf_defines;
const char *object_id;
const char *val;
int ret;

ret = snd_config_search(tplg_pp->input_cfg, "Define", &conf_defines);
Expand All @@ -1614,14 +1615,30 @@ pre_process_object_variables_expand_fcn(snd_config_t **dst, const char *str, voi
if (ret >= 0)
return ret;

/* No global define found, proceeed to object attribute search */
if (snd_config_get_id(object_cfg, &object_id) < 0)
return -EINVAL;

/* find variable from object attribute values if not found in global definitions */
ret = pre_process_find_variable(dst, str, object_cfg);
if (ret < 0)
if (ret < 0) {
SNDERR("Failed to find definition for attribute %s in '%s' object\n",
str, object_id);
return ret;
}

/* the extracted value may contain a nested $-expression */
if (snd_config_get_string(*dst, &val) >= 0) {
if (val[0] == '$') {
char *var = strdup(val);

snd_config_delete(*dst);
ret = snd_config_evaluate_string(dst, var,
pre_process_object_variables_expand_fcn,
tplg_pp);
free(var);
}
}

return ret;
}
Expand Down

0 comments on commit 0029ab7

Please sign in to comment.