1 /*
2 * Control Interface - local header file
3 * Copyright (c) 2000 by Jaroslav Kysela <perex@perex.cz>
4 *
5 *
6 * This library is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as
8 * published by the Free Software Foundation; either version 2.1 of
9 * the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 *
20 */
21
22 #include "local.h"
23 #include <sound/tlv.h>
24
25 typedef struct _snd_ctl_ops {
26 int (*close)(snd_ctl_t *handle);
27 int (*nonblock)(snd_ctl_t *handle, int nonblock);
28 int (*async)(snd_ctl_t *handle, int sig, pid_t pid);
29 int (*subscribe_events)(snd_ctl_t *handle, int subscribe);
30 int (*card_info)(snd_ctl_t *handle, snd_ctl_card_info_t *info);
31 int (*element_list)(snd_ctl_t *handle, snd_ctl_elem_list_t *list);
32 int (*element_info)(snd_ctl_t *handle, snd_ctl_elem_info_t *info);
33 int (*element_add)(snd_ctl_t *handle, snd_ctl_elem_info_t *info);
34 int (*element_replace)(snd_ctl_t *handle, snd_ctl_elem_info_t *info);
35 int (*element_remove)(snd_ctl_t *handle, snd_ctl_elem_id_t *id);
36 int (*element_read)(snd_ctl_t *handle, snd_ctl_elem_value_t *control);
37 int (*element_write)(snd_ctl_t *handle, snd_ctl_elem_value_t *control);
38 int (*element_lock)(snd_ctl_t *handle, snd_ctl_elem_id_t *lock);
39 int (*element_unlock)(snd_ctl_t *handle, snd_ctl_elem_id_t *unlock);
40 int (*element_tlv)(snd_ctl_t *handle, int op_flag, unsigned int numid,
41 unsigned int *tlv, unsigned int tlv_size);
42 int (*hwdep_next_device)(snd_ctl_t *handle, int *device);
43 int (*hwdep_info)(snd_ctl_t *handle, snd_hwdep_info_t * info);
44 int (*pcm_next_device)(snd_ctl_t *handle, int *device);
45 int (*pcm_info)(snd_ctl_t *handle, snd_pcm_info_t * info);
46 int (*pcm_prefer_subdevice)(snd_ctl_t *handle, int subdev);
47 int (*rawmidi_next_device)(snd_ctl_t *handle, int *device);
48 int (*rawmidi_info)(snd_ctl_t *handle, snd_rawmidi_info_t * info);
49 int (*rawmidi_prefer_subdevice)(snd_ctl_t *handle, int subdev);
50 int (*set_power_state)(snd_ctl_t *handle, unsigned int state);
51 int (*get_power_state)(snd_ctl_t *handle, unsigned int *state);
52 int (*read)(snd_ctl_t *handle, snd_ctl_event_t *event);
53 int (*poll_descriptors_count)(snd_ctl_t *handle);
54 int (*poll_descriptors)(snd_ctl_t *handle, struct pollfd *pfds, unsigned int space);
55 int (*poll_revents)(snd_ctl_t *handle, struct pollfd *pfds, unsigned int nfds, unsigned short *revents);
56 } snd_ctl_ops_t;
57
58
59 struct _snd_ctl {
60 void *open_func;
61 char *name;
62 snd_ctl_type_t type;
63 const snd_ctl_ops_t *ops;
64 void *private_data;
65 int nonblock;
66 int poll_fd;
67 struct list_head async_handlers;
68 };
69
70 struct _snd_hctl_elem {
71 snd_ctl_elem_id_t id; /* must be always on top */
72 struct list_head list; /* links for list of all helems */
73 int compare_weight; /* compare weight (reversed) */
74 /* event callback */
75 snd_hctl_elem_callback_t callback;
76 void *callback_private;
77 /* links */
78 snd_hctl_t *hctl; /* associated handle */
79 };
80
81 struct _snd_hctl {
82 snd_ctl_t *ctl;
83 struct list_head elems; /* list of all controls */
84 unsigned int alloc;
85 unsigned int count;
86 snd_hctl_elem_t **pelems;
87 snd_hctl_compare_t compare;
88 snd_hctl_callback_t callback;
89 void *callback_private;
90 };
91
92
93 /* make local functions really local */
94 #define snd_ctl_new snd1_ctl_new
95
96 int snd_ctl_new(snd_ctl_t **ctlp, snd_ctl_type_t type, const char *name);
97 int _snd_ctl_poll_descriptor(snd_ctl_t *ctl);
98 #define _snd_ctl_async_descriptor _snd_ctl_poll_descriptor
99 int snd_ctl_hw_open(snd_ctl_t **handle, const char *name, int card, int mode);
100 int snd_ctl_shm_open(snd_ctl_t **handlep, const char *name, const char *sockname, const char *sname, int mode);
101 int snd_ctl_async(snd_ctl_t *ctl, int sig, pid_t pid);
102
103 #define CTLINABORT(x) ((x)->nonblock == 2)
104
105 #ifdef INTERNAL
106 int INTERNAL(snd_ctl_elem_info_get_dimensions)(const snd_ctl_elem_info_t *obj);
107 int INTERNAL(snd_ctl_elem_info_get_dimension)(const snd_ctl_elem_info_t *obj, unsigned int idx);
108 #endif /* INTERNAL */
109
110 int _snd_ctl_open_named_child(snd_ctl_t **pctl, const char *name,
111 snd_config_t *root, snd_config_t *conf,
112 int mode, snd_config_t *parent_conf);
113 static inline int
_snd_ctl_open_child(snd_ctl_t ** pctl,snd_config_t * root,snd_config_t * conf,int mode,snd_config_t * parent_conf)114 _snd_ctl_open_child(snd_ctl_t **pctl, snd_config_t *root,
115 snd_config_t *conf, int mode, snd_config_t *parent_conf)
116 {
117 return _snd_ctl_open_named_child(pctl, NULL, root, conf, mode, parent_conf);
118 }
119
120 int __snd_ctl_add_elem_set(snd_ctl_t *ctl, snd_ctl_elem_info_t *info,
121 unsigned int element_count,
122 unsigned int member_count);
123
124 int __snd_ctl_ascii_elem_id_parse(snd_ctl_elem_id_t *dst,
125 const char *str,
126 const char **ret_ptr);
127