ALSA project - the C library reference
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
ucm_local.h
1 /*
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.
6  *
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.
11  *
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
15  *
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.
22  *
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>
31  */
32 
33 
34 
35 #if 0
36 #define UC_MGR_DEBUG
37 #endif
38 
39 #include <pthread.h>
40 #include "local.h"
41 #include "use-case.h"
42 
43 #define MAX_FILE 256
44 #define ALSA_USE_CASE_DIR ALSA_CONFIG_DIR "/ucm"
45 
46 #define SEQUENCE_ELEMENT_TYPE_CDEV 1
47 #define SEQUENCE_ELEMENT_TYPE_CSET 2
48 #define SEQUENCE_ELEMENT_TYPE_SLEEP 3
49 #define SEQUENCE_ELEMENT_TYPE_EXEC 4
50 #define SEQUENCE_ELEMENT_TYPE_CSET_BIN_FILE 5
51 
52 struct ucm_value {
53  struct list_head list;
54  char *name;
55  char *data;
56 };
57 
59  struct list_head list;
60  unsigned int type;
61  union {
62  long sleep; /* Sleep time in microseconds if sleep element, else 0 */
63  char *cdev;
64  char *cset;
65  char *exec;
66  } data;
67 };
68 
69 /*
70  * Transition sequences. i.e. transition between one verb, device, mod to another
71  */
73  struct list_head list;
74  char *name;
75  struct list_head transition_list;
76 };
77 
78 /*
79  * Modifier Supported Devices.
80  */
81 enum dev_list_type {
82  DEVLIST_NONE,
83  DEVLIST_SUPPORTED,
84  DEVLIST_CONFLICTING
85 };
86 
87 struct dev_list_node {
88  struct list_head list;
89  char *name;
90 };
91 
92 struct dev_list {
93  enum dev_list_type type;
94  struct list_head list;
95 };
96 
97 /*
98  * Describes a Use Case Modifier and it's enable and disable sequences.
99  * A use case verb can have N modifiers.
100  */
102  struct list_head list;
103  struct list_head active_list;
104 
105  char *name;
106  char *comment;
107 
108  /* modifier enable and disable sequences */
109  struct list_head enable_list;
110  struct list_head disable_list;
111 
112  /* modifier transition list */
113  struct list_head transition_list;
114 
115  /* list of devices supported or conflicting */
116  struct dev_list dev_list;
117 
118  /* values */
119  struct list_head value_list;
120 };
121 
122 /*
123  * Describes a Use Case Device and it's enable and disable sequences.
124  * A use case verb can have N devices.
125  */
127  struct list_head list;
128  struct list_head active_list;
129 
130  char *name;
131  char *comment;
132 
133  /* device enable and disable sequences */
134  struct list_head enable_list;
135  struct list_head disable_list;
136 
137  /* device transition list */
138  struct list_head transition_list;
139 
140  /* list of devices supported or conflicting */
141  struct dev_list dev_list;
142 
143  /* value list */
144  struct list_head value_list;
145 };
146 
147 /*
148  * Describes a Use Case Verb and it's enable and disable sequences.
149  * A use case verb can have N devices and N modifiers.
150  */
152  struct list_head list;
153 
154  unsigned int active: 1;
155 
156  char *name;
157  char *comment;
158 
159  /* verb enable and disable sequences */
160  struct list_head enable_list;
161  struct list_head disable_list;
162 
163  /* verb transition list */
164  struct list_head transition_list;
165 
166  /* hardware devices that can be used with this use case */
167  struct list_head device_list;
168 
169  /* modifiers that can be used with this use case */
170  struct list_head modifier_list;
171 
172  /* value list */
173  struct list_head value_list;
174 };
175 
176 /*
177  * Manages a sound card and all its use cases.
178  */
180  char *card_name;
181  char *comment;
182 
183  /* use case verb, devices and modifier configs parsed from files */
184  struct list_head verb_list;
185 
186  /* default settings - sequence */
187  struct list_head default_list;
188 
189  /* default settings - value list */
190  struct list_head value_list;
191 
192  /* current status */
193  struct use_case_verb *active_verb;
194  struct list_head active_devices;
195  struct list_head active_modifiers;
196 
197  /* locking */
198  pthread_mutex_t mutex;
199 
200  /* change to list of ctl handles */
201  snd_ctl_t *ctl;
202  char *ctl_dev;
203 };
204 
205 #define uc_error SNDERR
206 
207 #ifdef UC_MGR_DEBUG
208 #define uc_dbg SNDERR
209 #else
210 #define uc_dbg(fmt, arg...) do { } while (0)
211 #endif
212 
213 void uc_mgr_error(const char *fmt, ...);
214 void uc_mgr_stdout(const char *fmt, ...);
215 
216 int uc_mgr_config_load(const char *file, snd_config_t **cfg);
217 int uc_mgr_import_master_config(snd_use_case_mgr_t *uc_mgr);
218 int uc_mgr_scan_master_configs(const char **_list[]);
219 
220 void uc_mgr_free_sequence_element(struct sequence_element *seq);
221 void uc_mgr_free_transition_element(struct transition_sequence *seq);
222 void uc_mgr_free_verb(snd_use_case_mgr_t *uc_mgr);
223 void uc_mgr_free(snd_use_case_mgr_t *uc_mgr);