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 
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 
84 
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:
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 
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  Driver* m_driver;
1663  bool m_outgoing;
1664  u_int64_t m_timeout;
1665  u_int64_t m_maxcall;
1666  u_int64_t m_maxPDD; // Timeout while waiting for some progress on outgoing calls
1667  u_int64_t m_dtmfTime;
1668  unsigned int m_toutAns;
1669  unsigned int m_dtmfSeq;
1670  String m_dtmfText;
1671  String m_dtmfDetected;
1672 
1673 protected:
1674  String m_status;
1675  String m_address;
1676  String m_targetid;
1677  String m_billid;
1678  bool m_answered;
1679 
1680 public:
1684  virtual ~Channel();
1685 
1691  virtual void* getObject(const String& name) const;
1692 
1697  static Mutex& paramMutex();
1698 
1704  virtual void complete(Message& msg, bool minimal = false) const;
1705 
1713  Message* message(const char* name, bool minimal = false, bool data = false);
1714 
1725  Message* message(const char* name, const NamedList* original, const char* params = 0, bool minimal = false, bool data = false);
1726 
1737  inline Message* message(const char* name, const NamedList& original, const char* params = 0, bool minimal = false, bool data = false)
1738  { return message(name,&original,params,minimal,data); }
1739 
1745  virtual bool msgProgress(Message& msg);
1746 
1752  virtual bool msgRinging(Message& msg);
1753 
1759  virtual bool msgAnswered(Message& msg);
1760 
1767  virtual bool msgTone(Message& msg, const char* tone);
1768 
1775  virtual bool msgText(Message& msg, const char* text);
1776 
1783  virtual bool msgDrop(Message& msg, const char* reason);
1784 
1790  virtual bool msgTransfer(Message& msg);
1791 
1797  virtual bool msgUpdate(Message& msg);
1798 
1804  virtual bool msgMasquerade(Message& msg);
1805 
1810  virtual void msgStatus(Message& msg);
1811 
1817  virtual bool msgControl(Message& msg);
1818 
1824  virtual void checkTimers(Message& msg, const Time& tmr);
1825 
1832  virtual bool callPrerouted(Message& msg, bool handled);
1833 
1839  virtual bool callRouted(Message& msg);
1840 
1845  virtual void callAccept(Message& msg);
1846 
1853  virtual void callRejected(const char* error, const char* reason = 0, const Message* msg = 0);
1854 
1860  virtual void callConnect(Message& msg);
1861 
1866  virtual bool setDebug(Message& msg);
1867 
1872  inline const String& status() const
1873  { return m_status; }
1874 
1879  inline const String& address() const
1880  { return m_address; }
1881 
1886  inline bool isOutgoing() const
1887  { return m_outgoing; }
1888 
1893  inline bool isIncoming() const
1894  { return !m_outgoing; }
1895 
1900  inline bool isAnswered() const
1901  { return m_answered; }
1902 
1907  const char* direction() const;
1908 
1913  inline Driver* driver() const
1914  { return m_driver; }
1915 
1920  inline u_int64_t timeout() const
1921  { return m_timeout; }
1922 
1927  inline void timeout(u_int64_t tout)
1928  { m_timeout = tout; }
1929 
1934  inline u_int64_t maxcall() const
1935  { return m_maxcall; }
1936 
1941  inline void maxcall(u_int64_t tout)
1942  { m_maxcall = tout; }
1943 
1949  inline void setMaxcall(const Message& msg, int defTout = -1)
1950  { setMaxcall(&msg,defTout); }
1951 
1957  void setMaxcall(const Message* msg, int defTout = -1);
1958 
1964  inline u_int64_t maxPDD() const
1965  { return m_maxPDD; }
1966 
1972  inline void maxPDD(u_int64_t tout)
1973  { m_maxPDD = tout; }
1974 
1980  void setMaxPDD(const Message& msg);
1981 
1987  inline const String& targetid() const
1988  { return m_targetid; }
1989 
1995  inline const String& billid() const
1996  { return m_billid; }
1997 
2002  void initChan();
2003 
2010  bool startRouter(Message* msg);
2011 
2016  static unsigned int allocId();
2017 
2022  void filterDebug(const String& item);
2023 
2028  inline const NamedList& parameters() const
2029  { return m_parameters; }
2030 
2036  virtual void dispatched(const Message& msg, bool handled);
2037 
2038 protected:
2042  Channel(Driver* driver, const char* id = 0, bool outgoing = false);
2043 
2047  Channel(Driver& driver, const char* id = 0, bool outgoing = false);
2048 
2053  void cleanup();
2054 
2058  void dropChan();
2059 
2064  virtual void zeroRefs();
2065 
2070  virtual void connected(const char* reason);
2071 
2077  virtual void disconnected(bool final, const char* reason);
2078 
2083  virtual void setDisconnect(const NamedList* params);
2084 
2090  virtual void endDisconnect(const Message& msg, bool handled);
2091 
2096  virtual void setId(const char* newId);
2097 
2103  virtual Message* getDisconnect(const char* reason);
2104 
2110  void status(const char* newstat);
2111 
2116  virtual void statusParams(String& str);
2117 
2122  inline void setOutgoing(bool outgoing = true)
2123  { m_outgoing = outgoing; }
2124 
2130  bool dtmfSequence(Message& msg);
2131 
2137  bool dtmfEnqueue(Message* msg);
2138 
2145  bool dtmfInband(const char* tone);
2146 
2153  bool toneDetect(const char* sniffer = 0);
2154 
2160  { return m_parameters; }
2161 
2162 private:
2163  void init();
2164  Channel(); // no default constructor please
2165 };
2166 
2171 class YATE_API Driver : public Module
2172 {
2173  friend class Router;
2174  friend class Channel;
2175 
2176 private:
2177  bool m_init;
2178  bool m_varchan;
2179  String m_prefix;
2180  ObjList m_chans;
2181  int m_routing;
2182  int m_routed;
2183  int m_total;
2184  unsigned int m_nextid;
2185  int m_timeout;
2186  int m_maxroute;
2187  int m_maxchans;
2188  int m_chanCount;
2189  bool m_dtmfDups;
2190  volatile bool m_doExpire;
2191 
2192 public:
2198  virtual void* getObject(const String& name) const;
2199 
2204  inline const String& prefix() const
2205  { return m_prefix; }
2206 
2211  inline bool varchan() const
2212  { return m_varchan; }
2213 
2218  inline ObjList& channels()
2219  { return m_chans; }
2220 
2226  virtual Channel* find(const String& id) const;
2227 
2232  virtual bool isBusy() const;
2233 
2238  virtual void dropAll(Message &msg);
2239 
2245  virtual bool canAccept(bool routers = true);
2246 
2251  virtual bool canRoute();
2252 
2257  unsigned int nextid();
2258 
2263  inline unsigned int lastid() const
2264  { return m_nextid; }
2265 
2270  inline int timeout() const
2271  { return m_timeout; }
2272 
2277  inline int routing() const
2278  { return m_routing; }
2279 
2284  inline int routed() const
2285  { return m_routed; }
2286 
2291  inline int total() const
2292  { return m_total; }
2293 
2298  inline int chanCount() const
2299  { return m_chanCount; }
2300 
2305  inline int maxChans() const
2306  { return m_maxchans; }
2307 
2308 protected:
2314  Driver(const char* name, const char* type = 0);
2315 
2319  virtual void initialize();
2320 
2326  void setup(const char* prefix = 0, bool minimal = false);
2327 
2334  virtual bool received(Message &msg, int id);
2335 
2340  virtual void genUpdate(Message& msg);
2341 
2348  virtual bool hasLine(const String& line) const;
2349 
2356  virtual bool msgRoute(Message& msg);
2357 
2364  virtual bool msgExecute(Message& msg, String& dest) = 0;
2365 
2373  virtual bool commandComplete(Message& msg, const String& partLine, const String& partWord);
2374 
2379  virtual void statusModule(String& str);
2380 
2385  virtual void statusParams(String& str);
2386 
2391  virtual void statusDetail(String& str);
2392 
2398  virtual bool setDebug(Message& msg, const String& target);
2399 
2403  virtual void loadLimits();
2404 
2409  inline void varchan(bool variable)
2410  { m_varchan = variable; }
2411 
2416  inline void timeout(int tout)
2417  { m_timeout = tout; }
2418 
2423  inline void maxRoute(int ncalls)
2424  { m_maxroute = ncalls; }
2425 
2430  inline void maxChans(int ncalls)
2431  { m_maxchans = ncalls; }
2432 
2437  inline void dtmfDups(bool duplicates)
2438  { m_dtmfDups = duplicates; }
2439 
2440 private:
2441  Driver(); // no default constructor please
2442 };
2443 
2448 class YATE_API Router : public Thread
2449 {
2450  YNOCOPY(Router); // no automatic copies please
2451 private:
2452  Driver* m_driver;
2453  String m_id;
2454  Message* m_msg;
2455 
2456 public:
2463  Router(Driver* driver, const char* id, Message* msg);
2464 
2468  virtual void run();
2469 
2474  virtual bool route();
2475 
2479  virtual void cleanup();
2480 
2481 protected:
2486  const String& id() const
2487  { return m_id; }
2488 };
2489 
2494 class YATE_API CallAccount
2495 {
2497 private:
2498  Mutex* m_mutex;
2499  NamedList m_inbParams;
2500  NamedList m_outParams;
2501  NamedList m_regParams;
2502 
2503 public:
2508  void pickAccountParams(const NamedList& params);
2509 
2510 
2515  void setInboundParams(NamedList& params);
2516 
2521  void setOutboundParams(NamedList& params);
2522 
2527  void setRegisterParams(NamedList& params);
2528 
2533  inline const NamedList& inboundParams() const
2534  { return m_inbParams; }
2535 
2540  inline const NamedList& outboundParams() const
2541  { return m_outParams; }
2542 
2547  inline const NamedList& registerParams() const
2548  { return m_regParams; }
2549 
2550 protected:
2555  inline CallAccount(Mutex* mutex)
2556  : m_mutex(mutex), m_inbParams(""), m_outParams(""), m_regParams("")
2557  { }
2558 };
2559 
2565 YATE_API bool isE164(const char* str);
2566 
2567 }; // namespace TelEngine
2568 
2569 #endif /* __YATEPHONE_H */
2570 
2571 /* vi: set ts=8 sw=4 sts=4 noet: */
CallEndpoint * getPeer() const
Definition: yatephone.h:1172
bool varchan() const
Definition: yatephone.h:2211
bool null() const
Definition: yateclass.h:1967
virtual void setDisconnect(const NamedList *params)
Definition: yatephone.h:1326
static NamedCounter * getCurrentObjCounter(bool always=false)
bool isAnswered() const
Definition: yatephone.h:1900
const FormatInfo * src
Definition: yatephone.h:140
void dtmfDups(bool duplicates)
Definition: yatephone.h:2437
int frameSize
Definition: yatephone.h:73
DataFormat(const String &value)
Definition: yatephone.h:212
int sampleRate
Definition: yatephone.h:83
const DataFormat & getFormat() const
Definition: yatephone.h:344
A class that holds just a block of raw data.
Definition: yateclass.h:3774
static int relayId(const char *name)
Definition: yatephone.h:1474
virtual bool valid() const
Definition: yatephone.h:358
Definition: yateclass.h:949
A regexp matching class.
Definition: yateclass.h:2902
An unidirectional data translator (codec)
Definition: yatephone.h:838
const String & targetid() const
Definition: yatephone.h:1987
void setMaxcall(const Message &msg, int defTout=-1)
Definition: yatephone.h:1949
ObjList * skipNull() const
virtual void attached(bool added)
Definition: yatephone.h:381
CallEndpoint * getCall() const
Definition: yatephone.h:1078
DataEndpoint * getPeer() const
Definition: yatephone.h:1071
DataConsumer(const char *format="slin")
Definition: yatephone.h:406
static void install(TranslatorFactory *factory)
DataFormat(const DataFormat &value)
Definition: yatephone.h:204
const FormatInfo * dest
Definition: yatephone.h:142
Post-dispatching message hook.
Definition: yatengine.h:676
unsigned long timeStamp() const
Definition: yatephone.h:351
virtual const String & toString() const
Definition: yatephone.h:1158
Definition: yatephone.h:138
void timeout(u_int64_t tout)
Definition: yatephone.h:1927
Thread support class.
Definition: yateclass.h:5529
const String & billid() const
Definition: yatephone.h:1995
void setOutgoing(bool outgoing=true)
Definition: yatephone.h:2122
Mutex * mutex() const
Definition: yatephone.h:1204
Data source with own thread.
Definition: yatephone.h:581
const String & id() const
Definition: yatephone.h:2486
const String & type() const
Definition: yatephone.h:1380
static unsigned int updateDelay()
Definition: yatephone.h:1393
int depth
Definition: yatephone.h:53
int height
Definition: yatephone.h:48
TranslatorFactory(const char *name=0)
Definition: yatephone.h:846
bool isIncoming() const
Definition: yatephone.h:1893
Call routing thread.
Definition: yatephone.h:2448
bool disconnect(const char *reason=0, bool notify=true, const NamedList *params=0)
Definition: yatephone.h:1229
int timeout() const
Definition: yatephone.h:2270
int frameSize(int defValue=0) const
Definition: yatephone.h:257
bool filterInstalled() const
Definition: yatephone.h:1407
virtual bool valid() const
Definition: yatephone.h:686
A multiple message receiver.
Definition: yatengine.h:607
CallAccount(Mutex *mutex)
Definition: yatephone.h:2555
Definition: yatephone.h:397
const NamedList & registerParams() const
Definition: yatephone.h:2547
An abstract communication channel.
Definition: yatephone.h:1655
A message handler relay.
Definition: yatengine.h:623
bool isOutgoing() const
Definition: yatephone.h:1886
int numChannels(int defValue=1) const
Definition: yatephone.h:282
DataSource * getConnSource() const
Definition: yatephone.h:439
virtual bool setFormat(const DataFormat &format)
Definition: yatephone.h:337
DataFlags
Definition: yatephone.h:306
static unsigned long invalidStamp()
Definition: yatephone.h:373
int lookup(const char *str, const TokenDict *tokens, int defvalue=0, int base=0)
int sampleRate(int defValue=0) const
Definition: yatephone.h:274
int width
Definition: yatephone.h:43
u_int64_t timeout() const
Definition: yatephone.h:1920
FormatInfo()
Definition: yatephone.h:111
const String & status() const
Definition: yatephone.h:1872
int frameTime(int defValue=0) const
Definition: yatephone.h:265
const NamedList & inboundParams() const
Definition: yatephone.h:2533
ObjList & channels()
Definition: yatephone.h:2218
int routing() const
Definition: yatephone.h:2277
const String & id() const
Definition: yatephone.h:1165
An abstract call endpoint.
Definition: yatephone.h:1127
DataSource * getSource() const
Definition: yatephone.h:989
An unidirectional data translator (codec)
Definition: yatephone.h:651
void varchan(bool variable)
Definition: yatephone.h:2409
ObjList * getConsumers() const
Definition: yatephone.h:800
A time holding class.
Definition: yateclass.h:3536
virtual void connected(const char *reason)
Definition: yatephone.h:1313
DataNode(const char *format=0)
Definition: yatephone.h:320
DataFormat(const FormatInfo *format)
Definition: yatephone.h:236
void maxChans(int ncalls)
Definition: yatephone.h:2430
A holder for a debug level.
Definition: yateclass.h:309
Definition: yatephone.h:477
Definition: yatephone.h:59
int numChannels
Definition: yatephone.h:88
A message container class.
Definition: yatengine.h:312
A Data format.
Definition: yatephone.h:182
unsigned long nextStamp() const
Definition: yatephone.h:562
bool converter
Definition: yatephone.h:93
ThreadedSource(const char *format="slin")
Definition: yatephone.h:620
const String & prefix() const
Definition: yatephone.h:2204
u_int64_t maxPDD() const
Definition: yatephone.h:1964
A Channel driver module.
Definition: yatephone.h:2171
DataConsumer * getPeerRecord() const
Definition: yatephone.h:1016
static const String & audioType()
const NamedList & outboundParams() const
Definition: yatephone.h:2540
const String & name() const
Definition: yatephone.h:1085
const char * name
Definition: yatephone.h:63
void timeout(int tout)
Definition: yatephone.h:2416
int chanCount() const
Definition: yatephone.h:2298
const char * c_str(const String *str)
Definition: yateclass.h:2805
NamedList & operator=(const NamedList &value)
DataTranslator * getTranslator() const
Definition: yatephone.h:549
A data transfer endpoint capable of sending and/or receiving data.
Definition: yatephone.h:927
const FormatInfo * getInfo() const
bool relayInstalled(int id) const
Definition: yatephone.h:1505
A named string container class.
Definition: yateclass.h:4553
static void updateDelay(unsigned int delay)
Definition: yatephone.h:1400
void maxcall(u_int64_t tout)
Definition: yatephone.h:1941
Ephemeral mutex or semaphore locking object.
Definition: yateclass.h:5357
DataSource * getOverSource() const
Definition: yatephone.h:446
DataConsumer * getConsumer() const
Definition: yatephone.h:1002
void clearCall(const CallEndpoint *call)
Definition: yatephone.h:1093
int cost
Definition: yatephone.h:144
unsigned int lastid() const
Definition: yatephone.h:2263
virtual void disconnected(bool final, const char *reason)
Definition: yatephone.h:1320
int total() const
Definition: yatephone.h:2291
virtual DataSource * getTransSource() const
Definition: yatephone.h:693
virtual DataSource * getTransSource() const
Definition: yatephone.h:453
DataConsumer * getCallRecord() const
Definition: yatephone.h:1030
const NamedList & parameters() const
Definition: yatephone.h:2028
DataSource(const char *format="slin")
Definition: yatephone.h:486
Definition: yateclass.h:217
virtual bool nativeConnect(DataEndpoint *peer)
Definition: yatephone.h:1109
NamedCounter * objectsCounter() const
Definition: yatephone.h:914
A C-style string handling class.
Definition: yateclass.h:1832
void maxRoute(int ncalls)
Definition: yatephone.h:2423
Driver * driver() const
Definition: yatephone.h:1913
const String & address() const
Definition: yatephone.h:1879
DataFormat & operator=(const DataFormat &value)
Definition: yatephone.h:243
Definition: yateclass.h:683
DataFormat(const char *value)
Definition: yatephone.h:196
Priority
Definition: yateclass.h:5539
virtual const char * name() const
Definition: yatephone.h:907
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
u_int64_t maxcall() const
Definition: yatephone.h:1934
An object list class.
Definition: yateclass.h:1229
Definition: yatephone.h:298
NamedList & parameters()
Definition: yatephone.h:2159
DataFormat(const NamedList &value)
Definition: yatephone.h:220
void YNOCOPY(class type)
A Plugin that implements a module.
Definition: yatephone.h:1357
void maxPDD(u_int64_t tout)
Definition: yatephone.h:1972
DataFormat()
Definition: yatephone.h:188
static const String & empty()
bool disconnect(const char *reason, const NamedList &params)
Definition: yatephone.h:1238
virtual int costFormat(const DataFormat &format)
Definition: yatephone.h:329
int frameTime
Definition: yatephone.h:78
Settings for an account handling calls.
Definition: yatephone.h:2494
int routed() const
Definition: yatephone.h:2284
Plugin support.
Definition: yatengine.h:1023
Mutex support.
Definition: yateclass.h:5131
virtual bool control(NamedList &params)
Definition: yatephone.h:366
const char * type
Definition: yatephone.h:68
Definition: yateclass.h:830
int maxChans() const
Definition: yatephone.h:2305
DataFormat(const String *value)
Definition: yatephone.h:228
Definition: yatephone.h:39
Message * message(const char *name, const NamedList &original, const char *params=0, bool minimal=false, bool data=false)
Definition: yatephone.h:1737
A repository for media formats.
Definition: yatephone.h:151
Atomic counter with name.
Definition: yateclass.h:3232
bool isE164(const char *str)