OPAL  Version 3.14.3
lid.h
Go to the documentation of this file.
1 /*
2  * lid.h
3  *
4  * Line Interface Device
5  *
6  * Open Phone Abstraction Library
7  *
8  * Copyright (c) 1999-2001 Equivalence Pty. Ltd.
9  *
10  * The contents of this file are subject to the Mozilla Public License
11  * Version 1.0 (the "License"); you may not use this file except in
12  * compliance with the License. You may obtain a copy of the License at
13  * http://www.mozilla.org/MPL/
14  *
15  * Software distributed under the License is distributed on an "AS IS"
16  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
17  * the License for the specific language governing rights and limitations
18  * under the License.
19  *
20  * The Original Code is Open H323 Library.
21  *
22  * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
23  *
24  * Portions of this code were written with the assisance of funding from
25  * Quicknet Technologies, Inc. http://www.quicknet.net.
26  *
27  * Contributor(s): ______________________________________.
28  *
29  * $Revision: 31808 $
30  * $Author: rjongbloed $
31  * $Date: 2014-04-30 10:54:16 +1000 (Wed, 30 Apr 2014) $
32  */
33 
34 #ifndef OPAL_LIDS_LID_H
35 #define OPAL_LIDS_LID_H
36 
37 #ifdef P_USE_PRAGMA
38 #pragma interface
39 #endif
40 
41 #include <opal_config.h>
42 
43 #if OPAL_LID
44 
45 #include <opal/mediafmt.h>
46 
47 
49 
53 class OpalLineInterfaceDevice : public PObject
54 {
55  PCLASSINFO(OpalLineInterfaceDevice, PObject);
56 
57  public:
61 
64  virtual PBoolean Open(
65  const PString & device
66  ) = 0;
67 
70  virtual PBoolean IsOpen() const;
71 
74  virtual PBoolean Close();
75 
79  virtual PString GetDeviceType() const = 0;
80 
85  virtual PString GetDeviceName() const = 0;
86 
89  virtual PStringArray GetAllNames() const = 0;
90 
96  virtual PString GetDescription() const = 0;
97 
100  virtual unsigned GetLineCount() const = 0;
101 
108  virtual PBoolean IsLineTerminal(
109  unsigned line
110  ) = 0;
111 
112 
115  virtual PBoolean IsLinePresent(
116  unsigned line,
117  PBoolean force = false
118  );
119 
120 
126  virtual PBoolean IsLineOffHook(
127  unsigned line
128  ) = 0;
129 
135  virtual PBoolean SetLineOffHook(
136  unsigned line,
137  PBoolean newState = true
138  ) = 0;
139 
143  virtual PBoolean SetLineOnHook(
144  unsigned line
145  ) { return SetLineOffHook(line, false); }
146 
150  virtual PBoolean HookFlash(
151  unsigned line,
152  unsigned flashTime = 200
153  );
154 
157  virtual PBoolean HasHookFlash(unsigned line);
158 
159 
170  virtual PBoolean IsLineRinging(
171  unsigned line,
172  DWORD * cadence = NULL
173  );
174 
192  virtual PBoolean RingLine(
193  unsigned line,
194  PINDEX nCadence,
195  const unsigned * pattern = NULL,
196  unsigned frequency = 400
197  );
198 
199 
210  virtual PBoolean SetLineConnected(
211  unsigned line
212  );
213 
224  virtual PBoolean IsLineConnected(
225  unsigned line
226  );
227 
228 
240  virtual PBoolean IsLineDisconnected(
241  unsigned line,
242  PBoolean checkForWink = true
243  );
244 
245 
248  virtual PBoolean SetLineToLineDirect(
249  unsigned line1,
250  unsigned line2,
251  PBoolean connect
252  );
253 
256  virtual PBoolean IsLineToLineDirect(
257  unsigned line1,
258  unsigned line2
259  );
260 
261 
264  virtual OpalMediaFormatList GetMediaFormats() const = 0;
265 
268  virtual PBoolean SetReadFormat(
269  unsigned line,
270  const OpalMediaFormat & mediaFormat
271  ) = 0;
272 
275  virtual PBoolean SetWriteFormat(
276  unsigned line,
277  const OpalMediaFormat & mediaFormat
278  ) = 0;
279 
283  unsigned line
284  ) = 0;
285 
289  unsigned line
290  ) = 0;
291 
294  virtual PBoolean StopReading(
295  unsigned line
296  );
297 
300  virtual PBoolean StopWriting(
301  unsigned line
302  );
303 
308  virtual bool UsesRTP() const;
309 
314  virtual PBoolean SetReadFrameSize(
315  unsigned line,
316  PINDEX frameSize
317  );
318 
323  virtual PBoolean SetWriteFrameSize(
324  unsigned line,
325  PINDEX frameSize
326  );
327 
331  virtual PINDEX GetReadFrameSize(
332  unsigned line
333  );
334 
338  virtual PINDEX GetWriteFrameSize(
339  unsigned line
340  );
341 
344  virtual PBoolean ReadFrame(
345  unsigned line,
346  void * buf,
347  PINDEX & count
348  ) = 0;
349 
352  virtual PBoolean WriteFrame(
353  unsigned line,
354  const void * buf,
355  PINDEX count,
356  PINDEX & written
357  ) = 0;
358 
362  virtual PBoolean ReadBlock(
363  unsigned line,
364  void * buf,
365  PINDEX count
366  );
367 
370  virtual PBoolean WriteBlock(
371  unsigned line,
372  const void * buf,
373  PINDEX count
374  );
375 
376 
379  virtual unsigned GetAverageSignalLevel(
380  unsigned line,
381  PBoolean playback
382  );
383 
384 
387  virtual PBoolean EnableAudio(
388  unsigned line,
389  PBoolean enable = true
390  );
391 
394  PBoolean DisableAudio(
395  unsigned line
396  ) { return EnableAudio(line, false); }
397 
400  virtual PBoolean IsAudioEnabled(
401  unsigned line
402  ) const;
403 
404 
405  enum {
406  MaxVolume = 100
407  };
408 
413  virtual PBoolean SetRecordVolume(
414  unsigned line,
415  unsigned volume
416  );
417 
422  virtual PBoolean SetPlayVolume(
423  unsigned line,
424  unsigned volume
425  );
426 
431  virtual PBoolean GetRecordVolume(
432  unsigned line,
433  unsigned & volume
434  );
435 
440  virtual PBoolean GetPlayVolume(
441  unsigned line,
442  unsigned & volume
443  );
444 
445 
446  enum AECLevels {
454  };
455 
459  virtual AECLevels GetAEC(
460  unsigned line
461  ) const;
462 
466  virtual PBoolean SetAEC(
467  unsigned line,
468  AECLevels level
469  );
470 
474  virtual PBoolean GetVAD(
475  unsigned line
476  ) const;
477 
481  virtual PBoolean SetVAD(
482  unsigned line,
483  PBoolean enable
484  );
485 
486 
500  virtual PBoolean GetCallerID(
501  unsigned line,
502  PString & idString,
503  PBoolean full = false
504  );
505 
527  virtual PBoolean SetCallerID(
528  unsigned line,
529  const PString & idString
530  );
531 
534  virtual PBoolean SendVisualMessageWaitingIndicator(
535  unsigned line,
536  PBoolean on
537  );
538 
539 
540  enum {
543  };
544 
548  virtual PBoolean PlayDTMF(
549  unsigned line,
550  const char * digits,
551  DWORD onTime = DefaultDTMFOnTime,
552  DWORD offTime = DefaultDTMFOffTime
553  );
554 
564  virtual char ReadDTMF(
565  unsigned line
566  );
567 
572  virtual PBoolean GetRemoveDTMF(
573  unsigned line
574  );
575 
580  virtual PBoolean SetRemoveDTMF(
581  unsigned line,
582  PBoolean removeTones
583  );
584 
585 
587  NoTone = -1, // indicates no tones
588  DialTone, // Dial tone
589  RingTone, // Ring indication tone
590  BusyTone, // Line engaged tone
591  CongestionTone,// aka fast busy tone
592  ClearTone, // Call failed/disconnected tone (often same as busy tone)
593  MwiTone, // Message Waiting Tone
594  RoutingTone, // Call is being routed (not normal for PSTN, but VoIP can take a while)
595  CNGTone, // Fax CNG tone
596  CEDTone, // Fax CED tone
599  };
600 
604  unsigned line
605  );
606 
610  unsigned line,
611  unsigned timeout = 3000
612  );
613 
616  virtual PBoolean WaitForTone(
617  unsigned line,
618  CallProgressTones tone,
619  unsigned timeout = 3000
620  );
621 
644  virtual bool SetToneDescription(
645  unsigned line,
646  CallProgressTones tone,
647  const PString & description
648  );
649 
654  };
655 
659  virtual bool SetToneParameters(
660  unsigned line,
661  CallProgressTones tone,
662  unsigned frequency1,
663  unsigned frequency2,
664  ToneMixingModes mode,
665  PINDEX numCadences,
666  const unsigned * onTimes,
667  const unsigned * offTimes
668  );
669 
672  virtual PBoolean PlayTone(
673  unsigned line,
674  CallProgressTones tone
675  );
676 
679  virtual PBoolean IsTonePlaying(
680  unsigned line
681  );
682 
685  virtual PBoolean StopTone(
686  unsigned line
687  );
688 
689 
691  struct DialParams {
693  : m_requireTones(false)
694  , m_dialToneTimeout(2500)
695  , m_dialStartDelay(500)
698  , m_progressTimeout(5000)
699  , m_commaDelay(2000)
700  { }
701 
703  unsigned m_dialToneTimeout;
704  unsigned m_dialStartDelay;
705  unsigned m_dialDigitTime;
707  unsigned m_progressTimeout;
708  unsigned m_commaDelay;
709  };
710 
726  virtual CallProgressTones DialOut(
727  unsigned line,
728  const PString & number,
729  const DialParams & params = DialParams()
730  );
731 
732 
736  virtual unsigned GetWinkDuration(
737  unsigned line
738  );
739 
743  virtual PBoolean SetWinkDuration(
744  unsigned line,
745  unsigned winkDuration
746  );
747 
748 
783  };
784 
788 
791  PString GetCountryCodeName() const;
792 
795  static PString GetCountryCodeName(T35CountryCodes code);
796 
799  static T35CountryCodes GetCountryCode(const PString & name);
800 
802  {
803  const char * m_isoName;
804  unsigned m_dialCode;
806  const char * m_fullName;
807  const char * m_tone[NumTones];
808  };
809 
812  static const T35CountryInfo & GetCountryInfo(T35CountryCodes code);
813 
814 
820  virtual PBoolean SetCountryCode(
821  T35CountryCodes country
822  );
823 
826  virtual PBoolean SetCountryCodeName(
827  const PString & countryName
828  );
829 
832  virtual PStringList GetCountryCodeNameList() const;
833 
834 
837  virtual PBoolean PlayAudio(
838  unsigned line,
839  const PString & filename
840  );
841 
844  virtual PBoolean StopAudio(
845  unsigned line
846  );
847 
848 
852  virtual PBoolean RecordAudioStart(
853  unsigned line,
854  const PString & filename
855  );
856 
861  virtual PBoolean RecordAudioStop(
862  unsigned line
863  );
864 
865 
868  int GetErrorNumber() const { return osError; }
869 
872  PString GetErrorText() const;
873 
874  virtual void PrintOn(
875  ostream & strm
876  ) const;
877 
881  const PString & type,
882  void * parameters = NULL
883  );
884 
890  const PString & descriptor,
891  void * parameters = NULL
892  );
893 
896  static PStringList GetAllTypes();
897 
902  static PStringList GetAllDevices();
903 
904 
905  protected:
907  mutable int osError;
911  std::vector<bool> m_LineAudioEnabled;
913 #if PTRACING
914  friend ostream & operator<<(ostream & o, CallProgressTones t);
915 #endif
916 };
917 
918 
919 PLIST(OpalLIDList, OpalLineInterfaceDevice);
920 
921 
922 
925 class OpalLine : public PObject
926 {
927  PCLASSINFO(OpalLine, PObject);
928  public:
933  OpalLine(
934  OpalLineInterfaceDevice & device,
935  unsigned lineNumber,
936  const char * userToken = NULL
937  );
939 
946  void PrintOn(
947  ostream & strm
948  ) const;
950 
959  virtual PBoolean IsTerminal() { return device.IsLineTerminal(lineNumber); }
960 
961 
964  virtual PBoolean IsPresent(
965  PBoolean force = false
966  ) { return device.IsLinePresent(lineNumber, force); }
967 
968 
974  virtual PBoolean IsOffHook() { return device.IsLineOffHook(lineNumber); }
975 
981  virtual PBoolean SetOffHook() { return device.SetLineOffHook(lineNumber, true); }
982 
986  virtual PBoolean SetOnHook() { return device.SetLineOffHook(lineNumber, false); }
987 
991  virtual PBoolean HookFlash(
992  unsigned flashTime = 200
993  ) { return device.HookFlash(lineNumber, flashTime); }
994 
997  virtual PBoolean HasHookFlash() { return device.HasHookFlash(lineNumber); }
998 
999 
1010  virtual PBoolean IsRinging(
1011  DWORD * cadence = NULL
1012  );
1013 
1017  virtual unsigned GetRingCount(
1018  DWORD * cadence = NULL
1019  );
1020 
1038  virtual PBoolean Ring(
1039  PINDEX nCadence,
1040  const unsigned * pattern = NULL,
1041  unsigned frequency = 400
1042  ) { return device.RingLine(lineNumber, nCadence, pattern, frequency); }
1043 
1044 
1055  virtual PBoolean SetConnected() { return device.SetLineConnected(lineNumber); }
1056 
1064  virtual PBoolean IsConnected() { return device.IsLineConnected(lineNumber); }
1065 
1066 
1070  virtual PBoolean IsDisconnected() { return device.IsLineDisconnected(lineNumber); }
1071 
1074  virtual PBoolean SetReadFormat(
1075  const OpalMediaFormat & mediaFormat
1076  ) { return device.SetReadFormat(lineNumber, mediaFormat); }
1077 
1080  virtual PBoolean SetWriteFormat(
1081  const OpalMediaFormat & mediaFormat
1082  ) { return device.SetWriteFormat(lineNumber, mediaFormat); }
1083 
1086  virtual OpalMediaFormat GetReadFormat() { return device.GetReadFormat(lineNumber); }
1087 
1090  virtual OpalMediaFormat GetWriteFormat() { return device.GetWriteFormat(lineNumber); }
1091 
1094  virtual PBoolean StopReading() { return device.StopReading(lineNumber); }
1095 
1098  virtual PBoolean StopWriting() { return device.StopWriting(lineNumber); }
1099 
1104  virtual PBoolean SetReadFrameSize(
1105  PINDEX frameSize
1106  ) { return device.SetReadFrameSize(lineNumber, frameSize); }
1107 
1112  virtual PBoolean SetWriteFrameSize(
1113  PINDEX frameSize
1114  ) { return device.SetWriteFrameSize(lineNumber, frameSize); }
1115 
1119  virtual PINDEX GetReadFrameSize() { return device.GetReadFrameSize(lineNumber); }
1120 
1124  virtual PINDEX GetWriteFrameSize() { return device.GetWriteFrameSize(lineNumber); }
1125 
1128  virtual PBoolean ReadFrame(
1129  void * buf,
1130  PINDEX & count
1131  ) { return device.ReadFrame(lineNumber, buf, count); }
1132 
1135  virtual PBoolean WriteFrame(
1136  const void * buf,
1137  PINDEX count,
1138  PINDEX & written
1139  ) { return device.WriteFrame(lineNumber, buf, count, written); }
1140 
1144  virtual PBoolean ReadBlock(
1145  void * buf,
1146  PINDEX count
1147  ) { return device.ReadBlock(lineNumber, buf, count); }
1148 
1151  virtual PBoolean WriteBlock(
1152  const void * buf,
1153  PINDEX count
1154  ) { return device.WriteBlock(lineNumber, buf, count); }
1155 
1156 
1159  virtual unsigned GetAverageSignalLevel(
1160  PBoolean playback
1161  ) { return device.GetAverageSignalLevel(lineNumber, playback); }
1162 
1163 
1166  virtual PBoolean EnableAudio(
1167  PBoolean enable = true
1168  ) { return device.EnableAudio(lineNumber, enable); }
1169 
1172  PBoolean DisableAudio() { return EnableAudio(false); }
1173 
1176  virtual PBoolean IsAudioEnabled() const { return device.IsAudioEnabled(lineNumber); }
1177 
1178 
1183  virtual PBoolean SetRecordVolume(
1184  unsigned volume
1185  ) { return device.SetRecordVolume(lineNumber, volume); }
1186 
1191  virtual PBoolean SetPlayVolume(
1192  unsigned volume
1193  ) { return device.SetPlayVolume(lineNumber, volume); }
1194 
1199  virtual PBoolean GetRecordVolume(
1200  unsigned & volume
1201  ) { return device.GetRecordVolume(lineNumber, volume); }
1202 
1207  virtual PBoolean GetPlayVolume(
1208  unsigned & volume
1209  ) { return device.GetPlayVolume(lineNumber, volume); }
1210 
1211 
1215  virtual OpalLineInterfaceDevice::AECLevels GetAEC() const { return device.GetAEC(lineNumber); }
1216 
1220  virtual PBoolean SetAEC(
1222  ) { return device.SetAEC(lineNumber, level); }
1223 
1224 
1228  virtual PBoolean GetVAD() const { return device.GetVAD(lineNumber); }
1229 
1233  virtual PBoolean SetVAD(
1234  PBoolean enable
1235  ) { return device.SetVAD(lineNumber, enable); }
1236 
1237 
1251  virtual PBoolean GetCallerID(
1252  PString & idString,
1253  PBoolean full = false
1254  ) { return device.GetCallerID(lineNumber, idString, full); }
1255 
1277  virtual PBoolean SetCallerID(
1278  const PString & idString
1279  ) { return device.SetCallerID(lineNumber, idString); }
1280 
1284  PBoolean on
1285  ) { return device.SendVisualMessageWaitingIndicator(lineNumber, on); }
1286 
1287 
1291  virtual PBoolean PlayDTMF(
1292  const char * digits,
1295  ) { return device.PlayDTMF(lineNumber, digits, onTime, offTime); }
1296 
1306  virtual char ReadDTMF() { return device.ReadDTMF(lineNumber); }
1307 
1312  virtual PBoolean GetRemoveDTMF() { return device.GetRemoveDTMF(lineNumber); }
1313 
1318  virtual PBoolean SetRemoveDTMF(
1319  PBoolean removeTones
1320  ) { return device.SetRemoveDTMF(lineNumber, removeTones); }
1321 
1322 
1326 
1330  unsigned timeout = 3000
1331  ) { return device.WaitForToneDetect(lineNumber, timeout); }
1332 
1335  virtual PBoolean WaitForTone(
1337  unsigned timeout = 3000
1338  ) { return device.WaitForTone(lineNumber, tone, timeout); }
1339 
1342  virtual PBoolean PlayTone(
1344  ) { return device.PlayTone(lineNumber, tone); }
1345 
1348  virtual PBoolean IsTonePlaying() { return device.IsTonePlaying(lineNumber); }
1349 
1352  virtual PBoolean StopTone() { return device.StopTone(lineNumber); }
1353 
1354 
1371  const PString & number,
1373  ) { return device.DialOut(lineNumber, number, params); }
1375 
1381 
1384  unsigned GetLineNumber() const { return lineNumber; }
1385 
1388  PString GetToken() const { return token; }
1389 
1392  void SetToken(const PString & t) { token = t; }
1394 
1395  protected:
1397  unsigned lineNumber;
1398  PString token;
1399  PTimeInterval ringStoppedTime;
1400  PTimeInterval ringInterCadenceTime;
1401 
1402  PTimeInterval ringTick;
1403  unsigned ringCount;
1405 };
1406 
1407 
1408 PLIST(OpalLineList, OpalLine);
1409 
1410 
1417 class OpalLIDRegistration : public PCaselessString
1418 {
1419  PCLASSINFO(OpalLIDRegistration, PCaselessString);
1420  public:
1426  const char * name
1427  );
1428 
1433 
1438  virtual OpalLineInterfaceDevice * Create(
1439  void * parameters
1440  ) const = 0;
1442 
1443  protected:
1446 
1448 };
1449 
1450 
1451 #define OPAL_REGISTER_LID_FUNCTION(cls, type, param) \
1452 static class cls##_Registration : public OpalLIDRegistration { \
1453  public: \
1454  cls##_Registration() : OpalLIDRegistration(type) { } \
1455  OpalLineInterfaceDevice * Create(void * param) const; \
1456 } instance_##cls##_Registration; \
1457 OpalLineInterfaceDevice * cls##_Registration::Create(void * param) const
1458 
1459 #ifndef OPAL_NO_PARAM
1460 #define OPAL_NO_PARAM
1461 #endif
1462 
1463 #define OPAL_REGISTER_LID(cls, type) \
1464  OPAL_REGISTER_LID_FUNCTION(cls, type, OPAL_NO_PARAM) \
1465  { return new cls; }
1466 
1467 #define OPAL_REGISTER_LID_PARAM(cls, type) \
1468  OPAL_REGISTER_LID_FUNCTION(cls, type, parameter) \
1469  { return new cls(parameter); }
1470 
1471 #endif // OPAL_LID
1472 
1473 #endif // OPAL_LIDS_LID_H
1474 
1475 
1476 // End of File ///////////////////////////////////////////////////////////////