Yate
|
00001 /* 00002 * yatephone.h 00003 * This file is part of the YATE Project http://YATE.null.ro 00004 * 00005 * Drivers, channels and telephony related classes 00006 * 00007 * Yet Another Telephony Engine - a fully featured software PBX and IVR 00008 * Copyright (C) 2004-2006 Null Team 00009 * 00010 * This program is free software; you can redistribute it and/or modify 00011 * it under the terms of the GNU General Public License as published by 00012 * the Free Software Foundation; either version 2 of the License, or 00013 * (at your option) any later version. 00014 * 00015 * This program is distributed in the hope that it will be useful, 00016 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 * GNU General Public License for more details. 00019 * 00020 * You should have received a copy of the GNU General Public License 00021 * along with this program; if not, write to the Free Software 00022 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. 00023 */ 00024 00025 #ifndef __YATEPHONE_H 00026 #define __YATEPHONE_H 00027 00028 #ifndef __cplusplus 00029 #error C++ is required 00030 #endif 00031 00032 #include <yatengine.h> 00033 00037 namespace TelEngine { 00038 00042 struct YATE_API ImageInfo { 00046 int width; 00047 00051 int height; 00052 00056 int depth; 00057 }; 00058 00062 struct YATE_API FormatInfo { 00066 const char* name; 00067 00071 const char* type; 00072 00076 int frameSize; 00077 00081 int frameTime; 00082 00086 int sampleRate; 00087 00091 int numChannels; 00092 00096 bool converter; 00097 00103 int guessSamples(int len) const; 00104 00109 int dataRate() const; 00110 00114 inline FormatInfo() 00115 : name(0), type("audio"), 00116 frameSize(0), frameTime(0), 00117 sampleRate(8000), numChannels(1), 00118 converter(false) 00119 { } 00120 00124 inline FormatInfo(const char* _name, int fsize = 0, int ftime = 10000, 00125 const char* _type = "audio", int srate = 8000, int nchan = 1, bool convert = false) 00126 : name(_name), type(_type), 00127 frameSize(fsize), frameTime(ftime), 00128 sampleRate(srate), numChannels(nchan), 00129 converter(convert) 00130 { } 00131 }; 00132 00133 class DataEndpoint; 00134 class CallEndpoint; 00135 class Driver; 00136 00141 struct YATE_API TranslatorCaps { 00143 const FormatInfo* src; 00145 const FormatInfo* dest; 00147 int cost; 00148 }; 00149 00154 class YATE_API FormatRepository 00155 { 00156 private: 00157 FormatRepository(); 00158 FormatRepository& operator=(const FormatRepository&); 00159 public: 00165 static const FormatInfo* getFormat(const String& name); 00166 00178 static const FormatInfo* addFormat(const String& name, int fsize, int ftime, const String& type = "audio", int srate = 8000, int nchan = 1); 00179 }; 00180 00185 class YATE_API DataFormat : public String 00186 { 00187 public: 00191 inline DataFormat() 00192 : m_parsed(0) 00193 { } 00194 00199 inline DataFormat(const char* value) 00200 : String(value), m_parsed(0) 00201 { } 00202 00207 inline DataFormat(const DataFormat& value) 00208 : String(value), m_parsed(value.getInfo()) 00209 { } 00210 00215 inline DataFormat(const String& value) 00216 : String(value), m_parsed(0) 00217 { } 00218 00223 inline DataFormat(const String* value) 00224 : String(value), m_parsed(0) 00225 { } 00226 00231 inline DataFormat(const FormatInfo* format) 00232 : String(format ? format->name : (const char*)0), m_parsed(format) 00233 { } 00234 00238 inline DataFormat& operator=(const DataFormat& value) 00239 { String::operator=(value); return *this; } 00240 00245 const FormatInfo* getInfo() const; 00246 00252 inline int frameSize(int defValue = 0) const 00253 { return getInfo() ? getInfo()->frameSize : defValue; } 00254 00260 inline int frameTime(int defValue = 0) const 00261 { return getInfo() ? getInfo()->frameTime : defValue; } 00262 00269 inline int sampleRate(int defValue = 0) const 00270 { return getInfo() ? getInfo()->sampleRate : defValue; } 00271 00277 inline int numChannels(int defValue = 1) const 00278 { return getInfo() ? getInfo()->numChannels : defValue; } 00279 00280 protected: 00284 virtual void changed(); 00285 00286 private: 00287 mutable const FormatInfo* m_parsed; 00288 }; 00289 00293 class YATE_API DataNode : public RefObject 00294 { 00295 friend class DataEndpoint; 00296 00297 public: 00301 enum DataFlags { 00302 DataStart = 0x0001, 00303 DataEnd = 0x0002, 00304 DataMark = 0x0004, 00305 DataSilent = 0x0008, 00306 DataMissed = 0x0010, 00307 DataError = 0x0020, 00308 DataPrivate = 0x0100 00309 }; 00310 00315 inline DataNode(const char* format = 0) 00316 : m_format(format), m_timestamp(0) 00317 { } 00318 00324 virtual int costFormat(const DataFormat& format) 00325 { return -1; } 00326 00332 virtual bool setFormat(const DataFormat& format) 00333 { return false; } 00334 00339 inline const DataFormat& getFormat() const 00340 { return m_format; } 00341 00346 inline unsigned long timeStamp() const 00347 { return m_timestamp; } 00348 00353 virtual bool valid() const 00354 { return true; } 00355 00361 virtual bool control(NamedList& params) 00362 { return false; } 00363 00368 inline static unsigned long invalidStamp() 00369 { return (unsigned long)-1; } 00370 00371 protected: 00377 virtual void attached(bool added) 00378 { } 00379 00380 DataFormat m_format; 00381 unsigned long m_timestamp; 00382 }; 00383 00384 class DataSource; 00385 class DataTranslator; 00386 class TranslatorFactory; 00387 class ThreadedSourcePrivate; 00388 00392 class YATE_API DataConsumer : public DataNode 00393 { 00394 friend class DataSource; 00395 00396 public: 00401 inline DataConsumer(const char* format = "slin") 00402 : DataNode(format), 00403 m_source(0), m_override(0), 00404 m_regularTsDelta(0), m_overrideTsDelta(0), m_lastTsTime(0) 00405 { } 00406 00410 virtual void destroyed(); 00411 00417 virtual void* getObject(const String& name) const; 00418 00428 virtual unsigned long Consume(const DataBlock& data, unsigned long tStamp, unsigned long flags) = 0; 00429 00434 inline DataSource* getConnSource() const 00435 { return m_source; } 00436 00441 inline DataSource* getOverSource() const 00442 { return m_override; } 00443 00448 virtual DataSource* getTransSource() const 00449 { return 0; } 00450 00451 protected: 00457 virtual bool synchronize(DataSource* source); 00458 00459 private: 00460 unsigned long Consume(const DataBlock& data, unsigned long tStamp, 00461 unsigned long flags, DataSource* source); 00462 DataSource* m_source; 00463 DataSource* m_override; 00464 long m_regularTsDelta; 00465 long m_overrideTsDelta; 00466 u_int64_t m_lastTsTime; 00467 }; 00468 00472 class YATE_API DataSource : public DataNode, public Mutex 00473 { 00474 friend class DataTranslator; 00475 00476 public: 00481 inline DataSource(const char* format = "slin") 00482 : DataNode(format), Mutex(false,"DataSource"), 00483 m_nextStamp(invalidStamp()), m_translator(0) { } 00484 00488 virtual void destroyed(); 00489 00495 virtual void* getObject(const String& name) const; 00496 00501 virtual bool valid() const; 00502 00510 unsigned long Forward(const DataBlock& data, unsigned long tStamp = invalidStamp(), 00511 unsigned long flags = 0); 00512 00519 bool attach(DataConsumer* consumer, bool override = false); 00520 00526 bool detach(DataConsumer* consumer); 00527 00531 void clear(); 00532 00537 inline DataTranslator* getTranslator() const 00538 { return m_translator; } 00539 00544 void synchronize(unsigned long tStamp); 00545 00550 inline unsigned long nextStamp() const 00551 { return m_nextStamp; } 00552 00553 protected: 00554 unsigned long m_nextStamp; 00555 DataTranslator* m_translator; 00556 ObjList m_consumers; 00557 private: 00558 inline void setTranslator(DataTranslator* translator) 00559 { m_translator = translator; } 00560 bool detachInternal(DataConsumer* consumer); 00561 }; 00562 00567 class YATE_API ThreadedSource : public DataSource 00568 { 00569 friend class ThreadedSourcePrivate; 00570 public: 00574 virtual void destroyed(); 00575 00582 bool start(const char* name = "ThreadedSource", Thread::Priority prio = Thread::Normal); 00583 00587 void stop(); 00588 00593 Thread* thread() const; 00594 00599 bool running() const; 00600 00601 protected: 00606 inline ThreadedSource(const char* format = "slin") 00607 : DataSource(format), m_thread(0) 00608 { } 00609 00613 virtual void run() = 0; 00614 00619 virtual void cleanup(); 00620 00626 bool looping(bool runConsumers = false) const; 00627 00628 private: 00629 ThreadedSourcePrivate* m_thread; 00630 }; 00631 00637 class YATE_API DataTranslator : public DataConsumer 00638 { 00639 friend class TranslatorFactory; 00640 public: 00646 DataTranslator(const char* sFormat, const char* dFormat); 00647 00654 DataTranslator(const char* sFormat, DataSource* source = 0); 00655 00659 ~DataTranslator(); 00660 00666 virtual void* getObject(const String& name) const; 00667 00672 virtual bool valid() const 00673 { return m_tsource && m_tsource->valid(); } 00674 00679 virtual DataSource* getTransSource() const 00680 { return m_tsource; } 00681 00686 DataTranslator* getFirstTranslator(); 00687 00692 const DataTranslator* getFirstTranslator() const; 00693 00702 static ObjList* srcFormats(const DataFormat& dFormat = "slin", int maxCost = -1, unsigned int maxLen = 0, ObjList* lst = 0); 00703 00712 static ObjList* destFormats(const DataFormat& sFormat = "slin", int maxCost = -1, unsigned int maxLen = 0, ObjList* lst = 0); 00713 00722 static ObjList* allFormats(const ObjList* formats, bool existing = true, bool sameRate = true, bool sameChans = true); 00723 00732 static ObjList* allFormats(const String& formats, bool existing = true, bool sameRate = true, bool sameChans = true); 00733 00740 static bool canConvert(const DataFormat& fmt1, const DataFormat& fmt2 = "slin"); 00741 00748 static int cost(const DataFormat& sFormat, const DataFormat& dFormat); 00749 00756 static DataTranslator* create(const DataFormat& sFormat, const DataFormat& dFormat); 00757 00765 static bool attachChain(DataSource* source, DataConsumer* consumer, bool override = false); 00766 00773 static bool detachChain(DataSource* source, DataConsumer* consumer); 00774 00779 static void setMaxChain(unsigned int maxChain); 00780 00781 protected: 00787 virtual bool synchronize(DataSource* source); 00788 00793 static void install(TranslatorFactory* factory); 00794 00799 static void uninstall(TranslatorFactory* factory); 00800 00801 private: 00802 DataTranslator(); // No default constructor please 00803 static void compose(); 00804 static void compose(TranslatorFactory* factory); 00805 static bool canConvert(const FormatInfo* fmt1, const FormatInfo* fmt2); 00806 DataSource* m_tsource; 00807 static Mutex s_mutex; 00808 static ObjList s_factories; 00809 static unsigned int s_maxChain; 00810 }; 00811 00817 class YATE_API TranslatorFactory : public GenObject 00818 { 00819 protected: 00823 inline TranslatorFactory() 00824 { DataTranslator::install(this); } 00825 00826 public: 00830 virtual ~TranslatorFactory(); 00831 00836 virtual void removed(const TranslatorFactory* factory); 00837 00844 virtual DataTranslator* create(const DataFormat& sFormat, const DataFormat& dFormat) = 0; 00845 00850 virtual const TranslatorCaps* getCapabilities() const = 0; 00851 00858 virtual bool converts(const DataFormat& sFormat, const DataFormat& dFormat) const; 00859 00864 virtual unsigned int length() const; 00865 00871 virtual bool intermediate(const FormatInfo* info) const; 00872 00877 virtual const FormatInfo* intermediate() const; 00878 }; 00879 00885 class YATE_API DataEndpoint : public RefObject 00886 { 00887 public: 00888 00892 DataEndpoint(CallEndpoint* call = 0, const char* name = "audio"); 00893 00897 virtual void destroyed(); 00898 00904 virtual void* getObject(const String& name) const; 00905 00910 virtual const String& toString() const; 00911 00916 Mutex* mutex() const; 00917 00922 static Mutex& commonMutex(); 00923 00929 bool connect(DataEndpoint* peer); 00930 00935 bool disconnect(); 00936 00941 void setSource(DataSource* source = 0); 00942 00947 inline DataSource* getSource() const 00948 { return m_source; } 00949 00954 void setConsumer(DataConsumer* consumer = 0); 00955 00960 inline DataConsumer* getConsumer() const 00961 { return m_consumer; } 00962 00968 void setPeerRecord(DataConsumer* consumer = 0); 00969 00974 inline DataConsumer* getPeerRecord() const 00975 { return m_peerRecord; } 00976 00982 void setCallRecord(DataConsumer* consumer = 0); 00983 00988 inline DataConsumer* getCallRecord() const 00989 { return m_callRecord; } 00990 00996 bool clearData(DataNode* node); 00997 01003 bool addSniffer(DataConsumer* sniffer); 01004 01010 bool delSniffer(DataConsumer* sniffer); 01011 01017 inline DataConsumer* getSniffer(const String& name) 01018 { return static_cast<DataConsumer*>(m_sniffers[name]); } 01019 01023 void clearSniffers(); 01024 01029 inline DataEndpoint* getPeer() const 01030 { return m_peer; } 01031 01036 inline CallEndpoint* getCall() const 01037 { return m_call; } 01038 01043 inline const String& name() const 01044 { return m_name; } 01045 01051 inline void clearCall(const CallEndpoint* call) 01052 { if (call == m_call) m_call = 0; } 01053 01059 virtual bool control(NamedList& params); 01060 01061 protected: 01067 virtual bool nativeConnect(DataEndpoint* peer) 01068 { return false; } 01069 01070 private: 01071 String m_name; 01072 DataSource* m_source; 01073 DataConsumer* m_consumer; 01074 DataEndpoint* m_peer; 01075 CallEndpoint* m_call; 01076 DataConsumer* m_peerRecord; 01077 DataConsumer* m_callRecord; 01078 ObjList m_sniffers; 01079 }; 01080 01085 class YATE_API CallEndpoint : public RefObject 01086 { 01087 friend class DataEndpoint; 01088 01089 private: 01090 CallEndpoint* m_peer; 01091 String m_id; 01092 01093 protected: 01094 ObjList m_data; 01095 Mutex* m_mutex; 01096 01097 public: 01101 virtual void destroyed(); 01102 01108 virtual void* getObject(const String& name) const; 01109 01114 virtual const String& toString() const 01115 { return m_id; } 01116 01121 inline const String& id() const 01122 { return m_id; } 01123 01128 inline CallEndpoint* getPeer() const 01129 { return m_peer; } 01130 01136 bool getPeerId(String& id) const; 01137 01142 String getPeerId() const; 01143 01148 inline Mutex* mutex() const 01149 { return m_mutex; } 01150 01155 static Mutex& commonMutex(); 01156 01164 bool connect(CallEndpoint* peer, const char* reason = 0, bool notify = true); 01165 01173 inline bool disconnect(const char* reason = 0, bool notify = true, const NamedList* params = 0) 01174 { return disconnect(false,reason,notify,params); } 01175 01182 inline bool disconnect(const char* reason, const NamedList& params) 01183 { return disconnect(false,reason,true,¶ms); } 01184 01190 DataEndpoint* getEndpoint(const char* type = "audio") const; 01191 01197 DataEndpoint* setEndpoint(const char* type = "audio"); 01198 01203 void clearEndpoint(const char* type = 0); 01204 01210 void setSource(DataSource* source = 0, const char* type = "audio"); 01211 01217 DataSource* getSource(const char* type = "audio") const; 01218 01224 void setConsumer(DataConsumer* consumer = 0, const char* type = "audio"); 01225 01231 DataConsumer* getConsumer(const char* type = "audio") const; 01232 01239 bool clearData(DataNode* node, const char* type = "audio"); 01240 01241 protected: 01245 CallEndpoint(const char* id = 0); 01246 01251 virtual void connected(const char* reason) { } 01252 01258 virtual void disconnected(bool final, const char* reason) { } 01259 01264 virtual void setDisconnect(const NamedList* params) { } 01265 01273 void setPeer(CallEndpoint* peer, const char* reason = 0, bool notify = true, const NamedList* params = 0); 01274 01279 void setEndpoint(DataEndpoint* endPoint); 01280 01285 virtual void setId(const char* newId); 01286 01287 private: 01288 bool disconnect(bool final, const char* reason, bool notify, const NamedList* params); 01289 }; 01290 01295 class YATE_API Module : public Plugin, public Mutex, public MessageReceiver, public DebugEnabler 01296 { 01297 private: 01298 bool m_init; 01299 int m_relays; 01300 String m_name; 01301 String m_type; 01302 Regexp m_filter; 01303 u_int64_t m_changed; 01304 static unsigned int s_delay; 01305 01306 public: 01312 virtual void* getObject(const String& name) const; 01313 01318 inline const String& name() const 01319 { return m_name; } 01320 01325 inline const String& type() const 01326 { return m_type; } 01327 01332 void changed(); 01333 01338 inline static unsigned int updateDelay() 01339 { return s_delay; } 01340 01345 inline static void updateDelay(unsigned int delay) 01346 { s_delay = delay; } 01347 01352 inline bool filterInstalled() const 01353 { return !m_filter.null(); } 01354 01360 bool filterDebug(const String& item) const; 01361 01369 static bool itemComplete(String& itemList, const String& item, const String& partWord); 01370 01371 protected: 01375 enum { 01376 // Module messages 01377 Status = 0x00000001, 01378 Timer = 0x00000002, 01379 Level = 0x00000004, 01380 Command = 0x00000008, 01381 Help = 0x00000010, 01382 Halt = 0x00000020, 01383 Route = 0x00000040, 01384 // Driver messages 01385 Execute = 0x00000100, 01386 Drop = 0x00000200, 01387 // Channel messages 01388 Locate = 0x00000400, 01389 Masquerade = 0x00000800, 01390 Ringing = 0x00001000, 01391 Answered = 0x00002000, 01392 Tone = 0x00004000, 01393 Text = 0x00008000, 01394 Progress = 0x00010000, 01395 Update = 0x00020000, 01396 Transfer = 0x00040000, 01397 Control = 0x00080000, 01398 // Instant messenging related 01399 ImRoute = 0x00100000, 01400 ImExecute = 0x00200000, 01401 // Last possible public ID 01402 PubLast = 0x0fffffff, 01403 // Private messages base ID 01404 Private = 0x10000000 01405 } RelayID; 01406 01412 static const char* messageName(int id); 01413 01420 Module(const char* name, const char* type = 0, bool earlyInit = false); 01421 01425 virtual ~Module(); 01426 01430 virtual void initialize(); 01431 01435 void setup(); 01436 01443 bool installRelay(int id, unsigned priority = 100); 01444 01451 bool installRelay(const char* name, unsigned priority = 100); 01452 01460 bool installRelay(int id, const char* name, unsigned priority = 100); 01461 01467 bool installRelay(MessageRelay* relay); 01468 01475 bool uninstallRelay(MessageRelay* relay, bool delRelay = true); 01476 01483 bool uninstallRelay(int id, bool delRelay = true); 01484 01489 bool uninstallRelays(); 01490 01497 virtual bool received(Message &msg, int id); 01498 01503 virtual void genUpdate(Message& msg); 01504 01509 virtual void msgTimer(Message& msg); 01510 01515 virtual void msgStatus(Message& msg); 01516 01522 virtual bool msgRoute(Message& msg); 01523 01530 virtual bool msgCommand(Message& msg); 01531 01536 virtual void statusModule(String& str); 01537 01542 virtual void statusParams(String& str); 01543 01548 virtual void statusDetail(String& str); 01549 01556 virtual bool commandExecute(String& retVal, const String& line); 01557 01565 virtual bool commandComplete(Message& msg, const String& partLine, const String& partWord); 01566 01572 virtual bool setDebug(Message& msg, const String& target); 01573 01574 private: 01575 Module(); // no default constructor please 01576 static TokenDict s_messages[]; 01577 ObjList m_relayList; 01578 }; 01579 01584 class YATE_API Channel : public CallEndpoint, public DebugEnabler 01585 { 01586 friend class Driver; 01587 friend class Router; 01588 01589 private: 01590 NamedList m_parameters; 01591 Driver* m_driver; 01592 bool m_outgoing; 01593 u_int64_t m_timeout; 01594 u_int64_t m_maxcall; 01595 u_int64_t m_dtmfTime; 01596 unsigned int m_dtmfSeq; 01597 String m_dtmfText; 01598 String m_dtmfDetected; 01599 String m_lastPeerId; 01600 01601 protected: 01602 String m_status; 01603 String m_address; 01604 String m_targetid; 01605 String m_billid; 01606 bool m_answered; 01607 01608 public: 01612 virtual ~Channel(); 01613 01619 virtual void* getObject(const String& name) const; 01620 01626 virtual void complete(Message& msg, bool minimal = false) const; 01627 01635 Message* message(const char* name, bool minimal = false, bool data = false); 01636 01647 Message* message(const char* name, const NamedList* original, const char* params = 0, bool minimal = false, bool data = false); 01648 01659 inline Message* message(const char* name, const NamedList& original, const char* params = 0, bool minimal = false, bool data = false) 01660 { return message(name,&original,params,minimal,data); } 01661 01667 virtual bool msgProgress(Message& msg); 01668 01674 virtual bool msgRinging(Message& msg); 01675 01681 virtual bool msgAnswered(Message& msg); 01682 01689 virtual bool msgTone(Message& msg, const char* tone); 01690 01697 virtual bool msgText(Message& msg, const char* text); 01698 01705 virtual bool msgDrop(Message& msg, const char* reason); 01706 01712 virtual bool msgTransfer(Message& msg); 01713 01719 virtual bool msgUpdate(Message& msg); 01720 01726 virtual bool msgMasquerade(Message& msg); 01727 01732 virtual void msgStatus(Message& msg); 01733 01739 virtual bool msgControl(Message& msg); 01740 01746 virtual void checkTimers(Message& msg, const Time& tmr); 01747 01754 virtual bool callPrerouted(Message& msg, bool handled); 01755 01761 virtual bool callRouted(Message& msg); 01762 01767 virtual void callAccept(Message& msg); 01768 01775 virtual void callRejected(const char* error, const char* reason = 0, const Message* msg = 0); 01776 01782 virtual void callConnect(Message& msg); 01783 01788 virtual bool setDebug(Message& msg); 01789 01794 inline const String& status() const 01795 { return m_status; } 01796 01801 inline const String& address() const 01802 { return m_address; } 01803 01808 inline bool isOutgoing() const 01809 { return m_outgoing; } 01810 01815 inline bool isIncoming() const 01816 { return !m_outgoing; } 01817 01822 inline bool isAnswered() const 01823 { return m_answered; } 01824 01829 const char* direction() const; 01830 01835 inline Driver* driver() const 01836 { return m_driver; } 01837 01842 inline u_int64_t timeout() const 01843 { return m_timeout; } 01844 01849 inline void timeout(u_int64_t tout) 01850 { m_timeout = tout; } 01851 01856 inline u_int64_t maxcall() const 01857 { return m_maxcall; } 01858 01863 inline void maxcall(u_int64_t tout) 01864 { m_maxcall = tout; } 01865 01870 inline void setMaxcall(const Message& msg) 01871 { setMaxcall(&msg); } 01872 01877 void setMaxcall(const Message* msg); 01878 01884 inline const String& targetid() const 01885 { return m_targetid; } 01886 01892 inline const String& billid() const 01893 { return m_billid; } 01894 01899 const String& lastPeerId() const 01900 { return m_lastPeerId; } 01901 01906 void initChan(); 01907 01914 bool startRouter(Message* msg); 01915 01920 static unsigned int allocId(); 01921 01926 void filterDebug(const String& item); 01927 01928 protected: 01932 Channel(Driver* driver, const char* id = 0, bool outgoing = false); 01933 01937 Channel(Driver& driver, const char* id = 0, bool outgoing = false); 01938 01943 void cleanup(); 01944 01948 void dropChan(); 01949 01954 virtual void zeroRefs(); 01955 01960 virtual void connected(const char* reason); 01961 01967 virtual void disconnected(bool final, const char* reason); 01968 01973 virtual void setDisconnect(const NamedList* params); 01974 01979 virtual void setId(const char* newId); 01980 01986 virtual Message* getDisconnect(const char* reason); 01987 01993 void status(const char* newstat); 01994 01999 virtual void statusParams(String& str); 02000 02005 inline void setOutgoing(bool outgoing = true) 02006 { m_outgoing = outgoing; } 02007 02013 bool dtmfSequence(Message& msg); 02014 02020 bool dtmfEnqueue(Message* msg); 02021 02028 bool dtmfInband(const char* tone); 02029 02036 bool toneDetect(const char* sniffer = 0); 02037 02042 inline NamedList& parameters() 02043 { return m_parameters; } 02044 02049 inline const NamedList& parameters() const 02050 { return m_parameters; } 02051 02052 private: 02053 void init(); 02054 Channel(); // no default constructor please 02055 }; 02056 02061 class YATE_API Driver : public Module 02062 { 02063 friend class Router; 02064 friend class Channel; 02065 02066 private: 02067 bool m_init; 02068 bool m_varchan; 02069 String m_prefix; 02070 ObjList m_chans; 02071 int m_routing; 02072 int m_routed; 02073 int m_total; 02074 unsigned int m_nextid; 02075 int m_timeout; 02076 int m_maxroute; 02077 int m_maxchans; 02078 bool m_dtmfDups; 02079 02080 public: 02086 virtual void* getObject(const String& name) const; 02087 02092 inline const String& prefix() const 02093 { return m_prefix; } 02094 02099 inline bool varchan() const 02100 { return m_varchan; } 02101 02106 inline ObjList& channels() 02107 { return m_chans; } 02108 02114 virtual Channel* find(const String& id) const; 02115 02120 virtual bool isBusy() const; 02121 02126 virtual void dropAll(Message &msg); 02127 02133 virtual bool canAccept(bool routers = true); 02134 02139 virtual bool canRoute(); 02140 02145 unsigned int nextid(); 02146 02151 inline unsigned int lastid() const 02152 { return m_nextid; } 02153 02158 inline int timeout() const 02159 { return m_timeout; } 02160 02165 inline int routing() const 02166 { return m_routing; } 02167 02172 inline int routed() const 02173 { return m_routed; } 02174 02179 inline int total() const 02180 { return m_total; } 02181 02182 protected: 02188 Driver(const char* name, const char* type = 0); 02189 02193 virtual void initialize(); 02194 02200 void setup(const char* prefix = 0, bool minimal = false); 02201 02208 virtual bool received(Message &msg, int id); 02209 02214 virtual void genUpdate(Message& msg); 02215 02222 virtual bool hasLine(const String& line) const; 02223 02230 virtual bool msgRoute(Message& msg); 02231 02238 virtual bool msgExecute(Message& msg, String& dest) = 0; 02239 02247 virtual bool commandComplete(Message& msg, const String& partLine, const String& partWord); 02248 02253 virtual void statusModule(String& str); 02254 02259 virtual void statusParams(String& str); 02260 02265 virtual void statusDetail(String& str); 02266 02272 virtual bool setDebug(Message& msg, const String& target); 02273 02277 virtual void loadLimits(); 02278 02283 inline void varchan(bool variable) 02284 { m_varchan = variable; } 02285 02290 inline void timeout(int tout) 02291 { m_timeout = tout; } 02292 02297 inline void maxRoute(int ncalls) 02298 { m_maxroute = ncalls; } 02299 02304 inline void maxChans(int ncalls) 02305 { m_maxchans = ncalls; } 02306 02311 inline void dtmfDups(bool duplicates) 02312 { m_dtmfDups = duplicates; } 02313 02314 private: 02315 Driver(); // no default constructor please 02316 }; 02317 02322 class YATE_API Router : public Thread 02323 { 02324 private: 02325 Driver* m_driver; 02326 String m_id; 02327 Message* m_msg; 02328 02329 public: 02336 Router(Driver* driver, const char* id, Message* msg); 02337 02341 virtual void run(); 02342 02347 virtual bool route(); 02348 02352 virtual void cleanup(); 02353 02354 protected: 02359 const String& id() const 02360 { return m_id; } 02361 }; 02362 02368 YATE_API bool isE164(const char* str); 02369 02370 }; // namespace TelEngine 02371 02372 #endif /* __YATEPHONE_H */ 02373 02374 /* vi: set ts=8 sw=4 sts=4 noet: */