Changed error reporting.

git-svn-id: http://yate.null.ro/svn/yate/trunk@534 acf43c95-373e-0410-b603-e72c3f656dc1
This commit is contained in:
paulc 2005-10-03 13:59:42 +00:00
parent 041dfbd65d
commit 95238d119d
2 changed files with 54 additions and 32 deletions

View File

@ -385,7 +385,7 @@ void PriSpan::handleEvent(pri_event &ev)
{
switch (ev.e) {
case PRI_EVENT_DCHAN_UP:
Debug(DebugInfo,"D-channel up on span %d",m_span);
Debug(DebugMild,"D-channel up on span %d",m_span);
m_ok = true;
m_restart = Time::now() + 1000000;
{
@ -676,8 +676,8 @@ const char *PriChan::chanStatus() const
void PriChan::idle()
{
if (m_timeout && (Time::now() > m_timeout)) {
Debug("PriChan",DebugWarn,"Timeout %s channel %s (%d/%d)",
chanStatus(),id().c_str(),m_chan,m_span->span());
Debug("PriChan",DebugWarn,"Timeout %s channel %s (%s)",
chanStatus(),id().c_str(),address().c_str());
m_timeout = 0;
hangup(PRI_CAUSE_RECOVERY_ON_TIMER_EXPIRE);
}
@ -702,14 +702,14 @@ void PriChan::closeData()
bool PriChan::answer()
{
if (!m_ring) {
Debug("PriChan",DebugWarn,"Answer request on %s channel %d on span %d",
chanStatus(),m_chan,m_span->span());
Debug("PriChan",DebugWarn,"Answer request on %s channel %s (%s)",
chanStatus(),id().c_str(),address().c_str());
return false;
}
m_ring = false;
m_timeout = 0;
status(chanStatus());
Debug(this,DebugInfo,"Answering on %s (%d/%d)",id().c_str(),m_span->span(),m_chan);
Debug(this,DebugInfo,"Answering on %s (%s)",id().c_str(),address().c_str());
::pri_answer(m_span->pri(),(q931_call*)m_call,m_chan,!m_isdn);
return true;
}
@ -725,8 +725,8 @@ void PriChan::hangup(int cause)
cause = PRI_CAUSE_INVALID_MSG_UNSPECIFIED;
const char *reason = pri_cause2str(cause);
if (inUse())
Debug(this,DebugInfo,"Hanging up %s in state %s: %s (%d)",
id().c_str(),chanStatus(),reason,cause);
Debug(this,DebugInfo,"Hanging up %s (%s) in state %s: %s (%d)",
id().c_str(),address().c_str(),chanStatus(),reason,cause);
m_timeout = 0;
m_targetid.clear();
disconnect(reason);
@ -748,13 +748,13 @@ void PriChan::hangup(int cause)
void PriChan::answered()
{
if (!m_call) {
Debug("PriChan",DebugWarn,"Answer detected on %s %s channel %d on span %d",
chanStatus(),id().c_str(),m_chan,m_span->span());
Debug("PriChan",DebugWarn,"Answer detected on %s channel %s (%s)",
chanStatus(),id().c_str(),address().c_str());
return;
}
m_timeout = 0;
status(chanStatus());
Debug(this,DebugInfo,"Remote answered on %s (%d/%d)",id().c_str(),m_span->span(),m_chan);
Debug(this,DebugInfo,"Remote answered on %s (%s)",id().c_str(),address().c_str());
Message *m = message("call.answered");
m->addParam("span",String(m_span->span()));
m->addParam("channel",String(m_chan));
@ -764,8 +764,8 @@ void PriChan::answered()
void PriChan::gotDigits(const char *digits, bool overlapped)
{
if (null(digits)) {
Debug(this,DebugMild,"Received empty digits string in mode %s channel %s (%d/%d)",
(overlapped ? "overlapped" : "keypad"),id().c_str(),m_span->span(),m_chan);
Debug(this,DebugMild,"Received empty digits string in mode %s channel %s (%s)",
(overlapped ? "overlapped" : "keypad"),id().c_str(),address().c_str());
return;
}
Message *m = message("chan.dtmf");
@ -786,7 +786,7 @@ void PriChan::sendDigit(char digit)
bool PriChan::call(Message &msg, const char *called)
{
if (m_span->outOfOrder()) {
Debug("PriChan",DebugInfo,"Span %d is out of order, failing call",m_span->span());
Debug("PriChan",DebugMild,"Span %d is out of order, failing call",m_span->span());
msg.setParam("error","offline");
return false;
}
@ -808,7 +808,8 @@ bool PriChan::call(Message &msg, const char *called)
else
msg.userData(this);
m_inband = msg.getBoolValue("dtmfinband",m_span->inband());
Output("Calling '%s' on %s (%d/%d)",called,id().c_str(),m_span->span(),m_chan);
Output("Calling '%s' on %s (%s)",
called,id().c_str(),address().c_str());
char *caller = (char *)msg.getValue("caller");
int callerplan = msg.getIntValue("callerplan",dict_str2dplan,m_span->dplan());
char *callername = (char *)msg.getValue("callername");
@ -974,9 +975,8 @@ bool PriDriver::msgExecute(Message& msg, String& dest)
c = findFree(chan.toInteger(-1));
if (c) {
Debug(this,DebugInfo,"Will call '%s' on chan %s (%d) (%d/%d)",
num.c_str(),c->id().c_str(),c->absChan(),
c->span()->span(),c->chan());
Debug(this,DebugInfo,"Will call '%s' on chan %s (%s)",
num.c_str(),c->id().c_str(),c->address().c_str());
return c->call(msg,num);
}
else {

View File

@ -107,7 +107,7 @@ private:
class WpData : public Thread
{
public:
WpData(WpSpan* span, const char* card, const char* device);
WpData(WpSpan* span, const char* card, const char* device, Configuration& cfg, const String& sect);
~WpData();
virtual void run();
private:
@ -115,6 +115,9 @@ private:
HANDLE m_fd;
unsigned char* m_buffer;
WpChan **m_chans;
int m_samples;
unsigned char m_rdError;
unsigned char m_wrError;
};
class WpDriver : public PriDriver
@ -132,6 +135,7 @@ public:
INIT_PLUGIN(WpDriver);
#define WP_HEADER 16
#define MAX_DATA_ERRORS 250
static int wp_recv(HANDLE fd, void *buf, int buflen, int flags = 0)
{
@ -322,15 +326,19 @@ void WpConsumer::Consume(const DataBlock &data, unsigned long tStamp)
put(buf[i]);
}
WpData::WpData(WpSpan* span, const char* card, const char* device)
: Thread("WpData"), m_span(span), m_fd(INVALID_HANDLE_VALUE), m_buffer(0), m_chans(0)
WpData::WpData(WpSpan* span, const char* card, const char* device, Configuration& cfg, const String& sect)
: Thread("WpData"), m_span(span), m_fd(INVALID_HANDLE_VALUE),
m_buffer(0), m_chans(0), m_samples(50), m_rdError(0), m_wrError(0)
{
Debug(&__plugin,DebugAll,"WpData::WpData(%p) [%p]",span,this);
Debug(&__plugin,DebugAll,"WpData::WpData(%p,'%s','%s') [%p]",
span,card,device,this);
HANDLE fd = wp_open(card,device);
if (fd != INVALID_HANDLE_VALUE) {
m_fd = fd;
m_span->m_data = this;
}
m_samples = cfg.getIntValue("general","samples",m_samples);
m_samples = cfg.getIntValue(sect,"samples",m_samples);
}
WpData::~WpData()
@ -348,9 +356,8 @@ WpData::~WpData()
void WpData::run()
{
Debug(&__plugin,DebugAll,"WpData::run() [%p]",this);
int samp = 50;
int bchans = m_span->bchans();
int buflen = samp*bchans;
int buflen = m_samples*bchans;
int sz = buflen+WP_HEADER;
m_buffer = (unsigned char*)::malloc(sz);
// Build a compacted list of allocated B channels
@ -365,13 +372,14 @@ void WpData::run()
while (m_span && (m_fd >= 0)) {
Thread::check();
bool oob = false;
bool rd = wp_select(m_fd,samp,&oob);
bool rd = wp_select(m_fd,m_samples,&oob);
if (oob) {
XDebug("wpdata_recv_oob",DebugAll,"pre buf=%p len=%d sz=%d",m_buffer,buflen,sz);
int r = wp_recv(m_fd,m_buffer,sz,MSG_OOB);
XDebug("wpdata_recv_oob",DebugAll,"post r=%d",r);
if (r > 0)
Debug("wpdata_recv_oob",DebugInfo,"Read %d bytes of OOB data",r);
Debug(&__plugin,DebugInfo,"Read %d bytes of OOB data on span %d [%p]",
r,m_span->span(),this);
}
if (rd) {
@ -380,8 +388,15 @@ void WpData::run()
int r = wp_recv(m_fd,m_buffer,sz,0/*MSG_NOSIGNAL*/);
XDebug("wpdata_recv",DebugAll,"post r=%d",r);
r -= WP_HEADER;
if (m_buffer[0])
Debug(&__plugin,DebugMild,"Read data error 0x%02X [%p]",m_buffer[0],this);
if (m_buffer[0]) {
if (!m_rdError)
Debug(&__plugin,DebugWarn,"Read data error 0x%02X on span %d [%p]",
m_buffer[0],m_span->span(),this);
if (m_rdError < MAX_DATA_ERRORS)
m_rdError++;
}
else
m_rdError = 0;
// We should have read N bytes for each B channel
if ((r > 0) && ((r % bchans) == 0)) {
r /= bchans;
@ -396,7 +411,7 @@ void WpData::run()
}
m_span->unlock();
}
int wr = samp;
int wr = m_samples;
::memset(m_buffer,0,WP_HEADER);
unsigned char* dat = m_buffer + WP_HEADER;
m_span->lock();
@ -411,8 +426,15 @@ void WpData::run()
XDebug("wpdata_send",DebugAll,"pre buf=%p len=%d sz=%d",m_buffer,wr,sz);
int w = wp_send(m_fd,m_buffer,wr,MSG_DONTWAIT);
XDebug("wpdata_send",DebugAll,"post w=%d",w);
if (w != wr)
Debug(&__plugin,DebugMild,"Wrote %d bytes instead of %d [%p]",w,wr,this);
if (w != wr) {
if (!m_wrError)
Debug(&__plugin,DebugWarn,"Wrote %d data bytes instead of %d on span %d [%p]",
w,wr,m_span->span(),this);
if (m_wrError < MAX_DATA_ERRORS)
m_wrError++;
}
else
m_wrError = 0;
}
}
}
@ -459,7 +481,7 @@ PriSpan* WpDriver::createSpan(PriDriver* driver, int span, int first, int chans,
ps->startup();
dev.clear();
dev << "w" << span << "g2";
WpData* dat = new WpData(ps,card,cfg.getValue(sect,"bgroup",dev));
WpData* dat = new WpData(ps,card,cfg.getValue(sect,"bgroup",dev),cfg,sect);
dat->startup();
return ps;
}