- use symbolic constants and macros to play with the debug flag

on the frame counters. Document it in the header file.
- provide a single exit point for a function;
- mark XXX some unclear parts of the code.



git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@21933 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
Luigi Rizzo
2006-04-21 14:49:21 +00:00
parent e61e34e8a1
commit 0dbf814a79
4 changed files with 25 additions and 26 deletions

View File

@@ -114,8 +114,8 @@ static int ast_serialize_showchan(struct ast_channel *c, char *buf, size_t size)
c->nativeformats, c->nativeformats,
c->writeformat, c->writeformat,
c->readformat, c->readformat,
c->fds[0], c->fin & 0x7fffffff, (c->fin & 0x80000000) ? " (DEBUGGED)" : "", c->fds[0], c->fin & ~DEBUGCHAN_FLAG, (c->fin & DEBUGCHAN_FLAG) ? " (DEBUGGED)" : "",
c->fout & 0x7fffffff, (c->fout & 0x80000000) ? " (DEBUGGED)" : "", (long)c->whentohangup, c->fout & ~DEBUGCHAN_FLAG, (c->fout & DEBUGCHAN_FLAG) ? " (DEBUGGED)" : "", (long)c->whentohangup,
hour, hour,
min, min,
sec, sec,

View File

@@ -2049,12 +2049,9 @@ static struct ast_frame *__ast_read(struct ast_channel *chan, int dropaudio)
} }
/* High bit prints debugging */ /* High bit prints debugging */
if (chan->fin & 0x80000000) if (chan->fin & DEBUGCHAN_FLAG)
ast_frame_dump(chan->name, f, "<<"); ast_frame_dump(chan->name, f, "<<");
if ((chan->fin & 0x7fffffff) == 0x7fffffff) chan->fin = FRAMECOUNT_INC(chan->fin);
chan->fin &= 0x80000000;
else
chan->fin++;
done: done:
ast_mutex_unlock(&chan->lock); ast_mutex_unlock(&chan->lock);
@@ -2272,30 +2269,28 @@ int ast_write(struct ast_channel *chan, struct ast_frame *fr)
/* Stop if we're a zombie or need a soft hangup */ /* Stop if we're a zombie or need a soft hangup */
ast_channel_lock(chan); ast_channel_lock(chan);
if (ast_test_flag(chan, AST_FLAG_ZOMBIE) || ast_check_hangup(chan)) { if (ast_test_flag(chan, AST_FLAG_ZOMBIE) || ast_check_hangup(chan))
ast_channel_unlock(chan); goto done;
return -1;
}
/* Handle any pending masquerades */ /* Handle any pending masquerades */
if (chan->masq && ast_do_masquerade(chan)) { if (chan->masq && ast_do_masquerade(chan)) {
ast_log(LOG_WARNING, "Failed to perform masquerade\n"); ast_log(LOG_WARNING, "Failed to perform masquerade\n");
ast_channel_unlock(chan); goto done;
return -1;
} }
if (chan->masqr) { if (chan->masqr) {
ast_channel_unlock(chan); res = 0; /* XXX explain, why 0 ? */
return 0; goto done;
} }
if (chan->generatordata) { if (chan->generatordata) {
if (ast_test_flag(chan, AST_FLAG_WRITE_INT)) if (ast_test_flag(chan, AST_FLAG_WRITE_INT))
ast_deactivate_generator(chan); ast_deactivate_generator(chan);
else { else {
ast_channel_unlock(chan); res = 0; /* XXX explain, why 0 ? */
return 0; goto done;
} }
} }
/* High bit prints debugging */ /* High bit prints debugging */
if (chan->fout & 0x80000000) if (chan->fout & DEBUGCHAN_FLAG)
ast_frame_dump(chan->name, fr, ">>"); ast_frame_dump(chan->name, fr, ">>");
CHECK_BLOCKING(chan); CHECK_BLOCKING(chan);
switch(fr->frametype) { switch(fr->frametype) {
@@ -2348,6 +2343,7 @@ int ast_write(struct ast_channel *chan, struct ast_frame *fr)
queue_frame_to_spies(chan, f, SPY_WRITE); queue_frame_to_spies(chan, f, SPY_WRITE);
if (chan->monitor && chan->monitor->write_stream) { if (chan->monitor && chan->monitor->write_stream) {
/* XXX must explain this code */
#ifndef MONITOR_CONSTANT_DELAY #ifndef MONITOR_CONSTANT_DELAY
int jump = chan->insmpl - chan->outsmpl - 4 * f->samples; int jump = chan->insmpl - chan->outsmpl - 4 * f->samples;
if (jump >= 0) { if (jump >= 0) {
@@ -2383,11 +2379,9 @@ int ast_write(struct ast_channel *chan, struct ast_frame *fr)
if (res < 0) if (res < 0)
chan->_softhangup |= AST_SOFTHANGUP_DEV; chan->_softhangup |= AST_SOFTHANGUP_DEV;
else { else {
if ((chan->fout & 0x7fffffff) == 0x7fffffff) chan->fout = FRAMECOUNT_INC(chan->fout);
chan->fout &= 0x80000000;
else
chan->fout++;
} }
done:
ast_channel_unlock(chan); ast_channel_unlock(chan);
return res; return res;
} }

7
cli.c
View File

@@ -626,7 +626,6 @@ static int handle_debuglevel(int fd, int argc, char *argv[])
return RESULT_SUCCESS; return RESULT_SUCCESS;
} }
#define DEBUGCHAN_FLAG 0x80000000
/* XXX todo: merge next two functions!!! */ /* XXX todo: merge next two functions!!! */
static int handle_debugchan(int fd, int argc, char *argv[]) static int handle_debugchan(int fd, int argc, char *argv[])
{ {
@@ -756,8 +755,10 @@ static int handle_showchan(int fd, int argc, char *argv[])
ast_getformatname_multiple(nf, sizeof(nf), c->nativeformats), ast_getformatname_multiple(nf, sizeof(nf), c->nativeformats),
ast_getformatname_multiple(wf, sizeof(wf), c->writeformat), ast_getformatname_multiple(wf, sizeof(wf), c->writeformat),
ast_getformatname_multiple(rf, sizeof(rf), c->readformat), ast_getformatname_multiple(rf, sizeof(rf), c->readformat),
c->fds[0], c->fin & 0x7fffffff, (c->fin & 0x80000000) ? " (DEBUGGED)" : "", c->fds[0],
c->fout & 0x7fffffff, (c->fout & 0x80000000) ? " (DEBUGGED)" : "", (long)c->whentohangup, c->fin & ~DEBUGCHAN_FLAG, (c->fin & DEBUGCHAN_FLAG) ? " (DEBUGGED)" : "",
c->fout & ~DEBUGCHAN_FLAG, (c->fout & DEBUGCHAN_FLAG) ? " (DEBUGGED)" : "",
(long)c->whentohangup,
cdrtime, c->_bridge ? c->_bridge->name : "<none>", ast_bridged_channel(c) ? ast_bridged_channel(c)->name : "<none>", cdrtime, c->_bridge ? c->_bridge->name : "<none>", ast_bridged_channel(c) ? ast_bridged_channel(c)->name : "<none>",
c->context, c->exten, c->priority, c->callgroup, c->pickupgroup, ( c->appl ? c->appl : "(N/A)" ), c->context, c->exten, c->priority, c->callgroup, c->pickupgroup, ( c->appl ? c->appl : "(N/A)" ),
( c-> data ? S_OR(c->data, "(Empty)") : "(None)"), ( c-> data ? S_OR(c->data, "(Empty)") : "(None)"),

View File

@@ -403,9 +403,13 @@ struct ast_channel {
unsigned long insmpl; unsigned long insmpl;
unsigned long outsmpl; unsigned long outsmpl;
/* Frames in/out counters */ /* Frames in/out counters. The high bit is a debug mask, so
* the counter is only in the remaining bits
*/
unsigned int fin; unsigned int fin;
unsigned int fout; unsigned int fout;
#define DEBUGCHAN_FLAG 0x80000000
#define FRAMECOUNT_INC(x) ( ((x) & DEBUGCHAN_FLAG) | ((x++) & ~DEBUGCHAN_FLAG) )
/* Why is the channel hanged up */ /* Why is the channel hanged up */
int hangupcause; int hangupcause;