From 0b0c16d4a7899c09126c5f12836a3c90ecebc099 Mon Sep 17 00:00:00 2001 From: Ranjani Sridharan Date: Fri, 23 Apr 2021 13:32:26 -0700 Subject: [PATCH] topology: pre-process-class: add funcion to get the name of the unique attribute in a class Every class must have a unique attribute that will be used to instantiate the object. The value provided for this attribute must be unique within the same alsaconf node for objects of the same class. Add a helper function to get the name of the attribute that must have a unique value in the object instance. For example, when instantiating 2 buffer widgets within a pipeline, they must be given unique instance attribute values as: Object.Widget.buffer.0{} and Object.Widget.buffer.1{}. Signed-off-by: Ranjani Sridharan Signed-off-by: Jaroslav Kysela --- topology/pre-process-class.c | 25 +++++++++++++++++++++++++ topology/pre-processor.h | 2 ++ 2 files changed, 27 insertions(+) diff --git a/topology/pre-process-class.c b/topology/pre-process-class.c index 9033343..3d09a86 100644 --- a/topology/pre-process-class.c +++ b/topology/pre-process-class.c @@ -150,3 +150,28 @@ snd_config_t *tplg_class_find_attribute_by_name(struct tplg_pre_processor *tplg_ free(attr_str); return attr; } + +/* get the name of the attribute that must have a unique value in the object instance */ +const char *tplg_class_get_unique_attribute_name(struct tplg_pre_processor *tplg_pp, + snd_config_t *class) +{ + snd_config_t *unique; + const char *unique_name, *class_id; + int ret; + + if (snd_config_get_id(class, &class_id) < 0) + return NULL; + + ret = snd_config_search(class, "attributes.unique", &unique); + if (ret < 0) { + SNDERR("No unique attribute in class '%s'\n", class_id); + return NULL; + } + + if (snd_config_get_string(unique, &unique_name) < 0) { + SNDERR("Invalid name for unique attribute in class '%s'\n", class_id); + return NULL; + } + + return unique_name; +} diff --git a/topology/pre-processor.h b/topology/pre-processor.h index a5cfa0a..04e1cfc 100644 --- a/topology/pre-processor.h +++ b/topology/pre-processor.h @@ -35,6 +35,8 @@ snd_config_t *tplg_class_find_attribute_by_name(struct tplg_pre_processor *tplg_ bool tplg_class_is_attribute_mandatory(const char *attr, snd_config_t *class_cfg); bool tplg_class_is_attribute_immutable(const char *attr, snd_config_t *class_cfg); bool tplg_class_is_attribute_unique(const char *attr, snd_config_t *class_cfg); +const char *tplg_class_get_unique_attribute_name(struct tplg_pre_processor *tplg_pp, + snd_config_t *class); /* config helpers */ snd_config_t *tplg_find_config(snd_config_t *config, const char *name); -- 2.47.1