[asterisk-commits] file: branch group/stasis_cache_usage r392846 - /team/group/stasis_cache_usag...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Tue Jun 25 09:03:54 CDT 2013
Author: file
Date: Tue Jun 25 09:03:52 2013
New Revision: 392846
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=392846
Log:
Yet another move over to hitting stasis cache (except where it isn't completely possible)
Modified:
team/group/stasis_cache_usage/main/manager.c
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=392846&r1=392845&r2=392846
==============================================================================
--- team/group/stasis_cache_usage/main/manager.c (original)
+++ team/group/stasis_cache_usage/main/manager.c Tue Jun 25 09:03:52 2013
@@ -3691,9 +3691,8 @@
const char *name = astman_get_header(m, "Channel");
const char *cvariables = astman_get_header(m, "Variables");
char *variables = ast_strdupa(S_OR(cvariables, ""));
- struct ast_channel *c;
- struct ast_bridge *bridge;
- char bridge_text[256];
+ RAII_VAR(struct ao2_container *, cached_channels, NULL, ao2_cleanup);
+ struct stasis_message *msg;
struct timeval now = ast_tvnow();
long elapsed_seconds = 0;
int channels = 0;
@@ -3704,7 +3703,7 @@
AST_APP_ARG(name)[100];
);
struct ast_str *str = ast_str_create(1000);
- struct ast_channel_iterator *iter = NULL;
+ struct ao2_iterator it_chans;
if (!ast_strlen_zero(id)) {
snprintf(idText, sizeof(idText), "ActionID: %s\r\n", id);
@@ -3718,14 +3717,15 @@
}
if (all) {
- if (!(iter = ast_channel_iterator_all_new())) {
+ if (!(cached_channels = stasis_cache_dump(ast_channel_topic_all_cached_by_name(), ast_channel_snapshot_type()))) {
ast_free(str);
astman_send_error(s, m, "Memory Allocation Failure");
return 1;
}
- c = ast_channel_iterator_next(iter);
+ it_chans = ao2_iterator_init(cached_channels, 0);
+ msg = ao2_iterator_next(&it_chans);
} else {
- if (!(c = ast_channel_get_by_name(name))) {
+ if (!(msg = stasis_cache_get(ast_channel_topic_all_cached_by_name(), ast_channel_snapshot_type(), name))) {
astman_send_error(s, m, "No such channel");
ast_free(str);
return 0;
@@ -3739,10 +3739,11 @@
}
/* if we look by name, we break after the first iteration */
- for (; c; c = ast_channel_iterator_next(iter)) {
- ast_channel_lock(c);
-
- if (!ast_strlen_zero(cvariables)) {
+ for (; msg; msg = ao2_iterator_next(&it_chans)) {
+ struct ast_channel_snapshot *snapshot = stasis_message_data(msg);
+ struct ast_channel *c;
+
+ if (!ast_strlen_zero(cvariables) && (c = ast_channel_get_by_name(snapshot->name))) {
int i;
ast_str_reset(str);
for (i = 0; i < vars.argc; i++) {
@@ -3759,94 +3760,56 @@
ast_str_append(&str, 0, "Variable: %s=%s\r\n", vars.name[i], ret);
}
+ ast_channel_unref(c);
}
channels++;
- bridge = ast_channel_get_bridge(c);
- if (bridge) {
- snprintf(bridge_text, sizeof(bridge_text), "BridgeID: %s\r\n",
- bridge->uniqueid);
- ao2_ref(bridge, -1);
- } else {
- bridge_text[0] = '\0';
- }
- if (ast_channel_pbx(c)) {
- if (!ast_tvzero(ast_channel_creationtime(c))) {
- elapsed_seconds = now.tv_sec - ast_channel_creationtime(c).tv_sec;
- }
- astman_append(s,
- "Event: Status\r\n"
- "Privilege: Call\r\n"
- "Channel: %s\r\n"
- "CallerIDNum: %s\r\n"
- "CallerIDName: %s\r\n"
- "ConnectedLineNum: %s\r\n"
- "ConnectedLineName: %s\r\n"
- "Accountcode: %s\r\n"
- "ChannelState: %d\r\n"
- "ChannelStateDesc: %s\r\n"
- "Context: %s\r\n"
- "Extension: %s\r\n"
- "Priority: %d\r\n"
- "Seconds: %ld\r\n"
- "%s"
- "Uniqueid: %s\r\n"
- "%s"
- "%s"
- "\r\n",
- ast_channel_name(c),
- S_COR(ast_channel_caller(c)->id.number.valid, ast_channel_caller(c)->id.number.str, "<unknown>"),
- S_COR(ast_channel_caller(c)->id.name.valid, ast_channel_caller(c)->id.name.str, "<unknown>"),
- S_COR(ast_channel_connected(c)->id.number.valid, ast_channel_connected(c)->id.number.str, "<unknown>"),
- S_COR(ast_channel_connected(c)->id.name.valid, ast_channel_connected(c)->id.name.str, "<unknown>"),
- ast_channel_accountcode(c),
- ast_channel_state(c),
- ast_state2str(ast_channel_state(c)),
- ast_channel_context(c), ast_channel_exten(c), ast_channel_priority(c),
- (long) elapsed_seconds,
- bridge_text,
- ast_channel_uniqueid(c),
- ast_str_buffer(str),
- idText);
- } else {
- astman_append(s,
- "Event: Status\r\n"
- "Privilege: Call\r\n"
- "Channel: %s\r\n"
- "CallerIDNum: %s\r\n"
- "CallerIDName: %s\r\n"
- "ConnectedLineNum: %s\r\n"
- "ConnectedLineName: %s\r\n"
- "Account: %s\r\n"
- "State: %s\r\n"
- "%s"
- "Uniqueid: %s\r\n"
- "%s"
- "%s"
- "\r\n",
- ast_channel_name(c),
- S_COR(ast_channel_caller(c)->id.number.valid, ast_channel_caller(c)->id.number.str, "<unknown>"),
- S_COR(ast_channel_caller(c)->id.name.valid, ast_channel_caller(c)->id.name.str, "<unknown>"),
- S_COR(ast_channel_connected(c)->id.number.valid, ast_channel_connected(c)->id.number.str, "<unknown>"),
- S_COR(ast_channel_connected(c)->id.name.valid, ast_channel_connected(c)->id.name.str, "<unknown>"),
- ast_channel_accountcode(c),
- ast_state2str(ast_channel_state(c)),
- bridge_text,
- ast_channel_uniqueid(c),
- ast_str_buffer(str),
- idText);
- }
-
- ast_channel_unlock(c);
- c = ast_channel_unref(c);
+
+ if (!ast_tvzero(snapshot->creationtime)) {
+ elapsed_seconds = now.tv_sec - snapshot->creationtime.tv_sec;
+ }
+ astman_append(s,
+ "Event: Status\r\n"
+ "Privilege: Call\r\n"
+ "Channel: %s\r\n"
+ "CallerIDNum: %s\r\n"
+ "CallerIDName: %s\r\n"
+ "ConnectedLineNum: %s\r\n"
+ "ConnectedLineName: %s\r\n"
+ "Accountcode: %s\r\n"
+ "ChannelState: %d\r\n"
+ "ChannelStateDesc: %s\r\n"
+ "Context: %s\r\n"
+ "Extension: %s\r\n"
+ "Priority: %d\r\n"
+ "Seconds: %ld\r\n"
+ "%s"
+ "Uniqueid: %s\r\n"
+ "%s"
+ "%s"
+ "\r\n",
+ snapshot->name,
+ S_OR(snapshot->caller_number, "<unknown>"),
+ S_OR(snapshot->caller_name, "<unknown>"),
+ S_OR(snapshot->connected_number, "<unknown>"),
+ S_OR(snapshot->connected_name, "<unknown>"),
+ snapshot->accountcode,
+ snapshot->state,
+ ast_state2str(snapshot->state),
+ snapshot->context, snapshot->exten, snapshot->priority,
+ (long) elapsed_seconds,
+ snapshot->bridgeid,
+ snapshot->uniqueid,
+ ast_str_buffer(str),
+ idText);
if (!all) {
break;
}
}
- if (iter) {
- ast_channel_iterator_destroy(iter);
+ if (all) {
+ ao2_iterator_destroy(&it_chans);
}
astman_append(s,
More information about the asterisk-commits
mailing list