summaryrefslogtreecommitdiff
path: root/funcs/func_global.c
diff options
context:
space:
mode:
authorMatthew Jordan <mjordan@digium.com>2013-05-04 15:24:31 +0000
committerMatthew Jordan <mjordan@digium.com>2013-05-04 15:24:31 +0000
commitb3bb6608eff9d9ad37eade92cc85506df08655b7 (patch)
treec08adea1569ccaee45e08355992c6991449b6b57 /funcs/func_global.c
parent1eac5a798899713501ae9f647ecd8b035f74eecd (diff)
Migrate SHARED's use of the VarSet AMI event to Stasis-Core
This patch removes the direct call to AMI from the SHARED function and instead call Stasis-Core. Stasis-Core delivers the notification that a shared variable has changed on a channel to all interested consumers. (issue ASTERISK-21462) git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@387630 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'funcs/func_global.c')
-rw-r--r--funcs/func_global.c43
1 files changed, 34 insertions, 9 deletions
diff --git a/funcs/func_global.c b/funcs/func_global.c
index 0a4b89dae..a688ef0a5 100644
--- a/funcs/func_global.c
+++ b/funcs/func_global.c
@@ -39,7 +39,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include "asterisk/pbx.h"
#include "asterisk/channel.h"
#include "asterisk/app.h"
-#include "asterisk/manager.h"
+#include "asterisk/stasis_channels.h"
/*** DOCUMENTATION
<function name="GLOBAL" language="en_US">
@@ -83,7 +83,25 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
using it in a set of calculations (or you might be surprised by the result).</para>
</description>
</function>
-
+ <managerEvent language="en_US" name="VarSet">
+ <managerEventInstance class="EVENT_FLAG_DIALPLAN">
+ <synopsis>Raised when a variable is shared between channels.</synopsis>
+ <syntax>
+ <xi:include xpointer="xpointer(/docs/managerEvent[@name='Newchannel']/managerEventInstance/syntax/parameter)" />
+ <parameter name="Variable">
+ <para>The SHARED variable being set.</para>
+ <note><para>The variable name will always be enclosed with
+ <literal>SHARED()</literal></para></note>
+ </parameter>
+ <parameter name="Value">
+ <para>The new value of the variable.</para>
+ </parameter>
+ </syntax>
+ <see-also>
+ <ref type="function">SHARED</ref>
+ </see-also>
+ </managerEventInstance>
+ </managerEvent>
***/
static void shared_variable_free(void *data);
@@ -197,6 +215,8 @@ static int shared_write(struct ast_channel *chan, const char *cmd, char *data, c
AST_APP_ARG(chan);
);
struct ast_channel *c_ref = NULL;
+ int len;
+ RAII_VAR(char *, shared_buffer, NULL, ast_free);
if (ast_strlen_zero(data)) {
ast_log(LOG_WARNING, "SHARED() requires an argument: SHARED(<var>[,<chan>])\n");
@@ -215,6 +235,15 @@ static int shared_write(struct ast_channel *chan, const char *cmd, char *data, c
chan = c_ref;
}
+ len = 9 + strlen(args.var); /* SHARED() + var */
+ shared_buffer = ast_malloc(len);
+ if (!shared_buffer) {
+ if (c_ref) {
+ ast_channel_unref(c_ref);
+ }
+ return -1;
+ }
+
ast_channel_lock(chan);
if (!(varstore = ast_channel_datastore_find(chan, &shared_variable_info, NULL))) {
@@ -255,13 +284,9 @@ static int shared_write(struct ast_channel *chan, const char *cmd, char *data, c
var = ast_var_assign(args.var, S_OR(value, ""));
AST_LIST_INSERT_HEAD(varshead, var, entries);
- manager_event(EVENT_FLAG_DIALPLAN, "VarSet",
- "Channel: %s\r\n"
- "Variable: SHARED(%s)\r\n"
- "Value: %s\r\n"
- "Uniqueid: %s\r\n",
- chan ? ast_channel_name(chan) : "none", args.var, value,
- chan ? ast_channel_uniqueid(chan) : "none");
+
+ sprintf(shared_buffer, "SHARED(%s)", args.var);
+ ast_channel_publish_varset(chan, shared_buffer, value);
ast_channel_unlock(chan);