From 1422c09afdd79d8b1253707c7fb67256f579c408 Mon Sep 17 00:00:00 2001 From: Ranjani Sridharan Date: Fri, 23 Apr 2021 12:35:56 -0700 Subject: [PATCH] topology: pre-process-class: Add function to look up attribute definition in class Add a helper function look up attribute definition in the "DefineAttribute" config in the class definition. 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 9e7f4fc..cd4c7c3 100644 --- a/topology/pre-process-class.c +++ b/topology/pre-process-class.c @@ -66,3 +66,28 @@ snd_config_t *tplg_class_lookup(struct tplg_pre_processor *tplg_pp, snd_config_t free(class_config_id); return class_cfg; } + +/* find the attribute config by name in the class definition */ +snd_config_t *tplg_class_find_attribute_by_name(struct tplg_pre_processor *tplg_pp, + snd_config_t *class, const char *name) +{ + snd_config_t *attr = NULL; + const char *class_id; + char *attr_str; + int ret; + + if (snd_config_get_id(class, &class_id) < 0) + return NULL; + + attr_str = tplg_snprintf("DefineAttribute.%s", name); + if (!attr_str) + return NULL; + + ret = snd_config_search(class, attr_str, &attr); + if (ret < 0) + SNDERR("No definition for attribute '%s' in class '%s'\n", + name, class_id); + + free(attr_str); + return attr; +} diff --git a/topology/pre-processor.h b/topology/pre-processor.h index 8c32ce3..d7d1b11 100644 --- a/topology/pre-processor.h +++ b/topology/pre-processor.h @@ -28,6 +28,8 @@ void tplg_pp_config_debug(struct tplg_pre_processor *tplg_pp, snd_config_t *cfg) /* class helpers */ snd_config_t *tplg_class_lookup(struct tplg_pre_processor *tplg_pp, snd_config_t *cfg); +snd_config_t *tplg_class_find_attribute_by_name(struct tplg_pre_processor *tplg_pp, + snd_config_t *class, const char *name); /* config helpers */ snd_config_t *tplg_find_config(snd_config_t *config, const char *name);