From 94eaca13cebede3d99940b8742eae081e0a50671 Mon Sep 17 00:00:00 2001 From: Ranjani Sridharan Date: Fri, 23 Apr 2021 11:06:29 -0700 Subject: [PATCH] topology: pre-processor: Add a couple of config helpers 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 Signed-off-by: Jaroslav Kysela --- topology/pre-processor.c | 40 ++++++++++++++++++++++++++++++++++++++++ topology/pre-processor.h | 5 +++++ 2 files changed, 45 insertions(+) diff --git a/topology/pre-processor.c b/topology/pre-processor.c index 5ddd4f9..100c9ad 100644 --- a/topology/pre-processor.c +++ b/topology/pre-processor.c @@ -31,6 +31,46 @@ #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, ...) { diff --git a/topology/pre-processor.h b/topology/pre-processor.h index 9a7b6f1..cac464b 100644 --- a/topology/pre-processor.h +++ b/topology/pre-processor.h @@ -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