00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
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);
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);
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);
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();
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);
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);
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);
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);
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
01393 Status = 0x00000001,
01394 Timer = 0x00000002,
01395 Level = 0x00000004,
01396 Command = 0x00000008,
01397 Help = 0x00000010,
01398 Halt = 0x00000020,
01399 Route = 0x00000040,
01400
01401 Execute = 0x00000100,
01402 Drop = 0x00000200,
01403
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
01415 ImRoute = 0x00100000,
01416 ImExecute = 0x00200000,
01417
01418 PubLast = 0x0fffffff,
01419
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();
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);
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
01658 virtual void complete(Message& msg, bool minimal = false) const;
01659
01667 Message* message(const char* name, bool minimal = false, bool data = false);
01668
01679 Message* message(const char* name, const NamedList* original, const char* params = 0, bool minimal = false, bool data = false);
01680
01691 inline Message* message(const char* name, const NamedList& original, const char* params = 0, bool minimal = false, bool data = false)
01692 { return message(name,&original,params,minimal,data); }
01693
01699 virtual bool msgProgress(Message& msg);
01700
01706 virtual bool msgRinging(Message& msg);
01707
01713 virtual bool msgAnswered(Message& msg);
01714
01721 virtual bool msgTone(Message& msg, const char* tone);
01722
01729 virtual bool msgText(Message& msg, const char* text);
01730
01737 virtual bool msgDrop(Message& msg, const char* reason);
01738
01744 virtual bool msgTransfer(Message& msg);
01745
01751 virtual bool msgUpdate(Message& msg);
01752
01758 virtual bool msgMasquerade(Message& msg);
01759
01764 virtual void msgStatus(Message& msg);
01765
01771 virtual bool msgControl(Message& msg);
01772
01778 virtual void checkTimers(Message& msg, const Time& tmr);
01779
01786 virtual bool callPrerouted(Message& msg, bool handled);
01787
01793 virtual bool callRouted(Message& msg);
01794
01799 virtual void callAccept(Message& msg);
01800
01807 virtual void callRejected(const char* error, const char* reason = 0, const Message* msg = 0);
01808
01814 virtual void callConnect(Message& msg);
01815
01820 virtual bool setDebug(Message& msg);
01821
01826 inline const String& status() const
01827 { return m_status; }
01828
01833 inline const String& address() const
01834 { return m_address; }
01835
01840 inline bool isOutgoing() const
01841 { return m_outgoing; }
01842
01847 inline bool isIncoming() const
01848 { return !m_outgoing; }
01849
01854 inline bool isAnswered() const
01855 { return m_answered; }
01856
01861 const char* direction() const;
01862
01867 inline Driver* driver() const
01868 { return m_driver; }
01869
01874 inline u_int64_t timeout() const
01875 { return m_timeout; }
01876
01881 inline void timeout(u_int64_t tout)
01882 { m_timeout = tout; }
01883
01888 inline u_int64_t maxcall() const
01889 { return m_maxcall; }
01890
01895 inline void maxcall(u_int64_t tout)
01896 { m_maxcall = tout; }
01897
01902 inline void setMaxcall(const Message& msg)
01903 { setMaxcall(&msg); }
01904
01909 void setMaxcall(const Message* msg);
01910
01916 inline const String& targetid() const
01917 { return m_targetid; }
01918
01924 inline const String& billid() const
01925 { return m_billid; }
01926
01931 const String& lastPeerId() const
01932 { return m_lastPeerId; }
01933
01938 void initChan();
01939
01946 bool startRouter(Message* msg);
01947
01952 static unsigned int allocId();
01953
01958 void filterDebug(const String& item);
01959
01964 inline const NamedList& parameters() const
01965 { return m_parameters; }
01966
01972 virtual void dispatched(const Message& msg, bool handled);
01973
01974 protected:
01978 Channel(Driver* driver, const char* id = 0, bool outgoing = false);
01979
01983 Channel(Driver& driver, const char* id = 0, bool outgoing = false);
01984
01989 void cleanup();
01990
01994 void dropChan();
01995
02000 virtual void zeroRefs();
02001
02006 virtual void connected(const char* reason);
02007
02013 virtual void disconnected(bool final, const char* reason);
02014
02019 virtual void setDisconnect(const NamedList* params);
02020
02026 virtual void endDisconnect(const Message& msg, bool handled);
02027
02032 virtual void setId(const char* newId);
02033
02039 virtual Message* getDisconnect(const char* reason);
02040
02046 void status(const char* newstat);
02047
02052 virtual void statusParams(String& str);
02053
02058 inline void setOutgoing(bool outgoing = true)
02059 { m_outgoing = outgoing; }
02060
02066 bool dtmfSequence(Message& msg);
02067
02073 bool dtmfEnqueue(Message* msg);
02074
02081 bool dtmfInband(const char* tone);
02082
02089 bool toneDetect(const char* sniffer = 0);
02090
02095 inline NamedList& parameters()
02096 { return m_parameters; }
02097
02098 private:
02099 void init();
02100 Channel();
02101 };
02102
02107 class YATE_API Driver : public Module
02108 {
02109 friend class Router;
02110 friend class Channel;
02111
02112 private:
02113 bool m_init;
02114 bool m_varchan;
02115 String m_prefix;
02116 ObjList m_chans;
02117 int m_routing;
02118 int m_routed;
02119 int m_total;
02120 unsigned int m_nextid;
02121 int m_timeout;
02122 int m_maxroute;
02123 int m_maxchans;
02124 bool m_dtmfDups;
02125
02126 public:
02132 virtual void* getObject(const String& name) const;
02133
02138 inline const String& prefix() const
02139 { return m_prefix; }
02140
02145 inline bool varchan() const
02146 { return m_varchan; }
02147
02152 inline ObjList& channels()
02153 { return m_chans; }
02154
02160 virtual Channel* find(const String& id) const;
02161
02166 virtual bool isBusy() const;
02167
02172 virtual void dropAll(Message &msg);
02173
02179 virtual bool canAccept(bool routers = true);
02180
02185 virtual bool canRoute();
02186
02191 unsigned int nextid();
02192
02197 inline unsigned int lastid() const
02198 { return m_nextid; }
02199
02204 inline int timeout() const
02205 { return m_timeout; }
02206
02211 inline int routing() const
02212 { return m_routing; }
02213
02218 inline int routed() const
02219 { return m_routed; }
02220
02225 inline int total() const
02226 { return m_total; }
02227
02228 protected:
02234 Driver(const char* name, const char* type = 0);
02235
02239 virtual void initialize();
02240
02246 void setup(const char* prefix = 0, bool minimal = false);
02247
02254 virtual bool received(Message &msg, int id);
02255
02260 virtual void genUpdate(Message& msg);
02261
02268 virtual bool hasLine(const String& line) const;
02269
02276 virtual bool msgRoute(Message& msg);
02277
02284 virtual bool msgExecute(Message& msg, String& dest) = 0;
02285
02293 virtual bool commandComplete(Message& msg, const String& partLine, const String& partWord);
02294
02299 virtual void statusModule(String& str);
02300
02305 virtual void statusParams(String& str);
02306
02311 virtual void statusDetail(String& str);
02312
02318 virtual bool setDebug(Message& msg, const String& target);
02319
02323 virtual void loadLimits();
02324
02329 inline void varchan(bool variable)
02330 { m_varchan = variable; }
02331
02336 inline void timeout(int tout)
02337 { m_timeout = tout; }
02338
02343 inline void maxRoute(int ncalls)
02344 { m_maxroute = ncalls; }
02345
02350 inline void maxChans(int ncalls)
02351 { m_maxchans = ncalls; }
02352
02357 inline void dtmfDups(bool duplicates)
02358 { m_dtmfDups = duplicates; }
02359
02360 private:
02361 Driver();
02362 };
02363
02368 class YATE_API Router : public Thread
02369 {
02370 YNOCOPY(Router);
02371 private:
02372 Driver* m_driver;
02373 String m_id;
02374 Message* m_msg;
02375
02376 public:
02383 Router(Driver* driver, const char* id, Message* msg);
02384
02388 virtual void run();
02389
02394 virtual bool route();
02395
02399 virtual void cleanup();
02400
02401 protected:
02406 const String& id() const
02407 { return m_id; }
02408 };
02409
02415 YATE_API bool isE164(const char* str);
02416
02417 };
02418
02419 #endif
02420
02421