From d8e9466e594dd62779bbc19eb2a379c79413f0d9 Mon Sep 17 00:00:00 2001 From: Ranjani Sridharan Date: Fri, 23 Apr 2021 13:36:48 -0700 Subject: [PATCH] topology: pre-process-class: function to get attribute type Add a helper function to get attribute type from the attribute definition and convert them to SND_CONFIG_TYPE_* values. When no type if provided for an attribute, type defaults to integer. Signed-off-by: Ranjani Sridharan Signed-off-by: Jaroslav Kysela --- topology/pre-process-class.c | 32 ++++++++++++++++++++++++++++++++ topology/pre-processor.h | 3 ++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/topology/pre-process-class.c b/topology/pre-process-class.c index 3d09a86..b039716 100644 --- a/topology/pre-process-class.c +++ b/topology/pre-process-class.c @@ -17,6 +17,7 @@ The full GNU General Public License is included in this distribution in the file called LICENSE.GPL. */ +#include #include #include #include @@ -175,3 +176,34 @@ const char *tplg_class_get_unique_attribute_name(struct tplg_pre_processor *tplg return unique_name; } + +/* get attribute type from the definition */ +snd_config_type_t tplg_class_get_attribute_type(struct tplg_pre_processor *tplg_pp, + snd_config_t *attr) +{ + snd_config_t *type; + const char *s; + int ret; + + /* default to integer if no type is given */ + ret = snd_config_search(attr, "type", &type); + if (ret < 0) + return SND_CONFIG_TYPE_INTEGER; + + ret = snd_config_get_string(type, &s); + assert(ret >= 0); + + if (!strcmp(s, "string")) + return SND_CONFIG_TYPE_STRING; + + if (!strcmp(s, "compound")) + return SND_CONFIG_TYPE_COMPOUND; + + if (!strcmp(s, "real")) + return SND_CONFIG_TYPE_REAL; + + if (!strcmp(s, "integer64")) + return SND_CONFIG_TYPE_INTEGER64; + + return SND_CONFIG_TYPE_INTEGER; +} diff --git a/topology/pre-processor.h b/topology/pre-processor.h index 04e1cfc..17a7dd5 100644 --- a/topology/pre-processor.h +++ b/topology/pre-processor.h @@ -37,11 +37,12 @@ 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); +snd_config_type_t tplg_class_get_attribute_type(struct tplg_pre_processor *tplg_pp, + snd_config_t *attr); /* config helpers */ snd_config_t *tplg_find_config(snd_config_t *config, const char *name); int tplg_config_make_add(snd_config_t **config, const char *id, snd_config_type_t type, snd_config_t *parent); - char *tplg_snprintf(char *fmt, ...); #endif