[asterisk-commits] file: branch group/stasis_cache_usage r392699 - in /team/group/stasis_cache_u...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Jun 24 08:10:24 CDT 2013


Author: file
Date: Mon Jun 24 08:10:22 2013
New Revision: 392699

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=392699
Log:
Add progress so far.

The following now hits the stasis cache:
1. CLI: core show channels
2. CLI: core show bridges
3. CLI:core show bridge
4. AMI: CoreShowChannels

Thanks snuffy for the channel specific parts!

Modified:
    team/group/stasis_cache_usage/include/asterisk/stasis_channels.h
    team/group/stasis_cache_usage/main/bridging.c
    team/group/stasis_cache_usage/main/channel_internal_api.c
    team/group/stasis_cache_usage/main/cli.c
    team/group/stasis_cache_usage/main/manager.c
    team/group/stasis_cache_usage/main/stasis_channels.c

Modified: team/group/stasis_cache_usage/include/asterisk/stasis_channels.h
URL: http://svnview.digium.com/svn/asterisk/team/group/stasis_cache_usage/include/asterisk/stasis_channels.h?view=diff&rev=392699&r1=392698&r2=392699
==============================================================================
--- team/group/stasis_cache_usage/include/asterisk/stasis_channels.h (original)
+++ team/group/stasis_cache_usage/include/asterisk/stasis_channels.h Mon Jun 24 08:10:22 2013
@@ -60,6 +60,7 @@
 		AST_STRING_FIELD(connected_name);   /*!< Connected Line Name */
 		AST_STRING_FIELD(connected_number); /*!< Connected Line Number */
 		AST_STRING_FIELD(language);         /*!< The default spoken language for the channel */
+		AST_STRING_FIELD(bridgeid);         /*!< Unique Bridge Identifier */
 	);
 
 	struct timeval creationtime;            /*!< The time of channel creation */

Modified: team/group/stasis_cache_usage/main/bridging.c
URL: http://svnview.digium.com/svn/asterisk/team/group/stasis_cache_usage/main/bridging.c?view=diff&rev=392699&r1=392698&r2=392699
==============================================================================
--- team/group/stasis_cache_usage/main/bridging.c (original)
+++ team/group/stasis_cache_usage/main/bridging.c Mon Jun 24 08:10:22 2013
@@ -6467,38 +6467,27 @@
 	return cmp;
 }
 
-struct bridge_complete {
-	/*! Nth match to return. */
-	int state;
-	/*! Which match currently on. */
-	int which;
-};
-
-static int complete_bridge_search(void *obj, void *arg, void *data, int flags)
-{
-	struct bridge_complete *search = data;
-
-	if (++search->which > search->state) {
-		return CMP_MATCH;
-	}
-	return 0;
-}
-
 static char *complete_bridge(const char *word, int state)
 {
-	char *ret;
-	struct ast_bridge *bridge;
-	struct bridge_complete search = {
-		.state = state,
-		};
-
-	bridge = ao2_callback_data(bridges, ast_strlen_zero(word) ? 0 : OBJ_PARTIAL_KEY,
-		complete_bridge_search, (char *) word, &search);
-	if (!bridge) {
-		return NULL;
-	}
-	ret = ast_strdup(bridge->uniqueid);
-	ao2_ref(bridge, -1);
+	char *ret = NULL;
+	int wordlen = strlen(word), which = 0;
+	RAII_VAR(struct ao2_container *, cached_bridges, NULL, ao2_cleanup);
+	struct ao2_iterator iter;
+	struct stasis_message *msg;
+
+	cached_bridges = stasis_cache_dump(ast_bridge_topic_all_cached(), ast_bridge_snapshot_type());
+
+	iter = ao2_iterator_init(cached_bridges, 0);
+	for (; (msg = ao2_iterator_next(&iter)); ao2_ref(msg, -1)) {
+		struct ast_bridge_snapshot *snapshot = stasis_message_data(msg);
+
+		if (!strncasecmp(word, snapshot->uniqueid, wordlen) && (++which > state)) {
+			ret = ast_strdup(snapshot->uniqueid);
+			break;
+		}
+	}
+	ao2_iterator_destroy(&iter);
+
 	return ret;
 }
 
