Skip to content

Commit 19b5097

Browse files
InterLinked1Friendly Automation
authored andcommitted
func_volume: Add read capability to function.
Up until now, the VOLUME function has been write only, so that TX/RX values can be set but not read afterwards. Now, previously set TX/RX values can be read later. ASTERISK-29439 Change-Id: Ia23e92fa2e755c36e9c8e69f2940d2703ccccb5f
1 parent 2193cf1 commit 19b5097

File tree

2 files changed

+51
-1
lines changed

2 files changed

+51
-1
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Subject: func_volume now can be read
2+
3+
The VOLUME function can now also be used
4+
to read existing values previously set.

funcs/func_volume.c

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
/*** DOCUMENTATION
4343
<function name="VOLUME" language="en_US">
4444
<synopsis>
45-
Set the TX or RX volume of a channel.
45+
Set or get the TX or RX volume of a channel.
4646
</synopsis>
4747
<syntax>
4848
<parameter name="direction" required="true">
@@ -221,9 +221,55 @@ static int volume_write(struct ast_channel *chan, const char *cmd, char *data, c
221221
return 0;
222222
}
223223

224+
static int volume_read(struct ast_channel *chan, const char *cmd, char *data, char *buffer, size_t buflen)
225+
{
226+
struct ast_datastore *datastore = NULL;
227+
struct volume_information *vi = NULL;
228+
229+
/* Separate options from argument */
230+
231+
AST_DECLARE_APP_ARGS(args,
232+
AST_APP_ARG(direction);
233+
AST_APP_ARG(options);
234+
);
235+
236+
if (!chan) {
237+
ast_log(LOG_WARNING, "No channel was provided to %s function.\n", cmd);
238+
return -1;
239+
}
240+
241+
AST_STANDARD_APP_ARGS(args, data);
242+
243+
ast_channel_lock(chan);
244+
if (!(datastore = ast_channel_datastore_find(chan, &volume_datastore, NULL))) {
245+
ast_channel_unlock(chan);
246+
return -1; /* no active audiohook, nothing to read */
247+
} else {
248+
ast_channel_unlock(chan);
249+
vi = datastore->data;
250+
}
251+
252+
/* Obtain current gain using volume information structure */
253+
if (ast_strlen_zero(args.direction)) {
254+
ast_log(LOG_ERROR, "Direction must be specified for VOLUME function\n");
255+
return -1;
256+
}
257+
258+
if (!strcasecmp(args.direction, "tx")) {
259+
snprintf(buffer, buflen, "%f", vi->tx_gain);
260+
} else if (!strcasecmp(args.direction, "rx")) {
261+
snprintf(buffer, buflen, "%f", vi->rx_gain);
262+
} else {
263+
ast_log(LOG_ERROR, "Direction must be either RX or TX\n");
264+
}
265+
266+
return 0;
267+
}
268+
224269
static struct ast_custom_function volume_function = {
225270
.name = "VOLUME",
226271
.write = volume_write,
272+
.read = volume_read,
227273
};
228274

229275
static int unload_module(void)

0 commit comments

Comments
 (0)