mirror of
https://github.com/alsa-project/alsa-utils
synced 2024-12-23 01:56:31 +01:00
topology: pre-process-class: Add helper function to look up class definition
Add a helper function to look up the class definition for an object. ex: for an object instance, Object.Widget.pga.0{}, the function returns the config pointing to Class.Widget.pga{} in the input conf. Signed-off-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com> Signed-off-by: Jaroslav Kysela <perex@perex.cz>
This commit is contained in:
parent
eb514c6bd7
commit
c832f48404
3 changed files with 72 additions and 1 deletions
|
@ -8,7 +8,7 @@ endif
|
||||||
%.1: %.rst
|
%.1: %.rst
|
||||||
rst2man $< > $@
|
rst2man $< > $@
|
||||||
|
|
||||||
alsatplg_SOURCES = topology.c pre-processor.c
|
alsatplg_SOURCES = topology.c pre-processor.c pre-process-class.c
|
||||||
|
|
||||||
noinst_HEADERS = topology.h pre-processor.h
|
noinst_HEADERS = topology.h pre-processor.h
|
||||||
|
|
||||||
|
|
68
topology/pre-process-class.c
Normal file
68
topology/pre-process-class.c
Normal file
|
@ -0,0 +1,68 @@
|
||||||
|
/*
|
||||||
|
Copyright(c) 2021 Intel Corporation
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of version 2 of the GNU General Public License as
|
||||||
|
published by the Free Software Foundation.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful, but
|
||||||
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
The full GNU General Public License is included in this distribution
|
||||||
|
in the file called LICENSE.GPL.
|
||||||
|
*/
|
||||||
|
#include <limits.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <alsa/input.h>
|
||||||
|
#include <alsa/output.h>
|
||||||
|
#include <alsa/conf.h>
|
||||||
|
#include <alsa/error.h>
|
||||||
|
#include "topology.h"
|
||||||
|
#include "pre-processor.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Helper function to look up class definition from the Object config.
|
||||||
|
* ex: For an object declaration, Object.Widget.pga.0{}, return the config correspdonding to
|
||||||
|
* Class.Widget.pga{}. Note that input config , "cfg" does not include the "Object" node.
|
||||||
|
*/
|
||||||
|
snd_config_t *tplg_class_lookup(struct tplg_pre_processor *tplg_pp, snd_config_t *cfg)
|
||||||
|
{
|
||||||
|
snd_config_iterator_t first, end;
|
||||||
|
snd_config_t *class, *class_cfg = NULL;
|
||||||
|
const char *class_type, *class_name;
|
||||||
|
char *class_config_id;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
if (snd_config_get_id(cfg, &class_type) < 0)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
first = snd_config_iterator_first(cfg);
|
||||||
|
end = snd_config_iterator_end(cfg);
|
||||||
|
|
||||||
|
if (first == end) {
|
||||||
|
SNDERR("No class name provided for object type: %s\n", class_type);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
class = snd_config_iterator_entry(first);
|
||||||
|
|
||||||
|
if (snd_config_get_id(class, &class_name) < 0)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
class_config_id = tplg_snprintf("Class.%s.%s", class_type, class_name);
|
||||||
|
if (!class_config_id)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
ret = snd_config_search(tplg_pp->input_cfg, class_config_id, &class_cfg);
|
||||||
|
if (ret < 0)
|
||||||
|
SNDERR("No Class definition found for %s\n", class_config_id);
|
||||||
|
|
||||||
|
free(class_config_id);
|
||||||
|
return class_cfg;
|
||||||
|
}
|
|
@ -26,6 +26,9 @@
|
||||||
void tplg_pp_debug(char *fmt, ...);
|
void tplg_pp_debug(char *fmt, ...);
|
||||||
void tplg_pp_config_debug(struct tplg_pre_processor *tplg_pp, snd_config_t *cfg);
|
void tplg_pp_config_debug(struct tplg_pre_processor *tplg_pp, snd_config_t *cfg);
|
||||||
|
|
||||||
|
/* class helpers */
|
||||||
|
snd_config_t *tplg_class_lookup(struct tplg_pre_processor *tplg_pp, snd_config_t *cfg);
|
||||||
|
|
||||||
/* config helpers */
|
/* config helpers */
|
||||||
snd_config_t *tplg_find_config(snd_config_t *config, const char *name);
|
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,
|
int tplg_config_make_add(snd_config_t **config, const char *id, snd_config_type_t type,
|
||||||
|
|
Loading…
Reference in a new issue