@@ -6507,8 +6496,9 @@
 #define FORMAT_HDR "%-36s %5s %-15s %s\n"
 #define FORMAT_ROW "%-36s %5u %-15s %s\n"
 
+	RAII_VAR(struct ao2_container *, cached_bridges, NULL, ao2_cleanup);
 	struct ao2_iterator iter;
-	struct ast_bridge *bridge;
+	struct stasis_message *msg;
 
 	switch (cmd) {
 	case CLI_INIT:
@@ -6521,17 +6511,18 @@
 		return NULL;
 	}
 
-/* BUGBUG this command may need to be changed to look at the stasis cache. */
+	cached_bridges = stasis_cache_dump(ast_bridge_topic_all_cached(), ast_bridge_snapshot_type());
+
 	ast_cli(a->fd, FORMAT_HDR, "Bridge-ID", "Chans", "Type", "Technology");
-	iter = ao2_iterator_init(bridges, 0);
-	for (; (bridge = ao2_iterator_next(&iter)); ao2_ref(bridge, -1)) {
-		ast_bridge_lock(bridge);
+	iter = ao2_iterator_init(cached_bridges, 0);
+	for (; (msg = ao2_iterator_next(&iter)); ao2_ref(msg, -1)) {
+		struct ast_bridge_snapshot *snapshot = stasis_message_data(msg);
+
 		ast_cli(a->fd, FORMAT_ROW,
-			bridge->uniqueid,
-			bridge->num_channels,
-			bridge->v_table ? bridge->v_table->name : "<unknown>",
-			bridge->technology ? bridge->technology->name : "<unknown>");
-		ast_bridge_unlock(bridge);
+			snapshot->uniqueid,
+			snapshot->num_channels,
+			S_OR(snapshot->subclass, "<unknown>"),
+			S_OR(snapshot->technology, "<unknown>"));
 	}
 	ao2_iterator_destroy(&iter);
 	return CLI_SUCCESS;
@@ -6540,10 +6531,28 @@
 #undef FORMAT_ROW
 }
 
