mirror of
				https://github.com/alsa-project/alsa-lib.git
				synced 2025-11-03 09:01:52 -05:00 
			
		
		
		
	ucm: substitute the merged tree completely
We need to define the common shared configuration like for multiple
HDMI devices or so. Substitute the whole merged configuration tree
including identifiers.
Fixes: https://github.com/alsa-project/alsa-lib/issues/67
Fixes: dcef48f13d
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
			
			
This commit is contained in:
		
							parent
							
								
									30d12e930c
								
							
						
					
					
						commit
						32addac948
					
				
					 4 changed files with 66 additions and 4 deletions
				
			
		| 
						 | 
				
			
			@ -401,7 +401,7 @@ int uc_mgr_evaluate_condition(snd_use_case_mgr_t *uc_mgr,
 | 
			
		|||
		err = uc_mgr_evaluate_inplace(uc_mgr, a);
 | 
			
		||||
		if (err < 0)
 | 
			
		||||
			return err;
 | 
			
		||||
		err = uc_mgr_config_tree_merge(parent, a, before, after);
 | 
			
		||||
		err = uc_mgr_config_tree_merge(uc_mgr, parent, a, before, after);
 | 
			
		||||
		if (err < 0)
 | 
			
		||||
			return err;
 | 
			
		||||
		snd_config_delete(a);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -206,7 +206,8 @@ static int compound_merge(const char *id,
 | 
			
		|||
	return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int uc_mgr_config_tree_merge(snd_config_t *parent, snd_config_t *new_ctx,
 | 
			
		||||
int uc_mgr_config_tree_merge(snd_use_case_mgr_t *uc_mgr,
 | 
			
		||||
			     snd_config_t *parent, snd_config_t *new_ctx,
 | 
			
		||||
			     snd_config_t *before, snd_config_t *after)
 | 
			
		||||
{
 | 
			
		||||
	snd_config_iterator_t i, next;
 | 
			
		||||
| 
						 | 
				
			
			@ -214,6 +215,10 @@ int uc_mgr_config_tree_merge(snd_config_t *parent, snd_config_t *new_ctx,
 | 
			
		|||
	const char *id;
 | 
			
		||||
	int err;
 | 
			
		||||
 | 
			
		||||
	err = uc_mgr_substitute_tree(uc_mgr, new_ctx);
 | 
			
		||||
	if (err < 0)
 | 
			
		||||
		return err;
 | 
			
		||||
 | 
			
		||||
	snd_config_for_each(i, next, new_ctx) {
 | 
			
		||||
		n = snd_config_iterator_entry(i);
 | 
			
		||||
		err = snd_config_remove(n);
 | 
			
		||||
| 
						 | 
				
			
			@ -271,7 +276,7 @@ int uc_mgr_evaluate_include(snd_use_case_mgr_t *uc_mgr,
 | 
			
		|||
		err = uc_mgr_evaluate_inplace(uc_mgr, a);
 | 
			
		||||
		if (err < 0)
 | 
			
		||||
			return err;
 | 
			
		||||
		err = uc_mgr_config_tree_merge(parent, a, before, after);
 | 
			
		||||
		err = uc_mgr_config_tree_merge(uc_mgr, parent, a, before, after);
 | 
			
		||||
		if (err < 0)
 | 
			
		||||
			return err;
 | 
			
		||||
		snd_config_delete(a);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -307,7 +307,11 @@ int uc_mgr_get_substituted_value(snd_use_case_mgr_t *uc_mgr,
 | 
			
		|||
				 char **_rvalue,
 | 
			
		||||
				 const char *value);
 | 
			
		||||
 | 
			
		||||
int uc_mgr_config_tree_merge(snd_config_t *parent, snd_config_t *new_ctx,
 | 
			
		||||
int uc_mgr_substitute_tree(snd_use_case_mgr_t *uc_mgr,
 | 
			
		||||
			   snd_config_t *node);
 | 
			
		||||
 | 
			
		||||
int uc_mgr_config_tree_merge(snd_use_case_mgr_t *uc_mgr,
 | 
			
		||||
			     snd_config_t *parent, snd_config_t *new_ctx,
 | 
			
		||||
			     snd_config_t *before, snd_config_t *after);
 | 
			
		||||
 | 
			
		||||
int uc_mgr_evaluate_inplace(snd_use_case_mgr_t *uc_mgr,
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -395,3 +395,56 @@ __error:
 | 
			
		|||
	free(r);
 | 
			
		||||
	return err;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static inline int uc_mgr_substitute_check(const char *s)
 | 
			
		||||
{
 | 
			
		||||
	return s && strstr(s, "${") != NULL;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int uc_mgr_substitute_tree(snd_use_case_mgr_t *uc_mgr, snd_config_t *node)
 | 
			
		||||
{
 | 
			
		||||
	snd_config_iterator_t i, next;
 | 
			
		||||
	snd_config_t *n;
 | 
			
		||||
	const char *id, *s2;
 | 
			
		||||
	char *s;
 | 
			
		||||
	int err;
 | 
			
		||||
 | 
			
		||||
	err = snd_config_get_id(node, &id);
 | 
			
		||||
	if (err < 0)
 | 
			
		||||
		return err;
 | 
			
		||||
	if (uc_mgr_substitute_check(id)) {
 | 
			
		||||
		err = uc_mgr_get_substituted_value(uc_mgr, &s, id);
 | 
			
		||||
		if (err < 0)
 | 
			
		||||
			return err;
 | 
			
		||||
		err = snd_config_set_id(node, s);
 | 
			
		||||
		free(s);
 | 
			
		||||
		if (err < 0) {
 | 
			
		||||
			uc_error("unable to set substituted id '%s' (old id '%s')", s, id);
 | 
			
		||||
			return err;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	if (snd_config_get_type(node) != SND_CONFIG_TYPE_COMPOUND) {
 | 
			
		||||
		if (snd_config_get_type(node) == SND_CONFIG_TYPE_STRING) {
 | 
			
		||||
			err = snd_config_get_string(node, &s2);
 | 
			
		||||
			if (err < 0)
 | 
			
		||||
				return err;
 | 
			
		||||
			if (!uc_mgr_substitute_check(s2))
 | 
			
		||||
				return 0;
 | 
			
		||||
			err = uc_mgr_get_substituted_value(uc_mgr, &s, s2);
 | 
			
		||||
			if (err < 0)
 | 
			
		||||
				return err;
 | 
			
		||||
			err = snd_config_set_string(node, s);
 | 
			
		||||
			free(s);
 | 
			
		||||
			if (err < 0)
 | 
			
		||||
				return err;
 | 
			
		||||
		}
 | 
			
		||||
		return 0;
 | 
			
		||||
	}
 | 
			
		||||
	snd_config_for_each(i, next, node) {
 | 
			
		||||
		n = snd_config_iterator_entry(i);
 | 
			
		||||
		err = uc_mgr_substitute_tree(uc_mgr, n);
 | 
			
		||||
		if (err < 0)
 | 
			
		||||
			return err;
 | 
			
		||||
	}
 | 
			
		||||
	return 0;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue