From 963578af1e1ab617850a0848adf182521c8e3b94 Mon Sep 17 00:00:00 2001 From: Ranjani Sridharan Date: Fri, 23 Apr 2021 13:41:45 -0700 Subject: [PATCH] topology: pre-process-class: add function to look up token_ref for an attribute in class Some attributes may have the token_ref set which is used to look up the token value for the tuple data that is appended to the object's private data. For example, in the buffer widget object: DefineAttribute."size" { # Token reference and type token_ref "sof_tkn_buffer.word" } The token_ref must include the reference to the vendor token object name followed by the type of the tuple. Signed-off-by: Ranjani Sridharan Signed-off-by: Jaroslav Kysela --- topology/pre-process-class.c | 27 +++++++++++++++++++++++++++ topology/pre-processor.h | 2 ++ 2 files changed, 29 insertions(+) diff --git a/topology/pre-process-class.c b/topology/pre-process-class.c index b039716..909865a 100644 --- a/topology/pre-process-class.c +++ b/topology/pre-process-class.c @@ -207,3 +207,30 @@ snd_config_type_t tplg_class_get_attribute_type(struct tplg_pre_processor *tplg_ return SND_CONFIG_TYPE_INTEGER; } + +/* get token_ref for attribute with name attr_name in the class */ +const char *tplg_class_get_attribute_token_ref(struct tplg_pre_processor *tplg_pp, + snd_config_t *class, const char *attr_name) +{ + snd_config_t *attributes, *attr, *token_ref; + const char *token; + int ret; + + ret = snd_config_search(class, "DefineAttribute", &attributes); + if (ret < 0) + return NULL; + + ret = snd_config_search(attributes, attr_name, &attr); + if (ret < 0) + return NULL; + + ret = snd_config_search(attr, "token_ref", &token_ref); + if (ret < 0) + return NULL; + + ret = snd_config_get_string(token_ref, &token); + if (ret < 0) + return NULL; + + return token; +} diff --git a/topology/pre-processor.h b/topology/pre-processor.h index 17a7dd5..81063b7 100644 --- a/topology/pre-processor.h +++ b/topology/pre-processor.h @@ -39,6 +39,8 @@ const char *tplg_class_get_unique_attribute_name(struct tplg_pre_processor *tplg snd_config_t *class); snd_config_type_t tplg_class_get_attribute_type(struct tplg_pre_processor *tplg_pp, snd_config_t *attr); +const char *tplg_class_get_attribute_token_ref(struct tplg_pre_processor *tplg_pp, + snd_config_t *class, const char *attr_name); /* config helpers */ snd_config_t *tplg_find_config(snd_config_t *config, const char *name);