[asterisk-commits] mjordan: branch mjordan/12-stasis-performance r414965 - in /team/mjordan/12-s...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri May 30 17:55:38 CDT 2014


Author: mjordan
Date: Fri May 30 17:55:29 2014
New Revision: 414965

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=414965
Log:
Re-enable automerge

Modified:
    team/mjordan/12-stasis-performance/   (props changed)
    team/mjordan/12-stasis-performance/include/asterisk/channel.h
    team/mjordan/12-stasis-performance/main/channel.c
    team/mjordan/12-stasis-performance/main/manager.c
    team/mjordan/12-stasis-performance/main/stasis_channels.c

Propchange: team/mjordan/12-stasis-performance/
------------------------------------------------------------------------------
    automerge = *

Modified: team/mjordan/12-stasis-performance/include/asterisk/channel.h
URL: http://svnview.digium.com/svn/asterisk/team/mjordan/12-stasis-performance/include/asterisk/channel.h?view=diff&rev=414965&r1=414964&r2=414965
==============================================================================
--- team/mjordan/12-stasis-performance/include/asterisk/channel.h (original)
+++ team/mjordan/12-stasis-performance/include/asterisk/channel.h Fri May 30 17:55:29 2014
@@ -4190,6 +4190,15 @@
 struct ast_flags *ast_channel_flags(struct ast_channel *chan);
 
 /*!
+ * \since 12.4.0
+ * \brief Return whether or not any manager variables have been set
+ *
+ * \retval 0 if no manager variables are expected
+ * \retval 1 if manager variables are expected
+ */
+int ast_channel_has_manager_vars(void);
+
+/*!
  * \since 12
  * \brief Sets the variables to be stored in the \a manager_vars field of all
  * snapshots.

Modified: team/mjordan/12-stasis-performance/main/channel.c
URL: http://svnview.digium.com/svn/asterisk/team/mjordan/12-stasis-performance/main/channel.c?view=diff&rev=414965&r1=414964&r2=414965
==============================================================================
--- team/mjordan/12-stasis-performance/main/channel.c (original)
+++ team/mjordan/12-stasis-performance/main/channel.c Fri May 30 17:55:29 2014
@@ -1279,7 +1279,7 @@
 				     "musicclass", musicclass);
 	}
 
-	ast_channel_publish_blob(chan, ast_channel_hold_type(), blob);
+	ast_channel_publish_cached_blob(chan, ast_channel_hold_type(), blob);
 
 	res = ast_queue_frame(chan, &f);
 	ast_channel_unlock(chan);
@@ -1292,7 +1292,7 @@
 	int res;
 
 	ast_channel_lock(chan);
-	ast_channel_publish_blob(chan, ast_channel_unhold_type(), NULL);
+	ast_channel_publish_cached_blob(chan, ast_channel_unhold_type(), NULL);
 
 	res = ast_queue_frame(chan, &f);
 	ast_channel_unlock(chan);
@@ -3639,7 +3639,7 @@
 		return;
 	}
 
-	ast_channel_publish_blob(chan, ast_channel_dtmf_begin_type(), blob);
+	ast_channel_publish_cached_blob(chan, ast_channel_dtmf_begin_type(), blob);
 }
 
 static void send_dtmf_end_event(struct ast_channel *chan,
@@ -3656,7 +3656,7 @@
 		return;
 	}
 
-	ast_channel_publish_blob(chan, ast_channel_dtmf_end_type(), blob);
+	ast_channel_publish_cached_blob(chan, ast_channel_dtmf_end_type(), blob);
 }
 
 static void ast_read_generator_actions(struct ast_channel *chan, struct ast_frame *f)
@@ -7408,6 +7408,17 @@
 		ast_free(var);
 	}
 	AST_RWLIST_UNLOCK(&channelvars);
+}
+
+int ast_channel_has_manager_vars(void)
+{
+	int vars_present;
+
+	AST_RWLIST_RDLOCK(&channelvars);
+	vars_present = !AST_LIST_EMPTY(&channelvars);
+	AST_RWLIST_UNLOCK(&channelvars);
+
+	return vars_present;
 }
 
 void ast_channel_set_manager_vars(size_t varc, char **vars)

Modified: team/mjordan/12-stasis-performance/main/manager.c
URL: http://svnview.digium.com/svn/asterisk/team/mjordan/12-stasis-performance/main/manager.c?view=diff&rev=414965&r1=414964&r2=414965
==============================================================================
--- team/mjordan/12-stasis-performance/main/manager.c (original)
+++ team/mjordan/12-stasis-performance/main/manager.c Fri May 30 17:55:29 2014
@@ -99,6 +99,7 @@
 #include "asterisk/bridge.h"
 #include "asterisk/features_config.h"
 #include "asterisk/rtp_engine.h"
+#include "asterisk/translate.h"
 
 /*** DOCUMENTATION
 	<manager name="Ping" language="en_US">
@@ -3845,95 +3846,110 @@
 static int action_status(struct mansession *s, const struct message *m)
 {
 	const char *name = astman_get_header(m, "Channel");
-	const char *cvariables = astman_get_header(m, "Variables");
-	char *variables = ast_strdupa(S_OR(cvariables, ""));
-	RAII_VAR(struct ao2_container *, cached_channels, NULL, ao2_cleanup);
-	struct stasis_message *msg;
+	const char *chan_variables = astman_get_header(m, "Variables");
+	const char *id = astman_get_header(m, "ActionID");
+	char *variables = ast_strdupa(S_OR(chan_variables, ""));
+	struct ast_str *variable_str = ast_str_create(1024);
+	struct ast_str *write_transpath = ast_str_alloca(256);
+	struct ast_str *read_transpath = ast_str_alloca(256);
+	struct ast_channel *chan;
+	char nativeformats[256];
 	int channels = 0;
 	int all = ast_strlen_zero(name); /* set if we want all channels */
