mirror of
https://github.com/openharmony/third_party_alsa-utils.git
synced 2026-07-19 20:43:35 -04:00
topology: pre-process-class: Add functions to check attribute constraints
Add helper functions to check if an attribute is
mandatory, immutable or unique in the class definition.
ex: for a host widget component, these are defined
as follows:
attributes {
#
# host objects instantiated within the same alsaconf node must have unique
# direction attribute
#
unique "direction"
mandatory [
"type"
"stream_name"
]
immutable [
"uuid"
]
}
Signed-off-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
This commit is contained in:
committed by
Jaroslav Kysela
parent
1422c09afd
commit
7bf31094e2
@@ -26,6 +26,65 @@
|
||||
#include "topology.h"
|
||||
#include "pre-processor.h"
|
||||
|
||||
bool tplg_class_is_attribute_check(const char *attr, snd_config_t *class_cfg, char *category)
|
||||
{
|
||||
snd_config_iterator_t i, next;
|
||||
snd_config_t *cfg, *n;
|
||||
int ret;
|
||||
|
||||
ret = snd_config_search(class_cfg, category, &cfg);
|
||||
if (ret < 0)
|
||||
return false;
|
||||
|
||||
snd_config_for_each(i, next, cfg) {
|
||||
const char *id, *s;
|
||||
|
||||
n = snd_config_iterator_entry(i);
|
||||
if (snd_config_get_id(n, &id) < 0)
|
||||
continue;
|
||||
|
||||
if (snd_config_get_string(n, &s) < 0)
|
||||
continue;
|
||||
|
||||
if (!strcmp(attr, s))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/* check if attribute is mandatory */
|
||||
bool tplg_class_is_attribute_mandatory(const char *attr, snd_config_t *class_cfg)
|
||||
{
|
||||
return tplg_class_is_attribute_check(attr, class_cfg, "attributes.mandatory");
|
||||
}
|
||||
|
||||
/* check if attribute is immutable */
|
||||
bool tplg_class_is_attribute_immutable(const char *attr, snd_config_t *class_cfg)
|
||||
{
|
||||
return tplg_class_is_attribute_check(attr, class_cfg, "attributes.immutable");
|
||||
}
|
||||
|
||||
/* check if attribute is unique */
|
||||
bool tplg_class_is_attribute_unique(const char *attr, snd_config_t *class_cfg)
|
||||
{
|
||||
snd_config_t *unique;
|
||||
const char *s;
|
||||
int ret;
|
||||
|
||||
ret = snd_config_search(class_cfg, "attributes.unique", &unique);
|
||||
if (ret < 0)
|
||||
return false;
|
||||
|
||||
if (snd_config_get_string(unique, &s) < 0)
|
||||
return false;
|
||||
|
||||
if (!strcmp(attr, s))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* 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
|
||||
|
||||
@@ -18,6 +18,8 @@
|
||||
#define __PRE_PROCESSOR_H
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
#include "topology.h"
|
||||
|
||||
#define DEBUG_MAX_LENGTH 256
|
||||
@@ -30,6 +32,9 @@ void tplg_pp_config_debug(struct tplg_pre_processor *tplg_pp, snd_config_t *cfg)
|
||||
snd_config_t *tplg_class_lookup(struct tplg_pre_processor *tplg_pp, snd_config_t *cfg);
|
||||
snd_config_t *tplg_class_find_attribute_by_name(struct tplg_pre_processor *tplg_pp,
|
||||
snd_config_t *class, const char *name);
|
||||
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);
|
||||
|
||||
/* config helpers */
|
||||
snd_config_t *tplg_find_config(snd_config_t *config, const char *name);
|
||||
|
||||
Reference in New Issue
Block a user