ALSA project - the C library reference
|
00001 /* 00002 * This library is free software; you can redistribute it and/or 00003 * modify it under the terms of the GNU Lesser General Public 00004 * License as published by the Free Software Foundation; either 00005 * version 2 of the License, or (at your option) any later version. 00006 * 00007 * This library is distributed in the hope that it will be useful, 00008 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00009 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00010 * Lesser General Public License for more details. 00011 * 00012 * You should have received a copy of the GNU Lesser General Public 00013 * License along with this library; if not, write to the Free Software 00014 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00015 * 00016 * Support for the verb/device/modifier core logic and API, 00017 * command line tool and file parser was kindly sponsored by 00018 * Texas Instruments Inc. 00019 * Support for multiple active modifiers and devices, 00020 * transition sequences, multiple client access and user defined use 00021 * cases was kindly sponsored by Wolfson Microelectronics PLC. 00022 * 00023 * Copyright (C) 2008-2010 SlimLogic Ltd 00024 * Copyright (C) 2010 Wolfson Microelectronics PLC 00025 * Copyright (C) 2010 Texas Instruments Inc. 00026 * Copyright (C) 2010 Red Hat Inc. 00027 * Authors: Liam Girdwood <lrg@slimlogic.co.uk> 00028 * Stefan Schmidt <stefan@slimlogic.co.uk> 00029 * Justin Xu <justinx@slimlogic.co.uk> 00030 * Jaroslav Kysela <perex@perex.cz> 00031 */ 00032 00033 00034 00035 #if 0 00036 #define UC_MGR_DEBUG 00037 #endif 00038 00039 #include <pthread.h> 00040 #include "local.h" 00041 #include "use-case.h" 00042 00043 #define MAX_FILE 256 00044 #define ALSA_USE_CASE_DIR ALSA_CONFIG_DIR "/ucm" 00045 00046 #define SEQUENCE_ELEMENT_TYPE_CDEV 1 00047 #define SEQUENCE_ELEMENT_TYPE_CSET 2 00048 #define SEQUENCE_ELEMENT_TYPE_SLEEP 3 00049 #define SEQUENCE_ELEMENT_TYPE_EXEC 4 00050 00051 struct ucm_value { 00052 struct list_head list; 00053 char *name; 00054 char *data; 00055 }; 00056 00057 struct sequence_element { 00058 struct list_head list; 00059 unsigned int type; 00060 union { 00061 long sleep; /* Sleep time in microseconds if sleep element, else 0 */ 00062 char *cdev; 00063 char *cset; 00064 char *exec; 00065 } data; 00066 }; 00067 00068 /* 00069 * Transition sequences. i.e. transition between one verb, device, mod to another 00070 */ 00071 struct transition_sequence { 00072 struct list_head list; 00073 char *name; 00074 struct list_head transition_list; 00075 }; 00076 00077 /* 00078 * Modifier Supported Devices. 00079 */ 00080 enum dev_list_type { 00081 DEVLIST_NONE, 00082 DEVLIST_SUPPORTED, 00083 DEVLIST_CONFLICTING 00084 }; 00085 00086 struct dev_list_node { 00087 struct list_head list; 00088 char *name; 00089 }; 00090 00091 struct dev_list { 00092 enum dev_list_type type; 00093 struct list_head list; 00094 }; 00095 00096 /* 00097 * Describes a Use Case Modifier and it's enable and disable sequences. 00098 * A use case verb can have N modifiers. 00099 */ 00100 struct use_case_modifier { 00101 struct list_head list; 00102 struct list_head active_list; 00103 00104 char *name; 00105 char *comment; 00106 00107 /* modifier enable and disable sequences */ 00108 struct list_head enable_list; 00109 struct list_head disable_list; 00110 00111 /* modifier transition list */ 00112 struct list_head transition_list; 00113 00114 /* list of devices supported or conflicting */ 00115 struct dev_list dev_list; 00116 00117 /* values */ 00118 struct list_head value_list; 00119 }; 00120 00121 /* 00122 * Describes a Use Case Device and it's enable and disable sequences. 00123 * A use case verb can have N devices. 00124 */ 00125 struct use_case_device { 00126 struct list_head list; 00127 struct list_head active_list; 00128 00129 char *name; 00130 char *comment; 00131 00132 /* device enable and disable sequences */ 00133 struct list_head enable_list; 00134 struct list_head disable_list; 00135 00136 /* device transition list */ 00137 struct list_head transition_list; 00138 00139 /* list of devices supported or conflicting */ 00140 struct dev_list dev_list; 00141 00142 /* value list */ 00143 struct list_head value_list; 00144 }; 00145 00146 /* 00147 * Describes a Use Case Verb and it's enable and disable sequences. 00148 * A use case verb can have N devices and N modifiers. 00149 */ 00150 struct use_case_verb { 00151 struct list_head list; 00152 00153 unsigned int active: 1; 00154 00155 char *name; 00156 char *comment; 00157 00158 /* verb enable and disable sequences */ 00159 struct list_head enable_list; 00160 struct list_head disable_list; 00161 00162 /* verb transition list */ 00163 struct list_head transition_list; 00164 00165 /* hardware devices that can be used with this use case */ 00166 struct list_head device_list; 00167 00168 /* modifiers that can be used with this use case */ 00169 struct list_head modifier_list; 00170 00171 /* value list */ 00172 struct list_head value_list; 00173 }; 00174 00175 /* 00176 * Manages a sound card and all its use cases. 00177 */ 00178 struct snd_use_case_mgr { 00179 char *card_name; 00180 char *comment; 00181 00182 /* use case verb, devices and modifier configs parsed from files */ 00183 struct list_head verb_list; 00184 00185 /* default settings - sequence */ 00186 struct list_head default_list; 00187 00188 /* default settings - value list */ 00189 struct list_head value_list; 00190 00191 /* current status */ 00192 struct use_case_verb *active_verb; 00193 struct list_head active_devices; 00194 struct list_head active_modifiers; 00195 00196 /* locking */ 00197 pthread_mutex_t mutex; 00198 00199 /* change to list of ctl handles */ 00200 snd_ctl_t *ctl; 00201 char *ctl_dev; 00202 }; 00203 00204 #define uc_error SNDERR 00205 00206 #ifdef UC_MGR_DEBUG 00207 #define uc_dbg SNDERR 00208 #else 00209 #define uc_dbg(fmt, arg...) do { } while (0) 00210 #endif 00211 00212 void uc_mgr_error(const char *fmt, ...); 00213 void uc_mgr_stdout(const char *fmt, ...); 00214 00215 int uc_mgr_config_load(const char *file, snd_config_t **cfg); 00216 int uc_mgr_import_master_config(snd_use_case_mgr_t *uc_mgr); 00217 int uc_mgr_scan_master_configs(const char **_list[]); 00218 00219 void uc_mgr_free_sequence_element(struct sequence_element *seq); 00220 void uc_mgr_free_transition_element(struct transition_sequence *seq); 00221 void uc_mgr_free_verb(snd_use_case_mgr_t *uc_mgr); 00222 void uc_mgr_free(snd_use_case_mgr_t *uc_mgr);