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 explicit 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 YNOCOPY(FormatRepository); // no automatic copies please 00157 private: 00158 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 NamedList 00186 { 00187 public: 00191 inline DataFormat() 00192 : NamedList((const char*)0), m_parsed(0) 00193 { } 00194 00199 inline DataFormat(const char* value) 00200 : NamedList(value), m_parsed(0) 00201 { } 00202 00207 inline DataFormat(const DataFormat& value) 00208 : NamedList(value), m_parsed(value.getInfo()) 00209 { } 00210 00215 inline DataFormat(const String& value) 00216 : NamedList(value), m_parsed(0) 00217 { } 00218 00223 inline DataFormat(const NamedList& value) 00224 : NamedList(value), m_parsed(0) 00225 { } 00226 00231 inline DataFormat(const String* value) 00232 : NamedList(value ? value->c_str() : (const char*)0), m_parsed(0) 00233 { } 00234 00239 inline explicit DataFormat(const FormatInfo* format) 00240 : NamedList(format ? format->name : (const char*)0), m_parsed(format) 00241 { } 00242 00246 inline DataFormat& operator=(const DataFormat& value) 00247 { NamedList::operator=(value); m_parsed = value.getInfo(); return *this; } 00248 00253 const FormatInfo* getInfo() const; 00254 00260 inline int frameSize(int defValue = 0) const 00261 { return getInfo() ? getInfo()->frameSize : defValue; } 00262 00268 inline int frameTime(int defValue = 0) const 00269 { return getInfo() ? getInfo()->frameTime : defValue; } 00270 00277 inline int sampleRate(int defValue = 0) const 00278 { return getInfo() ? getInfo()->sampleRate : defValue; } 00279 00285 inline int numChannels(int defValue = 1) const 00286 { return getInfo() ? getInfo()->numChannels : defValue; } 00287 00288 protected: 00292 virtual void changed(); 00293 00294 private: 00295 mutable const FormatInfo* m_parsed; 00296 }; 00297 00301 class YATE_API DataNode : public RefObject 00302 { 00303 friend class DataEndpoint; 00304 YNOCOPY(DataNode); // no automatic copies please 00305 public: 00309 enum DataFlags { 00310 DataStart = 0x0001, 00311 DataEnd = 0x0002, 00312 DataMark = 0x0004, 00313 DataSilent = 0x0008, 00314 DataMissed = 0x0010, 00315 DataError = 0x0020, 00316 DataPrivate = 0x0100 00317 }; 00318 00323 inline explicit DataNode(const char* format = 0) 00324 : m_format(format), m_timestamp(0) 00325 { } 00326 00332 virtual int costFormat(const DataFormat& format) 00333 { return -1; } 00334 00340 virtual bool setFormat(const DataFormat& format) 00341 { return false; } 00342 00347 inline const DataFormat& getFormat() const 00348 { return m_format; } 00349 00354 inline unsigned long timeStamp() const 00355 { return m_timestamp; } 00356 00361 virtual bool valid() const 00362 { return true; } 00363 00369 virtual bool control(NamedList& params) 00370 { return false; } 00371 00376 inline static unsigned long invalidStamp() 00377 { return (unsigned long)-1; } 00378 00379 protected: 00385 virtual void attached(bool added) 00386 { } 00387 00388 DataFormat m_format; 00389 unsigned long m_timestamp; 00390 }; 00391 00392 class DataSource; 00393 class DataTranslator; 00394 class TranslatorFactory; 00395 class ThreadedSourcePrivate; 00396 00400 class YATE_API DataConsumer : public DataNode 00401 { 00402 friend class DataSource; 00403 00404 public: 00409 inline explicit DataConsumer(const char* format = "slin") 00410 : DataNode(format), 00411 m_source(0), m_override(0), 00412 m_regularTsDelta(0), m_overrideTsDelta(0), m_lastTsTime(0) 00413 { } 00414 00418 virtual void destroyed(); 00419 00425 virtual void* getObject(const String& name) const; 00426 00436 virtual unsigned long Consume(const DataBlock& data, unsigned long tStamp, unsigned long flags) = 0; 00437 00442 inline DataSource* getConnSource() const 00443 { return m_source; } 00444 00449 inline DataSource* getOverSource() const 00450 { return m_override; } 00451 00456 virtual DataSource* getTransSource() const 00457 { return 0; } 00458 00459 protected: 00465 virtual bool synchronize(DataSource* source); 00466 00467 private: 00468 unsigned long Consume(const DataBlock& data, unsigned long tStamp, 00469 unsigned long flags, DataSource* source); 00470 DataSource* m_source; 00471 DataSource* m_override; 00472 long m_regularTsDelta; 00473 long m_overrideTsDelta; 00474 u_int64_t m_lastTsTime; 00475 }; 00476 00480 class YATE_API DataSource : public DataNode, public Mutex 00481 { 00482 friend class DataTranslator; 00483 YNOCOPY(DataSource); // no automatic copies please 00484 public: 00489 inline explicit DataSource(const char* format = "slin") 00490 : DataNode(format), Mutex(false,"DataSource"), 00491 m_nextStamp(invalidStamp()), m_translator(0) { } 00492 00496 virtual void destroyed(); 00497 00503 virtual void* getObject(const String& name) const; 00504 00509 virtual bool valid() const; 00510 00518 unsigned long Forward(const DataBlock& data, unsigned long tStamp = invalidStamp(), 00519 unsigned long flags = 0); 00520 00527 bool attach(DataConsumer* consumer, bool override = false); 00528 00534 bool detach(DataConsumer* consumer); 00535 00539 void clear(); 00540 00545 inline DataTranslator* getTranslator() const 00546 { return m_translator; } 00547 00552 void synchronize(unsigned long tStamp); 00553 00558 inline unsigned long nextStamp() const 00559 { return m_nextStamp; } 00560 00561 protected: 00562 unsigned long m_nextStamp; 00563 ObjList m_consumers; 00564 private: 00565 inline void setTranslator(DataTranslator* translator) { 00566 Lock mylock(this); 00567 m_translator = translator; 00568 } 00569 bool detachInternal(DataConsumer* consumer); 00570 DataTranslator* m_translator; 00571 }; 00572 00577 class YATE_API ThreadedSource : public DataSource 00578 { 00579 friend class ThreadedSourcePrivate; 00580 public: 00584 virtual void destroyed(); 00585 00592 bool start(const char* name = "ThreadedSource", Thread::Priority prio = Thread::Normal); 00593 00597 void stop(); 00598 00603 Thread* thread() const; 00604 00609 bool running() const; 00610 00611 protected: 00616 inline explicit ThreadedSource(const char* format = "slin") 00617 : DataSource(format), m_thread(0) 00618 { } 00619 00623 virtual void run() = 0; 00624 00629 virtual void cleanup(); 00630 00636 bool looping(bool runConsumers = false) const; 00637 00638 private: 00639 ThreadedSourcePrivate* m_thread; 00640 }; 00641 00647 class YATE_API DataTranslator : public DataConsumer 00648 { 00649 friend class TranslatorFactory; 00650 public: 00656 DataTranslator(const char* sFormat, const char* dFormat); 00657 00664 explicit DataTranslator(const char* sFormat, DataSource* source = 0); 00665 00669 ~DataTranslator(); 00670 00676 virtual void* getObject(const String& name) const; 00677 00682 virtual bool valid() const 00683 { return m_tsource && m_tsource->valid(); } 00684 00689 virtual DataSource* getTransSource() const 00690 { return m_tsource; } 00691 00696 DataTranslator* getFirstTranslator(); 00697 00702 const DataTranslator* getFirstTranslator() const; 00703 00712 static ObjList* srcFormats(const DataFormat& dFormat = "slin", int maxCost = -1, unsigned int maxLen = 0, ObjList* lst = 0); 00713 00722 static ObjList* destFormats(const DataFormat& sFormat = "slin", int maxCost = -1, unsigned int maxLen = 0, ObjList* lst = 0); 00723 00732 static ObjList* allFormats(const ObjList* formats, bool existing = true, bool sameRate = true, bool sameChans = true); 00733 00742 static ObjList* allFormats(const String& formats, bool existing = true, bool sameRate = true, bool sameChans = true); 00743 00750 static bool canConvert(const DataFormat& fmt1, const DataFormat& fmt2 = "slin"); 00751 00758 static int cost(const DataFormat& sFormat, const DataFormat& dFormat); 00759 00766 static DataTranslator* create(const DataFormat& sFormat, const DataFormat& dFormat); 00767 00775 static bool attachChain(DataSource* source, DataConsumer* consumer, bool override = false); 00776 00783 static bool detachChain(DataSource* source, DataConsumer* consumer); 00784 00789 static void setMaxChain(unsigned int maxChain); 00790 00791 protected: 00797 virtual bool synchronize(DataSource* source); 00798 00803 static void install(TranslatorFactory* factory); 00804 00809 static void uninstall(TranslatorFactory* factory); 00810 00811 private: 00812 DataTranslator(); // No default constructor please 00813 static void compose(); 00814 static void compose(TranslatorFactory* factory); 00815 static bool canConvert(const FormatInfo* fmt1, const FormatInfo* fmt2); 00816 DataSource* m_tsource; 00817 static Mutex s_mutex; 00818 static ObjList s_factories; 00819 static unsigned int s_maxChain; 00820 }; 00821 00827 class YATE_API TranslatorFactory : public GenObject 00828 { 00829 YNOCOPY(TranslatorFactory); // no automatic copies please 00830 protected: 00835 inline explicit TranslatorFactory(const char* name = 0) 00836 : m_name(name ? name : "?") 00837 { DataTranslator::install(this); } 00838 00839 public: 00843 virtual ~TranslatorFactory(); 00844 00849 virtual void removed(const TranslatorFactory* factory); 00850 00857 virtual DataTranslator* create(const DataFormat& sFormat, const DataFormat& dFormat) = 0; 00858 00863 virtual const TranslatorCaps* getCapabilities() const = 0; 00864 00871 virtual bool converts(const DataFormat& sFormat, const DataFormat& dFormat) const; 00872 00877 virtual unsigned int length() const; 00878 00884 virtual bool intermediate(const FormatInfo* info) const; 00885 00890 virtual const FormatInfo* intermediate() const; 00891 00896 virtual const char* name() const 00897 { return m_name; } 00898 00899 private: 00900 const char* m_name; 00901 }; 00902 00908 class YATE_API DataEndpoint : public RefObject 00909 { 00910 YNOCOPY(DataEndpoint); // no automatic copies please 00911 public: 00915 explicit DataEndpoint(CallEndpoint* call = 0, const char* name = "audio"); 00916 00920 virtual void destroyed(); 00921 00927 virtual void* getObject(const String& name) const; 00928 00933 virtual const String& toString() const; 00934 00939 Mutex* mutex() const; 00940 00945 static Mutex& commonMutex(); 00946 00952 bool connect(DataEndpoint* peer); 00953 00958 bool disconnect(); 00959 00964 void setSource(DataSource* source = 0); 00965 00970 inline DataSource* getSource() const 00971 { return m_source; } 00972 00977 void setConsumer(DataConsumer* consumer = 0); 00978 00983 inline DataConsumer* getConsumer() const 00984 { return m_consumer; } 00985 00991 void setPeerRecord(DataConsumer* consumer = 0); 00992 00997 inline DataConsumer* getPeerRecord() const 00998 { return m_peerRecord; } 00999 01005 void setCallRecord(DataConsumer* consumer = 0); 01006 01011 inline DataConsumer* getCallRecord() const 01012 { return m_callRecord; } 01013 01019 bool clearData(DataNode* node); 01020 01026 bool addSniffer(DataConsumer* sniffer); 01027 01033 bool delSniffer(DataConsumer* sniffer); 01034 01040 inline DataConsumer* getSniffer(const String& name) 01041 { return static_cast<DataConsumer*>(m_sniffers[name]); } 01042 01046 void clearSniffers(); 01047 01052 inline DataEndpoint* getPeer() const 01053 { return m_peer; } 01054 01059 inline CallEndpoint* getCall() const 01060 { return m_call; } 01061 01066 inline const String& name() const 01067 { return m_name; } 01068 01074 inline void clearCall(const CallEndpoint* call) 01075 { if (call == m_call) m_call = 0; } 01076 01082 virtual bool control(NamedList& params); 01083 01084 protected: 01090 virtual bool nativeConnect(DataEndpoint* peer) 01091 { return false; } 01092 01093 private: 01094 String m_name; 01095 DataSource* m_source; 01096 DataConsumer* m_consumer; 01097 DataEndpoint* m_peer; 01098 CallEndpoint* m_call; 01099 DataConsumer* m_peerRecord; 01100 DataConsumer* m_callRecord; 01101 ObjList m_sniffers; 01102 }; 01103 01108 class YATE_API CallEndpoint : public RefObject 01109 { 01110 friend class DataEndpoint; 01111 YNOCOPY(CallEndpoint); // no automatic copies please 01112 private: 01113 CallEndpoint* m_peer; 01114 String m_id; 01115 01116 protected: 01117 ObjList m_data; 01118 Mutex* m_mutex; 01119 01120 public: 01124 virtual void destroyed(); 01125 01131 virtual void* getObject(const String& name) const; 01132 01137 virtual const String& toString() const 01138 { return m_id; } 01139 01144 inline const String& id() const 01145 { return m_id; } 01146 01151 inline CallEndpoint* getPeer() const 01152 { return m_peer; } 01153 01159 bool getPeerId(String& id) const; 01160 01165 String getPeerId() const; 01166 01171 inline Mutex* mutex() const 01172 { return m_mutex; } 01173 01178 static Mutex& commonMutex(); 01179 01187 bool connect(CallEndpoint* peer, const char* reason = 0, bool notify = true); 01188 01196 inline bool disconnect(const char* reason = 0, bool notify = true, const NamedList* params = 0) 01197 { return disconnect(false,reason,notify,params); } 01198 01205 inline bool disconnect(const char* reason, const NamedList& params) 01206 { return disconnect(false,reason,true,¶ms); } 01207 01213 DataEndpoint* getEndpoint(const char* type = "audio") const; 01214 01220 DataEndpoint* setEndpoint(const char* type = "audio"); 01221 01226 void clearEndpoint(const char* type = 0); 01227 01233 void setSource(DataSource* source = 0, const char* type = "audio"); 01234 01240 DataSource* getSource(const char* type = "audio") const; 01241 01247 void setConsumer(DataConsumer* consumer = 0, const char* type = "audio"); 01248 01254 DataConsumer* getConsumer(const char* type = "audio") const; 01255 01262 bool clearData(DataNode* node, const char* type = "audio"); 01263 01264 protected: 01268 CallEndpoint(const char* id = 0); 01269 01274 virtual void connected(const char* reason) { } 01275 01281 virtual void disconnected(bool final, const char* reason) { } 01282 01287 virtual void setDisconnect(const NamedList* params) { } 01288 01296 void setPeer(CallEndpoint* peer, const char* reason = 0, bool notify = true, const NamedList* params = 0); 01297 01302 void setEndpoint(DataEndpoint* endPoint); 01303 01308 virtual void setId(const char* newId); 01309 01310 private: 01311 bool disconnect(bool final, const char* reason, bool notify, const NamedList* params); 01312 }; 01313 01318 class YATE_API Module : public Plugin, public Mutex, public MessageReceiver 01319 { 01320 YNOCOPY(Module); // no automatic copies please 01321 private: 01322 bool m_init; 01323 int m_relays; 01324 String m_type; 01325 Regexp m_filter; 01326 u_int64_t m_changed; 01327 static unsigned int s_delay; 01328 01329 public: 01335 virtual void* getObject(const String& name) const; 01336 01341 inline const String& type() const 01342 { return m_type; } 01343 01348 void changed(); 01349 01354 inline static unsigned int updateDelay() 01355 { return s_delay; } 01356 01361 inline static void updateDelay(unsigned int delay) 01362 { s_delay = delay; } 01363 01368 inline bool filterInstalled() const 01369 { return !m_filter.null(); } 01370 01376 bool filterDebug(const String& item) const; 01377 01385 static bool itemComplete(String& itemList, const String& item, const String& partWord); 01386 01387 protected: 01391 enum { 01392 // Module messages 01393 Status = 0x00000001, 01394 Timer = 0x00000002, 01395 Level = 0x00000004, 01396 Command = 0x00000008, 01397 Help = 0x00000010, 01398 Halt = 0x00000020, 01399 Route = 0x00000040, 01400 // Driver messages 01401 Execute = 0x00000100, 01402 Drop = 0x00000200, 01403 // Channel messages 01404 Locate = 0x00000400, 01405 Masquerade = 0x00000800, 01406 Ringing = 0x00001000, 01407 Answered = 0x00002000, 01408 Tone = 0x00004000, 01409 Text = 0x00008000, 01410 Progress = 0x00010000, 01411 Update = 0x00020000, 01412 Transfer = 0x00040000, 01413 Control = 0x00080000, 01414 // Instant messenging related 01415 ImRoute = 0x00100000, 01416 ImExecute = 0x00200000, 01417 // Last possible public ID 01418 PubLast = 0x0fffffff, 01419 // Private messages base ID 01420 Private = 0x10000000 01421 } RelayID; 01422 01428 static const char* messageName(int id); 01429 01435 static inline int relayId(const char* name) 01436 { return lookup(name,s_messages); } 01437 01444 Module(const char* name, const char* type = 0, bool earlyInit = false); 01445 01449 virtual ~Module(); 01450 01454 virtual void initialize(); 01455 01459 void setup(); 01460 01466 inline bool relayInstalled(int id) const 01467 { return (id & m_relays) != 0; } 01468 01475 bool installRelay(int id, unsigned priority = 100); 01476 01483 bool installRelay(const char* name, unsigned priority = 100); 01484 01492 bool installRelay(int id, const char* name, unsigned priority = 100); 01493 01499 bool installRelay(MessageRelay* relay); 01500 01507 bool uninstallRelay(MessageRelay* relay, bool delRelay = true); 01508 01515 bool uninstallRelay(int id, bool delRelay = true); 01516 01521 bool uninstallRelays(); 01522 01529 virtual bool received(Message &msg, int id); 01530 01535 virtual void genUpdate(Message& msg); 01536 01541 virtual void msgTimer(Message& msg); 01542 01547 virtual void msgStatus(Message& msg); 01548 01554 virtual bool msgRoute(Message& msg); 01555 01562 virtual bool msgCommand(Message& msg); 01563 01568 virtual void statusModule(String& str); 01569 01574 virtual void statusParams(String& str); 01575 01580 virtual void statusDetail(String& str); 01581 01588 virtual bool commandExecute(String& retVal, const String& line); 01589 01597 virtual bool commandComplete(Message& msg, const String& partLine, const String& partWord); 01598 01604 virtual bool setDebug(Message& msg, const String& target); 01605 01606 private: 01607 Module(); // no default constructor please 01608 static TokenDict s_messages[]; 01609 ObjList m_relayList; 01610 }; 01611 01616 class YATE_API Channel : public CallEndpoint, public DebugEnabler, public MessageNotifier 01617 { 01618 friend class Driver; 01619 friend class Router; 01620 YNOCOPY(Channel); // no automatic copies please 01621 private: 01622 NamedList m_parameters; 01623 Driver* m_driver; 01624 bool m_outgoing; 01625 u_int64_t m_timeout; 01626 u_int64_t m_maxcall; 01627 u_int64_t m_dtmfTime; 01628 unsigned int m_dtmfSeq; 01629 String m_dtmfText; 01630 String m_dtmfDetected; 01631 String m_lastPeerId; 01632 01633 protected: 01634 String m_status; 01635 String m_address; 01636 String m_targetid; 01637 String m_billid; 01638 bool m_answered; 01639 01640 public: 01644 virtual ~Channel(); 01645 01651 virtual void* getObject(const String& name) const; 01652 01657 static Mutex& paramMutex(); 01658 01664 virtual void complete(Message& msg, bool minimal = false) const; 01665 01673 Message* message(const char* name, bool minimal = false, bool data = false); 01674 01685 Message* message(const char* name, const NamedList* original, const char* params = 0, bool minimal = false, bool data = false); 01686 01697 inline Message* message(const char* name, const NamedList& original, const char* params = 0, bool minimal = false, bool data = false) 01698 { return message(name,&original,params,minimal,data); } 01699 01705 virtual bool msgProgress(Message& msg); 01706 01712 virtual bool msgRinging(Message& msg); 01713 01719 virtual bool msgAnswered(Message& msg); 01720 01727 virtual bool msgTone(Message& msg, const char* tone); 01728 01735 virtual bool msgText(Message& msg, const char* text); 01736 01743 virtual bool msgDrop(Message& msg, const char* reason); 01744 01750 virtual bool msgTransfer(Message& msg); 01751 01757 virtual bool msgUpdate(Message& msg); 01758 01764 virtual bool msgMasquerade(Message& msg); 01765 01770 virtual void msgStatus(Message& msg); 01771 01777 virtual bool msgControl(Message& msg); 01778 01784 virtual void checkTimers(Message& msg, const Time& tmr); 01785 01792 virtual bool callPrerouted(Message& msg, bool handled); 01793 01799 virtual bool callRouted(Message& msg); 01800 01805 virtual void callAccept(Message& msg); 01806 01813 virtual void callRejected(const char* error, const char* reason = 0, const Message* msg = 0); 01814 01820 virtual void callConnect(Message& msg); 01821 01826 virtual bool setDebug(Message& msg); 01827 01832 inline const String& status() const 01833 { return m_status; } 01834 01839 inline const String& address() const 01840 { return m_address; } 01841 01846 inline bool isOutgoing() const 01847 { return m_outgoing; } 01848 01853 inline bool isIncoming() const 01854 { return !m_outgoing; } 01855 01860 inline bool isAnswered() const 01861 { return m_answered; } 01862 01867 const char* direction() const; 01868 01873 inline Driver* driver() const 01874 { return m_driver; } 01875 01880 inline u_int64_t timeout() const 01881 { return m_timeout; } 01882 01887 inline void timeout(u_int64_t tout) 01888 { m_timeout = tout; } 01889 01894 inline u_int64_t maxcall() const 01895 { return m_maxcall; } 01896 01901 inline void maxcall(u_int64_t tout) 01902 { m_maxcall = tout; } 01903 01908 inline void setMaxcall(const Message& msg) 01909 { setMaxcall(&msg); } 01910 01915 void setMaxcall(const Message* msg); 01916 01922 inline const String& targetid() const 01923 { return m_targetid; } 01924 01930 inline const String& billid() const 01931 { return m_billid; } 01932 01937 const String& lastPeerId() const 01938 { return m_lastPeerId; } 01939 01944 void initChan(); 01945 01952 bool startRouter(Message* msg); 01953 01958 static unsigned int allocId(); 01959 01964 void filterDebug(const String& item); 01965 01970 inline const NamedList& parameters() const 01971 { return m_parameters; } 01972 01978 virtual void dispatched(const Message& msg, bool handled); 01979 01980 protected: 01984 Channel(Driver* driver, const char* id = 0, bool outgoing = false); 01985 01989 Channel(Driver& driver, const char* id = 0, bool outgoing = false); 01990 01995 void cleanup(); 01996 02000 void dropChan(); 02001 02006 virtual void zeroRefs(); 02007 02012 virtual void connected(const char* reason); 02013 02019 virtual void disconnected(bool final, const char* reason); 02020 02025 virtual void setDisconnect(const NamedList* params); 02026 02032 virtual void endDisconnect(const Message& msg, bool handled); 02033 02038 virtual void setId(const char* newId); 02039 02045 virtual Message* getDisconnect(const char* reason); 02046 02052 void status(const char* newstat); 02053 02058 virtual void statusParams(String& str); 02059 02064 inline void setOutgoing(bool outgoing = true) 02065 { m_outgoing = outgoing; } 02066 02072 bool dtmfSequence(Message& msg); 02073 02079 bool dtmfEnqueue(Message* msg); 02080 02087 bool dtmfInband(const char* tone); 02088 02095 bool toneDetect(const char* sniffer = 0); 02096 02101 inline NamedList& parameters() 02102 { return m_parameters; } 02103 02104 private: 02105 void init(); 02106 Channel(); // no default constructor please 02107 }; 02108 02113 class YATE_API Driver : public Module 02114 { 02115 friend class Router; 02116 friend class Channel; 02117 02118 private: 02119 bool m_init; 02120 bool m_varchan; 02121 String m_prefix; 02122 ObjList m_chans; 02123 int m_routing; 02124 int m_routed; 02125 int m_total; 02126 unsigned int m_nextid; 02127 int m_timeout; 02128 int m_maxroute; 02129 int m_maxchans; 02130 bool m_dtmfDups; 02131 02132 public: 02138 virtual void* getObject(const String& name) const; 02139 02144 inline const String& prefix() const 02145 { return m_prefix; } 02146 02151 inline bool varchan() const 02152 { return m_varchan; } 02153 02158 inline ObjList& channels() 02159 { return m_chans; } 02160 02166 virtual Channel* find(const String& id) const; 02167 02172 virtual bool isBusy() const; 02173 02178 virtual void dropAll(Message &msg); 02179 02185 virtual bool canAccept(bool routers = true); 02186 02191 virtual bool canRoute(); 02192 02197 unsigned int nextid(); 02198 02203 inline unsigned int lastid() const 02204 { return m_nextid; } 02205 02210 inline int timeout() const 02211 { return m_timeout; } 02212 02217 inline int routing() const 02218 { return m_routing; } 02219 02224 inline int routed() const 02225 { return m_routed; } 02226 02231 inline int total() const 02232 { return m_total; } 02233 02234 protected: 02240 Driver(const char* name, const char* type = 0); 02241 02245 virtual void initialize(); 02246 02252 void setup(const char* prefix = 0, bool minimal = false); 02253 02260 virtual bool received(Message &msg, int id); 02261 02266 virtual void genUpdate(Message& msg); 02267 02274 virtual bool hasLine(const String& line) const; 02275 02282 virtual bool msgRoute(Message& msg); 02283 02290 virtual bool msgExecute(Message& msg, String& dest) = 0; 02291 02299 virtual bool commandComplete(Message& msg, const String& partLine, const String& partWord); 02300 02305 virtual void statusModule(String& str); 02306 02311 virtual void statusParams(String& str); 02312 02317 virtual void statusDetail(String& str); 02318 02324 virtual bool setDebug(Message& msg, const String& target); 02325 02329 virtual void loadLimits(); 02330 02335 inline void varchan(bool variable) 02336 { m_varchan = variable; } 02337 02342 inline void timeout(int tout) 02343 { m_timeout = tout; } 02344 02349 inline void maxRoute(int ncalls) 02350 { m_maxroute = ncalls; } 02351 02356 inline void maxChans(int ncalls) 02357 { m_maxchans = ncalls; } 02358 02363 inline void dtmfDups(bool duplicates) 02364 { m_dtmfDups = duplicates; } 02365 02366 private: 02367 Driver(); // no default constructor please 02368 }; 02369 02374 class YATE_API Router : public Thread 02375 { 02376 YNOCOPY(Router); // no automatic copies please 02377 private: 02378 Driver* m_driver; 02379 String m_id; 02380 Message* m_msg; 02381 02382 public: 02389 Router(Driver* driver, const char* id, Message* msg); 02390 02394 virtual void run(); 02395 02400 virtual bool route(); 02401 02405 virtual void cleanup(); 02406 02407 protected: 02412 const String& id() const 02413 { return m_id; } 02414 }; 02415 02421 YATE_API bool isE164(const char* str); 02422 02423 }; // namespace TelEngine 02424 02425 #endif /* __YATEPHONE_H */ 02426 02427 /* vi: set ts=8 sw=4 sts=4 noet: */