1 /* Copyright 2016 The Chromium OS Authors. All rights reserved.
2  * Use of this source code is governed by a BSD-style license that can be
3  * found in the LICENSE file.
4  */
5 
6 #ifndef _CRAS_ALSA_MIXER_NAME_H
7 #define _CRAS_ALSA_MIXER_NAME_H
8 
9 #include "cras_types.h"
10 
11 #ifdef __cplusplus
12 extern "C" {
13 #endif
14 
15 /* Type of mixer control. */
16 typedef enum mixer_name_type {
17 	MIXER_NAME_UNDEFINED,
18 	MIXER_NAME_MAIN_VOLUME,
19 	MIXER_NAME_VOLUME,
20 } mixer_name_type;
21 
22 /* Represents a list of mixer names found in ALSA. */
23 struct mixer_name {
24 	const char* name;
25 	enum CRAS_STREAM_DIRECTION dir;
26 	mixer_name_type type;
27 	struct mixer_name *prev, *next;
28 };
29 
30 /* Add a name to the list.
31  *
32  * Args:
33  *    names - A list of controls (may be NULL).
34  *    name - The name to add.
35  *    dir - The direction for this control.
36  *    type - The type control being added.
37  *
38  * Returns:
39  *    Returns the new head of the list (which changes only
40  *    when names is NULL).
41  */
42 struct mixer_name *mixer_name_add(struct mixer_name *names,
43 				  const char *name,
44 				  enum CRAS_STREAM_DIRECTION dir,
45 				  mixer_name_type type);
46 
47 /* Add an array of name to the list.
48  *
49  * Args:
50  *    names - A list of controls (may be NULL).
51  *    name_array - The names to add.
52  *    name_array_size - The size of name_array.
53  *    dir - The direction for these controls.
54  *    type - The type controls being added.
55  *
56  * Returns:
57  *    Returns the new head of the list (which changes only
58  *    when names is NULL).
59  */
60 struct mixer_name *mixer_name_add_array(struct mixer_name *names,
61 					const char * const *name_array,
62 					size_t name_array_size,
63 					enum CRAS_STREAM_DIRECTION dir,
64 					mixer_name_type type);
65 
66 /* Frees a list of names.
67  *
68  * Args:
69  *    names - A list of names.
70  */
71 void mixer_name_free(struct mixer_name *names);
72 
73 /* Find the mixer_name for the given direction, name, and type.
74  *
75  * Args:
76  *    names - A list of names (may be NULL).
77  *    name - The name to find, or NULL to match by type.
78 
79  *    dir - The direction to match.
80  *    type - The type to match, or MIXER_NAME_UNDEFINED to
81  *           match by name only.
82  *
83  * Returns:
84  *    Returns a pointer to the matching struct mixer_name or NULL if
85  *    not found.
86  */
87 struct mixer_name *mixer_name_find(struct mixer_name *names,
88 				   const char *name,
89 				   enum CRAS_STREAM_DIRECTION dir,
90 				   mixer_name_type type);
91 
92 /* Dump the list of mixer names to DEBUG logs.
93  *
94  * Args:
95  *    names - A list of names to dump.
96  *    message - A message to print beforehand.
97  */
98 void mixer_name_dump(struct mixer_name *names, const char *message);
99 
100 #ifdef __cplusplus
101 }
102 #endif
103 
104 #endif /* _CRAS_ALSA_MIXER_NAME_H */
105