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

index 90333435f39097f6aa974d91361873e6902567c3..3d09a8627fa84f9a7311622800ea2545865708d9 100644 (file)
@@ -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;
+}
index a5cfa0acb3cb2cd41bde247c6c95b149f7700a65..04e1cfcafd8829f4cc2b734e24841f311672bd38 100644 (file)
@@ -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);