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