-	const char *id = astman_get_header(m, "ActionID");
-	char idText[256];
+	char id_text[256];
+	struct ast_channel_iterator *it_chans = NULL;
 	AST_DECLARE_APP_ARGS(vars,
 		AST_APP_ARG(name)[100];
 	);
-	struct ast_str *str = ast_str_create(1000);
-	struct ao2_iterator it_chans;
-	//struct timeval now = ast_tvnow();
-
-	if (!ast_strlen_zero(id)) {
-		snprintf(idText, sizeof(idText), "ActionID: %s\r\n", id);
-	} else {
-		idText[0] = '\0';
+
+	if (!variable_str) {
+		astman_send_error(s, m, "Memory Allocation Failure");
+		return 1;
 	}
 
 	if (!(function_capable_string_allowed_with_auths(variables, s->session->writeperm))) {
+		ast_free(variable_str);
 		astman_send_error(s, m, "Status Access Forbidden: Variables");
 		return 0;
 	}
 
 	if (all) {
-		if (!(cached_channels = stasis_cache_dump(ast_channel_cache_by_name(), ast_channel_snapshot_type()))) {
-			ast_free(str);
+		if (!(it_chans = ast_channel_iterator_all_new())) {
+			ast_free(variable_str);
 			astman_send_error(s, m, "Memory Allocation Failure");
 			return 1;
 		}
-		it_chans = ao2_iterator_init(cached_channels, 0);
-		msg = ao2_iterator_next(&it_chans);
+		chan = ast_channel_iterator_next(it_chans);
 	} else {
-		if (!(msg = stasis_cache_get(ast_channel_cache_by_name(), ast_channel_snapshot_type(), name))) {
+		chan = ast_channel_get_by_name(name);
+		if (!chan) {
 			astman_send_error(s, m, "No such channel");
-			ast_free(str);
+			ast_free(variable_str);
 			return 0;
 		}
 	}
 
 	astman_send_ack(s, m, "Channel status will follow");
 
-	if (!ast_strlen_zero(cvariables)) {
+	if (!ast_strlen_zero(id)) {
+		snprintf(id_text, sizeof(id_text), "ActionID: %s\r\n", id);
+	} else {
+		id_text[0] = '\0';
+	}
+
+	if (!ast_strlen_zero(chan_variables)) {
 		AST_STANDARD_APP_ARGS(vars, variables);
 	}
 
 	/* if we look by name, we break after the first iteration */
-	for (; msg; ao2_ref(msg, -1), msg = all ? ao2_iterator_next(&it_chans) : NULL) {
-		struct ast_channel_snapshot *snapshot = stasis_message_data(msg);
-		struct ast_channel *c;
-		struct ast_str *built = ast_manager_build_channel_state_string_prefix(snapshot, "");
-//		long elapsed_seconds = 0;
-
-		if (!built) {
-			continue;
-		}
-
-		if (!ast_strlen_zero(cvariables) && (c = ast_channel_get_by_name(snapshot->name))) {
+	for (; chan; all ? chan = ast_channel_iterator_next(it_chans) : 0) {
+		struct timeval now;
+		long elapsed_seconds;
+		struct ast_bridge *bridge;
+
+		ast_channel_lock(chan);
+
+		now = ast_tvnow();
+		elapsed_seconds = ast_tvdiff_sec(now, ast_channel_creationtime(chan));
+
+		if (!ast_strlen_zero(chan_variables)) {
 			int i;
-			ast_str_reset(str);
+			ast_str_reset(variable_str);
 			for (i = 0; i < vars.argc; i++) {
 				char valbuf[512], *ret = NULL;
 
 				if (vars.name[i][strlen(vars.name[i]) - 1] == ')') {
-					if (ast_func_read(c, vars.name[i], valbuf, sizeof(valbuf)) < 0) {
+					if (ast_func_read(chan, vars.name[i], valbuf, sizeof(valbuf)) < 0) {
 						valbuf[0] = '\0';
 					}
 					ret = valbuf;
 				} else {
-					pbx_retrieve_variable(c, vars.name[i], &ret, valbuf, sizeof(valbuf), NULL);
+					pbx_retrieve_variable(chan, vars.name[i], &ret, valbuf, sizeof(valbuf), NULL);
 				}
 
-				ast_str_append(&str, 0, "Variable: %s=%s\r\n", vars.name[i], ret);
+				ast_str_append(&variable_str, 0, "Variable: %s=%s\r\n", vars.name[i], ret);
 			}
-			ast_channel_unref(c);
 		}
 
 		channels++;
 
-
-		if (!ast_tvzero(snapshot->creationtime)) {
-//			elapsed_seconds = now.tv_sec - snapshot->creationtime.tv_sec;
-		}
-/*
+		bridge = ast_channel_get_bridge(chan);
+
 		astman_append(s,
 			"Event: Status\r\n"
 			"Privilege: Call\r\n"
+			"Channel: %s\r\n"
+			"ChannelState: %u\r\n"
+			"ChannelStateDesc: %s\r\n"
+			"CallerIDNum: %s\r\n"
+			"CallerIDName: %s\r\n"
+			"ConnectedLineNum: %s\r\n"
+			"ConnectedLineName: %s\r\n"
+			"Accountcode: %s\r\n"
+			"Context: %s\r\n"
+			"Exten: %s\r\n"
+			"Priority: %d\r\n"
+			"Uniqueid: %s\r\n"
 			"Type: %s\r\n"
 			"DNID: %s\r\n"
 			"EffectiveConnectedLineNum: %s\r\n"
@@ -3953,43 +3969,56 @@
 			"Seconds: %ld\r\n"
 			"%s"
 			"%s"
-			"%s"
 			"\r\n",
-			snapshot->type,
-			snapshot->caller_dnid,
-			S_OR(snapshot->effective_number, "<unknown>"),
-			S_OR(snapshot->effective_name, "<unknown>"),
-			snapshot->hanguptime.tv_sec,
-			snapshot->bridgeid,
-			snapshot->linkedid,
-			snapshot->appl,
-			snapshot->data,
-			snapshot->nativeformats,
-			snapshot->readformat,
-			snapshot->readtrans,
-			snapshot->writeformat,
-			snapshot->writetrans,
-			snapshot->callgroup,
-			snapshot->pickupgroup,
-			(long) elapsed_seconds,
-			ast_str_buffer(built),
-			ast_str_buffer(str),
-			idText);
-*/
-		ast_free(built);
-	}
-
-	if (all) {
-		ao2_iterator_destroy(&it_chans);
+			ast_channel_name(chan),
+			ast_channel_state(chan),
+			ast_state2str(ast_channel_state(chan)),
+			S_COR(ast_channel_caller(chan)->id.number.valid, ast_channel_caller(chan)->id.number.str, "<unknown>"),
+			S_COR(ast_channel_caller(chan)->id.name.valid, ast_channel_caller(chan)->id.name.str, "<unknown>"),
+			S_COR(ast_channel_connected(chan)->id.number.valid, ast_channel_connected(chan)->id.number.str, "<unknown>"),
+			S_COR(ast_channel_connected(chan)->id.name.valid, ast_channel_connected(chan)->id.name.str, "<unknown>"),
+			ast_channel_accountcode(chan),
+			ast_channel_context(chan),
+			ast_channel_exten(chan),
+			ast_channel_priority(chan),
+			ast_channel_uniqueid(chan),
+			ast_channel_tech(chan)->type,
+			S_OR(ast_channel_dialed(chan)->number.str, ""),
+			S_COR(ast_channel_connected_effective_id(chan).number.valid, ast_channel_connected_effective_id(chan).number.str, "<unknown>"),
+			S_COR(ast_channel_connected_effective_id(chan).name.valid, ast_channel_connected_effective_id(chan).name.str, "<unknown>"),
+			ast_channel_whentohangup(chan)->tv_sec,
+			bridge ? bridge->uniqueid : "",
+			ast_channel_linkedid(chan),
+			ast_channel_appl(chan),
+			ast_channel_data(chan),
+			ast_getformatname_multiple(nativeformats, sizeof(nativeformats), ast_channel_nativeformats(chan)),
+			ast_getformatname(ast_channel_readformat(chan)),
+			ast_translate_path_to_str(ast_channel_readtrans(chan), &read_transpath),
+			ast_getformatname(ast_channel_writeformat(chan)),
+			ast_translate_path_to_str(ast_channel_writetrans(chan), &write_transpath),
+			ast_channel_callgroup(chan),
+			ast_channel_pickupgroup(chan),
+			(long)elapsed_seconds,
+			ast_str_buffer(variable_str),
+			id_text);
+
+		ao2_cleanup(bridge);
+
+		ast_channel_unlock(chan);
+		chan = ast_channel_unref(chan);
+	}
+
+	if (it_chans) {
+		ast_channel_iterator_destroy(it_chans);
 	}
 
 	astman_append(s,
 		"Event: StatusComplete\r\n"
 		"%s"
 		"Items: %d\r\n"
-		"\r\n", idText, channels);
-
-	ast_free(str);
+		"\r\n", id_text, channels);
+
+	ast_free(variable_str);
 
 	return 0;
 }

Modified: team/mjordan/12-stasis-performance/main/stasis_channels.c
URL: http://svnview.digium.com/svn/asterisk/team/mjordan/12-stasis-performance/main/stasis_channels.c?view=diff&rev=414965&r1=414964&r2=414965
==============================================================================
--- team/mjordan/12-stasis-performance/main/stasis_channels.c (original)
+++ team/mjordan/12-stasis-performance/main/stasis_channels.c Fri May 30 17:55:29 2014
@@ -693,9 +693,12 @@
 		return;
 	}
 
-	if (chan) {
+	if (chan && !ast_channel_has_manager_vars()) {
 		ast_channel_publish_cached_blob(chan, ast_channel_varset_type(), blob);
 	} else {
+		/* This function is NULL safe. If there are manager variables,
+		 * we have to produce the full snapshot.
+		 */
 		ast_channel_publish_blob(chan, ast_channel_varset_type(), blob);
 	}
 	ast_json_unref(blob);




More information about the asterisk-commits mailing list