OPAL  Version 3.12.9
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: 24178 $
30  * $Author: rjongbloed $
31  * $Date: 2010-04-06 10:10:56 +1000 (Tue, 06 Apr 2010) $
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/buildopts.h>
42 
43 #include <opal/mediafmt.h>
44 
45 
47 
51 class OpalLineInterfaceDevice : public PObject
52 {
53  PCLASSINFO(OpalLineInterfaceDevice, PObject);
54 
55  public:
59 
62  virtual PBoolean Open(
63  const PString & device
64  ) = 0;
65 
68  virtual PBoolean IsOpen() const;
69 
72  virtual PBoolean Close();
73 
77  virtual PString GetDeviceType() const = 0;
78 
83  virtual PString GetDeviceName() const = 0;
84 
87  virtual PStringArray GetAllNames() const = 0;
88 
94  virtual PString GetDescription() const = 0;
95 
98  virtual unsigned GetLineCount() const = 0;
99 
106  virtual PBoolean IsLineTerminal(
107  unsigned line
108  ) = 0;
109 
110 
113  virtual PBoolean IsLinePresent(
114  unsigned line,
115  PBoolean force = false
116  );
117 
118 
124  virtual PBoolean IsLineOffHook(
125  unsigned line
126  ) = 0;
127 
133  virtual PBoolean SetLineOffHook(
134  unsigned line,
135  PBoolean newState = true
136  ) = 0;
137 
141  virtual PBoolean SetLineOnHook(
142  unsigned line
143  ) { return SetLineOffHook(line, false); }
144 
148  virtual PBoolean HookFlash(
149  unsigned line,
150  unsigned flashTime = 200
151  );
152 
155  virtual PBoolean HasHookFlash(unsigned line);
156 
157 
168  virtual PBoolean IsLineRinging(
169  unsigned line,
170  DWORD * cadence = NULL
171  );
172 
190  virtual PBoolean RingLine(
191  unsigned line,
192  PINDEX nCadence,
193  const unsigned * pattern = NULL,
194  unsigned frequency = 400
195  );
196 
197 
208  virtual PBoolean SetLineConnected(
209  unsigned line
210  );
211 
222  virtual PBoolean IsLineConnected(
223  unsigned line
224  );
225 
226 
238  virtual PBoolean IsLineDisconnected(
239  unsigned line,
240  PBoolean checkForWink = true
241  );
242 
243 
246  virtual PBoolean SetLineToLineDirect(
247  unsigned line1,
248  unsigned line2,
249  PBoolean connect
250  );
251 
254  virtual PBoolean IsLineToLineDirect(
255  unsigned line1,
256  unsigned line2
257  );
258 
259 
262  virtual OpalMediaFormatList GetMediaFormats() const = 0;
263 
266  virtual PBoolean SetReadFormat(
267  unsigned line,
268  const OpalMediaFormat & mediaFormat
269  ) = 0;
270 
273  virtual PBoolean SetWriteFormat(
274  unsigned line,
275  const OpalMediaFormat & mediaFormat
276  ) = 0;
277 
281  unsigned line
282  ) = 0;
283 
287  unsigned line
288  ) = 0;
289 
292  virtual PBoolean StopReading(
293  unsigned line
294  );
295 
298  virtual PBoolean StopWriting(
299  unsigned line
300  );
301 
306  virtual bool UsesRTP() const;
307 
312  virtual PBoolean SetReadFrameSize(
313  unsigned line,
314  PINDEX frameSize
315  );
316 
321  virtual PBoolean SetWriteFrameSize(
322  unsigned line,
323  PINDEX frameSize
324  );
325 
329  virtual PINDEX GetReadFrameSize(
330  unsigned line
331  );
332 
336  virtual PINDEX GetWriteFrameSize(
337  unsigned line
338  );
339 
342  virtual PBoolean ReadFrame(
343  unsigned line,
344  void * buf,
345  PINDEX & count
346  ) = 0;
347 
350  virtual PBoolean WriteFrame(
351  unsigned line,
352  const void * buf,
353  PINDEX count,
354  PINDEX & written
355  ) = 0;
356 
360  virtual PBoolean ReadBlock(
361  unsigned line,
362  void * buf,
363  PINDEX count
364  );
365 
368  virtual PBoolean WriteBlock(
369  unsigned line,
370  const void * buf,
371  PINDEX count
372  );
373 
374 
377  virtual unsigned GetAverageSignalLevel(
378  unsigned line,
379  PBoolean playback
380  );
381 
382 
385  virtual PBoolean EnableAudio(
386  unsigned line,
387  PBoolean enable = true
388  );
389 
392  PBoolean DisableAudio(
393  unsigned line
394  ) { return EnableAudio(line, false); }
395 
398  virtual PBoolean IsAudioEnabled(
399  unsigned line
400  ) const;
401 
402 
403  enum {
404  MaxVolume = 100
405  };
406 
411  virtual PBoolean SetRecordVolume(
412  unsigned line,
413  unsigned volume
414  );
415 
420  virtual PBoolean SetPlayVolume(
421  unsigned line,
422  unsigned volume
423  );
424 
429  virtual PBoolean GetRecordVolume(
430  unsigned line,
431  unsigned & volume
432  );
433 
438  virtual PBoolean GetPlayVolume(
439  unsigned line,
440  unsigned & volume
441  );
442 
443 
444  enum AECLevels {
452  };
453 
457  virtual AECLevels GetAEC(
458  unsigned line
459  ) const;
460 
464  virtual PBoolean SetAEC(
465  unsigned line,
466  AECLevels level
467  );
468 
472  virtual PBoolean GetVAD(
473  unsigned line
474  ) const;
475 
479  virtual PBoolean SetVAD(
480  unsigned line,
481  PBoolean enable
482  );
483 
484 
498  virtual PBoolean GetCallerID(
499  unsigned line,
500  PString & idString,
501  PBoolean full = false
502  );
503 
525  virtual PBoolean SetCallerID(
526  unsigned line,
527  const PString & idString
528  );
529 
532  virtual PBoolean SendVisualMessageWaitingIndicator(
533  unsigned line,
534  PBoolean on
535  );
536 
537 
538  enum {
541  };
542 
546  virtual PBoolean PlayDTMF(
547  unsigned line,
548  const char * digits,
549  DWORD onTime = DefaultDTMFOnTime,
550  DWORD offTime = DefaultDTMFOffTime
551  );
552 
562  virtual char ReadDTMF(
563  unsigned line
564  );
565 
570  virtual PBoolean GetRemoveDTMF(
571  unsigned line
572  );
573 
578  virtual PBoolean SetRemoveDTMF(
579  unsigned line,
580  PBoolean removeTones
581  );
582 
583 
585  NoTone = -1, // indicates no tones
586  DialTone, // Dial tone
587  RingTone, // Ring indication tone
588  BusyTone, // Line engaged tone
589  CongestionTone,// aka fast busy tone
590  ClearTone, // Call failed/disconnected tone (often same as busy tone)
591  MwiTone, // Message Waiting Tone
592  RoutingTone, // Call is being routed (not normal for PSTN, but VoIP can take a while)
593  CNGTone, // Fax CNG tone
594  CEDTone, // Fax CED tone
597  };
598 
602  unsigned line
603  );
604 
608  unsigned line,
609  unsigned timeout = 3000
610  );
611 
614  virtual PBoolean WaitForTone(
615  unsigned line,
616  CallProgressTones tone,
617  unsigned timeout = 3000
618  );
619 
642  virtual bool SetToneDescription(
643  unsigned line,
644  CallProgressTones tone,
645  const PString & description
646  );
647 
652  };
653 
657  virtual bool SetToneParameters(
658  unsigned line,
659  CallProgressTones tone,
660  unsigned frequency1,
661  unsigned frequency2,
662  ToneMixingModes mode,
663  PINDEX numCadences,
664  const unsigned * onTimes,
665  const unsigned * offTimes
666  );
667 
670  virtual PBoolean PlayTone(
671  unsigned line,
672  CallProgressTones tone
673  );
674 
677  virtual PBoolean IsTonePlaying(
678  unsigned line
679  );
680 
683  virtual PBoolean StopTone(
684  unsigned line
685  );
686 
687 
689  struct DialParams {
691  : m_requireTones(false)
692  , m_dialToneTimeout(2500)
693  , m_dialStartDelay(500)
696  , m_progressTimeout(5000)
697  , m_commaDelay(2000)
698  { }
699 
701  unsigned m_dialToneTimeout;
702  unsigned m_dialStartDelay;
703  unsigned m_dialDigitTime;
705  unsigned m_progressTimeout;
706  unsigned m_commaDelay;
707  };
708 
724  virtual CallProgressTones DialOut(
725  unsigned line,
726  const PString & number,
727  const DialParams & params = DialParams()
728  );
729 
730 
734  virtual unsigned GetWinkDuration(
735  unsigned line
736  );
737 
741  virtual PBoolean SetWinkDuration(
742  unsigned line,
743  unsigned winkDuration
744  );
745 
746 
781  };
782 
786 
789  PString GetCountryCodeName() const;
790 
793  static PString GetCountryCodeName(T35CountryCodes code);
794  static T35CountryCodes GetCountryCode(const PString & name);
795 
801  virtual PBoolean SetCountryCode(
802  T35CountryCodes country
803  );
804 
807  virtual PBoolean SetCountryCodeName(
808  const PString & countryName
809  );
810 
813  virtual PStringList GetCountryCodeNameList() const;
814 
815 
818  virtual PBoolean PlayAudio(
819  unsigned line,
820  const PString & filename
821  );
822 
825  virtual PBoolean StopAudio(
826  unsigned line
827  );
828 
829 
833  virtual PBoolean RecordAudioStart(
834  unsigned line,
835  const PString & filename
836  );
837 
842  virtual PBoolean RecordAudioStop(
843  unsigned line
844  );
845 
846 
849  int GetErrorNumber() const { return osError; }
850 
853  PString GetErrorText() const;
854 
855  virtual void PrintOn(
856  ostream & strm
857  ) const;
858 
862  const PString & type,
863  void * parameters = NULL
864  );
865 
871  const PString & descriptor,
872  void * parameters = NULL
873  );
874 
877  static PStringList GetAllTypes();
878 
883  static PStringList GetAllDevices();
884 
885 
886  protected:
888  mutable int osError;
892  std::vector<bool> m_LineAudioEnabled;
894 #if PTRACING
895  friend ostream & operator<<(ostream & o, CallProgressTones t);
896 #endif
897 };
898 
899 
900 PLIST(OpalLIDList, OpalLineInterfaceDevice);
901 
902 
903 
906 class OpalLine : public PObject
907 {
908  PCLASSINFO(OpalLine, PObject);
909  public:
914  OpalLine(
915  OpalLineInterfaceDevice & device,
916  unsigned lineNumber,
917  const char * userToken = NULL
918  );
920 
927  void PrintOn(
928  ostream & strm
929  ) const;
931 
940  virtual PBoolean IsTerminal() { return device.IsLineTerminal(lineNumber); }
941 
942 
945  virtual PBoolean IsPresent(
946  PBoolean force = false
947  ) { return device.IsLinePresent(lineNumber, force); }
948 
949 
955  virtual PBoolean IsOffHook() { return device.IsLineOffHook(lineNumber); }
956 
962  virtual PBoolean SetOffHook() { return device.SetLineOffHook(lineNumber, true); }
963 
967  virtual PBoolean SetOnHook() { return device.SetLineOffHook(lineNumber, false); }
968 
972  virtual PBoolean HookFlash(
973  unsigned flashTime = 200
974  ) { return device.HookFlash(lineNumber, flashTime); }
975 
978  virtual PBoolean HasHookFlash() { return device.HasHookFlash(lineNumber); }
979 
980 
991  virtual PBoolean IsRinging(
992  DWORD * cadence = NULL
993  );
994 
998  virtual unsigned GetRingCount(
999  DWORD * cadence = NULL
1000  );
1001 
1019  virtual PBoolean Ring(
1020  PINDEX nCadence,
1021  const unsigned * pattern = NULL,
1022  unsigned frequency = 400
1023  ) { return device.RingLine(lineNumber, nCadence, pattern, frequency); }
1024 
1025 
1036  virtual PBoolean SetConnected() { return device.SetLineConnected(lineNumber); }
1037 
1045  virtual PBoolean IsConnected() { return device.IsLineConnected(lineNumber); }
1046 
1047 
1051  virtual PBoolean IsDisconnected() { return device.IsLineDisconnected(lineNumber); }
1052 
1055  virtual PBoolean SetReadFormat(
1056  const OpalMediaFormat & mediaFormat
1057  ) { return device.SetReadFormat(lineNumber, mediaFormat); }
1058 
1061  virtual PBoolean SetWriteFormat(
1062  const OpalMediaFormat & mediaFormat
1063  ) { return device.SetWriteFormat(lineNumber, mediaFormat); }
1064 
1067  virtual OpalMediaFormat GetReadFormat() { return device.GetReadFormat(lineNumber); }
1068 
1071  virtual OpalMediaFormat GetWriteFormat() { return device.GetWriteFormat(lineNumber); }
1072 
1075  virtual PBoolean StopReading() { return device.StopReading(lineNumber); }
1076 
1079  virtual PBoolean StopWriting() { return device.StopWriting(lineNumber); }
1080 
1085  virtual PBoolean SetReadFrameSize(
1086  PINDEX frameSize
1087  ) { return device.SetReadFrameSize(lineNumber, frameSize); }
1088 
1093  virtual PBoolean SetWriteFrameSize(
1094  PINDEX frameSize
1095  ) { return device.SetWriteFrameSize(lineNumber, frameSize); }
1096 
1100  virtual PINDEX GetReadFrameSize() { return device.GetReadFrameSize(lineNumber); }
1101 
1105  virtual PINDEX GetWriteFrameSize() { return device.GetWriteFrameSize(lineNumber); }
1106 
1109  virtual PBoolean ReadFrame(
1110  void * buf,
1111  PINDEX & count
1112  ) { return device.ReadFrame(lineNumber, buf, count); }
1113 
1116  virtual PBoolean WriteFrame(
1117  const void * buf,
1118  PINDEX count,
1119  PINDEX & written
1120  ) { return device.WriteFrame(lineNumber, buf, count, written); }
1121 
1125  virtual PBoolean ReadBlock(
1126  void * buf,
1127  PINDEX count
1128  ) { return device.ReadBlock(lineNumber, buf, count); }
1129 
1132  virtual PBoolean WriteBlock(
1133  const void * buf,
1134  PINDEX count
1135  ) { return device.WriteBlock(lineNumber, buf, count); }
1136 
1137 
1140  virtual unsigned GetAverageSignalLevel(
1141  PBoolean playback
1142  ) { return device.GetAverageSignalLevel(lineNumber, playback); }
1143 
1144 
1147  virtual PBoolean EnableAudio(
1148  PBoolean enable = true
1149  ) { return device.EnableAudio(lineNumber, enable); }
1150 
1153  PBoolean DisableAudio() { return EnableAudio(false); }
1154 
1157  virtual PBoolean IsAudioEnabled() const { return device.IsAudioEnabled(lineNumber); }
1158 
1159 
1164  virtual PBoolean SetRecordVolume(
1165  unsigned volume
1166  ) { return device.SetRecordVolume(lineNumber, volume); }
1167 
1172  virtual PBoolean SetPlayVolume(
1173  unsigned volume
1174  ) { return device.SetPlayVolume(lineNumber, volume); }
1175 
1180  virtual PBoolean GetRecordVolume(
1181  unsigned & volume
1182  ) { return device.GetRecordVolume(lineNumber, volume); }
1183 
1188  virtual PBoolean GetPlayVolume(
1189  unsigned & volume
1190  ) { return device.GetPlayVolume(lineNumber, volume); }
1191 
1192 
1196  virtual OpalLineInterfaceDevice::AECLevels GetAEC() const { return device.GetAEC(lineNumber); }
1197 
1201  virtual PBoolean SetAEC(
1203  ) { return device.SetAEC(lineNumber, level); }
1204 
1205 
1209  virtual PBoolean GetVAD() const { return device.GetVAD(lineNumber); }
1210 
1214  virtual PBoolean SetVAD(
1215  PBoolean enable
1216  ) { return device.SetVAD(lineNumber, enable); }
1217 
1218 
1232  virtual PBoolean GetCallerID(
1233  PString & idString,
1234  PBoolean full = false
1235  ) { return device.GetCallerID(lineNumber, idString, full); }
1236 
1258  virtual PBoolean SetCallerID(
1259  const PString & idString
1260  ) { return device.SetCallerID(lineNumber, idString); }
1261 
1265  PBoolean on
1266  ) { return device.SendVisualMessageWaitingIndicator(lineNumber, on); }
1267 
1268 
1272  virtual PBoolean PlayDTMF(
1273  const char * digits,
1276  ) { return device.PlayDTMF(lineNumber, digits, onTime, offTime); }
1277 
1287  virtual char ReadDTMF() { return device.ReadDTMF(lineNumber); }
1288 
1293  virtual PBoolean GetRemoveDTMF() { return device.GetRemoveDTMF(lineNumber); }
1294 
1299  virtual PBoolean SetRemoveDTMF(
1300  PBoolean removeTones
1301  ) { return device.SetRemoveDTMF(lineNumber, removeTones); }
1302 
1303 
1307 
1311  unsigned timeout = 3000
1312  ) { return device.WaitForToneDetect(lineNumber, timeout); }
1313 
1316  virtual PBoolean WaitForTone(
1318  unsigned timeout = 3000
1319  ) { return device.WaitForTone(lineNumber, tone, timeout); }
1320 
1323  virtual PBoolean PlayTone(
1325  ) { return device.PlayTone(lineNumber, tone); }
1326 
1329  virtual PBoolean IsTonePlaying() { return device.IsTonePlaying(lineNumber); }
1330 
1333  virtual PBoolean StopTone() { return device.StopTone(lineNumber); }
1334 
1335 
1352  const PString & number,
1354  ) { return device.DialOut(lineNumber, number, params); }
1356 
1362 
1365  unsigned GetLineNumber() const { return lineNumber; }
1366 
1369  PString GetToken() const { return token; }
1370 
1373  void SetToken(const PString & t) { token = t; }
1375 
1376  protected:
1378  unsigned lineNumber;
1379  PString token;
1380  PTimeInterval ringStoppedTime;
1381  PTimeInterval ringInterCadenceTime;
1382 
1383  PTimeInterval ringTick;
1384  unsigned ringCount;
1386 };
1387 
1388 
1389 PLIST(OpalLineList, OpalLine);
1390 
1391 
1398 class OpalLIDRegistration : public PCaselessString
1399 {
1400  PCLASSINFO(OpalLIDRegistration, PCaselessString);
1401  public:
1407  const char * name
1408  );
1409 
1414 
1419  virtual OpalLineInterfaceDevice * Create(
1420  void * parameters
1421  ) const = 0;
1423 
1424  protected:
1427 
1429 };
1430 
1431 
1432 #define OPAL_REGISTER_LID_FUNCTION(cls, type, param) \
1433 static class cls##_Registration : public OpalLIDRegistration { \
1434  public: \
1435  cls##_Registration() : OpalLIDRegistration(type) { } \
1436  OpalLineInterfaceDevice * Create(void * param) const; \
1437 } instance_##cls##_Registration; \
1438 OpalLineInterfaceDevice * cls##_Registration::Create(void * param) const
1439 
1440 #ifndef OPAL_NO_PARAM
1441 #define OPAL_NO_PARAM
1442 #endif
1443 
1444 #define OPAL_REGISTER_LID(cls, type) \
1445  OPAL_REGISTER_LID_FUNCTION(cls, type, OPAL_NO_PARAM) \
1446  { return new cls; }
1447 
1448 #define OPAL_REGISTER_LID_PARAM(cls, type) \
1449  OPAL_REGISTER_LID_FUNCTION(cls, type, parameter) \
1450  { return new cls(parameter); }
1451 
1452 
1453 #endif // OPAL_LIDS_LID_H
1454 
1455 
1456 // End of File ///////////////////////////////////////////////////////////////