Fixes in Windows

git-svn-id: http://voip.null.ro/svn/yate@730 acf43c95-373e-0410-b603-e72c3f656dc1
This commit is contained in:
paulc 2006-03-30 00:21:37 +00:00
parent 589b63a931
commit 3786b22abe
9 changed files with 89 additions and 32 deletions

View File

@ -4,6 +4,8 @@ Thu Mar 30 2006 Paul Chitescu <paulc-devel@null.ro>
- Added many options that can be set per external module instance
- Updated the PHP libraries to support the new functions
- Changed the return values of GetEvent() to comply with typechecks in PHP5
- Added extmodule and yradius to the Visual C++ workspace
- Made some fixes for Windows, solved some bugs exposed by the compiler
Wed Mar 29 2006 Paul Chitescu <paulc-devel@null.ro>
- Modified conference based on Andrew McDonald's idea of N-way mixing

View File

@ -436,7 +436,11 @@ bool File::canRetry() const
{
if (!m_error)
return true;
return (m_error == EAGAIN) || (m_error == EINTR) || (m_error == EWOULDBLOCK);
return (m_error == EAGAIN) || (m_error == EINTR)
#ifndef _WINDOWS
|| (m_error == EWOULDBLOCK)
#endif
;
}
bool File::setBlocking(bool block)

View File

@ -236,7 +236,7 @@ ConfRoom::ConfRoom(const String& name, const NamedList& params)
m_rate = params.getIntValue("rate",m_rate);
m_maxusers = params.getIntValue("maxusers",m_maxusers);
m_notify = params.getValue("notify");
m_lonely = params.getValue("lonely");
m_lonely = params.getBoolValue("lonely");
s_rooms.append(this);
// create outgoing call to room record utility channel
const char* callto = params.getValue("record");
@ -422,9 +422,9 @@ void ConfConsumer::Consume(const DataBlock& data, unsigned long tStamp)
// use square of the energy as extracting the square root is expensive
sum2 = (sum2 * DECAY_STORE + (int64_t)(samp*samp) * ATTACK_RATE) / DECAY_TOTAL;
if (min2 > sum2)
min2 = sum2;
min2 = (unsigned int)sum2;
}
m_energy2 = sum2;
m_energy2 = (unsigned int)sum2;
// TODO: find a better algorithm to adjust the noise threshold
min2 += min2 >> SHIFT_LEVEL;
// try to keep noise threshold slightly above minimum energy
@ -468,7 +468,7 @@ void ConfConsumer::consumed(const int* mixed, unsigned int samples)
int64_t sum2 = m_energy2;
while (n--)
sum2 = (sum2 * DECAY_STORE) / DECAY_TOTAL;
m_energy2 = sum2;
m_energy2 = (unsigned int)sum2;
}
return;
}

View File

