[asterisk-commits] file: branch group/stasis_cache_usage r392827 - in /team/group/stasis_cache_u...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Tue Jun 25 07:36:09 CDT 2013
Author: file
Date: Tue Jun 25 07:36:06 2013
New Revision: 392827
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=392827
Log:
Add some more progress!
core show channel now pulls from the stasis cache
Modified:
team/group/stasis_cache_usage/include/asterisk/channel.h
team/group/stasis_cache_usage/include/asterisk/stasis_channels.h
team/group/stasis_cache_usage/main/channel.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/pbx.c
team/group/stasis_cache_usage/main/stasis_channels.c
team/group/stasis_cache_usage/res/res_agi.c
Modified: team/group/stasis_cache_usage/include/asterisk/channel.h
URL: http://svnview.digium.com/svn/asterisk/team/group/stasis_cache_usage/include/asterisk/channel.h?view=diff&rev=392827&r1=392826&r2=392827
==============================================================================
--- team/group/stasis_cache_usage/include/asterisk/channel.h (original)
+++ team/group/stasis_cache_usage/include/asterisk/channel.h Tue Jun 25 07:36:06 2013
@@ -4191,6 +4191,18 @@
/*!
* \since 12
+ * \brief Gets the variables for a given channel, as set using pbx_builtin_setvar_helper().
+ *
+ * The returned variable list is an AO2 object, so ao2_cleanup() to free it.
+ *
+ * \param chan Channel to get variables for
+ * \return List of channel variables.
+ * \return \c NULL on error
+ */
+struct varshead *ast_channel_get_vars(struct ast_channel *chan);
+
+/*!
+ * \since 12
* \brief A topic which publishes the events for a particular channel.
*
* If the given \a chan is \c NULL, ast_channel_topic_all() is returned.
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=392827&r1=392826&r2=392827
==============================================================================
--- team/group/stasis_cache_usage/include/asterisk/stasis_channels.h (original)
+++ team/group/stasis_cache_usage/include/asterisk/stasis_channels.h Tue Jun 25 07:36:06 2013
@@ -39,6 +39,7 @@
struct ast_channel_snapshot {
AST_DECLARE_STRING_FIELDS(
AST_STRING_FIELD(name); /*!< ASCII unique channel name */
+ AST_STRING_FIELD(type); /*!< Type of channel technology */
AST_STRING_FIELD(accountcode); /*!< Account code for billing */
AST_STRING_FIELD(peeraccount); /*!< Peer account code for billing */
AST_STRING_FIELD(userfield); /*!< Userfield for CEL billing */
@@ -59,18 +60,30 @@
AST_STRING_FIELD(dialed_subaddr); /*!< Dialed subaddress */
AST_STRING_FIELD(connected_name); /*!< Connected Line Name */
AST_STRING_FIELD(connected_number); /*!< Connected Line Number */
+ AST_STRING_FIELD(effective_name); /*!< Effective Connected Line Name */
+ AST_STRING_FIELD(effective_number); /*!< Effective Connected Line Number */
AST_STRING_FIELD(language); /*!< The default spoken language for the channel */
AST_STRING_FIELD(bridgeid); /*!< Unique Bridge Identifier */
+ AST_STRING_FIELD(nativeformats); /*!< Native formats on the channel */
+ AST_STRING_FIELD(readformat); /*!< The current read format */
+ AST_STRING_FIELD(writeformat); /*!< The current write format */
+ AST_STRING_FIELD(writetrans); /*!< The current write translation path */
+ AST_STRING_FIELD(readtrans); /*!< The current read translation path */
);
+ char callid[AST_CALLID_BUFFER_LENGTH]; /*!< Callid for the channel */
struct timeval creationtime; /*!< The time of channel creation */
+ struct timeval hanguptime; /*!< When the channel should hang up */
enum ast_channel_state state; /*!< State of line */
int priority; /*!< Dialplan: Current extension priority */
int amaflags; /*!< AMA flags for billing */
int hangupcause; /*!< Why is the channel hanged up. See causes.h */
int caller_pres; /*!< Caller ID presentation. */
struct ast_flags flags; /*!< channel flags of AST_FLAG_ type */
+ ast_group_t callgroup; /*!< Call group */
+ ast_group_t pickupgroup; /*!< Pickup group */
struct varshead *manager_vars; /*!< Variables to be appended to manager events */
+ struct varshead *channel_vars; /*!< Variables set on the channel */
};
/*!
Modified: team/group/stasis_cache_usage/main/channel.c
URL: http://svnview.digium.com/svn/asterisk/team/group/stasis_cache_usage/main/channel.c?view=diff&rev=392827&r1=392826&r2=392827
==============================================================================
--- team/group/stasis_cache_usage/main/channel.c (original)
+++ team/group/stasis_cache_usage/main/channel.c Tue Jun 25 07:36:06 2013
@@ -5345,6 +5345,9 @@
if (direction && ast_channel_generatordata(chan)) {
generator_write_format_change(chan);
}
+
+ ast_channel_publish_snapshot(chan);
+
return 0;
}
@@ -5417,6 +5420,9 @@
if (direction && ast_channel_generatordata(chan)) {
generator_write_format_change(chan);
}
+
+ ast_channel_publish_snapshot(chan);
+
return res;
}
@@ -7759,7 +7765,7 @@
}
/*!
- * \brief Destructor for the return value from ast_channel_get_manager_vars().
+ * \brief Destructor for lists of variables.
* \param obj AO2 object.
*/
static void varshead_dtor(void *obj)
@@ -7770,6 +7776,31 @@
while ((var = AST_RWLIST_REMOVE_HEAD(head, entries))) {
ast_var_delete(var);
}
+}
+
+struct varshead *ast_channel_get_vars(struct ast_channel *chan)
+{
+ RAII_VAR(struct varshead *, ret, NULL, ao2_cleanup);
+ struct ast_var_t *cv;
+
+ ret = ao2_alloc(sizeof(*ret), varshead_dtor);
+
+ if (!ret) {
+ return NULL;
+ }
+
+ AST_LIST_TRAVERSE(ast_channel_varshead(chan), cv, entries) {
+ struct ast_var_t *var = ast_var_assign(ast_var_name(cv), ast_var_value(cv));
+
+ if (!var) {
+ return NULL;
+ }
+
+ AST_LIST_INSERT_TAIL(ret, var, entries);
+ }
+
+ ao2_ref(ret, +1);
+ return ret;
}
struct varshead *ast_channel_get_manager_vars(struct ast_channel *chan)
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=392827&r1=392826&r2=392827
==============================================================================
--- team/group/stasis_cache_usage/main/channel_internal_api.c (original)
+++ team/group/stasis_cache_usage/main/channel_internal_api.c Tue Jun 25 07:36:06 2013
@@ -865,6 +865,7 @@
void ast_channel_tech_set(struct ast_channel *chan, const struct ast_channel_tech *value)
{
chan->tech = value;
+ ast_channel_publish_snapshot(chan);
}
enum ast_channel_adsicpe ast_channel_adsicpe(const struct ast_channel *chan)
{
@@ -910,6 +911,7 @@
call_identifier_to,
call_identifier_from);
+ ast_channel_publish_snapshot(chan);
}
void ast_channel_state_set(struct ast_channel *chan, enum ast_channel_state value)
{
@@ -1034,6 +1036,7 @@
void ast_channel_whentohangup_set(struct ast_channel *chan, struct timeval *value)
{
chan->whentohangup = *value;
+ ast_channel_publish_snapshot(chan);
}
void ast_channel_varshead_set(struct ast_channel *chan, struct varshead *value)
{
@@ -1091,6 +1094,7 @@
void ast_channel_callgroup_set(struct ast_channel *chan, ast_group_t value)
{
chan->callgroup = value;
+ ast_channel_publish_snapshot(chan);
}
ast_group_t ast_channel_pickupgroup(const struct ast_channel *chan)
{
@@ -1099,6 +1103,7 @@
void ast_channel_pickupgroup_set(struct ast_channel *chan, ast_group_t value)
{
chan->pickupgroup = value;
+ ast_channel_publish_snapshot(chan);
}
struct ast_namedgroups *ast_channel_named_callgroups(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=392827&r1=392826&r2=392827
==============================================================================
--- team/group/stasis_cache_usage/main/cli.c (original)
+++ team/group/stasis_cache_usage/main/cli.c Tue Jun 25 07:36:06 2013
@@ -1407,23 +1407,15 @@
static char *handle_showchan(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
- struct ast_channel *c=NULL;
+ RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);
+ struct ast_channel_snapshot *snapshot;
struct timeval now;
char cdrtime[256];
- char nf[256];
- struct ast_str *write_transpath = ast_str_alloca(256);
- struct ast_str *read_transpath = ast_str_alloca(256);
struct ast_str *obuf;/*!< Buffer for variable, CDR variable, and trace output. */
struct ast_str *output;/*!< Accumulation buffer for all output. */
long elapsed_seconds=0;
int hour=0, min=0, sec=0;
- struct ast_callid *callid;
- char call_identifier_str[AST_CALLID_BUFFER_LENGTH] = "";
- struct ast_party_id effective_connected_id;
-#ifdef CHANNEL_TRACE
- int trace_enabled;
-#endif
- struct ast_bridge *bridge;
+ struct ast_var_t *var;
switch (cmd) {
case CLI_INIT:
@@ -1442,10 +1434,11 @@
now = ast_tvnow();
- if (!(c = ast_channel_get_by_name(a->argv[3]))) {
+ if (!(msg = stasis_cache_get(ast_channel_topic_all_cached_by_name(), ast_channel_snapshot_type(), a->argv[3]))) {
ast_cli(a->fd, "%s is not a known channel\n", a->argv[3]);
return CLI_SUCCESS;
}
+ snapshot = stasis_message_data(msg);
obuf = ast_str_thread_get(&ast_str_thread_global_buf, 16);
if (!obuf) {
@@ -1456,10 +1449,8 @@
return CLI_FAILURE;
}
- ast_channel_lock(c);
-
- if (!ast_tvzero(ast_channel_creationtime(c))) {
- elapsed_seconds = now.tv_sec - ast_channel_creationtime(c).tv_sec;
+ if (!ast_tvzero(snapshot->creationtime)) {
+ elapsed_seconds = now.tv_sec - snapshot->creationtime.tv_sec;
hour = elapsed_seconds / 3600;
min = (elapsed_seconds % 3600) / 60;
sec = elapsed_seconds % 60;
@@ -1467,15 +1458,6 @@
} else {
strcpy(cdrtime, "N/A");
}
-
- /* Construct the call identifier string based on the status of the channel's call identifier */
- if ((callid = ast_channel_callid(c))) {
- ast_callid_strnprint(call_identifier_str, sizeof(call_identifier_str), callid);
- ast_callid_unref(callid);
- }
-
- effective_connected_id = ast_channel_connected_effective_id(c);
- bridge = ast_channel_get_bridge(c);
ast_str_append(&output, 0,
" -- General --\n"
@@ -1492,15 +1474,11 @@
" DNID Digits: %s\n"
" Language: %s\n"
" State: %s (%d)\n"
- " Rings: %d\n"
" NativeFormats: %s\n"
" WriteFormat: %s\n"
" ReadFormat: %s\n"
" WriteTranscode: %s %s\n"
" ReadTranscode: %s %s\n"
- "1st File Descriptor: %d\n"
- " Frames in: %d%s\n"
- " Frames out: %d%s\n"
" Time to Hangup: %ld\n"
" Elapsed Time: %s\n"
" Bridge ID: %s\n"
@@ -1512,68 +1490,45 @@
" Pickup Group: %llu\n"
" Application: %s\n"
" Data: %s\n"
- " Blocking in: %s\n"
" Call Identifer: %s\n",
- ast_channel_name(c),
- ast_channel_tech(c)->type,
- ast_channel_uniqueid(c),
- ast_channel_linkedid(c),
- S_COR(ast_channel_caller(c)->id.number.valid, ast_channel_caller(c)->id.number.str, "(N/A)"),
- S_COR(ast_channel_caller(c)->id.name.valid, ast_channel_caller(c)->id.name.str, "(N/A)"),
- S_COR(ast_channel_connected(c)->id.number.valid, ast_channel_connected(c)->id.number.str, "(N/A)"),
- S_COR(ast_channel_connected(c)->id.name.valid, ast_channel_connected(c)->id.name.str, "(N/A)"),
- S_COR(effective_connected_id.number.valid, effective_connected_id.number.str, "(N/A)"),
- S_COR(effective_connected_id.name.valid, effective_connected_id.name.str, "(N/A)"),
- S_OR(ast_channel_dialed(c)->number.str, "(N/A)"),
- ast_channel_language(c),
- ast_state2str(ast_channel_state(c)),
- ast_channel_state(c),
- ast_channel_rings(c),
- ast_getformatname_multiple(nf, sizeof(nf), ast_channel_nativeformats(c)),
- ast_getformatname(ast_channel_writeformat(c)),
- ast_getformatname(ast_channel_readformat(c)),
- ast_channel_writetrans(c) ? "Yes" : "No",
- ast_translate_path_to_str(ast_channel_writetrans(c), &write_transpath),
- ast_channel_readtrans(c) ? "Yes" : "No",
- ast_translate_path_to_str(ast_channel_readtrans(c), &read_transpath),
- ast_channel_fd(c, 0),
- ast_channel_fin(c) & ~DEBUGCHAN_FLAG,
- (ast_channel_fin(c) & DEBUGCHAN_FLAG) ? " (DEBUGGED)" : "",
- ast_channel_fout(c) & ~DEBUGCHAN_FLAG,
- (ast_channel_fout(c) & DEBUGCHAN_FLAG) ? " (DEBUGGED)" : "",
- (long) ast_channel_whentohangup(c)->tv_sec,
+ snapshot->name,
+ snapshot->type,
+ snapshot->uniqueid,
+ snapshot->linkedid,
+ S_OR(snapshot->caller_number, "(N/A)"),
+ S_OR(snapshot->caller_name, "(N/A)"),
+ S_OR(snapshot->connected_number, "(N/A)"),
+ S_OR(snapshot->connected_name, "(N/A)"),
+ S_OR(snapshot->effective_number, "(N/A)"),
+ S_OR(snapshot->effective_name, "(N/A)"),
+ S_OR(snapshot->caller_dnid, "(N/A)"),
+ snapshot->language,
+ ast_state2str(snapshot->state),
+ snapshot->state,
+ snapshot->nativeformats,
+ snapshot->writeformat,
+ snapshot->readformat,
+ !ast_strlen_zero(snapshot->writetrans) ? "Yes" : "No",
+ snapshot->writetrans,
+ !ast_strlen_zero(snapshot->readtrans) ? "Yes" : "No",
+ snapshot->readtrans,
+ (long) snapshot->hanguptime.tv_sec,
cdrtime,
- bridge ? bridge->uniqueid : "(Not bridged)",
- ast_channel_context(c),
- ast_channel_exten(c),
- ast_channel_priority(c),
- ast_channel_callgroup(c),
- ast_channel_pickupgroup(c),
- (ast_channel_appl(c) ? ast_channel_appl(c) : "(N/A)" ),
- (ast_channel_data(c) ? S_OR(ast_channel_data(c), "(Empty)") : "(None)"),
- (ast_test_flag(ast_channel_flags(c), AST_FLAG_BLOCKING) ? ast_channel_blockproc(c) : "(Not Blocking)"),
- S_OR(call_identifier_str, "(None)"));
-
- if (pbx_builtin_serialize_variables(c, &obuf)) {
- ast_str_append(&output, 0, " Variables:\n%s\n", ast_str_buffer(obuf));
- }
-
- if (ast_cdr_serialize_variables(ast_channel_name(c), &obuf, '=', '\n')) {
- ast_str_append(&output, 0, " CDR Variables:\n%s\n", ast_str_buffer(obuf));
- }
-
-#ifdef CHANNEL_TRACE
- trace_enabled = ast_channel_trace_is_enabled(c);
- ast_str_append(&output, 0, " Context Trace: %s\n",
- trace_enabled ? "Enabled" : "Disabled");
- if (trace_enabled && ast_channel_trace_serialize(c, &obuf)) {
- ast_str_append(&output, 0, " Trace:\n%s\n", ast_str_buffer(obuf));
- }
-#endif
-
- ast_channel_unlock(c);
- c = ast_channel_unref(c);
- ao2_cleanup(bridge);
+ S_OR(snapshot->bridgeid, "(Not bridged)"),
+ snapshot->context,
+ snapshot->exten,
+ snapshot->priority,
+ snapshot->callgroup,
+ snapshot->pickupgroup,
+ S_OR(snapshot->appl, "(N/A)"),
+ S_OR(snapshot->data, "(Empty)"),
+ S_OR(snapshot->callid, "(None)"));
+
+ ast_str_append(&output, 0, " Variables:\n");
+
+ AST_LIST_TRAVERSE(snapshot->channel_vars, var, entries) {
+ ast_str_append(&output, 0, "%s=%s\n", ast_var_name(var), ast_var_value(var));
+ }
ast_cli(a->fd, "%s", ast_str_buffer(output));
ast_free(output);
Modified: team/group/stasis_cache_usage/main/pbx.c
URL: http://svnview.digium.com/svn/asterisk/team/group/stasis_cache_usage/main/pbx.c?view=diff&rev=392827&r1=392826&r2=392827
==============================================================================
--- team/group/stasis_cache_usage/main/pbx.c (original)
+++ team/group/stasis_cache_usage/main/pbx.c Tue Jun 25 07:36:06 2013
@@ -10983,6 +10983,10 @@
newvariable = ast_var_assign(name, value);
AST_LIST_INSERT_HEAD(headp, newvariable, entries);
ast_channel_publish_varset(chan, name, value);
+
+ if (headp != &globals) {
+ ast_channel_publish_snapshot(chan);
+ }
}
if (chan)
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=392827&r1=392826&r2=392827
==============================================================================
--- team/group/stasis_cache_usage/main/stasis_channels.c (original)
+++ team/group/stasis_cache_usage/main/stasis_channels.c Tue Jun 25 07:36:06 2013
@@ -37,6 +37,7 @@
#include "asterisk/stasis_channels.h"
#include "asterisk/pbx.h"
#include "asterisk/bridging.h"
+#include "asterisk/translate.h"
/*** DOCUMENTATION
<managerEvent language="en_US" name="VarSet">
@@ -121,14 +122,21 @@
static void channel_snapshot_dtor(void *obj)
{
struct ast_channel_snapshot *snapshot = obj;
+
ast_string_field_free_memory(snapshot);
ao2_cleanup(snapshot->manager_vars);
+ ao2_cleanup(snapshot->channel_vars);
}
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);
+ char nativeformats[256];
+ struct ast_str *write_transpath = ast_str_alloca(256);
+ struct ast_str *read_transpath = ast_str_alloca(256);
+ struct ast_party_id effective_connected_id;
+ struct ast_callid *callid;
/* no snapshots for dummy channels */
if (!ast_channel_tech(chan)) {
@@ -141,6 +149,7 @@
}
ast_string_field_set(snapshot, name, ast_channel_name(chan));
+ ast_string_field_set(snapshot, type, ast_channel_tech(chan)->type);
ast_string_field_set(snapshot, accountcode, ast_channel_accountcode(chan));
ast_string_field_set(snapshot, peeraccount, ast_channel_peeraccount(chan));
ast_string_field_set(snapshot, userfield, ast_channel_userfield(chan));
@@ -186,15 +195,37 @@
ast_string_field_set(snapshot, bridgeid, bridge->uniqueid);
}
+ ast_string_field_set(snapshot, nativeformats, ast_getformatname_multiple(nativeformats, sizeof(nativeformats),
+ ast_channel_nativeformats(chan)));
+ ast_string_field_set(snapshot, readformat, ast_getformatname(ast_channel_readformat(chan)));
+ ast_string_field_set(snapshot, writeformat, ast_getformatname(ast_channel_writeformat(chan)));
+ ast_string_field_set(snapshot, writetrans, ast_translate_path_to_str(ast_channel_writetrans(chan), &write_transpath));
+ ast_string_field_set(snapshot, readtrans, ast_translate_path_to_str(ast_channel_readtrans(chan), &read_transpath));
+
+ effective_connected_id = ast_channel_connected_effective_id(chan);
+ ast_string_field_set(snapshot, effective_name,
+ S_COR(effective_connected_id.name.valid, effective_connected_id.name.str, ""));
+ ast_string_field_set(snapshot, effective_number,
+ S_COR(effective_connected_id.number.valid, effective_connected_id.number.str, ""));
+
+ if ((callid = ast_channel_callid(chan))) {
+ ast_callid_strnprint(snapshot->callid, sizeof(snapshot->callid), callid);
+ ast_callid_unref(callid);
+ }
+
snapshot->creationtime = ast_channel_creationtime(chan);
+ snapshot->hanguptime = *(ast_channel_whentohangup(chan));
snapshot->state = ast_channel_state(chan);
snapshot->priority = ast_channel_priority(chan);
snapshot->amaflags = ast_channel_amaflags(chan);
snapshot->hangupcause = ast_channel_hangupcause(chan);
snapshot->flags = *ast_channel_flags(chan);
snapshot->caller_pres = ast_party_id_presentation(&ast_channel_caller(chan)->id);
+ snapshot->callgroup = ast_channel_callgroup(chan);
+ snapshot->pickupgroup = ast_channel_pickupgroup(chan);
snapshot->manager_vars = ast_channel_get_manager_vars(chan);
+ snapshot->channel_vars = ast_channel_get_vars(chan);
ao2_ref(snapshot, +1);
return snapshot;
Modified: team/group/stasis_cache_usage/res/res_agi.c
URL: http://svnview.digium.com/svn/asterisk/team/group/stasis_cache_usage/res/res_agi.c?view=diff&rev=392827&r1=392826&r2=392827
==============================================================================
--- team/group/stasis_cache_usage/res/res_agi.c (original)
+++ team/group/stasis_cache_usage/res/res_agi.c Tue Jun 25 07:36:06 2013
@@ -2759,16 +2759,18 @@
static int handle_channelstatus(struct ast_channel *chan, AGI *agi, int argc, const char * const argv[])
{
- struct ast_channel *c;
if (argc == 2) {
/* no argument: supply info on the current channel */
ast_agi_send(agi->fd, chan, "200 result=%d\n", ast_channel_state(chan));
return RESULT_SUCCESS;
} else if (argc == 3) {
+ RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);
+
/* one argument: look for info on the specified channel */
- if ((c = ast_channel_get_by_name(argv[2]))) {
- ast_agi_send(agi->fd, chan, "200 result=%d\n", ast_channel_state(c));
- c = ast_channel_unref(c);
+ if ((msg = stasis_cache_get(ast_channel_topic_all_cached_by_name(), ast_channel_snapshot_type(), argv[2]))) {
+ struct ast_channel_snapshot *snapshot = stasis_message_data(msg);
+
+ ast_agi_send(agi->fd, chan, "200 result=%d\n", snapshot->state);
return RESULT_SUCCESS;
}
/* if we get this far no channel name matched the argument given */
More information about the asterisk-commits
mailing list