<p>N A has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/15898">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">func_volume: Add read capability to function.<br><br>Up until now, the VOLUME function has been write<br>only, so that TX/RX values can be set but not<br>read afterwards. Now, previously set TX/RX values<br>can be read later.<br><br>ASTERISK-29439<br><br>Change-Id: Ia23e92fa2e755c36e9c8e69f2940d2703ccccb5f<br>---<br>A doc/CHANGES-staging/func_volume_read.txt<br>M funcs/func_volume.c<br>2 files changed, 51 insertions(+), 1 deletion(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/98/15898/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/doc/CHANGES-staging/func_volume_read.txt b/doc/CHANGES-staging/func_volume_read.txt</span><br><span>new file mode 100644</span><br><span>index 0000000..8ea27cd</span><br><span>--- /dev/null</span><br><span>+++ b/doc/CHANGES-staging/func_volume_read.txt</span><br><span>@@ -0,0 +1,4 @@</span><br><span style="color: hsl(120, 100%, 40%);">+Subject: func_volume now can be read</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+The VOLUME function can now also be used</span><br><span style="color: hsl(120, 100%, 40%);">+to read existing values previously set.</span><br><span>diff --git a/funcs/func_volume.c b/funcs/func_volume.c</span><br><span>index 8587479..a20bb76 100644</span><br><span>--- a/funcs/func_volume.c</span><br><span>+++ b/funcs/func_volume.c</span><br><span>@@ -42,7 +42,7 @@</span><br><span> /*** DOCUMENTATION</span><br><span> <function name="VOLUME" language="en_US"></span><br><span> <synopsis></span><br><span style="color: hsl(0, 100%, 40%);">- Set the TX or RX volume of a channel.</span><br><span style="color: hsl(120, 100%, 40%);">+ Set or get the TX or RX volume of a channel.</span><br><span> </synopsis></span><br><span> <syntax></span><br><span> <parameter name="direction" required="true"></span><br><span>@@ -221,9 +221,55 @@</span><br><span> return 0;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+static int volume_read(struct ast_channel *chan, const char *cmd, char *data, char *buffer, size_t buflen)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_datastore *datastore = NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+ struct volume_information *vi = NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ /* Separate options from argument */</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ AST_DECLARE_APP_ARGS(args,</span><br><span style="color: hsl(120, 100%, 40%);">+ AST_APP_ARG(direction);</span><br><span style="color: hsl(120, 100%, 40%);">+ AST_APP_ARG(options);</span><br><span style="color: hsl(120, 100%, 40%);">+ );</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!chan) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_log(LOG_WARNING, "No channel was provided to %s function.\n", cmd);</span><br><span style="color: hsl(120, 100%, 40%);">+ return -1;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ AST_STANDARD_APP_ARGS(args, data);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_channel_lock(chan);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!(datastore = ast_channel_datastore_find(chan, &volume_datastore, NULL))) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_channel_unlock(chan);</span><br><span style="color: hsl(120, 100%, 40%);">+ return -1; /* no active audiohook, nothing to read */</span><br><span style="color: hsl(120, 100%, 40%);">+ } else {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_channel_unlock(chan);</span><br><span style="color: hsl(120, 100%, 40%);">+ vi = datastore->data;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ /* Obtain current gain using volume information structure */</span><br><span style="color: hsl(120, 100%, 40%);">+ if (ast_strlen_zero(args.direction)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_log(LOG_ERROR, "Direction must be specified for VOLUME function\n");</span><br><span style="color: hsl(120, 100%, 40%);">+ return -1;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!strcasecmp(args.direction, "tx")) {</span><br><span style="color: hsl(120, 100%, 40%);">+ snprintf(buffer, buflen, "%f", vi->tx_gain);</span><br><span style="color: hsl(120, 100%, 40%);">+ } else if (!strcasecmp(args.direction, "rx")) {</span><br><span style="color: hsl(120, 100%, 40%);">+ snprintf(buffer, buflen, "%f", vi->rx_gain);</span><br><span style="color: hsl(120, 100%, 40%);">+ } else {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_log(LOG_ERROR, "Direction must be either RX or TX\n");</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ return 0;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> static struct ast_custom_function volume_function = {</span><br><span> .name = "VOLUME",</span><br><span> .write = volume_write,</span><br><span style="color: hsl(120, 100%, 40%);">+ .read = volume_read,</span><br><span> };</span><br><span> </span><br><span> static int unload_module(void)</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/15898">change 15898</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/c/asterisk/+/15898"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-Change-Id: Ia23e92fa2e755c36e9c8e69f2940d2703ccccb5f </div>
<div style="display:none"> Gerrit-Change-Number: 15898 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: N A <mail@interlinked.x10host.com> </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>