]> git.alsa-project.org Git - alsa-utils.git/commitdiff
topology: pre-processor: Add a couple of config helpers
authorRanjani Sridharan <ranjani.sridharan@linux.intel.com>
Fri, 23 Apr 2021 18:06:29 +0000 (11:06 -0700)
committerJaroslav Kysela <perex@perex.cz>
Tue, 25 May 2021 16:26:51 +0000 (18:26 +0200)
Add a couple of helper functions for searching config by ID and
creating and adding configs to a parent config.

Signed-off-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
topology/pre-processor.c
topology/pre-processor.h

index 5ddd4f908b831c427c2d9185bae81504d0e074d1..100c9ad22c8a72b511bb1f797f83681675aa2988 100644 (file)
 #include "topology.h"
 #include "pre-processor.h"
 
+/*
+ * Helper function to find config by id.
+ * Topology2.0 object names are constructed with attribute values separated by '.'.
+ * So snd_config_search() cannot be used as it interprets the '.' as the node separator.
+ */
+snd_config_t *tplg_find_config(snd_config_t *config, const char *name)
+{
+       snd_config_iterator_t i, next;
+       snd_config_t *n;
+       const char *id;
+
+       snd_config_for_each(i, next, config) {
+               n = snd_config_iterator_entry(i);
+               if (snd_config_get_id(n, &id) < 0)
+                       continue;
+
+               if (!strcmp(id, name))
+                       return n;
+       }
+
+       return NULL;
+}
+
+/* make a new config and add it to parent */
+int tplg_config_make_add(snd_config_t **config, const char *id, snd_config_type_t type,
+                        snd_config_t *parent)
+{
+       int ret;
+
+       ret = snd_config_make(config, id, type);
+       if (ret < 0)
+               return ret;
+
+       ret = snd_config_add(parent, *config);
+       if (ret < 0)
+               snd_config_delete(*config);
+
+       return ret;
+}
+
 #ifdef TPLG_DEBUG
 void tplg_pp_debug(char *fmt, ...)
 {
index 9a7b6f1406b2ade9e08bb65dd46d3d14c8bc8d3c..cac464b5576257f1c96704ca8d794a0cf5f6678f 100644 (file)
@@ -25,4 +25,9 @@
 /* debug helpers */
 void tplg_pp_debug(char *fmt, ...);
 void tplg_pp_config_debug(struct tplg_pre_processor *tplg_pp, snd_config_t *cfg);
+
+/* 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);
 #endif