[Asterisk-code-review] func_volume: Add read capability to function. (asterisk[master])

N A asteriskteam at digium.com
Thu May 20 08:21:04 CDT 2021


N A has uploaded this change for review. ( https://gerrit.asterisk.org/c/asterisk/+/15898 )


Change subject: func_volume: Add read capability to function.
......................................................................

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
---
A doc/CHANGES-staging/func_volume_read.txt
M funcs/func_volume.c
2 files changed, 51 insertions(+), 1 deletion(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/98/15898/1

diff --git a/doc/CHANGES-staging/func_volume_read.txt b/doc/CHANGES-staging/func_volume_read.txt
new file mode 100644
index 0000000..8ea27cd
--- /dev/null
+++ b/doc/CHANGES-staging/func_volume_read.txt
@@ -0,0 +1,4 @@
+Subject: func_volume now can be read
+
+The VOLUME function can now also be used
+to read existing values previously set.
diff --git a/funcs/func_volume.c b/funcs/func_volume.c
index 8587479..a20bb76 100644
--- a/funcs/func_volume.c
+++ b/funcs/func_volume.c
@@ -42,7 +42,7 @@
 /*** DOCUMENTATION
 	<function name="VOLUME" language="en_US">
 		<synopsis>
-			Set the TX or RX volume of a channel.
+			Set or get the TX or RX volume of a channel.
 		</synopsis>
 		<syntax>
 			<parameter name="direction" required="true">
@@ -221,9 +221,55 @@
 	return 0;
 }
 
+static int volume_read(struct ast_channel *chan, const char *cmd, char *data, char *buffer, size_t buflen)
+{
+	struct ast_datastore *datastore = NULL;
+	struct volume_information *vi = NULL;
+
+	/* Separate options from argument */
+
+	AST_DECLARE_APP_ARGS(args,
+		AST_APP_ARG(direction);
+		AST_APP_ARG(options);
+	);
+
+	if (!chan) {
+		ast_log(LOG_WARNING, "No channel was provided to %s function.\n", cmd);
+		return -1;
+	}
+
+	AST_STANDARD_APP_ARGS(args, data);
+
+	ast_channel_lock(chan);
+	if (!(datastore = ast_channel_datastore_find(chan, &volume_datastore, NULL))) {
+		ast_channel_unlock(chan);
+		return -1; /* no active audiohook, nothing to read */
+	} else {
+		ast_channel_unlock(chan);
+		vi = datastore->data;
+	}
+
+	/* Obtain current gain using volume information structure */
+	if (ast_strlen_zero(args.direction)) {
+		ast_log(LOG_ERROR, "Direction must be specified for VOLUME function\n");
+		return -1;
+	}
+
+	if (!strcasecmp(args.direction, "tx")) {
+		snprintf(buffer, buflen, "%f", vi->tx_gain);
+	} else if (!strcasecmp(args.direction, "rx")) {
+		snprintf(buffer, buflen, "%f", vi->rx_gain);
+	} else {
+		ast_log(LOG_ERROR, "Direction must be either RX or TX\n");
+	}
+
+	return 0;
+}
+
 static struct ast_custom_function volume_function = {
 	.name = "VOLUME",
 	.write = volume_write,
+	.read = volume_read,
 };
 
 static int unload_module(void)

-- 
To view, visit https://gerrit.asterisk.org/c/asterisk/+/15898
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Change-Id: Ia23e92fa2e755c36e9c8e69f2940d2703ccccb5f
Gerrit-Change-Number: 15898
Gerrit-PatchSet: 1
Gerrit-Owner: N A <mail at interlinked.x10host.com>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20210520/3f06e9c7/attachment-0001.html>


More information about the asterisk-code-review mailing list