source: mainline/uspace/lib/drv/generic/remote_audio_mixer.c@ a46e56b

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since a46e56b was a46e56b, checked in by Jakub Jermar <jakub@…>, 7 years ago

Prefer handle over ID in naming handle variables

  • Property mode set to 100644
File size: 9.2 KB
RevLine 
[53a7fda]1/*
2 * Copyright (c) 2011 Jan Vesely
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** @addtogroup libdrv
30 * @{
31 */
32/** @file
33 */
34
35#include <async.h>
36#include <errno.h>
37#include <assert.h>
38#include <str.h>
[9be30cdf]39#include <macros.h>
[53a7fda]40
41#include "audio_mixer_iface.h"
42#include "ddf/driver.h"
43
44typedef enum {
45 /** Asks for basic mixer info: Mixer name and number of controllable
46 * items.
47 * Answer:
48 * - ENOTSUP - call not supported
49 * - EOK - call successful, info is valid
50 * Answer arguments:
51 * - Mixer name
52 * - Number of controllable items
53 */
54 IPC_M_AUDIO_MIXER_GET_INFO,
55
56 /** Asks for item mixer info: Item name and number of controllable
57 * channels.
58 * Answer:
59 * - ENOTSUP - call not supported
60 * - ENOENT - no such item
61 * - EOK - call successful, info is valid
62 * Answer arguments:
63 * - Item name
64 * - Number of controllable channels
65 */
66 IPC_M_AUDIO_MIXER_GET_ITEM_INFO,
67
[1912b45]68 /** Set new control item setting
[53a7fda]69 * Answer:
70 * - ENOTSUP - call not supported
[1912b45]71 * - ENOENT - no such control item
[53a7fda]72 * - EOK - call successful, info is valid
73 */
[1912b45]74 IPC_M_AUDIO_MIXER_SET_ITEM_LEVEL,
[53a7fda]75
[1912b45]76 /** Get control item setting
[53a7fda]77 * Answer:
78 * - ENOTSUP - call not supported
[1912b45]79 * - ENOENT - no such control item
[53a7fda]80 * - EOK - call successful, info is valid
81 */
[1912b45]82 IPC_M_AUDIO_MIXER_GET_ITEM_LEVEL,
[53a7fda]83} audio_mixer_iface_funcs_t;
84
85/*
86 * CLIENT SIDE
87 */
[8a7d78cc]88
89/**
90 * Query audio mixer for basic info (name and items count).
91 * @param[in] exch IPC exchange connected to the device
92 * @param[out] name Audio mixer string identifier
93 * @param[out] items Number of items controlled by the mixer.
94 * @return Error code.
95 */
[33b8d024]96errno_t audio_mixer_get_info(async_exch_t *exch, char **name, unsigned *items)
[53a7fda]97{
98 if (!exch)
99 return EINVAL;
100 sysarg_t name_size, itemc;
[b7fd2a0]101 const errno_t ret = async_req_1_2(exch, DEV_IFACE_ID(AUDIO_MIXER_IFACE),
[53a7fda]102 IPC_M_AUDIO_MIXER_GET_INFO, &name_size, &itemc);
103 if (ret == EOK && name) {
104 char *name_place = calloc(1, name_size);
105 if (!name_place) {
106 /* Make the other side fail
107 * as it waits for read request */
108 async_data_read_start(exch, (void*)-1, 0);
109 return ENOMEM;
110 }
[b7fd2a0]111 const errno_t ret =
[53a7fda]112 async_data_read_start(exch, name_place, name_size);
113 if (ret != EOK) {
114 free(name_place);
115 return ret;
116 }
117 *name = name_place;
118 }
119 if (ret == EOK && items)
120 *items = itemc;
121 return ret;
122}
[4bbfb93]123
[8a7d78cc]124/**
125 * Query audio mixer for item specific info (name and channels count).
126 * @param[in] exch IPC exchange connected to the device
127 * @param[in] item The control item
128 * @param[out] name Control item string identifier.
129 * @param[out] channles Number of channels associated with this control item.
130 * @return Error code.
131 */
[b7fd2a0]132errno_t audio_mixer_get_item_info(async_exch_t *exch, unsigned item,
[33b8d024]133 char **name, unsigned *levels)
[53a7fda]134{
135 if (!exch)
136 return EINVAL;
[1912b45]137 sysarg_t name_size, lvls;
[b7fd2a0]138 const errno_t ret = async_req_2_2(exch, DEV_IFACE_ID(AUDIO_MIXER_IFACE),
[1912b45]139 IPC_M_AUDIO_MIXER_GET_ITEM_INFO, item, &name_size, &lvls);
[53a7fda]140 if (ret == EOK && name) {
141 char *name_place = calloc(1, name_size);
142 if (!name_place) {
143 /* Make the other side fail
144 * as it waits for read request */
145 async_data_read_start(exch, (void*)-1, 0);
146 return ENOMEM;
147 }
[b7fd2a0]148 const errno_t ret =
[53a7fda]149 async_data_read_start(exch, name_place, name_size);
150 if (ret != EOK) {
151 free(name_place);
152 return ret;
153 }
154 *name = name_place;
155 }
[1912b45]156 if (ret == EOK && levels)
157 *levels = lvls;
[53a7fda]158 return ret;
159}
[4bbfb93]160
[8a7d78cc]161/**
[1912b45]162 * Set control item to a new level.
[8a7d78cc]163 * @param[in] exch IPC exchange connected to the device.
164 * @param[in] item The control item controlling the channel.
[1912b45]165 * @param[in] level The new value.
[8a7d78cc]166 * @return Error code.
167 */
[b7fd2a0]168errno_t audio_mixer_set_item_level(async_exch_t *exch, unsigned item,
[1912b45]169 unsigned level)
[53a7fda]170{
171 if (!exch)
172 return EINVAL;
[1912b45]173 return async_req_3_0(exch, DEV_IFACE_ID(AUDIO_MIXER_IFACE),
174 IPC_M_AUDIO_MIXER_SET_ITEM_LEVEL, item, level);
[53a7fda]175}
[4bbfb93]176
[8a7d78cc]177/**
[1912b45]178 * Get current level of a control item.
[8a7d78cc]179 * @param[in] exch IPC exchange connected to the device.
180 * @param[in] item The control item controlling the channel.
181 * @param[in] channel The channel index.
[1912b45]182 * @param[out] level Currently set value.
[8a7d78cc]183 * @return Error code.
184 */
[b7fd2a0]185errno_t audio_mixer_get_item_level(async_exch_t *exch, unsigned item,
[1912b45]186 unsigned *level)
[53a7fda]187{
188 if (!exch)
189 return EINVAL;
[1912b45]190 sysarg_t current;
[b7fd2a0]191 const errno_t ret = async_req_2_1(exch, DEV_IFACE_ID(AUDIO_MIXER_IFACE),
[1912b45]192 IPC_M_AUDIO_MIXER_GET_ITEM_LEVEL, item, &current);
193 if (ret == EOK && level)
194 *level = current;
[53a7fda]195 return ret;
196}
197
198/*
199 * SERVER SIDE
200 */
[3be9d10]201static void remote_audio_mixer_get_info(ddf_fun_t *, void *, cap_call_handle_t, ipc_call_t *);
202static void remote_audio_mixer_get_item_info(ddf_fun_t *, void *, cap_call_handle_t, ipc_call_t *);
203static void remote_audio_mixer_get_item_level(ddf_fun_t *, void *, cap_call_handle_t, ipc_call_t *);
204static void remote_audio_mixer_set_item_level(ddf_fun_t *, void *, cap_call_handle_t, ipc_call_t *);
[53a7fda]205
206/** Remote audio mixer interface operations. */
[9be30cdf]207static const remote_iface_func_ptr_t remote_audio_mixer_iface_ops[] = {
[53a7fda]208 [IPC_M_AUDIO_MIXER_GET_INFO] = remote_audio_mixer_get_info,
209 [IPC_M_AUDIO_MIXER_GET_ITEM_INFO] = remote_audio_mixer_get_item_info,
[1912b45]210 [IPC_M_AUDIO_MIXER_GET_ITEM_LEVEL] = remote_audio_mixer_get_item_level,
211 [IPC_M_AUDIO_MIXER_SET_ITEM_LEVEL] = remote_audio_mixer_set_item_level,
[53a7fda]212};
213
214/** Remote audio mixer interface structure. */
[7f80313]215const remote_iface_t remote_audio_mixer_iface = {
[9be30cdf]216 .method_count = ARRAY_SIZE(remote_audio_mixer_iface_ops),
[53a7fda]217 .methods = remote_audio_mixer_iface_ops
218};
[4bbfb93]219
[53a7fda]220void remote_audio_mixer_get_info(
[a46e56b]221 ddf_fun_t *fun, void *iface, cap_call_handle_t chandle, ipc_call_t *call)
[53a7fda]222{
223 audio_mixer_iface_t *mixer_iface = iface;
224
225 if (!mixer_iface->get_info) {
[a46e56b]226 async_answer_0(chandle, ENOTSUP);
[53a7fda]227 return;
228 }
229 const char *name = NULL;
230 unsigned items = 0;
[b7fd2a0]231 const errno_t ret = mixer_iface->get_info(fun, &name, &items);
[53a7fda]232 const size_t name_size = name ? str_size(name) + 1 : 0;
[a46e56b]233 async_answer_2(chandle, ret, name_size, items);
[53a7fda]234 /* Send the name. */
235 if (ret == EOK && name_size > 0) {
236 size_t size;
[3be9d10]237 cap_call_handle_t name_id;
[53a7fda]238 if (!async_data_read_receive(&name_id, &size)) {
239 async_answer_0(name_id, EPARTY);
240 return;
241 }
242 if (size != name_size) {
243 async_answer_0(name_id, ELIMIT);
244 return;
245 }
246 async_data_read_finalize(name_id, name, name_size);
247 }
248}
[4bbfb93]249
[53a7fda]250void remote_audio_mixer_get_item_info(
[a46e56b]251 ddf_fun_t *fun, void *iface, cap_call_handle_t chandle, ipc_call_t *call)
[53a7fda]252{
253 audio_mixer_iface_t *mixer_iface = iface;
254
255 if (!mixer_iface->get_item_info) {
[a46e56b]256 async_answer_0(chandle, ENOTSUP);
[53a7fda]257 return;
258 }
259
260 const unsigned item = DEV_IPC_GET_ARG1(*call);
261 const char *name = NULL;
[1912b45]262 unsigned values = 0;
[b7fd2a0]263 const errno_t ret = mixer_iface->get_item_info(fun, item, &name, &values);
[53a7fda]264 const size_t name_size = name ? str_size(name) + 1 : 0;
[a46e56b]265 async_answer_2(chandle, ret, name_size, values);
[53a7fda]266 /* Send the name. */
267 if (ret == EOK && name_size > 0) {
268 size_t size;
[3be9d10]269 cap_call_handle_t name_id;
[53a7fda]270 if (!async_data_read_receive(&name_id, &size)) {
271 async_answer_0(name_id, EPARTY);
272 return;
273 }
274 if (size != name_size) {
275 async_answer_0(name_id, ELIMIT);
276 return;
277 }
278 async_data_read_finalize(name_id, name, name_size);
279 }
280}
[4bbfb93]281
[1912b45]282void remote_audio_mixer_set_item_level(
[a46e56b]283 ddf_fun_t *fun, void *iface, cap_call_handle_t chandle, ipc_call_t *call)
[53a7fda]284{
285 audio_mixer_iface_t *mixer_iface = iface;
286
[1912b45]287 if (!mixer_iface->set_item_level) {
[a46e56b]288 async_answer_0(chandle, ENOTSUP);
[53a7fda]289 return;
290 }
291 const unsigned item = DEV_IPC_GET_ARG1(*call);
[1912b45]292 const unsigned value = DEV_IPC_GET_ARG2(*call);
[b7fd2a0]293 const errno_t ret = mixer_iface->set_item_level(fun, item, value);
[a46e56b]294 async_answer_0(chandle, ret);
[53a7fda]295}
[4bbfb93]296
[1912b45]297void remote_audio_mixer_get_item_level(
[a46e56b]298 ddf_fun_t *fun, void *iface, cap_call_handle_t chandle, ipc_call_t *call)
[53a7fda]299{
300 audio_mixer_iface_t *mixer_iface = iface;
301
[1912b45]302 if (!mixer_iface->get_item_level) {
[a46e56b]303 async_answer_0(chandle, ENOTSUP);
[53a7fda]304 return;
305 }
306 const unsigned item = DEV_IPC_GET_ARG1(*call);
[1912b45]307 unsigned current = 0;
[b7fd2a0]308 const errno_t ret =
[1912b45]309 mixer_iface->get_item_level(fun, item, &current);
[a46e56b]310 async_answer_1(chandle, ret, current);
[53a7fda]311}
312
313/**
314 * @}
315 */
Note: See TracBrowser for help on using the repository browser.