mirror of
				https://github.com/asterisk/asterisk.git
				synced 2025-10-31 02:37:10 +00:00 
			
		
		
		
	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
This commit is contained in:
		| @@ -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); | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user