+/*! \brief Internal callback function for sending channels in a bridge to the CLI */
+static int bridge_show_specific_print_channel(void *obj, void *arg, int flags)
+{
+	const char *uniqueid = obj;
+	struct ast_cli_args *a = arg;
+	RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);
+	struct ast_channel_snapshot *snapshot;
+
+	if (!(msg = stasis_cache_get(ast_channel_topic_all_cached(), ast_channel_snapshot_type(), uniqueid))) {
+		return 0;
+	}
+	snapshot = stasis_message_data(msg);
+
+	ast_cli(a->fd, "Channel: %s\n", snapshot->name);
+
+	return 0;
+}
+
 static char *handle_bridge_show_specific(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 {
-	struct ast_bridge *bridge;
-	struct ast_bridge_channel *bridge_channel;
+	RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);
+	struct ast_bridge_snapshot *snapshot;
 
 	switch (cmd) {
 	case CLI_INIT:
@@ -6559,28 +6568,22 @@
 		return NULL;
 	}
 
-/* BUGBUG this command may need to be changed to look at the stasis cache. */
 	if (a->argc != 3) {
 		return CLI_SHOWUSAGE;
 	}
 
-	bridge = ao2_find(bridges, a->argv[2], OBJ_KEY);
-	if (!bridge) {
+	msg = stasis_cache_get(ast_bridge_topic_all_cached(), ast_bridge_snapshot_type(), a->argv[2]);
+	if (!msg) {
 		ast_cli(a->fd, "Bridge '%s' not found\n", a->argv[2]);
 		return CLI_SUCCESS;
 	}
 
-	ast_bridge_lock(bridge);
-	ast_cli(a->fd, "Id: %s\n", bridge->uniqueid);
-	ast_cli(a->fd, "Type: %s\n", bridge->v_table ? bridge->v_table->name : "<unknown>");
-	ast_cli(a->fd, "Technology: %s\n",
-		bridge->technology ? bridge->technology->name : "<unknown>");
-	ast_cli(a->fd, "Num-Channels: %u\n", bridge->num_channels);
-	AST_LIST_TRAVERSE(&bridge->channels, bridge_channel, entry) {
-		ast_cli(a->fd, "Channel: %s\n", ast_channel_name(bridge_channel->chan));
-	}
-	ast_bridge_unlock(bridge);
-	ao2_ref(bridge, -1);
+	snapshot = stasis_message_data(msg);
+	ast_cli(a->fd, "Id: %s\n", snapshot->uniqueid);
+	ast_cli(a->fd, "Type: %s\n", S_OR(snapshot->subclass, "<unknown>"));
+	ast_cli(a->fd, "Technology: %s\n", S_OR(snapshot->technology, "<unknown>"));
+	ast_cli(a->fd, "Num-Channels: %u\n", snapshot->num_channels);
+	ao2_callback(snapshot->channels, OBJ_NODATA, bridge_show_specific_print_channel, a);
 
 	return CLI_SUCCESS;
 }

Modified: team/group/stasis_cache_usage/main/channel_internal_api.c
URL: http://svnview.digium.com/svn/asterisk/team/group/stasis_cache_usage/main/channel_internal_api.c?view=diff&rev=392699&r1=392698&r2=392699
==============================================================================
--- team/group/stasis_cache_usage/main/channel_internal_api.c (original)
+++ team/group/stasis_cache_usage/main/channel_internal_api.c Mon Jun 24 08:10:22 2013
@@ -1274,6 +1274,7 @@
 void ast_channel_internal_bridge_set(struct ast_channel *chan, struct ast_bridge *value)
 {
 	chan->bridge = value;
+	ast_channel_publish_snapshot(chan);
 }
 
 struct ast_bridge_channel *ast_channel_internal_bridge_channel(const struct ast_channel *chan)

Modified: team/group/stasis_cache_usage/main/cli.c
URL: http://svnview.digium.com/svn/asterisk/team/group/stasis_cache_usage/main/cli.c?view=diff&rev=392699&r1=392698&r2=392699
==============================================================================
--- team/group/stasis_cache_usage/main/cli.c (original)
+++ team/group/stasis_cache_usage/main/cli.c Mon Jun 24 08:10:22 2013
@@ -61,6 +61,8 @@
 #include "asterisk/threadstorage.h"
 #include "asterisk/translate.h"
 #include "asterisk/bridging.h"
+#include "asterisk/stasis_channels.h"
+#include "asterisk/stasis_bridging.h"
 
 /*!
  * \brief List of restrictions per user.
@@ -877,9 +879,10 @@
 #define VERBOSE_FORMAT_STRING  "%-20.20s %-20.20s %-16.16s %4d %-7.7s %-12.12s %-25.25s %-15.15s %8.8s %-11.11s %-11.11s %-20.20s\n"
 #define VERBOSE_FORMAT_STRING2 "%-20.20s %-20.20s %-16.16s %-4.4s %-7.7s %-12.12s %-25.25s %-15.15s %8.8s %-11.11s %-11.11s %-20.20s\n"
 
-	struct ast_channel *c = NULL;
+	RAII_VAR(struct ao2_container *, channels, NULL, ao2_cleanup);
+	struct ao2_iterator it_chans;
+	struct stasis_message *msg;
 	int numchans = 0, concise = 0, verbose = 0, count = 0;
-	struct ast_channel_iterator *iter = NULL;
 
 	switch (cmd) {
 	case CLI_INIT:
@@ -911,6 +914,8 @@
 	} else if (a->argc != e->args - 1)
 		return CLI_SHOWUSAGE;
 
+	channels = stasis_cache_dump(ast_channel_topic_all_cached_by_name(), ast_channel_snapshot_type());
+
 	if (!count) {
 		if (!concise && !verbose)
 			ast_cli(a->fd, FORMAT_STRING2, "Channel", "Location", "State", "Application(Data)");
@@ -919,21 +924,14 @@
 				"CallerID", "Duration", "Accountcode", "PeerAccount", "BridgeID");
 	}
 
-	if (!count && !(iter = ast_channel_iterator_all_new())) {
-		return CLI_FAILURE;
-	}
-
-	for (; iter && (c = ast_channel_iterator_next(iter)); ast_channel_unref(c)) {
-		struct ast_bridge *bridge;
+	it_chans = ao2_iterator_init(channels, 0);
+	for (; (msg = ao2_iterator_next(&it_chans)); ao2_ref(msg, -1)) {
+		struct ast_channel_snapshot *cs = stasis_message_data(msg);
 		char durbuf[10] = "-";
 
-		ast_channel_lock(c);
-
-		bridge = ast_channel_get_bridge(c);
-
 		if (!count) {
-			if ((concise || verbose)  && !ast_tvzero(ast_channel_creationtime(c))) {
-				int duration = (int)(ast_tvdiff_ms(ast_tvnow(), ast_channel_creationtime(c)) / 1000);
+			if ((concise || verbose)  && !ast_tvzero(cs->creationtime)) {
+				int duration = (int)(ast_tvdiff_ms(ast_tvnow(), cs->creationtime) / 1000);
 				if (verbose) {
 					int durh = duration / 3600;
 					int durm = (duration % 3600) / 60;
@@ -944,44 +942,39 @@
 				}
 			}
 			if (concise) {
-				ast_cli(a->fd, CONCISE_FORMAT_STRING, ast_channel_name(c), ast_channel_context(c), ast_channel_exten(c), ast_channel_priority(c), ast_state2str(ast_channel_state(c)),
-					ast_channel_appl(c) ? ast_channel_appl(c) : "(None)",
-					S_OR(ast_channel_data(c), ""),	/* XXX different from verbose ? */
-					S_COR(ast_channel_caller(c)->id.number.valid, ast_channel_caller(c)->id.number.str, ""),
-					S_OR(ast_channel_accountcode(c), ""),
-					S_OR(ast_channel_peeraccount(c), ""),
-					ast_channel_amaflags(c),
+				ast_cli(a->fd, CONCISE_FORMAT_STRING, cs->name, cs->context, cs->exten, cs->priority, ast_state2str(cs->state),
+					S_OR(cs->appl, "(None)"),
+					cs->data,	
+					cs->caller_number,
+					cs->accountcode,
+					cs->peeraccount,
+					cs->amaflags,
 					durbuf,
-					bridge ? bridge->uniqueid : "(Not bridged)",
-					ast_channel_uniqueid(c));
+					cs->bridgeid,
+					cs->uniqueid);
 			} else if (verbose) {
-				ast_cli(a->fd, VERBOSE_FORMAT_STRING, ast_channel_name(c), ast_channel_context(c), ast_channel_exten(c), ast_channel_priority(c), ast_state2str(ast_channel_state(c)),
-					ast_channel_appl(c) ? ast_channel_appl(c) : "(None)",
-					ast_channel_data(c) ? S_OR(ast_channel_data(c), "(Empty)" ): "(None)",
-					S_COR(ast_channel_caller(c)->id.number.valid, ast_channel_caller(c)->id.number.str, ""),
+				ast_cli(a->fd, VERBOSE_FORMAT_STRING, cs->name, cs->context, cs->exten, cs->priority, ast_state2str(cs->state),
+					S_OR(cs->appl, "(None)"),
+					S_OR(cs->data, "(Empty)"),
+					cs->caller_number,
 					durbuf,
-					S_OR(ast_channel_accountcode(c), ""),
-					S_OR(ast_channel_peeraccount(c), ""),
-					bridge ? bridge->uniqueid : "(Not bridged)");
+					cs->accountcode,
+					cs->peeraccount,
+					cs->bridgeid);
 			} else {
 				char locbuf[40] = "(None)";
 				char appdata[40] = "(None)";
 
-				if (!ast_strlen_zero(ast_channel_context(c)) && !ast_strlen_zero(ast_channel_exten(c)))
-					snprintf(locbuf, sizeof(locbuf), "%s@%s:%d", ast_channel_exten(c), ast_channel_context(c), ast_channel_priority(c));
-				if (ast_channel_appl(c))
-					snprintf(appdata, sizeof(appdata), "%s(%s)", ast_channel_appl(c), S_OR(ast_channel_data(c), ""));
-				ast_cli(a->fd, FORMAT_STRING, ast_channel_name(c), locbuf, ast_state2str(ast_channel_state(c)), appdata);
-			}
-		}
-		ast_channel_unlock(c);
-		ao2_cleanup(bridge);
-	}
-
-	if (iter) {
-		ast_channel_iterator_destroy(iter);
-	}
-
+				if (!cs->context && !cs->exten)
+					snprintf(locbuf, sizeof(locbuf), "%s@%s:%d", cs->exten, cs->context, cs->priority);
+				if (cs->appl)
+					snprintf(appdata, sizeof(appdata), "%s(%s)", cs->appl, S_OR(cs->data, ""));
+				ast_cli(a->fd, FORMAT_STRING, cs->name, locbuf, ast_state2str(cs->state), appdata);
+			}
+		}
+	}
+	ao2_iterator_destroy(&it_chans);
+		
 	if (!concise) {
 		numchans = ast_active_channels();
 		ast_cli(a->fd, "%d active channel%s\n", numchans, ESS(numchans));

Modified: team/group/stasis_cache_usage/main/manager.c
URL: http://svnview.digium.com/svn/asterisk/team/group/stasis_cache_usage/main/manager.c?view=diff&rev=392699&r1=392698&r2=392699
==============================================================================
--- team/group/stasis_cache_usage/main/manager.c (original)
+++ team/group/stasis_cache_usage/main/manager.c Mon Jun 24 08:10:22 2013
@@ -92,8 +92,9 @@
 #include "asterisk/strings.h"
 #include "asterisk/stringfields.h"
 #include "asterisk/presencestate.h"
-#include "asterisk/stasis.h"
 #include "asterisk/stasis_message_router.h"
+#include "asterisk/stasis_channels.h"
+#include "asterisk/stasis_bridging.h"
 #include "asterisk/test.h"
 #include "asterisk/json.h"
 #include "asterisk/bridging.h"
@@ -5203,10 +5204,11 @@
 {
 	const char *actionid = astman_get_header(m, "ActionID");
 	char idText[256];
-	struct ast_channel *c = NULL;
 	int numchans = 0;
 	int duration, durh, durm, durs;
-	struct ast_channel_iterator *iter;
+	RAII_VAR(struct ao2_container *, channels, NULL, ao2_cleanup);
+	struct ao2_iterator it_chans;
+	struct stasis_message *msg;
 
 	if (!ast_strlen_zero(actionid)) {
 		snprintf(idText, sizeof(idText), "ActionID: %s\r\n", actionid);
@@ -5214,22 +5216,17 @@
 		idText[0] = '\0';
 	}
 
-	if (!(iter = ast_channel_iterator_all_new())) {
-		astman_send_error(s, m, "Memory Allocation Failure");
-		return 1;
-	}
+	channels = stasis_cache_dump(ast_channel_topic_all_cached_by_name(), ast_channel_snapshot_type());
 
 	astman_send_listack(s, m, "Channels will follow", "start");
 
-	for (; (c = ast_channel_iterator_next(iter)); ast_channel_unref(c)) {
-		struct ast_channel *bc;
+	it_chans = ao2_iterator_init(channels, 0);
+	for (; (msg = ao2_iterator_next(&it_chans)); ao2_ref(msg, -1)) {
+		struct ast_channel_snapshot *cs = stasis_message_data(msg);
 		char durbuf[10] = "";
 
-		ast_channel_lock(c);
-
-		bc = ast_bridged_channel(c);
-		if (!ast_tvzero(ast_channel_creationtime(c))) {
-			duration = (int)(ast_tvdiff_ms(ast_tvnow(), ast_channel_creationtime(c)) / 1000);
+		if (!ast_tvzero(cs->creationtime)) {
+			duration = (int)(ast_tvdiff_ms(ast_tvnow(), cs->creationtime) / 1000);
 			durh = duration / 3600;
 			durm = (duration % 3600) / 60;
 			durs = duration % 60;
@@ -5256,15 +5253,18 @@
 			"AccountCode: %s\r\n"
 			"BridgedChannel: %s\r\n"
 			"BridgedUniqueID: %s\r\n"
-			"\r\n", idText, ast_channel_name(c), ast_channel_uniqueid(c), ast_channel_context(c), ast_channel_exten(c), ast_channel_priority(c), ast_channel_state(c),
-			ast_state2str(ast_channel_state(c)), ast_channel_appl(c) ? ast_channel_appl(c) : "", ast_channel_data(c) ? S_OR(ast_channel_data(c), "") : "",
-			S_COR(ast_channel_caller(c)->id.number.valid, ast_channel_caller(c)->id.number.str, ""),
-			S_COR(ast_channel_caller(c)->id.name.valid, ast_channel_caller(c)->id.name.str, ""),
-			S_COR(ast_channel_connected(c)->id.number.valid, ast_channel_connected(c)->id.number.str, ""),
-			S_COR(ast_channel_connected(c)->id.name.valid, ast_channel_connected(c)->id.name.str, ""),
-			durbuf, S_OR(ast_channel_accountcode(c), ""), bc ? ast_channel_name(bc) : "", bc ? ast_channel_uniqueid(bc) : "");
-
-		ast_channel_unlock(c);
+			"\r\n", idText, cs->name, cs->uniqueid, cs->context, cs->exten, cs->priority, cs->state,
+			ast_state2str(cs->state),
+			cs->appl,
+			cs->data,
+			cs->caller_number,
+			cs->caller_name,
+			cs->connected_number,
+			cs->connected_name,
+			durbuf, 
+			cs->accountcode, 
+			"",
+			cs->bridgeid);
 
 		numchans++;
 	}
@@ -5275,8 +5275,6 @@
 		"ListItems: %d\r\n"
 		"%s"
 		"\r\n", numchans, idText);
-
-	ast_channel_iterator_destroy(iter);
 
 	return 0;
 }

Modified: team/group/stasis_cache_usage/main/stasis_channels.c
URL: http://svnview.digium.com/svn/asterisk/team/group/stasis_cache_usage/main/stasis_channels.c?view=diff&rev=392699&r1=392698&r2=392699
==============================================================================
--- team/group/stasis_cache_usage/main/stasis_channels.c (original)
+++ team/group/stasis_cache_usage/main/stasis_channels.c Mon Jun 24 08:10:22 2013
@@ -36,6 +36,7 @@
 #include "asterisk/astobj2.h"
 #include "asterisk/stasis_channels.h"
 #include "asterisk/pbx.h"
+#include "asterisk/bridging.h"
 
 /*** DOCUMENTATION
 	<managerEvent language="en_US" name="VarSet">
@@ -127,6 +128,7 @@
 struct ast_channel_snapshot *ast_channel_snapshot_create(struct ast_channel *chan)
 {
 	RAII_VAR(struct ast_channel_snapshot *, snapshot, NULL, ao2_cleanup);
+	RAII_VAR(struct ast_bridge *, bridge, NULL, ao2_cleanup);
 
 	/* no snapshots for dummy channels */
 	if (!ast_channel_tech(chan)) {
@@ -179,6 +181,10 @@
 	ast_string_field_set(snapshot, connected_number,
 		S_COR(ast_channel_connected(chan)->id.number.valid, ast_channel_connected(chan)->id.number.str, ""));
 	ast_string_field_set(snapshot, language, ast_channel_language(chan));
+
+	if ((bridge = ast_channel_get_bridge(chan))) {
+		ast_string_field_set(snapshot, bridgeid, bridge->uniqueid);
+	}
 
 	snapshot->creationtime = ast_channel_creationtime(chan);
 	snapshot->state = ast_channel_state(chan);




More information about the asterisk-commits mailing list