]> git.alsa-project.org Git - alsa-utils.git/commitdiff
topology: pre-process-class: function to get attribute type
authorRanjani Sridharan <ranjani.sridharan@linux.intel.com>
Fri, 23 Apr 2021 20:36:48 +0000 (13:36 -0700)
committerJaroslav Kysela <perex@perex.cz>
Tue, 25 May 2021 16:26:51 +0000 (18:26 +0200)
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 <ranjani.sridharan@linux.intel.com>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
topology/pre-process-class.c
topology/pre-processor.h

index 3d09a8627fa84f9a7311622800ea2545865708d9..b039716cc317f4e15d918505611eec9fbb1adbcc 100644 (file)
@@ -17,6 +17,7 @@
   The full GNU General Public License is included in this distribution
   in the file called LICENSE.GPL.
 */
+#include <assert.h>
 #include <limits.h>
 #include <stdio.h>
 #include <alsa/input.h>
@@ -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;
+}
index 04e1cfcafd8829f4cc2b734e24841f311672bd38..17a7dd569f2eaa93ce67062f5e1b05b3cf4ad7d4 100644 (file)
@@ -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