2 * This library is free software; you can redistribute it and/or
3 * modify it under the terms of the GNU Lesser General Public
4 * License as published by the Free Software Foundation; either
5 * version 2 of the License, or (at your option) any later version.
7 * This library is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 * Lesser General Public License for more details.
12 * You should have received a copy of the GNU Lesser General Public
13 * License along with this library; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 * Support for the verb/device/modifier core logic and API,
17 * command line tool and file parser was kindly sponsored by
18 * Texas Instruments Inc.
19 * Support for multiple active modifiers and devices,
20 * transition sequences, multiple client access and user defined use
21 * cases was kindly sponsored by Wolfson Microelectronics PLC.
23 * Copyright (C) 2008-2010 SlimLogic Ltd
24 * Copyright (C) 2010 Wolfson Microelectronics PLC
25 * Copyright (C) 2010 Texas Instruments Inc.
26 * Copyright (C) 2010 Red Hat Inc.
27 * Authors: Liam Girdwood <lrg@slimlogic.co.uk>
28 * Stefan Schmidt <stefan@slimlogic.co.uk>
29 * Justin Xu <justinx@slimlogic.co.uk>
30 * Jaroslav Kysela <perex@perex.cz>
33 #include "ucm_local.h"
35 void uc_mgr_error(const char *fmt,...)
39 fprintf(stderr, "ucm: ");
40 vfprintf(stderr, fmt, va);
44 void uc_mgr_stdout(const char *fmt,...)
48 vfprintf(stdout, fmt, va);
52 int uc_mgr_config_load(const char *file, snd_config_t **cfg)
59 fp = fopen(file, "r");
64 err = snd_input_stdio_attach(&in, fp, 1);
67 uc_error("could not open configuration file %s", file);
70 err = snd_config_top(&top);
73 err = snd_config_load(top, in);
75 uc_error("could not load configuration file %s", file);
76 snd_config_delete(top);
79 err = snd_input_close(in);
81 snd_config_delete(top);
88 void uc_mgr_free_value(struct list_head *base)
90 struct list_head *pos, *npos;
91 struct ucm_value *val;
93 list_for_each_safe(pos, npos, base) {
94 val = list_entry(pos, struct ucm_value, list);
102 void uc_mgr_free_dev_list(struct dev_list *dev_list)
104 struct list_head *pos, *npos;
105 struct dev_list_node *dlist;
107 list_for_each_safe(pos, npos, &dev_list->list) {
108 dlist = list_entry(pos, struct dev_list_node, list);
110 list_del(&dlist->list);
115 void uc_mgr_free_sequence_element(struct sequence_element *seq)
120 case SEQUENCE_ELEMENT_TYPE_CSET:
121 case SEQUENCE_ELEMENT_TYPE_EXEC:
122 free(seq->data.exec);
130 void uc_mgr_free_sequence(struct list_head *base)
132 struct list_head *pos, *npos;
133 struct sequence_element *seq;
135 list_for_each_safe(pos, npos, base) {
136 seq = list_entry(pos, struct sequence_element, list);
137 list_del(&seq->list);
138 uc_mgr_free_sequence_element(seq);
142 void uc_mgr_free_transition_element(struct transition_sequence *tseq)
145 uc_mgr_free_sequence(&tseq->transition_list);
149 void uc_mgr_free_transition(struct list_head *base)
151 struct list_head *pos, *npos;
152 struct transition_sequence *tseq;
154 list_for_each_safe(pos, npos, base) {
155 tseq = list_entry(pos, struct transition_sequence, list);
156 list_del(&tseq->list);
157 uc_mgr_free_transition_element(tseq);
161 void uc_mgr_free_modifier(struct list_head *base)
163 struct list_head *pos, *npos;
164 struct use_case_modifier *mod;
166 list_for_each_safe(pos, npos, base) {
167 mod = list_entry(pos, struct use_case_modifier, list);
170 uc_mgr_free_sequence(&mod->enable_list);
171 uc_mgr_free_sequence(&mod->disable_list);
172 uc_mgr_free_transition(&mod->transition_list);
173 uc_mgr_free_dev_list(&mod->dev_list);
174 uc_mgr_free_value(&mod->value_list);
175 list_del(&mod->list);
180 void uc_mgr_free_device(struct list_head *base)
182 struct list_head *pos, *npos;
183 struct use_case_device *dev;
185 list_for_each_safe(pos, npos, base) {
186 dev = list_entry(pos, struct use_case_device, list);
189 uc_mgr_free_sequence(&dev->enable_list);
190 uc_mgr_free_sequence(&dev->disable_list);
191 uc_mgr_free_transition(&dev->transition_list);
192 uc_mgr_free_dev_list(&dev->dev_list);
193 uc_mgr_free_value(&dev->value_list);
194 list_del(&dev->list);
199 void uc_mgr_free_verb(snd_use_case_mgr_t *uc_mgr)
201 struct list_head *pos, *npos;
202 struct use_case_verb *verb;
204 list_for_each_safe(pos, npos, &uc_mgr->verb_list) {
205 verb = list_entry(pos, struct use_case_verb, list);
208 uc_mgr_free_sequence(&verb->enable_list);
209 uc_mgr_free_sequence(&verb->disable_list);
210 uc_mgr_free_transition(&verb->transition_list);
211 uc_mgr_free_value(&verb->value_list);
212 uc_mgr_free_device(&verb->device_list);
213 uc_mgr_free_modifier(&verb->modifier_list);
214 list_del(&verb->list);
217 uc_mgr_free_sequence(&uc_mgr->default_list);
218 uc_mgr_free_value(&uc_mgr->value_list);
219 free(uc_mgr->comment);
220 uc_mgr->comment = NULL;
221 uc_mgr->active_verb = NULL;
222 INIT_LIST_HEAD(&uc_mgr->active_devices);
223 INIT_LIST_HEAD(&uc_mgr->active_modifiers);
224 if (uc_mgr->ctl != NULL) {
225 snd_ctl_close(uc_mgr->ctl);
228 free(uc_mgr->ctl_dev);
229 uc_mgr->ctl_dev = NULL;
232 void uc_mgr_free(snd_use_case_mgr_t *uc_mgr)
234 uc_mgr_free_verb(uc_mgr);
235 free(uc_mgr->card_name);