From: Matthew Jordan Date: Sat, 4 May 2013 15:24:31 +0000 (+0000) Subject: Migrate SHARED's use of the VarSet AMI event to Stasis-Core X-Git-Tag: 13.0.0-beta1~1849 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b3bb6608eff9d9ad37eade92cc85506df08655b7;p=thirdparty%2Fasterisk.git 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 --- diff --git a/funcs/func_global.c b/funcs/func_global.c index 0a4b89dae3..a688ef0a5b 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 @@ -83,7 +83,25 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$") using it in a set of calculations (or you might be surprised by the result). - + + + Raised when a variable is shared between channels. + + + + The SHARED variable being set. + The variable name will always be enclosed with + SHARED() + + + The new value of the variable. + + + + SHARED + + + ***/ 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([,])\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);