5183f05f59160811ccdce7c1c6bd16b464826fca
[rrq/lsp-utils.git] / lsp-alsa / libasound-config.lsp
1 ;; == Configuration Interface
2 ; https://alsa-project.org/alsa-doc/alsa-lib/group___config.html
3
4 ;; Type: snd_config_t
5 ; This is an opaque internal struct for configuration nodes. The ALSA
6 ; library uses pointers to this structure as handles to configuration
7 ; nodes. Applications don't access contents directly.
8
9 ;; Type: snd_config_update_t
10 ; This is an opaque internal struct for configuration private update
11 ; objects. The ALSA library uses this structure to save private update
12 ; information.
13
14 ;; Type: snd_config_iterator_t
15 ; This is a pointer to the opaque struct type used for configuration
16 ; compound iterators. The ALSA library uses these as handles for
17 ; configuration compound iterators. Applications don't access contents
18 ; directly.
19
20 ;; Enum: snd_config_type_t
21 (constant
22  'SND_CONFIG_TYPE_INTEGER 0
23  'SND_CONFIG_TYPE_INTEGER64 1
24  'SND_CONFIG_TYPE_REAL 2
25  'SND_CONFIG_TYPE_STRING 3
26  'SND_CONFIG_TYPE_POINTER 4
27  'SND_CONFIG_TYPE_COMPOUND 1024
28  )
29
30 ;; Type snd_devname_t
31 (struct 'snd_devname_t
32         "char*" ; char * name
33         "char*" ; char * comment
34         "void*" ; snd_devname_t * next
35  )
36
37 ;; Variable: snd_config_t *snd_config
38 ; Holds the ALSA configuration tree.
39 (import LIB "snd_config")
40 (define (snd_config@)
41   ((unpack "Lu" (address snd_config)) 0))
42
43 ;; Function: int snd_config_update()
44 ; Updates variable snd_config by rereading the global configuration
45 ; files (if needed).
46 (import LIB "snd_config_update" "int" "void")
47 (when (< (setf E (snd_config_update)))
48   (die 1 "** Cannot load the ALSA configuration tree: " E)
49   )
50
51 ;; Function: int snd_config_expand
52 ;; [in] snd_config_t *node = Handle to the expansion node
53 ;; [in] snd_config_t *root = Handle to the configuration root node
54 ;; [in] const char *args = Arguments string, can be NULL (last must be null)
55 ;; [in] snd_config_t *private_data = Handle to private data node for functions
56 ;; [out] snd_config_t **result
57 ; Expands a configuration node, applying arguments and functions. If
58 ; config has arguments (defined by a child with id @args), this
59 ; function replaces any string node beginning with $ with the
60 ; respective argument value, or the default argument value, or
61 ; nothing. Furthermore, any functions are evaluated (see
62 ; snd_config_evaluate). The resulting copy of config is returned in
63 ; result.
64 ;
65 ; Returns a non-negative value if successful, otherwise a negative
66 ; error code.
67 ;
68 ; The import is wrapped to return the result pointer or (negative)
69 ; error code.
70 (import** LIB "snd_config_expand"
71           "int" ; int snd_config_expand
72           "void*" ; snd_config_t *config
73           "void*" ; snd_config_t *root
74           "void*" ; const char *args
75           "void*" ; snd_config_t *private_data
76           ()      ; snd_config_t **result
77           )
78
79 ;; Function: int snd_config_evaluate
80 ;; [in,out] snd_config_t *node = node in root to evaluate
81 ;; [in] snd_config_t *root = configuration root
82 ;; [in] snd_config_t *private_data
83 ;; [*] snd_config_t **result = must be null!
84 ; Evaluates a configuration node at runtime. This function evaluates
85 ; any functions (@func) in config and replaces those nodes with the
86 ; respective function results. Returns a non-negative value if
87 ; successful, otherwise a negative error code.
88 (import LIB "snd_config_evaluate"
89         "int" ; int snd_config_evaluate
90         "void*" ; snd_config_t *config
91         "void*" ; snd_config_t *root
92         "void*" ;snd_config_t *private_data
93         "void*" ;snd_config_t **result 
94         )
95
96
97 ;; Term: (snd_config_get_id NODE)
98 ; Returns the id string for a configuration node.
99 ;
100 ;; Function: int snd_config_get_id(char** id)
101 ;; [in] const snd_config_t *config - Handle to the configuration node.
102 ;; [out] config, const char **value - node id
103 ; Returns 0 if successful, otherwise a negative error code. The
104 ; returned string is owned by the configuration node; the application
105 ; must not modify or delete it, and the string becomes invalid when
106 ; the node's id changes or when the node is freed. If the node does
107 ; not have an id, *id is set to NULL.
108 ;
109 ; The import is wrapped to return the id string or (negative) error
110 ; code.
111 (import** LIB "snd_config_get_id"
112           "int" ;; int snd_config_get_id
113           "void*"           ; [in] const snd_config_t *config,
114           (get-string-safe) ; [out] const char **id
115           )
116
117 ;; Function: int snd_config_get_integer(snd_config_t *node,int *value)
118 ; Returns the value of an integer ("lu") configuration node.
119 ;
120 ; @param node - the configuration node concerned.
121 ;
122 ; @param value - pointer for the return value.
123
124 ; The import is wrapped to return the integer as such, or (negative)
125 ; error code.
126 (import** LIB "snd_config_get_integer"
127           "int" ; int snd_config_get_integer
128           "void*" ; const snd_config_t *config,
129           () ; long *value
130           )
131
132 ;; Function: int snd_config_get_integer64
133 ; [in] snd_config_t *config
134 ; [out] int64_t *value
135 ;
136 ; Returns the value of a 64-bit-integer ("Lu") configuration node.
137
138 ; The import is wrapped to return the integer as such, or (negative)
139 ; error code.
140 (import** LIB "snd_config_get_integer64"
141           "int" ; int snd_config_get_integer64
142           "void*" ; const snd_config_t *config,
143           () ; long long *value
144           )
145
146 ;; Function: int snd_config_get_real
147 ;; [in] const snd_config_t *node
148 ;; [out] double *value
149 ;
150 ; Returns the value of a real-number configuration node.
151 ;
152 ; The import is wrapped to return the double as such, or (negative)
153 ; error code.
154 (import** LIB "snd_config_get_real"
155           "int" ; int snd_config_get_real
156           "void*" ; const snd_config_t *node,
157           ("lf") ; double *value
158           )
159
160 ; Returns the value of a real or integer configuration node as double. More...
161 ;; API function to return the double as such, or (negative) error code.
162 (import** LIB "snd_config_get_ireal"
163           "int" ; int snd_config_get_real
164           "void*" ; const snd_config_t *config,
165           ("lf") ; double *value)
166           )
167
168 ; Returns the value of a string configuration node. The returned
169 ; string is owned by the configuration node; the application must not
170 ; modify or delete it, and the string becomes invalid when the node's
171 ; value changes or when the node is freed.
172 ;
173 ;; API function to return the string (copied), or (negative) error
174 ;; code.
175 (import** LIB "snd_config_get_string"
176           "int" ; int snd_config_get_string (
177           "void*" ; const snd_config_t *config,
178           (get-string) ; const char **value)
179           )
180
181 ;; int  snd_config_get_ascii (const snd_config_t *config, char **value)
182 ; Returns the value of a configuration node as a string. This function
183 ; dynamically allocates the returned string. The application is
184 ; responsible for deleting it with free() when it is no longer used.
185 ; For a string node with NULL value, the returned string is NULL.
186
187
188 ; Returns the value of a pointer configuration node.
189 ;
190 ;; API function to return the pointer (value), or (negative) error.
191 (import** LIB "snd_config_get_pointer"
192           "int" ; int snd_config_get_pointer (
193           "void*" ; const snd_config_t *config,
194           () ; const void **value)
195         )
196
197 ; Returns the type of a configuration node.
198 (import LIB "snd_config_get_type"
199         "unsigned int" ; snd_config_type_t snd_config_get_type
200         "void*" ; const snd_config_t *config
201         )
202
203 ; Returns count of items in array, zero when the compound is not an
204 ; array, otherwise a negative error code.
205 (import LIB "snd_config_is_array"
206         "int" ; int snd_config_is_array
207         "void*" ; const snd_config_t *config
208         )
209
210 ;; ------- iterator functions --------
211
212 ; Returns an iterator pointing to a node's first child. More...
213 (import LIB "snd_config_iterator_first"
214         "void*" ;; snd_config_iterator_t snd_config_iterator_first
215         "void*" ; const snd_config_t *node
216         )
217
218 ; Returns an iterator pointing to the next sibling. More...
219 (import LIB "snd_config_iterator_next"
220         "void*" ; snd_config_iterator_t snd_config_iterator_next
221         "void*" ; const snd_config_iterator_t iterator
222         )
223
224 ; Returns an iterator that ends a node's children list.
225 ;; Parameters
226 ; [in]  config  Handle to a configuration node.
227 ;;
228 ; Returns n iterator that indicates the end of config's children list.
229 ; config must be a compound node. The return value can be understood
230 ; as pointing past the last child of config.
231 (import LIB "snd_config_iterator_end"
232         "void*" ; snd_config_iterator_t snd_config_iterator_end
233         "void*" ; const snd_config_t *config
234         )
235
236 ; Returns the configuration node handle pointed to by an iterator.
237 (import LIB "snd_config_iterator_entry"
238         "void*" ; snd_config_t * snd_config_iterator_entry
239         "void*" ; const snd_config_iterator_t iterator
240         )
241
242 ;;======================================================================
243 ; Extended API
244
245 ;; Term: (iterate NODE)
246 ; Make a list of a compound node's children by iterating over them.
247 (define (iterate NODE)
248   (let ((CUR (snd_config_iterator_first NODE))
249         (END (snd_config_iterator_end NODE))
250         (RES '()))
251     (while (!= CUR END)
252       (push (traverse (snd_config_iterator_entry CUR)) RES -1)
253       (setf CUR (snd_config_iterator_next CUR)))
254     (if (snd_config_is_array NODE)
255         (map list (sequence 0 (- (length RES) 1)) RES)
256       RES)))
257
258 ;; Term: (traverse NODE)
259 ; Return the pair (ID value) for a node. The value of a compound node
260 ; is the list of its child nodes.
261 (define (traverse NODE)
262   (let ((TYPE (snd_config_get_type NODE))
263         (ID (snd_config_get_id NODE)))
264     (list ID
265           (case TYPE
266             (0 (snd_config_get_integer NODE))
267             (1 (snd_config_get_integer64 NODE))
268             (2 (snd_config_get_real NODE))
269             (3 (snd_config_get_string NODE))
270             (4 (snd_config_get_integer NODE))
271             (5 (sym (string ">" (snd_config_get_pointer NODE))))
272             (1024 (iterate NODE))
273             (true (list 'unknown NODE TYPE))))))
274
275
276
277 "libasound-config.lsp"