@ -24,10 +24,18 @@
*/
#include <yatephone.h>
#ifdef _WINDOWS
#include <process.h>
#else
#include <yatepaths.h>
#include <sys/stat.h>
#include <sys/wait.h>
#endif
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
@ -280,9 +288,16 @@ private:
static bool runProgram(const char *script, const char *args)
{
#ifdef _WINDOWS
int pid = ::_spawnl(_P_DETACH,script,args,NULL);
if (pid < 0) {
Debug(DebugWarn, "Failed to _spawnl(): %d: %s", errno, strerror(errno));
return false;
}
#else
int pid = ::fork();
if (pid < 0) {
Debug(DebugWarn, "Failed to fork(): %s", strerror(errno));
Debug(DebugWarn, "Failed to fork(): %d: %s", errno, strerror(errno));
return false;
}
if (!pid) {
@ -291,6 +306,7 @@ static bool runProgram(const char *script, const char *args)
// Try to immunize child from ^C and ^\ the console may receive
::signal(SIGINT,SIG_IGN);
::signal(SIGQUIT,SIG_IGN);
// And restore default handlers for other signals
::signal(SIGTERM,SIG_DFL);
::signal(SIGHUP,SIG_DFL);
@ -301,10 +317,11 @@ static bool runProgram(const char *script, const char *args)
if (debugAt(DebugInfo))
::fprintf(stderr, "Execing program '%s' '%s'\n", script, args);
::execl(script, script, args, (char *)NULL);
::fprintf(stderr, "Failed to execute '%s': %s\n", script, strerror(errno));
::fprintf(stderr, "Failed to execute '%s': %d: %s\n", script, errno, strerror(errno));
// Shit happened. Die as quick and brutal as possible
::_exit(1);
}
#endif
Debug(DebugInfo,"Launched external program %s", script);
return true;
}
@ -353,7 +370,7 @@ void ExtModSource::run()
int64_t dly = tpos - Time::now();
if (dly > 0) {
XDebug("ExtModSource",DebugAll,"Sleeping for " FMT64 " usec",dly);
Thread::usleep(dly);
Thread::usleep((unsigned long)dly);
}
if (r <= 0)
continue;
@ -361,7 +378,7 @@ void ExtModSource::run()
Forward(buf,m_total/2);
buf.clear(false);
m_total += r;
tpos += (r*1000000ULL/m_brate);
tpos += (r*(u_int64_t)1000000/m_brate);
} while (r > 0);
Debug(DebugAll,"ExtModSource [%p] end of data total=%u",this,m_total);
m_chan->setRunning(false);
@ -763,8 +780,10 @@ void ExtModReceiver::die(bool clearChan)
// Now terminate the process and close its stdout pipe
closeIn();
#ifndef _WINDOWS
if (m_pid > 0)
::kill(m_pid,SIGTERM);
#endif
if (chan && clearChan)
chan->disconnect();
unuse();
@ -806,7 +825,7 @@ bool ExtModReceiver::received(Message &msg, int id)
while (ok) {
Thread::yield();
lock();
ok = m_waiting.find(&h);
ok = (m_waiting.find(&h) != 0);
if (ok && tout && (Time::now() > tout)) {
Debug(DebugWarn,"Message '%s' did not return in %d msec [%p]",
msg.c_str(),m_timeout,this);
@ -825,6 +844,9 @@ bool ExtModReceiver::received(Message &msg, int id)
bool ExtModReceiver::create(const char *script, const char *args)
{
#ifdef _WINDOWS
return false;
#else
String tmp(script);
int pid;
HANDLE ext2yate[2];
@ -898,6 +920,7 @@ bool ExtModReceiver::create(const char *script, const char *args)
closeAudio();
m_pid = pid;
return true;
#endif
}
void ExtModReceiver::cleanup()
@ -905,6 +928,7 @@ void ExtModReceiver::cleanup()
#ifdef DEBUG
Debugger debug(DebugAll,"ExtModReceiver::cleanup()"," [%p]",this);
#endif
#ifndef _WINDOWS
// We must call waitpid from here - same thread we started the child
if (m_pid > 0) {
// No thread switching if possible
@ -923,6 +947,7 @@ void ExtModReceiver::cleanup()
Debug(DebugMild,"Failed waitpid on %d: %s",m_pid,strerror(errno));
m_pid = 0;
}
#endif
unuse();
}

View File

@ -359,8 +359,8 @@ WpData::WpData(WpSpan* span, const char* card, const char* device, Configuration
m_samples = cfg.getIntValue("general","samples",m_samples);
m_samples = cfg.getIntValue(sect,"samples",m_samples);
m_swap = cfg.getIntValue("general","bitswap",m_swap);
m_swap = cfg.getIntValue(sect,"bitswap",m_swap);
m_swap = cfg.getBoolValue("general","bitswap",m_swap);
m_swap = cfg.getBoolValue(sect,"bitswap",m_swap);
}
WpData::~WpData()

View File

@ -1,8 +1,8 @@
/**
* wpchan.cpp
* wpchanw.cpp
* This file is part of the YATE Project http://YATE.null.ro
*
* Wanpipe PRI cards telephony driver
* Wanpipe PRI cards telephony driver for Windows
*
* Yet Another Telephony Engine - a fully featured software PBX and IVR
* Copyright (C) 2004, 2005 Null Team
@ -115,13 +115,14 @@ private:
class WpData : public Thread
{
public:
WpData(WpSpan* span, const char* card, const char* device, Thread::Priority prio);
WpData(WpSpan* span, const char* card, const char* device, Configuration& cfg, const String& sect);
~WpData();
virtual void run();
private:
WpSpan* m_span;
HANDLE m_fd;
WpChan **m_chans;
bool m_swap;
};
class WpReader : public Thread
@ -165,6 +166,14 @@ INIT_PLUGIN(WpDriver);
#define WP_BUFFER 8188 // maximum length of data = 8K - 4
static Thread::Priority cfgPriority(Configuration& cfg, const String& sect)
{
String tmp(cfg.getValue(sect,"thread"));
if (tmp.null())
tmp = cfg.getValue("general","thread");
return Thread::priority(tmp);
}
static void dump_buffer(const void* buf, int len)
{
String s;
@ -435,15 +444,17 @@ void WpConsumer::Consume(const DataBlock &data, unsigned long tStamp)
WpData::WpData(WpSpan* span, const char* card, const char* device, Thread::Priority prio)
: Thread("WpData",prio), m_span(span), m_fd(INVALID_HANDLE_VALUE), m_chans(0)
WpData::WpData(WpSpan* span, const char* card, const char* device, Configuration& cfg, const String& sect)
: Thread("WpData",cfgPriority(cfg,sect)), m_span(span), m_fd(INVALID_HANDLE_VALUE), m_chans(0), m_swap(true)
{
DDebug(&__plugin,DebugAll,"WpData::WpData(%p) [%p]",span,this);
DDebug(&__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_swap = cfg.getBoolValue("general","bitswap",m_swap);
m_swap = cfg.getBoolValue(sect,"bitswap",m_swap);
}
WpData::~WpData()
@ -491,7 +502,7 @@ void WpData::run()
for (b = 0; b < bchans; b++) {
WpSource *s = m_chans[b]->m_wp_s;
if (s)
s->put(PriDriver::bitswap(*dat));
s->put(m_swap ? PriDriver::bitswap(*dat) : *dat);
dat++;
}
}
@ -508,7 +519,8 @@ void WpData::run()
for (int n = samp; n > 0; n--) {
for (b = 0; b < bchans; b++) {
WpConsumer *c = m_chans[b]->m_wp_c;
*dat++ = PriDriver::bitswap(c ? c->get() : 0xff);
unsigned char d = c ? c->get() : 0xff;
*dat++ = m_swap ? PriDriver::bitswap(d) : d;
}
}
m_span->unlock();
@ -551,14 +563,6 @@ bool WpChan::openData(const char* format, int echoTaps)
return true;
}
static Thread::Priority cfgPriority(Configuration& cfg, const String& sect)
{
String tmp(cfg.getValue(sect,"thread"));
if (tmp.null())
tmp = cfg.getValue("general","thread");
return Thread::priority(tmp);
}
PriSpan* WpDriver::createSpan(PriDriver* driver, int span, int first, int chans, Configuration& cfg, const String& sect)
{
@ -579,7 +583,7 @@ PriSpan* WpDriver::createSpan(PriDriver* driver, int span, int first, int chans,
WpWriter* wr = new WpWriter(ps,card,dev);
WpReader* rd = new WpReader(ps,card,dev);
dev = cfg.getValue(sect,"bgroup","IF1");
WpData* dat = new WpData(ps,card,dev,cfgPriority(cfg,sect));
WpData* dat = new WpData(ps,card,dev,cfg,sect);
wr->startup();
rd->startup();
dat->startup();

View File

@ -271,7 +271,7 @@ public:
bool packTo(DataBlock& data) const;
bool getString(String& retval) const;
inline bool isValid() const
{ return m_type; }
{ return (m_type != 0); }
inline bool isVendor() const
{ return (m_type && (m_type->code == 26)) && (m_vendor == 0); }
inline int vendor() const
@ -738,7 +738,7 @@ bool RadAttrib::getString(String& retval) const
}
break;
case a_int:
retval = ntohl(*(int32_t*)m_value.data());
retval = (int)ntohl(*(int32_t*)m_value.data());
break;
default:
return false;
@ -747,7 +747,7 @@ bool RadAttrib::getString(String& retval) const
}
unsigned char RadiusClient::s_sessionId = (Time::now() & 0xff);
unsigned char RadiusClient::s_sessionId = (unsigned char)(Time::now() & 0xff);
RadiusClient::~RadiusClient()
{

View File

@ -194,6 +194,12 @@ Package=<4>
Begin Project Dependency
Project_Dep_Name _dbpbx
End Project Dependency
Begin Project Dependency
Project_Dep_Name _yradius
End Project Dependency
Begin Project Dependency
Project_Dep_Name _extmodule
End Project Dependency
}}}
###############################################################################
@ -582,6 +588,21 @@ Package=<4>
###############################################################################
Project: "_yradius"=.\_yradius.dsp - Package Owner=<4>
Package=<5>
{{{
}}}
Package=<4>
{{{
Begin Project Dependency
Project_Dep_Name Libyate
End Project Dependency
}}}
###############################################################################
Project: "_yrtpchan"=.\_yrtpchan.dsp - Package Owner=<4>
Package=<5>

View File

@ -72,6 +72,7 @@ typedef signed __int64 int64_t;
typedef unsigned __int64 u_int64_t;
typedef unsigned __int64 uint64_t;
typedef int pid_t;
typedef int socklen_t;
typedef unsigned long in_addr_t;