Yate
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
34namespace TelEngine {
35
39struct YATE_API ImageInfo {
43 int width;
44
48 int height;
49
53 int depth;
54};
55
59struct YATE_API FormatInfo {
63 const char* name;
64
68 const char* type;
69
74
79
84
89
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
130class DataEndpoint;
131class CallEndpoint;
132class Driver;
133
138struct YATE_API TranslatorCaps {
144 int cost;
145};
146
151class YATE_API FormatRepository
152{
153 YNOCOPY(FormatRepository); // no automatic copies please
154private:
156public:
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
182class YATE_API DataFormat : public NamedList
183{
184public:
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
285protected:
289 virtual void changed();
290
291private:
292 mutable const FormatInfo* m_parsed;
293};
294
298class YATE_API DataNode : public RefObject
299{
300 friend class DataEndpoint;
301 YNOCOPY(DataNode); // no automatic copies please
302public:
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
384protected:
385 DataFormat m_format;
386 unsigned long m_timestamp;
387};
388
389class DataSource;
390class DataTranslator;
391class TranslatorFactory;
392class ThreadedSourcePrivate;
393
397class YATE_API DataConsumer : public DataNode
398{
399 friend class DataSource;
400
401public:
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
456protected:
462 virtual bool synchronize(DataSource* source);
463
464private:
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
477class YATE_API DataSource : public DataNode, public Mutex
478{
479 friend class DataTranslator;
480 YNOCOPY(DataSource); // no automatic copies please
481public:
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
550 { return m_translator; }
551
556 void synchronize(unsigned long tStamp);
557
562 inline unsigned long nextStamp() const
563 { return m_nextStamp; }
564
565protected:
566 unsigned long m_nextStamp;
567 ObjList m_consumers;
568private:
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
581class YATE_API ThreadedSource : public DataSource
582{
583 friend class ThreadedSourcePrivate;
584public:
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
615protected:
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
642private:
643 ThreadedSourcePrivate* m_thread;
644};
645
651class YATE_API DataTranslator : public DataConsumer
652{
653 friend class TranslatorFactory;
654public:
660 DataTranslator(const char* sFormat, const char* dFormat);
661
668 explicit DataTranslator(const char* sFormat, DataSource* source = 0);
669
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
701
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
795protected:
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
822private:
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
838class YATE_API TranslatorFactory : public GenObject
839{
840 YNOCOPY(TranslatorFactory); // no automatic copies please
841protected:
846 inline explicit TranslatorFactory(const char* name = 0)
847 : m_name(name ? name : "?")
848 { m_counter = Thread::getCurrentObjCounter(true); DataTranslator::install(this); }
849
850public:
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
915 { return m_counter; }
916
917private:
918 const char* m_name;
919 NamedCounter* m_counter;
920};
921
927class YATE_API DataEndpoint : public RefObject
928{
929 YNOCOPY(DataEndpoint); // no automatic copies please
930public:
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
965
972
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
1003 { return m_consumer; }
1004
1010 void setPeerRecord(DataConsumer* consumer = 0);
1011
1017 { return m_peerRecord; }
1018
1024 void setCallRecord(DataConsumer* consumer = 0);
1025
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
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
1103protected:
1109 virtual bool nativeConnect(DataEndpoint* peer)
1110 { return false; }
1111
1112private:
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
1127class YATE_API CallEndpoint : public RefObject
1128{
1129 friend class DataEndpoint;
1130 YNOCOPY(CallEndpoint); // no automatic copies please
1131private:
1132 CallEndpoint* m_peer;
1133 const void* m_lastPeer;
1134 String m_id;
1135 String m_lastPeerId;
1136
1137protected:
1138 ObjList m_data;
1139 Mutex* m_mutex;
1140
1141public:
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
1187
1193 bool getLastPeerId(String& id) const;
1194
1199
1204 inline Mutex* mutex() const
1205 { return m_mutex; }
1206
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
1303protected:
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
1349private:
1350 bool disconnect(bool final, const char* reason, bool notify, const NamedList* params);
1351};
1352
1357class YATE_API Module : public Plugin, public Mutex, public MessageReceiver
1358{
1359 YNOCOPY(Module); // no automatic copies please
1360private:
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
1368public:
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
1426protected:
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 = 0x00ffffff,
1458 // Private messages base ID
1459 Private = 0x01000000
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
1539
1546 bool uninstallRelay(MessageRelay* relay, bool delRelay = true);
1547
1554 bool uninstallRelay(int id, bool delRelay = true);
1555
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
1645private:
1646 Module(); // no default constructor please
1647 static TokenDict s_messages[];
1648 ObjList m_relayList;
1649};
1650
1655class 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
1660private:
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
1674protected:
1675 String m_status;
1676 String m_address;
1677 String m_targetid;
1678 String m_billid;
1679 bool m_answered;
1680
1681public:
1685 virtual ~Channel();
1686
1692 virtual void* getObject(const String& name) const;
1693
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
1876 inline String& getStatus(String& buf, bool append = true) const {
1877 Lock lck(chanDataMutex());
1878 if (append)
1879 buf += m_status;
1880 else
1881 buf = m_status;
1882 return buf;
1883 }
1884
1892 inline void putStatus(NamedList& list, const char* param = "status", bool append = true) const {
1893 NamedString* ns = new NamedString(param);
1894 getStatus(*ns);
1895 if (append)
1896 list.addParam(ns);
1897 else
1898 list.setParam(ns);
1899 }
1900
1905 inline const String& address() const
1906 { return m_address; }
1907
1912 inline bool isOutgoing() const
1913 { return m_outgoing; }
1914
1919 inline bool isIncoming() const
1920 { return !m_outgoing; }
1921
1926 inline bool isAnswered() const
1927 { return m_answered; }
1928
1933 const char* direction() const;
1934
1939 inline Driver* driver() const
1940 { return m_driver; }
1941
1946 inline u_int64_t timeout() const
1947 { return m_timeout; }
1948
1953 inline void timeout(u_int64_t tout)
1954 { m_timeout = tout; }
1955
1960 inline u_int64_t maxcall() const
1961 { return m_maxcall; }
1962
1967 inline void maxcall(u_int64_t tout)
1968 { m_maxcall = tout; }
1969
1975 inline void setMaxcall(const Message& msg, int defTout = -1)
1976 { setMaxcall(&msg,defTout); }
1977
1983 void setMaxcall(const Message* msg, int defTout = -1);
1984
1990 inline u_int64_t maxPDD() const
1991 { return m_maxPDD; }
1992
1998 inline void maxPDD(u_int64_t tout)
1999 { m_maxPDD = tout; }
2000
2006 void setMaxPDD(const Message& msg);
2007
2013 inline const String& targetid() const
2014 { return m_targetid; }
2015
2021 inline const String& billid() const
2022 { return m_billid; }
2023
2028 void initChan();
2029
2037
2042 static unsigned int allocId();
2043
2048 void filterDebug(const String& item);
2049
2054 inline const NamedList& parameters() const
2055 { return m_parameters; }
2056
2062 inline void setChanParams(const NamedList& list, bool in = false) {
2063 const String& pref = in ? list[YSTRING("ichanparams-prefix")] : list[YSTRING("chanparams-prefix")];
2064 if (!pref)
2065 return;
2066 Lock lck(paramMutex());
2067 if (!m_chanParams)
2068 m_chanParams = new NamedList("");
2069 m_chanParams->copySubParams(list,pref,true,true);
2070 }
2071
2076 inline void copyChanParams(NamedList& list) const {
2077 if (!m_chanParams)
2078 return;
2079 Lock lck(paramMutex());
2080 list.copyParams(*m_chanParams);
2081 }
2082
2088 virtual void dispatched(const Message& msg, bool handled);
2089
2090protected:
2094 Channel(Driver* driver, const char* id = 0, bool outgoing = false);
2095
2099 Channel(Driver& driver, const char* id = 0, bool outgoing = false);
2100
2105 void cleanup();
2106
2110 void dropChan();
2111
2116 virtual void zeroRefs();
2117
2122 virtual void connected(const char* reason);
2123
2129 virtual void disconnected(bool final, const char* reason);
2130
2135 virtual void setDisconnect(const NamedList* params);
2136
2142 virtual void endDisconnect(const Message& msg, bool handled);
2143
2148 virtual void setId(const char* newId);
2149
2155 virtual Message* getDisconnect(const char* reason);
2156
2162 void status(const char* newstat);
2163
2169 inline const String& getStatus() const
2170 { return m_status; }
2171
2176 virtual void statusParams(String& str);
2177
2182 inline void setOutgoing(bool outgoing = true)
2183 { m_outgoing = outgoing; }
2184
2191
2198
2205 bool dtmfInband(const char* tone);
2206
2213 bool toneDetect(const char* sniffer = 0);
2214
2220 { return m_parameters; }
2221
2222private:
2223 void init();
2224 Channel(); // no default constructor please
2225 static Mutex s_chanDataMutex;
2226 // Just in case we are going to (re)move the channel data mutex!
2227 static inline Mutex* chanDataMutex()
2228 { return &s_chanDataMutex; }
2229};
2230
2235class YATE_API Driver : public Module
2236{
2237 friend class Router;
2238 friend class Channel;
2239
2240private:
2241 bool m_init;
2242 bool m_varchan;
2243 String m_prefix;
2244 ObjList m_chans;
2245 int m_routing;
2246 int m_routed;
2247 int m_total;
2248 unsigned int m_nextid;
2249 int m_timeout;
2250 int m_maxroute;
2251 int m_maxchans;
2252 int m_chanCount;
2253 bool m_dtmfDups;
2254 volatile bool m_doExpire;
2255
2256public:
2262 virtual void* getObject(const String& name) const;
2263
2268 inline const String& prefix() const
2269 { return m_prefix; }
2270
2275 inline bool varchan() const
2276 { return m_varchan; }
2277
2283 { return m_chans; }
2284
2290 virtual Channel* find(const String& id) const;
2291
2296 virtual bool isBusy() const;
2297
2302 virtual void dropAll(Message &msg);
2303
2309 virtual bool canAccept(bool routers = true);
2310
2315 virtual bool canRoute();
2316
2321 unsigned int nextid();
2322
2327 inline unsigned int lastid() const
2328 { return m_nextid; }
2329
2334 inline int timeout() const
2335 { return m_timeout; }
2336
2341 inline int routing() const
2342 { return m_routing; }
2343
2348 inline int routed() const
2349 { return m_routed; }
2350
2355 inline int total() const
2356 { return m_total; }
2357
2362 inline int chanCount() const
2363 { return m_chanCount; }
2364
2369 inline int maxChans() const
2370 { return m_maxchans; }
2371
2372protected:
2378 Driver(const char* name, const char* type = 0);
2379
2383 virtual void initialize();
2384
2390 void setup(const char* prefix = 0, bool minimal = false);
2391
2398 virtual bool received(Message &msg, int id);
2399
2404 virtual void genUpdate(Message& msg);
2405
2412 virtual bool hasLine(const String& line) const;
2413
2420 virtual bool msgRoute(Message& msg);
2421
2428 virtual bool msgExecute(Message& msg, String& dest) = 0;
2429
2437 virtual bool commandComplete(Message& msg, const String& partLine, const String& partWord);
2438
2443 virtual void statusModule(String& str);
2444
2449 virtual void statusParams(String& str);
2450
2455 virtual void statusDetail(String& str);
2456
2462 virtual bool setDebug(Message& msg, const String& target);
2463
2467 virtual void loadLimits();
2468
2473 virtual bool canStopCall() const
2474 { return false; }
2475
2480 inline void varchan(bool variable)
2481 { m_varchan = variable; }
2482
2487 inline void timeout(int tout)
2488 { m_timeout = tout; }
2489
2494 inline void maxRoute(int ncalls)
2495 { m_maxroute = ncalls; }
2496
2501 inline void maxChans(int ncalls)
2502 { m_maxchans = ncalls; }
2503
2508 inline void dtmfDups(bool duplicates)
2509 { m_dtmfDups = duplicates; }
2510
2511private:
2512 Driver(); // no default constructor please
2513};
2514
2519class YATE_API Router : public Thread
2520{
2521 YNOCOPY(Router); // no automatic copies please
2522private:
2523 Driver* m_driver;
2524 String m_id;
2525 Message* m_msg;
2526
2527public:
2534 Router(Driver* driver, const char* id, Message* msg);
2535
2539 virtual void run();
2540
2545 virtual bool route();
2546
2550 virtual void cleanup();
2551
2552protected:
2557 const String& id() const
2558 { return m_id; }
2559};
2560
2565class YATE_API CallAccount
2566{
2567 YNOCOPY(CallAccount);
2568private:
2569 Mutex* m_mutex;
2570 NamedList m_inbParams;
2571 NamedList m_outParams;
2572 NamedList m_regParams;
2573
2574public:
2579 void pickAccountParams(const NamedList& params);
2580
2581
2587
2593
2599
2604 inline const NamedList& inboundParams() const
2605 { return m_inbParams; }
2606
2611 inline const NamedList& outboundParams() const
2612 { return m_outParams; }
2613
2618 inline const NamedList& registerParams() const
2619 { return m_regParams; }
2620
2621protected:
2626 inline CallAccount(Mutex* mutex)
2627 : m_mutex(mutex), m_inbParams(""), m_outParams(""), m_regParams("")
2628 { }
2629};
2630
2636YATE_API bool isE164(const char* str);
2637
2638}; // namespace TelEngine
2639
2640#endif /* __YATEPHONE_H */
2641
2642/* vi: set ts=8 sw=4 sts=4 noet: */
A class that holds just a block of raw data.
Definition yateclass.h:4237
A holder for a debug level.
Definition yateclass.h:312
Definition yateclass.h:1049
Ephemeral mutex or semaphore locking object.
Definition yateclass.h:5833
Mutex support.
Definition yateclass.h:5607
Atomic counter with name.
Definition yateclass.h:3602
A named string container class.
Definition yateclass.h:5016
NamedList & operator=(const NamedList &value)
NamedList & setParam(NamedString *param)
Definition yateclass.h:5094
NamedList & copyParams(const NamedList &original)
NamedList & addParam(NamedString *param)
NamedList & copySubParams(const NamedList &original, const String &prefix, bool skipPrefix=true, bool replace=false)
A named string class.
Definition yateclass.h:3481
An object list class.
Definition yateclass.h:1454
ObjList * skipNull() const
Definition yateclass.h:1174
bool ref()
A regexp matching class.
Definition yateclass.h:3271
A C-style string handling class.
Definition yateclass.h:2131
const char * c_str() const
Definition yateclass.h:2236
bool null() const
Definition yateclass.h:2265
static const String & empty()
Settings for an account handling calls.
Definition yatephone.h:2566
void setInboundParams(NamedList &params)
void setRegisterParams(NamedList &params)
void pickAccountParams(const NamedList &params)
const NamedList & inboundParams() const
Definition yatephone.h:2604
CallAccount(Mutex *mutex)
Definition yatephone.h:2626
const NamedList & outboundParams() const
Definition yatephone.h:2611
const NamedList & registerParams() const
Definition yatephone.h:2618
void setOutboundParams(NamedList &params)
An abstract call endpoint.
Definition yatephone.h:1128
void setConsumer(DataConsumer *consumer=0, const String &type=CallEndpoint::audioType())
virtual void * getObject(const String &name) const
virtual void destroyed()
DataEndpoint * getEndpoint(const String &type=CallEndpoint::audioType()) const
DataSource * getSource(const String &type=CallEndpoint::audioType()) const
bool clearData(DataNode *node, const String &type=CallEndpoint::audioType())
bool getPeerId(String &id) const
virtual void connected(const char *reason)
Definition yatephone.h:1313
const String & id() const
Definition yatephone.h:1165
Mutex * mutex() const
Definition yatephone.h:1204
bool connect(CallEndpoint *peer, const char *reason=0, bool notify=true)
void setEndpoint(DataEndpoint *endPoint)
CallEndpoint(const char *id=0)
void clearEndpoint(const String &type=String::empty())
void setSource(DataSource *source=0, const String &type=CallEndpoint::audioType())
static const String & audioType()
virtual const String & toString() const
Definition yatephone.h:1158
bool disconnect(const char *reason, const NamedList &params)
Definition yatephone.h:1238
DataConsumer * getConsumer(const String &type=CallEndpoint::audioType()) const
CallEndpoint * getPeer() const
Definition yatephone.h:1172
virtual void setDisconnect(const NamedList *params)
Definition yatephone.h:1326
virtual void setId(const char *newId)
DataEndpoint * setEndpoint(const String &type=CallEndpoint::audioType())
bool disconnect(const char *reason=0, bool notify=true, const NamedList *params=0)
Definition yatephone.h:1229
String getPeerId() const
static Mutex & commonMutex()
bool getLastPeerId(String &id) const
virtual void disconnected(bool final, const char *reason)
Definition yatephone.h:1320
void setPeer(CallEndpoint *peer, const char *reason=0, bool notify=true, const NamedList *params=0)
An abstract communication channel.
Definition yatephone.h:1656
virtual bool msgRinging(Message &msg)
virtual void zeroRefs()
virtual void statusParams(String &str)
virtual bool msgMasquerade(Message &msg)
virtual void * getObject(const String &name) const
void setMaxPDD(const Message &msg)
virtual bool msgTransfer(Message &msg)
NamedList & parameters()
Definition yatephone.h:2219
void setMaxcall(const Message *msg, int defTout=-1)
virtual bool callRouted(Message &msg)
bool dtmfInband(const char *tone)
virtual bool msgProgress(Message &msg)
virtual void callConnect(Message &msg)
void putStatus(NamedList &list, const char *param="status", bool append=true) const
Definition yatephone.h:1892
Message * message(const char *name, bool minimal=false, bool data=false)
void timeout(u_int64_t tout)
Definition yatephone.h:1953
u_int64_t timeout() const
Definition yatephone.h:1946
void setMaxcall(const Message &msg, int defTout=-1)
Definition yatephone.h:1975
static unsigned int allocId()
bool dtmfEnqueue(Message *msg)
Message * message(const char *name, const NamedList &original, const char *params=0, bool minimal=false, bool data=false)
Definition yatephone.h:1738
const char * direction() const
virtual bool setDebug(Message &msg)
virtual bool msgDrop(Message &msg, const char *reason)
virtual void connected(const char *reason)
void setOutgoing(bool outgoing=true)
Definition yatephone.h:2182
String & getStatus(String &buf, bool append=true) const
Definition yatephone.h:1876
void maxPDD(u_int64_t tout)
Definition yatephone.h:1998
virtual bool msgAnswered(Message &msg)
virtual bool msgTone(Message &msg, const char *tone)
virtual void endDisconnect(const Message &msg, bool handled)
virtual Message * getDisconnect(const char *reason)
u_int64_t maxcall() const
Definition yatephone.h:1960
bool dtmfSequence(Message &msg)
Driver * driver() const
Definition yatephone.h:1939
const String & getStatus() const
Definition yatephone.h:2169
virtual void dispatched(const Message &msg, bool handled)
Channel(Driver &driver, const char *id=0, bool outgoing=false)
bool isIncoming() const
Definition yatephone.h:1919
bool isOutgoing() const
Definition yatephone.h:1912
void maxcall(u_int64_t tout)
Definition yatephone.h:1967
bool isAnswered() const
Definition yatephone.h:1926
virtual void callRejected(const char *error, const char *reason=0, const Message *msg=0)
Message * message(const char *name, const NamedList *original, const char *params=0, bool minimal=false, bool data=false)
bool startRouter(Message *msg)
virtual void msgStatus(Message &msg)
virtual bool callPrerouted(Message &msg, bool handled)
bool toneDetect(const char *sniffer=0)
virtual bool msgControl(Message &msg)
const String & billid() const
Definition yatephone.h:2021
virtual void callAccept(Message &msg)
virtual void setDisconnect(const NamedList *params)
void filterDebug(const String &item)
virtual void setId(const char *newId)
virtual bool msgUpdate(Message &msg)
const String & address() const
Definition yatephone.h:1905
virtual void complete(Message &msg, bool minimal=false) const
u_int64_t maxPDD() const
Definition yatephone.h:1990
void copyChanParams(NamedList &list) const
Definition yatephone.h:2076
Channel(Driver *driver, const char *id=0, bool outgoing=false)
void setChanParams(const NamedList &list, bool in=false)
Definition yatephone.h:2062
const NamedList & parameters() const
Definition yatephone.h:2054
virtual bool msgText(Message &msg, const char *text)
const String & targetid() const
Definition yatephone.h:2013
static Mutex & paramMutex()
virtual void disconnected(bool final, const char *reason)
void status(const char *newstat)
virtual void checkTimers(Message &msg, const Time &tmr)
Definition yatephone.h:398
virtual void * getObject(const String &name) const
DataConsumer(const char *format="slin")
Definition yatephone.h:406
virtual void destroyed()
DataSource * getOverSource() const
Definition yatephone.h:446
virtual DataSource * getTransSource() const
Definition yatephone.h:453
virtual bool synchronize(DataSource *source)
DataSource * getConnSource() const
Definition yatephone.h:439
virtual unsigned long Consume(const DataBlock &data, unsigned long tStamp, unsigned long flags)=0
A data transfer endpoint capable of sending and/or receiving data.
Definition yatephone.h:928
bool delSniffer(DataConsumer *sniffer)
virtual void * getObject(const String &name) const
bool addSniffer(DataConsumer *sniffer)
virtual void destroyed()
void clearCall(const CallEndpoint *call)
Definition yatephone.h:1093
void setConsumer(DataConsumer *consumer=0)
DataConsumer * getCallRecord() const
Definition yatephone.h:1030
virtual bool nativeConnect(DataEndpoint *peer)
Definition yatephone.h:1109
bool clearData(DataNode *node)
void setCallRecord(DataConsumer *consumer=0)
DataConsumer * getConsumer() const
Definition yatephone.h:1002
Mutex * mutex() const
DataEndpoint * getPeer() const
Definition yatephone.h:1071
DataConsumer * getPeerRecord() const
Definition yatephone.h:1016
DataSource * getSource() const
Definition yatephone.h:989
CallEndpoint * getCall() const
Definition yatephone.h:1078
virtual const String & toString() const
void setSource(DataSource *source=0)
DataConsumer * getSniffer(const String &name, bool ref=false)
DataEndpoint(CallEndpoint *call=0, const char *name="audio")
const String & name() const
Definition yatephone.h:1085
void setPeerRecord(DataConsumer *consumer=0)
static Mutex & commonMutex()
virtual bool control(NamedList &params)
bool connect(DataEndpoint *peer)
A Data format.
Definition yatephone.h:183
DataFormat()
Definition yatephone.h:188
DataFormat(const String *value)
Definition yatephone.h:228
DataFormat(const FormatInfo *format)
Definition yatephone.h:236
virtual void changed()
int frameSize(int defValue=0) const
Definition yatephone.h:257
int frameTime(int defValue=0) const
Definition yatephone.h:265
DataFormat(const String &value)
Definition yatephone.h:212
const FormatInfo * getInfo() const
DataFormat(const DataFormat &value)
Definition yatephone.h:204
DataFormat & operator=(const DataFormat &value)
Definition yatephone.h:243
int numChannels(int defValue=1) const
Definition yatephone.h:282
DataFormat(const char *value)
Definition yatephone.h:196
DataFormat(const NamedList &value)
Definition yatephone.h:220
int sampleRate(int defValue=0) const
Definition yatephone.h:274
Definition yatephone.h:299
virtual void attached(bool added)
Definition yatephone.h:381
virtual bool valid() const
Definition yatephone.h:358
unsigned long timeStamp() const
Definition yatephone.h:351
virtual int costFormat(const DataFormat &format)
Definition yatephone.h:329
DataNode(const char *format=0)
Definition yatephone.h:320
static unsigned long invalidStamp()
Definition yatephone.h:373
virtual bool setFormat(const DataFormat &format)
Definition yatephone.h:337
DataFlags
Definition yatephone.h:306
const DataFormat & getFormat() const
Definition yatephone.h:344
virtual bool control(NamedList &params)
Definition yatephone.h:366
Definition yatephone.h:478
void synchronize(unsigned long tStamp)
virtual void * getObject(const String &name) const
virtual void destroyed()
unsigned long Forward(const DataBlock &data, unsigned long tStamp=invalidStamp(), unsigned long flags=0)
unsigned long nextStamp() const
Definition yatephone.h:562
virtual bool valid() const
bool attach(DataConsumer *consumer, bool override=false)
bool detach(DataConsumer *consumer)
DataTranslator * getTranslator() const
Definition yatephone.h:549
DataSource(const char *format="slin")
Definition yatephone.h:486
virtual bool control(NamedList &params)
An unidirectional data translator (codec)
Definition yatephone.h:652
static ObjList * allFormats(const String &formats, bool existing=true, bool sameRate=true, bool sameChans=true)
static bool attachChain(DataSource *source, DataConsumer *consumer, bool override=false)
virtual void * getObject(const String &name) const
static ObjList * destFormats(const DataFormat &sFormat="slin", int maxCost=-1, unsigned int maxLen=0, ObjList *lst=0)
static bool canConvert(const DataFormat &fmt1, const DataFormat &fmt2="slin")
DataTranslator(const char *sFormat, const char *dFormat)
virtual bool valid() const
Definition yatephone.h:686
const DataTranslator * getFirstTranslator() const
static void uninstall(TranslatorFactory *factory)
static ObjList * allFormats(const ObjList *formats, bool existing=true, bool sameRate=true, bool sameChans=true)
ObjList * getConsumers() const
Definition yatephone.h:800
static ObjList * srcFormats(const DataFormat &dFormat="slin", int maxCost=-1, unsigned int maxLen=0, ObjList *lst=0)
static void install(TranslatorFactory *factory)
static DataTranslator * create(const DataFormat &sFormat, const DataFormat &dFormat)
virtual DataSource * getTransSource() const
Definition yatephone.h:693
static void setMaxChain(unsigned int maxChain)
static int cost(const DataFormat &sFormat, const DataFormat &dFormat)
DataTranslator * getFirstTranslator()
virtual bool synchronize(DataSource *source)
DataTranslator(const char *sFormat, DataSource *source=0)
static bool detachChain(DataSource *source, DataConsumer *consumer)
A Channel driver module.
Definition yatephone.h:2236
void setup(const char *prefix=0, bool minimal=false)
virtual bool msgExecute(Message &msg, String &dest)=0
Driver(const char *name, const char *type=0)
virtual void statusParams(String &str)
void timeout(int tout)
Definition yatephone.h:2487
virtual bool setDebug(Message &msg, const String &target)
virtual void statusModule(String &str)
virtual void * getObject(const String &name) const
int chanCount() const
Definition yatephone.h:2362
unsigned int nextid()
virtual bool canRoute()
virtual void dropAll(Message &msg)
virtual void genUpdate(Message &msg)
virtual void statusDetail(String &str)
int timeout() const
Definition yatephone.h:2334
bool varchan() const
Definition yatephone.h:2275
virtual void loadLimits()
virtual void initialize()
void maxRoute(int ncalls)
Definition yatephone.h:2494
unsigned int lastid() const
Definition yatephone.h:2327
const String & prefix() const
Definition yatephone.h:2268
virtual bool received(Message &msg, int id)
int maxChans() const
Definition yatephone.h:2369
int routing() const
Definition yatephone.h:2341
int routed() const
Definition yatephone.h:2348
virtual bool hasLine(const String &line) const
ObjList & channels()
Definition yatephone.h:2282
virtual bool canAccept(bool routers=true)
void varchan(bool variable)
Definition yatephone.h:2480
void dtmfDups(bool duplicates)
Definition yatephone.h:2508
virtual bool canStopCall() const
Definition yatephone.h:2473
virtual bool msgRoute(Message &msg)
virtual bool isBusy() const
void maxChans(int ncalls)
Definition yatephone.h:2501
virtual Channel * find(const String &id) const
virtual bool commandComplete(Message &msg, const String &partLine, const String &partWord)
int total() const
Definition yatephone.h:2355
A repository for media formats.
Definition yatephone.h:152
static const FormatInfo * getFormat(const String &name)
static const FormatInfo * addFormat(const String &name, int fsize, int ftime, const String &type="audio", int srate=8000, int nchan=1)
Post-dispatching message hook.
Definition yatengine.h:684
A multiple message receiver.
Definition yatengine.h:615
A message handler relay.
Definition yatengine.h:631
A message container class.
Definition yatengine.h:313
A Plugin that implements a module.
Definition yatephone.h:1358
virtual void statusParams(String &str)
virtual void msgTimer(Message &msg)
virtual bool setDebug(Message &msg, const String &target)
bool filterInstalled() const
Definition yatephone.h:1407
virtual void statusModule(String &str)
static const char * messageName(int id)
virtual void * getObject(const String &name) const
bool filterDebug(const String &item) const
virtual bool commandExecute(String &retVal, const String &line)
bool uninstallRelay(int id, bool delRelay=true)
bool relayInstalled(int id) const
Definition yatephone.h:1505
virtual void genUpdate(Message &msg)
virtual void statusDetail(String &str)
bool installRelay(MessageRelay *relay)
virtual void initialize()
static bool itemComplete(String &itemList, const String &item, const String &partWord)
bool uninstallRelay(MessageRelay *relay, bool delRelay=true)
virtual bool received(Message &msg, int id)
static unsigned int updateDelay()
Definition yatephone.h:1393
static int relayId(const char *name)
Definition yatephone.h:1474
const String & type() const
Definition yatephone.h:1380
enum TelEngine::Module::@0 RelayID
virtual void msgStatus(Message &msg)
Module(const char *name, const char *type=0, bool earlyInit=false)
bool installRelay(int id, unsigned priority=100)
virtual bool msgRoute(Message &msg)
virtual bool msgCommand(Message &msg)
virtual bool commandComplete(Message &msg, const String &partLine, const String &partWord)
bool installRelay(int id, const char *name, unsigned priority=100)
static void updateDelay(unsigned int delay)
Definition yatephone.h:1400
bool installRelay(const char *name, unsigned priority=100)
Plugin support.
Definition yatengine.h:1052
bool earlyInit() const
Definition yatengine.h:1112
const String & name() const
Definition yatengine.h:1098
Call routing thread.
Definition yatephone.h:2520
virtual bool route()
virtual void cleanup()
const String & id() const
Definition yatephone.h:2557
virtual void run()
Router(Driver *driver, const char *id, Message *msg)
Data source with own thread.
Definition yatephone.h:582
virtual void run()=0
virtual void destroyed()
bool start(const char *name="ThreadedSource", Thread::Priority prio=Thread::Normal)
bool looping(bool runConsumers=false) const
Thread * thread() const
ThreadedSource(const char *format="slin")
Definition yatephone.h:620
An unidirectional data translator (codec)
Definition yatephone.h:839
virtual const TranslatorCaps * getCapabilities() const =0
virtual const char * name() const
Definition yatephone.h:907
TranslatorFactory(const char *name=0)
Definition yatephone.h:846
virtual const FormatInfo * intermediate() const
virtual bool converts(const DataFormat &sFormat, const DataFormat &dFormat) const
virtual unsigned int length() const
virtual void removed(const TranslatorFactory *factory)
virtual DataTranslator * create(const DataFormat &sFormat, const DataFormat &dFormat)=0
virtual bool intermediate(const FormatInfo *info) const
NamedCounter * objectsCounter() const
Definition yatephone.h:914
Thread support class.
Definition yateclass.h:6005
Priority
Definition yateclass.h:6014
static NamedCounter * getCurrentObjCounter(bool always=false)
A time holding class.
Definition yateclass.h:3927
Definition yatemime.h:34
bool isE164(const char *str)
Definition yatephone.h:59
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
FormatInfo()
Definition yatephone.h:111
int frameTime
Definition yatephone.h:78
const char * type
Definition yatephone.h:68
int numChannels
Definition yatephone.h:88
const char * name
Definition yatephone.h:63
int frameSize
Definition yatephone.h:73
bool converter
Definition yatephone.h:93
int guessSamples(int len) const
int sampleRate
Definition yatephone.h:83
Definition yatephone.h:39
int width
Definition yatephone.h:43
int depth
Definition yatephone.h:53
int height
Definition yatephone.h:48
Definition yatephone.h:138
const FormatInfo * dest
Definition yatephone.h:142
int cost
Definition yatephone.h:144
const FormatInfo * src
Definition yatephone.h:140
Definition yateclass.h:848