mirror of
				https://github.com/alsa-project/alsa-lib.git
				synced 2025-11-03 09:01:52 -05:00 
			
		
		
		
	ucm: add cfg-save command
Allow to save whole (or partial) local UCM alsa library configuration to a file. Syntax (saves key1.key2 sub-tree): Sequence [ cfg-save "/tmp/my-file.conf:key1.key2" ] Signed-off-by: Jaroslav Kysela <perex@perex.cz>
This commit is contained in:
		
							parent
							
								
									f821f09727
								
							
						
					
					
						commit
						5e7c507152
					
				
					 4 changed files with 56 additions and 0 deletions
				
			
		| 
						 | 
					@ -573,6 +573,42 @@ static int execute_sysw(const char *sysw)
 | 
				
			||||||
	return 0;
 | 
						return 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static int execute_cfgsave(snd_use_case_mgr_t *uc_mgr, const char *filename)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						snd_config_t *config = uc_mgr->local_config;
 | 
				
			||||||
 | 
						char *file, *root;
 | 
				
			||||||
 | 
						snd_output_t *out;
 | 
				
			||||||
 | 
						int err = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						file = strdup(filename);
 | 
				
			||||||
 | 
						if (!file)
 | 
				
			||||||
 | 
							return -ENOMEM;
 | 
				
			||||||
 | 
						root = strchr(file, ':');
 | 
				
			||||||
 | 
						if (root) {
 | 
				
			||||||
 | 
							*root = '\0';
 | 
				
			||||||
 | 
							err = snd_config_search(config, root + 1, &config);
 | 
				
			||||||
 | 
							if (err < 0) {
 | 
				
			||||||
 | 
								uc_error("Unable to find subtree '%s'", root);
 | 
				
			||||||
 | 
								goto _err;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						err = snd_output_stdio_open(&out, file, "w+");
 | 
				
			||||||
 | 
						if (err < 0) {
 | 
				
			||||||
 | 
							uc_error("unable to open file '%s': %s", file, snd_strerror(err));
 | 
				
			||||||
 | 
							goto _err;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						err = snd_config_save(config, out);
 | 
				
			||||||
 | 
						snd_output_close(out);
 | 
				
			||||||
 | 
						if (err < 0) {
 | 
				
			||||||
 | 
							uc_error("unable to save configuration: %s", snd_strerror(err));
 | 
				
			||||||
 | 
							goto _err;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					_err:
 | 
				
			||||||
 | 
						free(file);
 | 
				
			||||||
 | 
						return err;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static int rewrite_device_value(snd_use_case_mgr_t *uc_mgr, const char *name, char **value)
 | 
					static int rewrite_device_value(snd_use_case_mgr_t *uc_mgr, const char *name, char **value)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	char *sval;
 | 
						char *sval;
 | 
				
			||||||
| 
						 | 
					@ -754,6 +790,11 @@ shell_retry:
 | 
				
			||||||
			if (err < 0)
 | 
								if (err < 0)
 | 
				
			||||||
				goto __fail;
 | 
									goto __fail;
 | 
				
			||||||
			break;
 | 
								break;
 | 
				
			||||||
 | 
							case SEQUENCE_ELEMENT_TYPE_CFGSAVE:
 | 
				
			||||||
 | 
								err = execute_cfgsave(uc_mgr, s->data.cfgsave);
 | 
				
			||||||
 | 
								if (err < 0)
 | 
				
			||||||
 | 
									goto __fail;
 | 
				
			||||||
 | 
								break;
 | 
				
			||||||
		default:
 | 
							default:
 | 
				
			||||||
			uc_error("unknown sequence command %i", s->type);
 | 
								uc_error("unknown sequence command %i", s->type);
 | 
				
			||||||
			break;
 | 
								break;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -924,6 +924,16 @@ exec:
 | 
				
			||||||
			goto exec;
 | 
								goto exec;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if (strcmp(cmd, "cfg-save") == 0) {
 | 
				
			||||||
 | 
								curr->type = SEQUENCE_ELEMENT_TYPE_CFGSAVE;
 | 
				
			||||||
 | 
								err = parse_string_substitute3(uc_mgr, n, &curr->data.cfgsave);
 | 
				
			||||||
 | 
								if (err < 0) {
 | 
				
			||||||
 | 
									uc_error("error: sysw requires a string!");
 | 
				
			||||||
 | 
									return err;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								continue;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if (strcmp(cmd, "comment") == 0)
 | 
							if (strcmp(cmd, "comment") == 0)
 | 
				
			||||||
			goto skip;
 | 
								goto skip;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -56,6 +56,7 @@
 | 
				
			||||||
#define SEQUENCE_ELEMENT_TYPE_CTL_REMOVE	9
 | 
					#define SEQUENCE_ELEMENT_TYPE_CTL_REMOVE	9
 | 
				
			||||||
#define SEQUENCE_ELEMENT_TYPE_CMPT_SEQ		10
 | 
					#define SEQUENCE_ELEMENT_TYPE_CMPT_SEQ		10
 | 
				
			||||||
#define SEQUENCE_ELEMENT_TYPE_SYSSET		11
 | 
					#define SEQUENCE_ELEMENT_TYPE_SYSSET		11
 | 
				
			||||||
 | 
					#define SEQUENCE_ELEMENT_TYPE_CFGSAVE		12
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct ucm_value {
 | 
					struct ucm_value {
 | 
				
			||||||
        struct list_head list;
 | 
					        struct list_head list;
 | 
				
			||||||
| 
						 | 
					@ -78,6 +79,7 @@ struct sequence_element {
 | 
				
			||||||
		char *cset;
 | 
							char *cset;
 | 
				
			||||||
		char *exec;
 | 
							char *exec;
 | 
				
			||||||
		char *sysw;
 | 
							char *sysw;
 | 
				
			||||||
 | 
							char *cfgsave;
 | 
				
			||||||
		struct component_sequence cmpt_seq; /* component sequence */
 | 
							struct component_sequence cmpt_seq; /* component sequence */
 | 
				
			||||||
	} data;
 | 
						} data;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -512,6 +512,9 @@ void uc_mgr_free_sequence_element(struct sequence_element *seq)
 | 
				
			||||||
	case SEQUENCE_ELEMENT_TYPE_SHELL:
 | 
						case SEQUENCE_ELEMENT_TYPE_SHELL:
 | 
				
			||||||
		free(seq->data.exec);
 | 
							free(seq->data.exec);
 | 
				
			||||||
		break;
 | 
							break;
 | 
				
			||||||
 | 
						case SEQUENCE_ELEMENT_TYPE_CFGSAVE:
 | 
				
			||||||
 | 
							free(seq->data.cfgsave);
 | 
				
			||||||
 | 
							break;
 | 
				
			||||||
	default:
 | 
						default:
 | 
				
			||||||
		break;
 | 
							break;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue