From fbe5346930ebe3773dc5d15b41609b668dea9e42 Mon Sep 17 00:00:00 2001 From: paulc Date: Fri, 7 Oct 2005 22:03:19 +0000 Subject: [PATCH] Fixes for Windows compilation suggested by Faizan Naqvi (Tili). Added names for thread priorities. Fixed the way some channels handle timestamps (broken by the delta->full API change). git-svn-id: http://voip.null.ro/svn/yate@536 acf43c95-373e-0410-b603-e72c3f656dc1 --- engine/Thread.cpp | 30 +++++++++++++++++++++++++++++- modules/extmodule.cpp | 2 +- modules/h323chan.cpp | 2 +- modules/moh.cpp | 2 +- modules/osschan.cpp | 2 +- modules/regexroute.cpp | 4 ++-- modules/tonegen.cpp | 2 +- modules/wpchan.cpp | 10 +++++++++- modules/wpchanw.cpp | 19 +++++++++++++++---- yateclass.h | 25 ++++++++++++++++++++++++- yatephone.h | 2 +- 11 files changed, 85 insertions(+), 15 deletions(-) diff --git a/engine/Thread.cpp b/engine/Thread.cpp index aa870e8a..26ac60be 100644 --- a/engine/Thread.cpp +++ b/engine/Thread.cpp @@ -84,6 +84,15 @@ static pthread_key_t current_key; static pthread_once_t current_key_once = PTHREAD_ONCE_INIT; #endif +static TokenDict s_prio[] = { + { "lowest", Thread::Lowest }, + { "low", Thread::Low }, + { "normal", Thread::Normal }, + { "high", Thread::High }, + { "highest", Thread::Highest }, + { 0, 0 } +}; + ObjList threads; Mutex tmutex(true); @@ -413,11 +422,20 @@ Thread::Thread(const char* name, Priority prio) : m_private(0) { #ifdef DEBUG - Debugger debug("Thread::Thread","(\"%s\") [%p]",name,this); + Debugger debug("Thread::Thread","(\"%s\",%d) [%p]",name,prio,this); #endif m_private = ThreadPrivate::create(this,name,prio); } +Thread::Thread(const char *name, const char* prio) + : m_private(0) +{ +#ifdef DEBUG + Debugger debug("Thread::Thread","(\"%s\",\"%s\") [%p]",name,prio,this); +#endif + m_private = ThreadPrivate::create(this,name,priority(prio)); +} + Thread::~Thread() { DDebug(DebugAll,"Thread::~Thread() [%p]",this); @@ -544,6 +562,16 @@ void Thread::usleep(unsigned long usec, bool exitCheck) check(); } +Thread::Priority Thread::priority(const char* name, Thread::Priority defvalue) +{ + return (Thread::Priority)lookup(name,s_prio,defvalue); +} + +const char* Thread::priority(Thread::Priority prio) +{ + return lookup(prio,s_prio); +} + void Thread::preExec() { #ifdef THREAD_KILL diff --git a/modules/extmodule.cpp b/modules/extmodule.cpp index 5d2cf61f..e47dba5d 100644 --- a/modules/extmodule.cpp +++ b/modules/extmodule.cpp @@ -238,7 +238,7 @@ void ExtModSource::run() if (r <= 0) continue; DataBlock buf(data,r,false); - Forward(buf,m_total); + Forward(buf,m_total/2); buf.clear(false); m_total += r; tpos += (r*1000000ULL/m_brate); diff --git a/modules/h323chan.cpp b/modules/h323chan.cpp index 9c6ca49c..05b2560f 100644 --- a/modules/h323chan.cpp +++ b/modules/h323chan.cpp @@ -1561,7 +1561,7 @@ BOOL YateH323AudioSource::Write(const void *buf, PINDEX len) { if (!m_exit) { m_data.assign((void *)buf,len,false); - Forward(m_data,len/2); + Forward(m_data); m_data.clear(false); writeDelay.Delay(len/16); } diff --git a/modules/moh.cpp b/modules/moh.cpp index f8972406..0738aa37 100644 --- a/modules/moh.cpp +++ b/modules/moh.cpp @@ -250,7 +250,7 @@ void MOHSource::run() XDebug("MOH",DebugAll,"Sleeping for " FMT64 " usec",dly); ::usleep((unsigned long)dly); } - Forward(m_data,m_data.length()*8000/m_brate); + Forward(m_data); tpos += (r*1000000ULL/m_brate); } while (r > 0); } diff --git a/modules/osschan.cpp b/modules/osschan.cpp index 447ab9fb..1ae36cb9 100644 --- a/modules/osschan.cpp +++ b/modules/osschan.cpp @@ -219,7 +219,7 @@ void OssSource::run() XDebug("OssSource",DebugAll,"Sleeping for " FMT64 " usec",dly); Thread::usleep((unsigned long)dly); } - Forward(data,data.length()/2); + Forward(data); m_total += r; tpos += (r*1000000ULL/m_brate); } while (r > 0); diff --git a/modules/regexroute.cpp b/modules/regexroute.cpp index e0e6cb0c..5f026d02 100644 --- a/modules/regexroute.cpp +++ b/modules/regexroute.cpp @@ -65,10 +65,10 @@ static void evalFunc(String &str) else if (str == "random") { str.clear(); for (unsigned int i = 0; i < par.length(); i++) { - if (par[i] == '?') + if (par.at(i) == '?') str << (int)(::random() % 10); else - str << par[i]; + str << par.at(i); } } else { diff --git a/modules/tonegen.cpp b/modules/tonegen.cpp index a69a6b18..3f570161 100644 --- a/modules/tonegen.cpp +++ b/modules/tonegen.cpp @@ -445,7 +445,7 @@ Tone* ToneSource::buildDtmf(const String& dtmf, int len, int gap) t->data = 0; t++; - int c = dtmf[i]; + int c = dtmf.at(i); if ((c >= '0') && (c <= '9')) c -= '0'; else if (c == '*') diff --git a/modules/wpchan.cpp b/modules/wpchan.cpp index ade9e4a4..022c3cc9 100644 --- a/modules/wpchan.cpp +++ b/modules/wpchan.cpp @@ -326,8 +326,16 @@ void WpConsumer::Consume(const DataBlock &data, unsigned long tStamp) put(buf[i]); } +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); +} + 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), + : Thread("WpData",cfgPriority(cfg,sect)), 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,'%s','%s') [%p]", diff --git a/modules/wpchanw.cpp b/modules/wpchanw.cpp index 8da9b32c..0dbddc08 100644 --- a/modules/wpchanw.cpp +++ b/modules/wpchanw.cpp @@ -113,7 +113,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, Thread::Priority prio); ~WpData(); virtual void run(); private: @@ -428,8 +428,10 @@ 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_chans(0) + + +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) { DDebug(&__plugin,DebugAll,"WpData::WpData(%p) [%p]",span,this); HANDLE fd = wp_open(card,device); @@ -544,6 +546,15 @@ 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) { Debug(this,DebugAll,"WpDriver::createSpan(%p,%d,%d,%d) [%p]",driver,span,first,chans,this); @@ -563,7 +574,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); + WpData* dat = new WpData(ps,card,dev,cfgPriority(cfg,sect)); wr->startup(); rd->startup(); dat->startup(); diff --git a/yateclass.h b/yateclass.h index 2db87909..4f5f34f0 100644 --- a/yateclass.h +++ b/yateclass.h @@ -35,7 +35,7 @@ #include #ifndef _WINDOWS -#ifdef WIN32 +#if defined(WIN32) || defined(_WIN32) #define _WINDOWS #endif #endif @@ -2508,6 +2508,22 @@ public: inline bool isCurrent() const { return current() == this; } + + /** + * Convert a priority name to a thread priority level + * @param name Name of the requested level + * @param defvalue Priority to return in case of an invalid name + * @return A thread priority level + */ + static Priority priority(const char* name, Priority defvalue = Normal); + + /** + * Convert a priority level to a textual name + * @param prio Priority level to convert + * @return Name of the level or NULL if an invalid argument was provided + */ + static const char* priority(Priority prio); + /** * Kills all other running threads. Ouch! * Must be called from the main thread or it does nothing. @@ -2528,6 +2544,13 @@ protected: */ Thread(const char *name = 0, Priority prio = Normal); + /** + * Creates and starts a new thread + * @param name Static name of the thread (for debugging purpose only) + * @param prio Thread priority level name + */ + Thread(const char *name, const char* prio); + /** * The destructor is called when the thread terminates */ diff --git a/yatephone.h b/yatephone.h index d69cef59..8ae2cb66 100644 --- a/yatephone.h +++ b/yatephone.h @@ -59,7 +59,7 @@ struct ImageInfo { /** * A structure to hold information about a data format. */ -struct FormatInfo { +struct YATE_API FormatInfo { /** * Standard no-blanks lowercase format name */