Yate: yatephone.h Source File

Yate

- Main Page
- Namespaces
- Classes
- Files

- File List

yatephone.h
1
22 #ifndef __YATEPHONE_H
23 #define __YATEPHONE_H
24
25 #ifndef __cplusplus
26 #error C++ is required
27 #endif
28
29 #include <yatengine.h>
30
34 namespace TelEngine {
35
39 struct YATE_API ImageInfo {
43 int width;
44
48 int height;
49
53 int depth;
54 };
55
59 struct YATE_API FormatInfo {
63 const char* name;
64
68 const char* type;
69
73 int frameSize;
74
78 int frameTime;
79
83 int sampleRate;
84
88 int numChannels;
89
93 bool converter;
94
100 int guessSamples(int len) const;
101
106 int dataRate() const;
107
111 inline FormatInfo()
112 : name(0), type("audio"),
113 frameSize(0), frameTime(0),
114 sampleRate(8000), numChannels(1),
115 converter(false)
116 { }
117
121 inline explicit FormatInfo(const char* _name, int fsize = 0, int ftime = 10000,
122 const char* _type = "audio", int srate = 8000, int nchan = 1, bool convert = false)
123 : name(_name), type(_type),
124 frameSize(fsize), frameTime(ftime),
125 sampleRate(srate), numChannels(nchan),
126 converter(convert)
127 { }
128 };
129
130 class DataEndpoint;
131 class CallEndpoint;
132 class Driver;
133
138 struct YATE_API TranslatorCaps {
140 const FormatInfo* src;
142 const FormatInfo* dest;
144 int cost;
145 };
146
151 class YATE_API FormatRepository
152 {
153 YNOCOPY(FormatRepository); // no automatic copies please
154 private:
155 FormatRepository();
156 public:
162 static const FormatInfo* getFormat(const String& name);
163
175 static const FormatInfo* addFormat(const String& name, int fsize, int ftime, const String& type = "audio", int srate = 8000, int nchan = 1);
176 };
177
182 class YATE_API DataFormat : public NamedList
183 {
184 public:
188 inline DataFormat()
189 : NamedList((const char*)0), m_parsed(0)
190 { }
191
196 inline DataFormat(const char* value)
197 : NamedList(value), m_parsed(0)
198 { }
199
204 inline DataFormat(const DataFormat& value)
205 : NamedList(value), m_parsed(value.getInfo())
206 { }
207
212 inline DataFormat(const String& value)
213 : NamedList(value), m_parsed(0)
214 { }
215
220 inline DataFormat(const NamedList& value)
221 : NamedList(value), m_parsed(0)
222 { }
223
228 inline DataFormat(const String* value)
229 : NamedList(value ? value->c_str() : (const char*)0), m_parsed(0)
230 { }
231
236 inline explicit DataFormat(const FormatInfo* format)
237 : NamedList(format ? format->name : (const char*)0), m_parsed(format)
238 { }
239
243 inline DataFormat& operator=(const DataFormat& value)
244 { NamedList::operator=(value); m_parsed = value.getInfo(); return *this; }
245
250 const FormatInfo* getInfo() const;
251
257 inline int frameSize(int defValue = 0) const
258 { return getInfo() ? getInfo()->frameSize : defValue; }
259
265 inline int frameTime(int defValue = 0) const
266 { return getInfo() ? getInfo()->frameTime : defValue; }
267
274 inline int sampleRate(int defValue = 0) const
275 { return getInfo() ? getInfo()->sampleRate : defValue; }
276
282 inline int numChannels(int defValue = 1) const
283 { return getInfo() ? getInfo()->numChannels : defValue; }
284
285 protected:
289 virtual void changed();
290
291 private:
292 mutable const FormatInfo* m_parsed;
293 };
294
298 class YATE_API DataNode : public RefObject
299 {
300 friend class DataEndpoint;
301 YNOCOPY(DataNode); // no automatic copies please
302 public:
306 enum DataFlags {
307 DataStart = 0x0001,
308 DataEnd = 0x0002,
309 DataMark = 0x0004,
310 DataSilent = 0x0008,
311 DataMissed = 0x0010,
312 DataError = 0x0020,
313 DataPrivate = 0x0100
314 };
315
320 inline explicit DataNode(const char* format = 0)
321 : m_format(format), m_timestamp(0)
322 { }
323
329 virtual int costFormat(const DataFormat& format)
330 { return -1; }
331
337 virtual bool setFormat(const DataFormat& format)
338 { return false; }
339
344 inline const DataFormat& getFormat() const
345 { return m_format; }
346
351 inline unsigned long timeStamp() const
352 { return m_timestamp; }
353
358 virtual bool valid() const
359 { return true; }
360
366 virtual bool control(NamedList& params)
367 { return false; }
368
373 inline static unsigned long invalidStamp()
374 { return (unsigned long)-1; }
375
381 virtual void attached(bool added)
382 { }
383
384 protected:
385 DataFormat m_format;
386 unsigned long m_timestamp;
387 };
388
389 class DataSource;
390 class DataTranslator;
391 class TranslatorFactory;
392 class ThreadedSourcePrivate;
393
397 class YATE_API DataConsumer : public DataNode
398 {
399 friend class DataSource;
400
401 public:
406 inline explicit DataConsumer(const char* format = "slin")
407 : DataNode(format),
408 m_source(0), m_override(0),
409 m_regularTsDelta(0), m_overrideTsDelta(0), m_lastTsTime(0)
410 { }
411
415 virtual void destroyed();
416
422 virtual void* getObject(const String& name) const;
423
433 virtual unsigned long Consume(const DataBlock& data, unsigned long tStamp, unsigned long flags) = 0;
434
439 inline DataSource* getConnSource() const
440 { return m_source; }
441
446 inline DataSource* getOverSource() const
447 { return m_override; }
448
453 virtual DataSource* getTransSource() const
454 { return 0; }
455
456 protected:
462 virtual bool synchronize(DataSource* source);
463
464 private:
465 unsigned long Consume(const DataBlock& data, unsigned long tStamp,
466 unsigned long flags, DataSource* source);
467 DataSource* m_source;
468 DataSource* m_override;
469 long m_regularTsDelta;
470 long m_overrideTsDelta;
471 u_int64_t m_lastTsTime;
472 };
473
477 class YATE_API DataSource : public DataNode, public Mutex
478 {
479 friend class DataTranslator;
480 YNOCOPY(DataSource); // no automatic copies please
481 public:
486 inline explicit DataSource(const char* format = "slin")
487 : DataNode(format), Mutex(false,"DataSource"),
488 m_nextStamp(invalidStamp()), m_translator(0) { }
489
493 virtual void destroyed();
494
500 virtual void* getObject(const String& name) const;
501
506 virtual bool valid() const;
507
513 virtual bool control(NamedList& params);
514
522 unsigned long Forward(const DataBlock& data, unsigned long tStamp = invalidStamp(),
523 unsigned long flags = 0);
524
531 bool attach(DataConsumer* consumer, bool override = false);
532
538 bool detach(DataConsumer* consumer);
539
543 void clear();
544
549 inline DataTranslator* getTranslator() const
550 { return m_translator; }
551
556 void synchronize(unsigned long tStamp);
557
562 inline unsigned long nextStamp() const
563 { return m_nextStamp; }
564
565 protected:
566 unsigned long m_nextStamp;
567 ObjList m_consumers;
568 private:
569 inline void setTranslator(DataTranslator* translator) {
570 Lock mylock(this);
571 m_translator = translator;
572 }
573 bool detachInternal(DataConsumer* consumer);
574 DataTranslator* m_translator;
575 };
576
581 class YATE_API ThreadedSource : public DataSource
582 {
583 friend class ThreadedSourcePrivate;
584 public:
588 virtual void destroyed();
589
596 bool start(const char* name = "ThreadedSource", Thread::Priority prio = Thread::Normal);
597
601 void stop();
602
607 Thread* thread() const;
608
613 bool running() const;
614
615 protected:
620 inline explicit ThreadedSource(const char* format = "slin")
621 : DataSource(format), m_thread(0)
622 { }
623
627 virtual void run() = 0;
628
633 virtual void cleanup();
634
640 bool looping(bool runConsumers = false) const;
641
642 private:
643 ThreadedSourcePrivate* m_thread;
644 };
645
651 class YATE_API DataTranslator : public DataConsumer
652 {
653 friend class TranslatorFactory;
654 public:
660 DataTranslator(const char* sFormat, const char* dFormat);
661
668 explicit DataTranslator(const char* sFormat, DataSource* source = 0);
669
673 ~DataTranslator();
674
680 virtual void* getObject(const String& name) const;
681
686 virtual bool valid() const
687 { return m_tsource && m_tsource->valid(); }
688
693 virtual DataSource* getTransSource() const
694 { return m_tsource; }
695
700 DataTranslator* getFirstTranslator();
701
706 const DataTranslator* getFirstTranslator() const;
707
716 static ObjList* srcFormats(const DataFormat& dFormat = "slin", int maxCost = -1, unsigned int maxLen = 0, ObjList* lst = 0);
717
726 static ObjList* destFormats(const DataFormat& sFormat = "slin", int maxCost = -1, unsigned int maxLen = 0, ObjList* lst = 0);
727
736 static ObjList* allFormats(const ObjList* formats, bool existing = true, bool sameRate = true, bool sameChans = true);
737
746 static ObjList* allFormats(const String& formats, bool existing = true, bool sameRate = true, bool sameChans = true);
747
754 static bool canConvert(const DataFormat& fmt1, const DataFormat& fmt2 = "slin");
755
762 static int cost(const DataFormat& sFormat, const DataFormat& dFormat);
763
770 static DataTranslator* create(const DataFormat& sFormat, const DataFormat& dFormat);
771
779 static bool attachChain(DataSource* source, DataConsumer* consumer, bool override = false);
780
787 static bool detachChain(DataSource* source, DataConsumer* consumer);
788
793 static void setMaxChain(unsigned int maxChain);
794
795 protected:
800 inline ObjList* getConsumers() const
801 { return m_tsource ? m_tsource->m_consumers.skipNull() : 0; }
802
808 virtual bool synchronize(DataSource* source);
809
814 static void install(TranslatorFactory* factory);
815
820 static void uninstall(TranslatorFactory* factory);
821
822 private:
823 DataTranslator(); // No default constructor please
824 static void compose();
825 static void compose(TranslatorFactory* factory);
826 static bool canConvert(const FormatInfo* fmt1, const FormatInfo* fmt2);
827 DataSource* m_tsource;
828 static Mutex s_mutex;
829 static ObjList s_factories;
830 static unsigned int s_maxChain;
831 };
832
838 class YATE_API TranslatorFactory : public GenObject
839 {
840 YNOCOPY(TranslatorFactory); // no automatic copies please
841 protected:
846 inline explicit TranslatorFactory(const char* name = 0)
847 : m_name(name ? name : "?")
848 { m_counter = Thread::getCurrentObjCounter(true); DataTranslator::install(this); }
849
850 public:
854 virtual ~TranslatorFactory();
855
860 virtual void removed(const TranslatorFactory* factory);
861
868 virtual DataTranslator* create(const DataFormat& sFormat, const DataFormat& dFormat) = 0;
869
874 virtual const TranslatorCaps* getCapabilities() const = 0;
875
882 virtual bool converts(const DataFormat& sFormat, const DataFormat& dFormat) const;
883
888 virtual unsigned int length() const;
889
895 virtual bool intermediate(const FormatInfo* info) const;
896
901 virtual const FormatInfo* intermediate() const;
902
907 virtual const char* name() const
908 { return m_name; }
909
914 inline NamedCounter* objectsCounter() const
915 { return m_counter; }
916
917 private:
918 const char* m_name;
919 NamedCounter* m_counter;
920 };
921
927 class YATE_API DataEndpoint : public RefObject
928 {
929 YNOCOPY(DataEndpoint); // no automatic copies please
930 public:
934 explicit DataEndpoint(CallEndpoint* call = 0, const char* name = "audio");
935
939 virtual void destroyed();
940
946 virtual void* getObject(const String& name) const;
947
952 virtual const String& toString() const;
953
958 Mutex* mutex() const;
959
964 static Mutex& commonMutex();
965
971 bool connect(DataEndpoint* peer);
972
977 bool disconnect();
978
983 void setSource(DataSource* source = 0);
984
989 inline DataSource* getSource() const
990 { return m_source; }
991
996 void setConsumer(DataConsumer* consumer = 0);
997
1002 inline DataConsumer* getConsumer() const
1003 { return m_consumer; }
1004
1010 void setPeerRecord(DataConsumer* consumer = 0);
1011
1016 inline DataConsumer* getPeerRecord() const
1017 { return m_peerRecord; }
1018
1024 void setCallRecord(DataConsumer* consumer = 0);
1025
1030 inline DataConsumer* getCallRecord() const
1031 { return m_callRecord; }
1032
1038 bool clearData(DataNode* node);
1039
1045 bool addSniffer(DataConsumer* sniffer);
1046
1052 bool delSniffer(DataConsumer* sniffer);
1053
1060 DataConsumer* getSniffer(const String& name, bool ref = false);
1061
1065 void clearSniffers();
1066
1071 inline DataEndpoint* getPeer() const
1072 { return m_peer; }
1073
1078 inline CallEndpoint* getCall() const
1079 { return m_call; }
1080
1085 inline const String& name() const
1086 { return m_name; }
1087
1093 inline void clearCall(const CallEndpoint* call)
1094 { if (call == m_call) m_call = 0; }
1095
1101 virtual bool control(NamedList& params);
1102
1103 protected:
1109 virtual bool nativeConnect(DataEndpoint* peer)
1110 { return false; }
1111
1112 private:
1113 String m_name;
1114 DataSource* m_source;
1115 DataConsumer* m_consumer;
1116 DataEndpoint* m_peer;
1117 CallEndpoint* m_call;
1118 DataConsumer* m_peerRecord;
1119 DataConsumer* m_callRecord;
1120 ObjList m_sniffers;
1121 };
1122
1127 class YATE_API CallEndpoint : public RefObject
1128 {
1129 friend class DataEndpoint;
1130 YNOCOPY(CallEndpoint); // no automatic copies please
1131 private:
1132 CallEndpoint* m_peer;
1133 const void* m_lastPeer;
1134 String m_id;
1135 String m_lastPeerId;
1136
1137 protected:
1138 ObjList m_data;
1139 Mutex* m_mutex;
1140
1141 public:
1145 virtual void destroyed();
1146
1152 virtual void* getObject(const String& name) const;
1153
1158 virtual const String& toString() const
1159 { return m_id; }
1160
1165 inline const String& id() const
1166 { return m_id; }
1167
1172 inline CallEndpoint* getPeer() const
1173 { return m_peer; }
1174
1180 bool getPeerId(String& id) const;
1181
1186 String getPeerId() const;
1187
1193 bool getLastPeerId(String& id) const;
1194
1198 void setLastPeerId();
1199
1204 inline Mutex* mutex() const
1205 { return m_mutex; }
1206
1211 static Mutex& commonMutex();
1212
1220 bool connect(CallEndpoint* peer, const char* reason = 0, bool notify = true);
1221
1229 inline bool disconnect(const char* reason = 0, bool notify = true, const NamedList* params = 0)
1230 { return disconnect(false,reason,notify,params); }
1231
1238 inline bool disconnect(const char* reason, const NamedList& params)
1239 { return disconnect(false,reason,true,&params); }
1240
1246 DataEndpoint* getEndpoint(const String& type = CallEndpoint::audioType()) const;
1247
1253 DataEndpoint* setEndpoint(const String& type = CallEndpoint::audioType());
1254
1259 void clearEndpoint(const String& type = String::empty());
1260
1266 void setSource(DataSource* source = 0, const String& type = CallEndpoint::audioType());
1267
1273 DataSource* getSource(const String& type = CallEndpoint::audioType()) const;
1274
1280 void setConsumer(DataConsumer* consumer = 0, const String& type = CallEndpoint::audioType());
1281
1287 DataConsumer* getConsumer(const String& type = CallEndpoint::audioType()) const;
1288
1295 bool clearData(DataNode* node, const String& type = CallEndpoint::audioType());
1296
1301 static const String& audioType();
1302
1303 protected:
1307 CallEndpoint(const char* id = 0);
1308
1313 virtual void connected(const char* reason) { }
1314
1320 virtual void disconnected(bool final, const char* reason) { }
1321
1326 virtual void setDisconnect(const NamedList* params) { }
1327
1335 void setPeer(CallEndpoint* peer, const char* reason = 0, bool notify = true, const NamedList* params = 0);
1336
1341 void setEndpoint(DataEndpoint* endPoint);
1342
1347 virtual void setId(const char* newId);
1348
1349 private:
1350 bool disconnect(bool final, const char* reason, bool notify, const NamedList* params);
1351 };
1352
1357 class YATE_API Module : public Plugin, public Mutex, public MessageReceiver
1358 {
1359 YNOCOPY(Module); // no automatic copies please
1360 private:
1361 bool m_init;
1362 int m_relays;
1363 String m_type;
1364 Regexp m_filter;
1365 u_int64_t m_changed;
1366 static unsigned int s_delay;
1367
1368 public:
1374 virtual void* getObject(const String& name) const;
1375
1380 inline const String& type() const
1381 { return m_type; }
1382
1387 void changed();
1388
1393 inline static unsigned int updateDelay()
1394 { return s_delay; }
1395
1400 inline static void updateDelay(unsigned int delay)
1401 { s_delay = delay; }
1402
1407 inline bool filterInstalled() const
1408 { return !m_filter.null(); }
1409
1415 bool filterDebug(const String& item) const;
1416
1424 static bool itemComplete(String& itemList, const String& item, const String& partWord);
1425
1426 protected:
1430 enum {
1431 // Module messages
1432 Status = 0x00000001,
1433 Timer = 0x00000002,
1434 Level = 0x00000004,
1435 Command = 0x00000008,
1436 Help = 0x00000010,
1437 Halt = 0x00000020,
1438 Route = 0x00000040,
1439 Stop = 0x00000080,
1440 // Driver messages
1441 Execute = 0x00000100,
1442 Drop = 0x00000200,
1443 // Channel messages
1444 Locate = 0x00000400,
1445 Masquerade = 0x00000800,
1446 Ringing = 0x00001000,
1447 Answered = 0x00002000,
1448 Tone = 0x00004000,
1449 Text = 0x00008000,
1450 Progress = 0x00010000,
1451 Update = 0x00020000,
1452 Transfer = 0x00040000,
1453 Control = 0x00080000,
1454 // Instant messaging related
1455 MsgExecute = 0x00100000,
1456 // Last possible public ID
1457 PubLast = 0x0fffffff,
1458 // Private messages base ID
1459 Private = 0x10000000
1460 } RelayID;
1461
1467 static const char* messageName(int id);
1468
1474 static inline int relayId(const char* name)
1475 { return lookup(name,s_messages); }
1476
1483 Module(const char* name, const char* type = 0, bool earlyInit = false);
1484
1488 virtual ~Module();
1489
1493 virtual void initialize();
1494
1498 void setup();
1499
1505 inline bool relayInstalled(int id) const
1506 { return (id & m_relays) != 0; }
1507
1514 bool installRelay(int id, unsigned priority = 100);
1515
1522 bool installRelay(const char* name, unsigned priority = 100);
1523
1531 bool installRelay(int id, const char* name, unsigned priority = 100);
1532
1538 bool installRelay(MessageRelay* relay);
1539
1546 bool uninstallRelay(MessageRelay* relay, bool delRelay = true);
1547
1554 bool uninstallRelay(int id, bool delRelay = true);
1555
1560 bool uninstallRelays();
1561
1568 virtual bool received(Message &msg, int id);
1569
1574 virtual void genUpdate(Message& msg);
1575
1580 virtual void msgTimer(Message& msg);
1581
1586 virtual void msgStatus(Message& msg);
1587
1593 virtual bool msgRoute(Message& msg);
1594
1601 virtual bool msgCommand(Message& msg);
1602
1607 virtual void statusModule(String& str);
1608
1613 virtual void statusParams(String& str);
1614
1619 virtual void statusDetail(String& str);
1620
1627 virtual bool commandExecute(String& retVal, const String& line);
1628
1636 virtual bool commandComplete(Message& msg, const String& partLine, const String& partWord);
1637
1643 virtual bool setDebug(Message& msg, const String& target);
1644
1645 private:
1646 Module(); // no default constructor please
1647 static TokenDict s_messages[];
1648 ObjList m_relayList;
1649 };
1650
1655 class YATE_API Channel : public CallEndpoint, public DebugEnabler, public MessageNotifier
1656 {
1657 friend class Driver;
1658 friend class Router;
1659 YNOCOPY(Channel); // no automatic copies please
1660 private:
1661 NamedList m_parameters;
1662 NamedList* m_chanParams; // Channel parameters to be set in all messages
1663 Driver* m_driver;
1664 bool m_outgoing;
1665 u_int64_t m_timeout;
1666 u_int64_t m_maxcall;
1667 u_int64_t m_maxPDD; // Timeout while waiting for some progress on outgoing calls
1668 u_int64_t m_dtmfTime;
1669 unsigned int m_toutAns;
1670 unsigned int m_dtmfSeq;
1671 String m_dtmfText;
1672 String m_dtmfDetected;
1673
1674 protected:
1675 String m_status;
1676 String m_address;
1677 String m_targetid;
1678 String m_billid;
1679 bool m_answered;
1680
1681 public:
1685 virtual ~Channel();
1686
1692 virtual void* getObject(const String& name) const;
1693
1698 static Mutex& paramMutex();
1699
1705 virtual void complete(Message& msg, bool minimal = false) const;
1706
1714 Message* message(const char* name, bool minimal = false, bool data = false);
1715
1726 Message* message(const char* name, const NamedList* original, const char* params = 0, bool minimal = false, bool data = false);
1727
1738 inline Message* message(const char* name, const NamedList& original, const char* params = 0, bool minimal = false, bool data = false)
1739 { return message(name,&original,params,minimal,data); }
1740
1746 virtual bool msgProgress(Message& msg);
1747
1753 virtual bool msgRinging(Message& msg);
1754
1760 virtual bool msgAnswered(Message& msg);
1761
1768 virtual bool msgTone(Message& msg, const char* tone);
1769
1776 virtual bool msgText(Message& msg, const char* text);
1777
1784 virtual bool msgDrop(Message& msg, const char* reason);
1785
1791 virtual bool msgTransfer(Message& msg);
1792
1798 virtual bool msgUpdate(Message& msg);
1799
1805 virtual bool msgMasquerade(Message& msg);
1806
1811 virtual void msgStatus(Message& msg);
1812
1818 virtual bool msgControl(Message& msg);
1819
1825 virtual void checkTimers(Message& msg, const Time& tmr);
1826
1833 virtual bool callPrerouted(Message& msg, bool handled);
1834
1840 virtual bool callRouted(Message& msg);
1841
1846 virtual void callAccept(Message& msg);
1847
1854 virtual void callRejected(const char* error, const char* reason = 0, const Message* msg = 0);
1855
1861 virtual void callConnect(Message& msg);
1862
1867 virtual bool setDebug(Message& msg);
1868
1873 inline const String& status() const
1874 { return m_status; }
1875
1880 inline const String& address() const
1881 { return m_address; }
1882
1887 inline bool isOutgoing() const
1888 { return m_outgoing; }
1889
1894 inline bool isIncoming() const
1895 { return !m_outgoing; }
1896
1901 inline bool isAnswered() const
1902 { return m_answered; }
1903
1908 const char* direction() const;
1909
1914 inline Driver* driver() const
1915 { return m_driver; }
1916
1921 inline u_int64_t timeout() const
1922 { return m_timeout; }
1923
1928 inline void timeout(u_int64_t tout)
1929 { m_timeout = tout; }
1930
1935 inline u_int64_t maxcall() const
1936 { return m_maxcall; }
1937
1942 inline void maxcall(u_int64_t tout)
1943 { m_maxcall = tout; }
1944
1950 inline void setMaxcall(const Message& msg, int defTout = -1)
1951 { setMaxcall(&msg,defTout); }
1952
1958 void setMaxcall(const Message* msg, int defTout = -1);
1959
1965 inline u_int64_t maxPDD() const
1966 { return m_maxPDD; }
1967
1973 inline void maxPDD(u_int64_t tout)
1974 { m_maxPDD = tout; }
1975
1981 void setMaxPDD(const Message& msg);
1982
1988 inline const String& targetid() const
1989 { return m_targetid; }
1990
1996 inline const String& billid() const
1997 { return m_billid; }
1998
2003 void initChan();
2004
2011 bool startRouter(Message* msg);
2012
2017 static unsigned int allocId();
2018
2023 void filterDebug(const String& item);
2024
2029 inline const NamedList& parameters() const
2030 { return m_parameters; }
2031
2037 inline void setChanParams(const NamedList& list, bool in = false) {
2038 const String& pref = in ? list[YSTRING("ichanparams-prefix")] : list[YSTRING("chanparams-prefix")];
2039 if (!pref)
2040 return;
2041 Lock lck(paramMutex());
2042 if (!m_chanParams)
2043 m_chanParams = new NamedList("");
2044 m_chanParams->copySubParams(list,pref,true,true);
2045 }
2046
2051 inline void copyChanParams(NamedList& list) const {
2052 if (!m_chanParams)
2053 return;
2054 Lock lck(paramMutex());
2055 list.copyParams(*m_chanParams);
2056 }
2057
2063 virtual void dispatched(const Message& msg, bool handled);
2064
2065 protected:
2069 Channel(Driver* driver, const char* id = 0, bool outgoing = false);
2070
2074 Channel(Driver& driver, const char* id = 0, bool outgoing = false);
2075
2080 void cleanup();
2081
2085 void dropChan();
2086
2091 virtual void zeroRefs();
2092
2097 virtual void connected(const char* reason);
2098
2104 virtual void disconnected(bool final, const char* reason);
2105
2110 virtual void setDisconnect(const NamedList* params);
2111
2117 virtual void endDisconnect(const Message& msg, bool handled);
2118
2123 virtual void setId(const char* newId);
2124
2130 virtual Message* getDisconnect(const char* reason);
2131
2137 void status(const char* newstat);
2138
2143 virtual void statusParams(String& str);
2144
2149 inline void setOutgoing(bool outgoing = true)
2150 { m_outgoing = outgoing; }
2151
2157 bool dtmfSequence(Message& msg);
2158
2164 bool dtmfEnqueue(Message* msg);
2165
2172 bool dtmfInband(const char* tone);
2173
2180 bool toneDetect(const char* sniffer = 0);
2181
2186 inline NamedList& parameters()
2187 { return m_parameters; }
2188
2189 private:
2190 void init();
2191 Channel(); // no default constructor please
2192 };
2193
2198 class YATE_API Driver : public Module
2199 {
2200 friend class Router;
2201 friend class Channel;
2202
2203 private:
2204 bool m_init;
2205 bool m_varchan;
2206 String m_prefix;
2207 ObjList m_chans;
2208 int m_routing;
2209 int m_routed;
2210 int m_total;
2211 unsigned int m_nextid;
2212 int m_timeout;
2213 int m_maxroute;
2214 int m_maxchans;
2215 int m_chanCount;
2216 bool m_dtmfDups;
2217 volatile bool m_doExpire;
2218
2219 public:
2225 virtual void* getObject(const String& name) const;
2226
2231 inline const String& prefix() const
2232 { return m_prefix; }
2233
2238 inline bool varchan() const
2239 { return m_varchan; }
2240
2245 inline ObjList& channels()
2246 { return m_chans; }
2247
2253 virtual Channel* find(const String& id) const;
2254
2259 virtual bool isBusy() const;
2260
2265 virtual void dropAll(Message &msg);
2266
2272 virtual bool canAccept(bool routers = true);
2273
2278 virtual bool canRoute();
2279
2284 unsigned int nextid();
2285
2290 inline unsigned int lastid() const
2291 { return m_nextid; }
2292
2297 inline int timeout() const
2298 { return m_timeout; }
2299
2304 inline int routing() const
2305 { return m_routing; }
2306
2311 inline int routed() const
2312 { return m_routed; }
2313
2318 inline int total() const
2319 { return m_total; }
2320
2325 inline int chanCount() const
2326 { return m_chanCount; }
2327
2332 inline int maxChans() const
2333 { return m_maxchans; }
2334
2335 protected:
2341 Driver(const char* name, const char* type = 0);
2342
2346 virtual void initialize();
2347
2353 void setup(const char* prefix = 0, bool minimal = false);
2354
2361 virtual bool received(Message &msg, int id);
2362
2367 virtual void genUpdate(Message& msg);
2368
2375 virtual bool hasLine(const String& line) const;
2376
2383 virtual bool msgRoute(Message& msg);
2384
2391 virtual bool msgExecute(Message& msg, String& dest) = 0;
2392
2400 virtual bool commandComplete(Message& msg, const String& partLine, const String& partWord);
2401
2406 virtual void statusModule(String& str);
2407
2412 virtual void statusParams(String& str);
2413
2418 virtual void statusDetail(String& str);
2419
2425 virtual bool setDebug(Message& msg, const String& target);
2426
2430 virtual void loadLimits();
2431
2436 inline void varchan(bool variable)
2437 { m_varchan = variable; }
2438
2443 inline void timeout(int tout)
2444 { m_timeout = tout; }
2445
2450 inline void maxRoute(int ncalls)
2451 { m_maxroute = ncalls; }
2452
2457 inline void maxChans(int ncalls)
2458 { m_maxchans = ncalls; }
2459
2464 inline void dtmfDups(bool duplicates)
2465 { m_dtmfDups = duplicates; }
2466
2467 private:
2468 Driver(); // no default constructor please
2469 };
2470
2475 class YATE_API Router : public Thread
2476 {
2477 YNOCOPY(Router); // no automatic copies please
2478 private:
2479 Driver* m_driver;
2480 String m_id;
2481 Message* m_msg;
2482
2483 public:
2490 Router(Driver* driver, const char* id, Message* msg);
2491
2495 virtual void run();
2496
2501 virtual bool route();
2502
2506 virtual void cleanup();
2507
2508 protected:
2513 const String& id() const
2514 { return m_id; }
2515 };
2516
2521 class YATE_API CallAccount
2522 {
2523 YNOCOPY(CallAccount);
2524 private:
2525 Mutex* m_mutex;
2526 NamedList m_inbParams;
2527 NamedList m_outParams;
2528 NamedList m_regParams;
2529
2530 public:
2535 void pickAccountParams(const NamedList& params);
2536
2537
2542 void setInboundParams(NamedList& params);
2543
2548 void setOutboundParams(NamedList& params);
2549
2554 void setRegisterParams(NamedList& params);
2555
2560 inline const NamedList& inboundParams() const
2561 { return m_inbParams; }
2562
2567 inline const NamedList& outboundParams() const
2568 { return m_outParams; }
2569
2574 inline const NamedList& registerParams() const
2575 { return m_regParams; }
2576
2577 protected:
2582 inline CallAccount(Mutex* mutex)
2583 : m_mutex(mutex), m_inbParams(""), m_outParams(""), m_regParams("")
2584 { }
2585 };
2586
2592 YATE_API bool isE164(const char* str);
2593
2594 }; // namespace TelEngine
2595
2596 #endif /* __YATEPHONE_H */
2597
2598 /* vi: set ts=8 sw=4 sts=4 noet: */
TelEngine::CallEndpoint::getPeer
CallEndpoint * getPeer() const
Definition: yatephone.h:1172
TelEngine::Driver::varchan
bool varchan() const
Definition: yatephone.h:2238
TelEngine::String::null
bool null() const
Definition: yateclass.h:2059
TelEngine::CallEndpoint::setDisconnect
virtual void setDisconnect(const NamedList *params)
Definition: yatephone.h:1326
TelEngine::Thread::getCurrentObjCounter
static NamedCounter * getCurrentObjCounter(bool always=false)
TelEngine::Channel::isAnswered
bool isAnswered() const
Definition: yatephone.h:1901
TelEngine::TranslatorCaps::src
const FormatInfo * src
Definition: yatephone.h:140
TelEngine::Driver::dtmfDups
void dtmfDups(bool duplicates)
Definition: yatephone.h:2464
TelEngine::FormatInfo::frameSize
int frameSize
Definition: yatephone.h:73
TelEngine::DataFormat::DataFormat
DataFormat(const String &value)
Definition: yatephone.h:212
TelEngine::FormatInfo::sampleRate
int sampleRate
Definition: yatephone.h:83
TelEngine::DataNode::getFormat
const DataFormat & getFormat() const
Definition: yatephone.h:344
TelEngine::DataBlock
A class that holds just a block of raw data.
Definition: yateclass.h:3994
TelEngine::Module::relayId
static int relayId(const char *name)
Definition: yatephone.h:1474
TelEngine::DataNode::valid
virtual bool valid() const
Definition: yatephone.h:358
TelEngine::RefObject
Definition: yateclass.h:967
TelEngine::Regexp
A regexp matching class.
Definition: yateclass.h:3051
TelEngine::TranslatorFactory
An unidirectional data translator (codec)
Definition: yatephone.h:838
TelEngine::Channel::targetid
const String & targetid() const
Definition: yatephone.h:1988
TelEngine::Channel::setMaxcall
void setMaxcall(const Message &msg, int defTout=-1)
Definition: yatephone.h:1950
TelEngine::ObjList::skipNull
ObjList * skipNull() const
TelEngine::DataNode::attached
virtual void attached(bool added)
Definition: yatephone.h:381
TelEngine::DataEndpoint::getCall
CallEndpoint * getCall() const
Definition: yatephone.h:1078
TelEngine::DataEndpoint::getPeer
DataEndpoint * getPeer() const
Definition: yatephone.h:1071
TelEngine::DataConsumer::DataConsumer
DataConsumer(const char *format="slin")
Definition: yatephone.h:406
TelEngine::DataTranslator::install
static void install(TranslatorFactory *factory)
TelEngine::DataFormat::DataFormat
DataFormat(const DataFormat &value)
Definition: yatephone.h:204
TelEngine::TranslatorCaps::dest
const FormatInfo * dest
Definition: yatephone.h:142
TelEngine::MessageNotifier
Post-dispatching message hook.
Definition: yatengine.h:676
TelEngine::DataNode::timeStamp
unsigned long timeStamp() const
Definition: yatephone.h:351
TelEngine::CallEndpoint::toString
virtual const String & toString() const
Definition: yatephone.h:1158
TelEngine::TranslatorCaps
Definition: yatephone.h:138
TelEngine::Channel::timeout
void timeout(u_int64_t tout)
Definition: yatephone.h:1928
TelEngine::Thread
Thread support class.
Definition: yateclass.h:5749
TelEngine::Channel::billid
const String & billid() const
Definition: yatephone.h:1996
TelEngine::Channel::setOutgoing
void setOutgoing(bool outgoing=true)
Definition: yatephone.h:2149
TelEngine::CallEndpoint::mutex
Mutex * mutex() const
Definition: yatephone.h:1204
TelEngine::YSTRING
constant YSTRING(const char *string)
TelEngine::ThreadedSource
Data source with own thread.
Definition: yatephone.h:581
TelEngine::Router::id
const String & id() const
Definition: yatephone.h:2513
TelEngine::Module::type
const String & type() const
Definition: yatephone.h:1380
TelEngine::Module::updateDelay
static unsigned int updateDelay()
Definition: yatephone.h:1393
TelEngine::ImageInfo::depth
int depth
Definition: yatephone.h:53
TelEngine::ImageInfo::height
int height
Definition: yatephone.h:48
TelEngine::TranslatorFactory::TranslatorFactory
TranslatorFactory(const char *name=0)
Definition: yatephone.h:846
TelEngine::Channel::isIncoming
bool isIncoming() const
Definition: yatephone.h:1894
TelEngine::Router
Call routing thread.
Definition: yatephone.h:2475
TelEngine::CallEndpoint::disconnect
bool disconnect(const char *reason=0, bool notify=true, const NamedList *params=0)
Definition: yatephone.h:1229
TelEngine::Driver::timeout
int timeout() const
Definition: yatephone.h:2297
TelEngine::DataFormat::frameSize
int frameSize(int defValue=0) const
Definition: yatephone.h:257
TelEngine::Module::filterInstalled
bool filterInstalled() const
Definition: yatephone.h:1407
TelEngine::DataTranslator::valid
virtual bool valid() const
Definition: yatephone.h:686
TelEngine::MessageReceiver
A multiple message receiver.
Definition: yatengine.h:607
TelEngine::CallAccount::CallAccount
CallAccount(Mutex *mutex)
Definition: yatephone.h:2582
TelEngine::DataConsumer
Definition: yatephone.h:397
TelEngine::CallAccount::registerParams
const NamedList & registerParams() const
Definition: yatephone.h:2574
TelEngine::Channel
An abstract communication channel.
Definition: yatephone.h:1655
TelEngine::MessageRelay
A message handler relay.
Definition: yatengine.h:623
TelEngine::Channel::isOutgoing
bool isOutgoing() const
Definition: yatephone.h:1887
TelEngine::DataFormat::numChannels
int numChannels(int defValue=1) const
Definition: yatephone.h:282
TelEngine::DataConsumer::getConnSource
DataSource * getConnSource() const
Definition: yatephone.h:439
TelEngine::NamedList::copyParams
NamedList & copyParams(const NamedList &original)
TelEngine::DataNode::setFormat
virtual bool setFormat(const DataFormat &format)
Definition: yatephone.h:337
TelEngine::Channel::setChanParams
void setChanParams(const NamedList &list, bool in=false)
Definition: yatephone.h:2037
TelEngine::DataNode::DataFlags
DataFlags
Definition: yatephone.h:306
TelEngine::DataNode::invalidStamp
static unsigned long invalidStamp()
Definition: yatephone.h:373
TelEngine::lookup
int lookup(const char *str, const TokenDict *tokens, int defvalue=0, int base=0)
TelEngine::DataFormat::sampleRate
int sampleRate(int defValue=0) const
Definition: yatephone.h:274
TelEngine::ImageInfo::width
int width
Definition: yatephone.h:43
TelEngine::Channel::timeout
u_int64_t timeout() const
Definition: yatephone.h:1921
TelEngine::FormatInfo::FormatInfo
FormatInfo()
Definition: yatephone.h:111
TelEngine::Channel::status
const String & status() const
Definition: yatephone.h:1873
TelEngine::DataFormat::frameTime
int frameTime(int defValue=0) const
Definition: yatephone.h:265
TelEngine::CallAccount::inboundParams
const NamedList & inboundParams() const
Definition: yatephone.h:2560
TelEngine::Driver::channels
ObjList & channels()
Definition: yatephone.h:2245
TelEngine::Driver::routing
int routing() const
Definition: yatephone.h:2304
TelEngine::CallEndpoint::id
const String & id() const
Definition: yatephone.h:1165
TelEngine::CallEndpoint
An abstract call endpoint.
Definition: yatephone.h:1127
TelEngine::DataEndpoint::getSource
DataSource * getSource() const
Definition: yatephone.h:989
TelEngine::DataTranslator
An unidirectional data translator (codec)
Definition: yatephone.h:651
TelEngine::Driver::varchan
void varchan(bool variable)
Definition: yatephone.h:2436
TelEngine::DataTranslator::getConsumers
ObjList * getConsumers() const
Definition: yatephone.h:800
TelEngine::Time
A time holding class.
Definition: yateclass.h:3685
TelEngine::CallEndpoint::connected
virtual void connected(const char *reason)
Definition: yatephone.h:1313
TelEngine::DataNode::DataNode
DataNode(const char *format=0)
Definition: yatephone.h:320
TelEngine::DataFormat::DataFormat
DataFormat(const FormatInfo *format)
Definition: yatephone.h:236
TelEngine::Driver::maxChans
void maxChans(int ncalls)
Definition: yatephone.h:2457
TelEngine::DebugEnabler
A holder for a debug level.
Definition: yateclass.h:309
TelEngine::DataSource
Definition: yatephone.h:477
TelEngine::FormatInfo
Definition: yatephone.h:59
TelEngine::FormatInfo::numChannels
int numChannels
Definition: yatephone.h:88
TelEngine::Message
A message container class.
Definition: yatengine.h:312
TelEngine::DataFormat
A Data format.
Definition: yatephone.h:182
TelEngine::DataSource::nextStamp
unsigned long nextStamp() const
Definition: yatephone.h:562
TelEngine::FormatInfo::converter
bool converter
Definition: yatephone.h:93
TelEngine::ThreadedSource::ThreadedSource
ThreadedSource(const char *format="slin")
Definition: yatephone.h:620
TelEngine::Driver::prefix
const String & prefix() const
Definition: yatephone.h:2231
TelEngine::Channel::maxPDD
u_int64_t maxPDD() const
Definition: yatephone.h:1965
TelEngine::Driver
A Channel driver module.
Definition: yatephone.h:2198
TelEngine::DataEndpoint::getPeerRecord
DataConsumer * getPeerRecord() const
Definition: yatephone.h:1016
TelEngine::CallEndpoint::audioType
static const String & audioType()
TelEngine::CallAccount::outboundParams
const NamedList & outboundParams() const
Definition: yatephone.h:2567
TelEngine::DataEndpoint::name
const String & name() const
Definition: yatephone.h:1085
TelEngine::FormatInfo::name
const char * name
Definition: yatephone.h:63
TelEngine::Driver::timeout
void timeout(int tout)
Definition: yatephone.h:2443
TelEngine::Driver::chanCount
int chanCount() const
Definition: yatephone.h:2325
TelEngine::c_str
const char * c_str(const String *str)
Definition: yateclass.h:2936
TelEngine::NamedList::operator=
NamedList & operator=(const NamedList &value)
TelEngine::DataSource::getTranslator
DataTranslator * getTranslator() const
Definition: yatephone.h:549
TelEngine::DataEndpoint
A data transfer endpoint capable of sending and/or receiving data.
Definition: yatephone.h:927
TelEngine::DataFormat::getInfo
const FormatInfo * getInfo() const
TelEngine::Module::relayInstalled
bool relayInstalled(int id) const
Definition: yatephone.h:1505
TelEngine::NamedList
A named string container class.
Definition: yateclass.h:4773
TelEngine::Module::updateDelay
static void updateDelay(unsigned int delay)
Definition: yatephone.h:1400
TelEngine::Channel::maxcall
void maxcall(u_int64_t tout)
Definition: yatephone.h:1942
TelEngine::Lock
Ephemeral mutex or semaphore locking object.
Definition: yateclass.h:5577
TelEngine::DataConsumer::getOverSource
DataSource * getOverSource() const
Definition: yatephone.h:446
TelEngine::DataEndpoint::getConsumer
DataConsumer * getConsumer() const
Definition: yatephone.h:1002
TelEngine::DataEndpoint::clearCall
void clearCall(const CallEndpoint *call)
Definition: yatephone.h:1093
TelEngine::TranslatorCaps::cost
int cost
Definition: yatephone.h:144
TelEngine::Driver::lastid
unsigned int lastid() const
Definition: yatephone.h:2290
TelEngine::CallEndpoint::disconnected
virtual void disconnected(bool final, const char *reason)
Definition: yatephone.h:1320
TelEngine::Driver::total
int total() const
Definition: yatephone.h:2318
TelEngine::DataTranslator::getTransSource
virtual DataSource * getTransSource() const
Definition: yatephone.h:693
TelEngine::DataConsumer::getTransSource
virtual DataSource * getTransSource() const
Definition: yatephone.h:453
TelEngine::DataEndpoint::getCallRecord
DataConsumer * getCallRecord() const
Definition: yatephone.h:1030
TelEngine::Channel::parameters
const NamedList & parameters() const
Definition: yatephone.h:2029
TelEngine::DataSource::DataSource
DataSource(const char *format="slin")
Definition: yatephone.h:486
TelEngine
Definition: yateclass.h:217
TelEngine::DataEndpoint::nativeConnect
virtual bool nativeConnect(DataEndpoint *peer)
Definition: yatephone.h:1109
TelEngine::TranslatorFactory::objectsCounter
NamedCounter * objectsCounter() const
Definition: yatephone.h:914
TelEngine::String
A C-style string handling class.
Definition: yateclass.h:1924
TelEngine::Driver::maxRoute
void maxRoute(int ncalls)
Definition: yatephone.h:2450
TelEngine::Channel::driver
Driver * driver() const
Definition: yatephone.h:1914
TelEngine::Channel::address
const String & address() const
Definition: yatephone.h:1880
TelEngine::DataFormat::operator=
DataFormat & operator=(const DataFormat &value)
Definition: yatephone.h:243
TelEngine::TokenDict
Definition: yateclass.h:683
TelEngine::DataFormat::DataFormat
DataFormat(const char *value)
Definition: yatephone.h:196
TelEngine::Thread::Priority
Priority
Definition: yateclass.h:5759
TelEngine::TranslatorFactory::name
virtual const char * name() const
Definition: yatephone.h:907
TelEngine::FormatInfo::FormatInfo
FormatInfo(const char *_name, int fsize=0, int ftime=10000, const char *_type="audio", int srate=8000, int nchan=1, bool convert=false)
Definition: yatephone.h:121
TelEngine::Channel::maxcall
u_int64_t maxcall() const
Definition: yatephone.h:1935
TelEngine::ObjList
An object list class.
Definition: yateclass.h:1247
TelEngine::DataNode
Definition: yatephone.h:298
TelEngine::Channel::copyChanParams
void copyChanParams(NamedList &list) const
Definition: yatephone.h:2051
TelEngine::Channel::parameters
NamedList & parameters()
Definition: yatephone.h:2186
TelEngine::DataFormat::DataFormat
DataFormat(const NamedList &value)
Definition: yatephone.h:220
TelEngine::YNOCOPY
void YNOCOPY(class type)
TelEngine::Module
A Plugin that implements a module.
Definition: yatephone.h:1357
TelEngine::Channel::maxPDD
void maxPDD(u_int64_t tout)
Definition: yatephone.h:1973
TelEngine::DataFormat::DataFormat
DataFormat()
Definition: yatephone.h:188
TelEngine::String::empty
static const String & empty()
TelEngine::CallEndpoint::disconnect
bool disconnect(const char *reason, const NamedList &params)
Definition: yatephone.h:1238
TelEngine::DataNode::costFormat
virtual int costFormat(const DataFormat &format)
Definition: yatephone.h:329
TelEngine::FormatInfo::frameTime
int frameTime
Definition: yatephone.h:78
TelEngine::CallAccount
Settings for an account handling calls.
Definition: yatephone.h:2521
TelEngine::Driver::routed
int routed() const
Definition: yatephone.h:2311
TelEngine::Plugin
Plugin support.
Definition: yatengine.h:1023
TelEngine::NamedList::copySubParams
NamedList & copySubParams(const NamedList &original, const String &prefix, bool skipPrefix=true, bool replace=false)
TelEngine::Mutex
Mutex support.
Definition: yateclass.h:5351
TelEngine::DataNode::control
virtual bool control(NamedList &params)
Definition: yatephone.h:366
TelEngine::FormatInfo::type
const char * type
Definition: yatephone.h:68
TelEngine::GenObject
Definition: yateclass.h:848
TelEngine::Driver::maxChans
int maxChans() const
Definition: yatephone.h:2332
TelEngine::DataFormat::DataFormat
DataFormat(const String *value)
Definition: yatephone.h:228
TelEngine::ImageInfo
Definition: yatephone.h:39
TelEngine::Channel::message
Message * message(const char *name, const NamedList &original, const char *params=0, bool minimal=false, bool data=false)
Definition: yatephone.h:1738
TelEngine::FormatRepository
A repository for media formats.
Definition: yatephone.h:151
TelEngine::NamedCounter
Atomic counter with name.
Definition: yateclass.h:3381
TelEngine::isE164
bool isE164(const char *str)