OPAL  Version 3.14.3
console_mgr.h
Go to the documentation of this file.
1 /*
2  * console_mgs.h
3  *
4  * An OpalManager derived class for use in a console application, providing
5  * a standard set of command line arguments for configuring many system
6  * parameters. Used by the sample applications such as faxopal, ovropal etc.
7  *
8  * Copyright (c) 2010 Vox Lucida 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 Phone Abstraction Library.
21  *
22  * The Initial Developer of the Original Code is Vox Lucida Pty. Ltd.
23  *
24  * Contributor(s): ______________________________________.
25  *
26  * $Revision: 32541 $
27  * $Author: rjongbloed $
28  * $Date: 2014-08-18 15:10:44 +1000 (Mon, 18 Aug 2014) $
29  */
30 
31 #ifndef OPAL_OPAL_CONSOLE_MGR_H
32 #define OPAL_OPAL_CONSOLE_MGR_H
33 
34 #ifdef P_USE_PRAGMA
35 #pragma interface
36 #endif
37 
38 #include <opal.h>
39 #include <opal/manager.h>
40 #include <sip/sipep.h>
41 #include <h323/h323ep.h>
42 #include <lids/lidep.h>
43 #include <lids/capi_ep.h>
44 #include <ep/pcss.h>
45 #include <ep/ivr.h>
46 #include <ep/opalmixer.h>
47 #include <ep/skinnyep.h>
48 
49 #include <ptclib/cli.h>
50 
51 
52 class OpalConsoleManager;
53 class OpalH281Client;
54 
55 
56 #define OPAL_CONSOLE_PREFIXES OPAL_PREFIX_SIP " " \
57  OPAL_PREFIX_H323 " " \
58  OPAL_PREFIX_SKINNY" " \
59  OPAL_PREFIX_PSTN " " \
60  OPAL_PREFIX_CAPI " "
61 
62 
67 {
68 protected:
70 
71  void AddRoutesFor(const OpalEndPoint * endpoint, const PString & defaultRoute);
72 
73 public:
74  virtual ~OpalConsoleEndPoint() { }
75  virtual void GetArgumentSpec(ostream & strm) const = 0;
76  enum InitResult {
80  };
81  virtual bool Initialise(PArgList & args, bool verbose, const PString & defaultRoute) = 0;
82 #if P_CLI
83  virtual void AddCommands(PCLI & cli) = 0;
84 #endif
85 
86 protected:
88 };
89 
90 
91 #if OPAL_SIP || OPAL_H323
92 class OpalRTPEndPoint;
93 
95 {
96 protected:
98 
99  void GetArgumentSpec(ostream & strm) const;
100  bool Initialise(PArgList & args, ostream & output, bool verbose);
101 
102 #if P_CLI
103  PDECLARE_NOTIFIER(PCLI::Arguments, OpalRTPConsoleEndPoint, CmdInterfaces);
104  PDECLARE_NOTIFIER(PCLI::Arguments, OpalRTPConsoleEndPoint, CmdCryptoSuites);
105  PDECLARE_NOTIFIER(PCLI::Arguments, OpalRTPConsoleEndPoint, CmdBandwidth);
106  PDECLARE_NOTIFIER(PCLI::Arguments, OpalRTPConsoleEndPoint, CmdUserInputMode);
107  PDECLARE_NOTIFIER(PCLI::Arguments, OpalRTPConsoleEndPoint, CmdStringOption);
108  void AddCommands(PCLI & cli);
109 #endif //P_CLI
110 
111  bool SetUIMode(const PCaselessString & str);
112 
113 protected:
115 };
116 #endif // OPAL_SIP || OPAL_H323
117 
118 
119 #if OPAL_SIP
121 {
122  PCLASSINFO(SIPConsoleEndPoint, SIPEndPoint)
123 public:
125 
126  virtual void GetArgumentSpec(ostream & strm) const;
127  virtual bool Initialise(PArgList & args, bool verbose, const PString & defaultRoute);
128 
129 #if P_CLI
130  PDECLARE_NOTIFIER(PCLI::Arguments, SIPConsoleEndPoint, CmdProxy);
131  PDECLARE_NOTIFIER(PCLI::Arguments, SIPConsoleEndPoint, CmdRegister);
132  virtual void AddCommands(PCLI & cli);
133 #endif // P_CLI
134 
135  virtual void OnRegistrationStatus(const RegistrationStatus & status);
136  bool DoRegistration(ostream & output,
137  bool verbose,
138  const PString & aor,
139  const PString & pwd,
140  const PArgList & args,
141  const char * authId,
142  const char * realm,
143  const char * proxy,
144  const char * mode,
145  const char * ttl);
146 };
147 #endif // OPAL_SIP
148 
149 
150 #if OPAL_H323
152 {
153  PCLASSINFO(H323ConsoleEndPoint, H323EndPoint)
154 public:
156  virtual void GetArgumentSpec(ostream & strm) const;
157  virtual bool Initialise(PArgList & args, bool verbose, const PString & defaultRoute);
158 
159 #if P_CLI
160  PDECLARE_NOTIFIER(PCLI::Arguments, H323ConsoleEndPoint, CmdTerminalType);
161  PDECLARE_NOTIFIER(PCLI::Arguments, H323ConsoleEndPoint, CmdAlias);
162  PDECLARE_NOTIFIER(PCLI::Arguments, H323ConsoleEndPoint, CmdGatekeeper);
163  PDECLARE_NOTIFIER(PCLI::Arguments, H323ConsoleEndPoint, CmdCompatibility);
164  virtual void AddCommands(PCLI & cli);
165 #endif // P_CLI
166 
168  bool UseGatekeeperFromArgs(const PArgList & args, const char * host, const char * ident, const char * pass, const char * inter);
169 };
170 #endif // OPAL_H323
171 
172 
173 #if OPAL_SKINNY
174 class OpalConsoleSkinnyEndPoint : public OpalSkinnyEndPoint, public OpalConsoleEndPoint
175 {
176  PCLASSINFO(OpalConsoleSkinnyEndPoint, OpalSkinnyEndPoint)
177 public:
178  OpalConsoleSkinnyEndPoint(OpalConsoleManager & manager);
179 
180  virtual void GetArgumentSpec(ostream & strm) const;
181  virtual bool Initialise(PArgList & args, bool verbose, const PString & defaultRoute);
182 
183 #if P_CLI
184  PDECLARE_NOTIFIER(PCLI::Arguments, OpalConsoleSkinnyEndPoint, CmdRegister);
185  PDECLARE_NOTIFIER(PCLI::Arguments, OpalConsoleSkinnyEndPoint, CmdStatus);
186  virtual void AddCommands(PCLI & cli);
187 #endif // P_CLI
188 };
189 #endif // OPAL_SKINNY
190 
191 
192 #if OPAL_LID
194 {
196 public:
198 
199  virtual void GetArgumentSpec(ostream & strm) const;
200  virtual bool Initialise(PArgList & args, bool verbose, const PString & defaultRoute);
201 
202 #if P_CLI
203  PDECLARE_NOTIFIER(PCLI::Arguments, OpalConsoleLineEndPoint, CmdCountry);
204  virtual void AddCommands(PCLI & cli);
205 #endif // P_CLI
206 };
207 #endif // OPAL_LID
208 
209 
210 #if OPAL_CAPI
211 class OpalConsoleCapiEndPoint : public OpalCapiEndPoint, public OpalConsoleEndPoint
212 {
213  PCLASSINFO(OpalConsoleCapiEndPoint, OpalCapiEndPoint)
214 public:
215  OpalConsoleCapiEndPoint(OpalConsoleManager & manager);
216 
217  virtual void GetArgumentSpec(ostream & strm) const;
218  virtual bool Initialise(PArgList & args, bool verbose, const PString & defaultRoute);
219 
220 #if P_CLI
221  virtual void AddCommands(PCLI & cli);
222 #endif // P_CLI
223 };
224 #endif // OPAL_CAPI
225 
226 
227 #if OPAL_HAS_PCSS
229 {
231 public:
233 
234  virtual void GetArgumentSpec(ostream & strm) const;
235  virtual bool Initialise(PArgList & args, bool verbose, const PString &);
236 
237 #if P_CLI
238  PDECLARE_NOTIFIER(PCLI::Arguments, OpalConsolePCSSEndPoint, CmdRingFileAndDevice);
239  PDECLARE_NOTIFIER(PCLI::Arguments, OpalConsolePCSSEndPoint, CmdRingbackTone);
240  PDECLARE_NOTIFIER(PCLI::Arguments, OpalConsolePCSSEndPoint, CmdVolume);
241  PDECLARE_NOTIFIER(PCLI::Arguments, OpalConsolePCSSEndPoint, CmdDefaultAudioDevice);
242  PDECLARE_NOTIFIER(PCLI::Arguments, OpalConsolePCSSEndPoint, CmdChangeAudioDevice);
243  PDECLARE_NOTIFIER(PCLI::Arguments, OpalConsolePCSSEndPoint, CmdAudioBuffers);
244 #if OPAL_VIDEO
245  PDECLARE_NOTIFIER(PCLI::Arguments, OpalConsolePCSSEndPoint, CmdDefaultVideoDevice);
246  PDECLARE_NOTIFIER(PCLI::Arguments, OpalConsolePCSSEndPoint, CmdChangeVideoDevice);
247  PDECLARE_NOTIFIER(PCLI::Arguments, OpalConsolePCSSEndPoint, CmdOpenVideoStream);
248  PDECLARE_NOTIFIER(PCLI::Arguments, OpalConsolePCSSEndPoint, CmdCloseVideoStream);
249 
250  bool SetPresentationVideoDevice(const PVideoDevice::OpenArgs & args) { return manager.SetVideoInputDevice(args, OpalVideoFormat::ePresentation); }
251  const PVideoDevice::OpenArgs & GetPresentationVideoDevice() const { return manager.GetVideoInputDevice(OpalVideoFormat::ePresentation); }
252  bool SetPresentationPreviewDevice(const PVideoDevice::OpenArgs & args) { return manager.SetVideoPreviewDevice(args, OpalVideoFormat::ePresentation); }
253  const PVideoDevice::OpenArgs & GetPresentationPreviewDevice() const { return manager.GetVideoPreviewDevice(OpalVideoFormat::ePresentation); }
254  bool SetPresentationOutputDevice(const PVideoDevice::OpenArgs & args) { return manager.SetVideoOutputDevice(args, OpalVideoFormat::ePresentation); }
255  const PVideoDevice::OpenArgs & GetPresentationOutputDevice() const { return manager.GetVideoOutputDevice(OpalVideoFormat::ePresentation); }
256  bool SetSpeakerVideoDevice(const PVideoDevice::OpenArgs & args) { return manager.SetVideoInputDevice(args, OpalVideoFormat::eSpeaker); }
257  const PVideoDevice::OpenArgs & GetSpeakerVideoDevice() const { return manager.GetVideoInputDevice(OpalVideoFormat::eSpeaker); }
258  bool SetSpeakerPreviewDevice(const PVideoDevice::OpenArgs & args) { return manager.SetVideoPreviewDevice(args, OpalVideoFormat::eSpeaker); }
259  const PVideoDevice::OpenArgs & GetSpeakerPreviewDevice() const { return manager.GetVideoPreviewDevice(OpalVideoFormat::eSpeaker); }
260  bool SetSpeakerOutputDevice(const PVideoDevice::OpenArgs & args) { return manager.SetVideoOutputDevice(args, OpalVideoFormat::eSpeaker); }
261  const PVideoDevice::OpenArgs & GetSpeakerOutputDevice() const { return manager.GetVideoOutputDevice(OpalVideoFormat::eSpeaker); }
262  bool SetSignVideoDevice(const PVideoDevice::OpenArgs & args) { return manager.SetVideoInputDevice(args, OpalVideoFormat::eSignLanguage); }
263  const PVideoDevice::OpenArgs & GetSignVideoDevice() const { return manager.GetVideoInputDevice(OpalVideoFormat::eSignLanguage); }
264  bool SetSignPreviewDevice(const PVideoDevice::OpenArgs & args) { return manager.SetVideoPreviewDevice(args, OpalVideoFormat::eSignLanguage); }
265  const PVideoDevice::OpenArgs & GetSignPreviewDevice() const { return manager.GetVideoPreviewDevice(OpalVideoFormat::eSignLanguage); }
266  bool SetSignOutputDevice(const PVideoDevice::OpenArgs & args) { return manager.SetVideoOutputDevice(args, OpalVideoFormat::eSignLanguage); }
267  const PVideoDevice::OpenArgs & GetSignOutputDevice() const { return manager.GetVideoOutputDevice(OpalVideoFormat::eSignLanguage); }
268 #endif // OPAL_VIDEO
269 #if OPAL_HAS_H281
270  PDECLARE_NOTIFIER(PCLI::Arguments, OpalConsolePCSSEndPoint, CmdExternalCameraControl);
271  PDECLARE_NOTIFIER(OpalH281Client, OpalConsolePCSSEndPoint, ExternalCameraControlNotification);
272 #endif
273 
274  virtual void AddCommands(PCLI & cli);
275 #endif // P_CLI
276 
277  void SetRingInfo(ostream & out, bool verbose, const PString & filename, const PString & device, const PString & driver);
278 
279  // Various call backs
280  virtual bool OnIncomingCall(OpalLocalConnection & connection);
281  virtual void OnConnected(OpalConnection & connection);
282  virtual void OnReleased(OpalConnection & connection);
283  virtual void ShutDown();
284 
285  protected:
286  PFilePath m_ringFileName;
287  PSoundChannel::Params m_ringChannelParams;
288  PThread * m_ringThread;
289  PSyncPoint m_ringSignal;
291  {
295  } m_ringState;
296  void RingThreadMain();
297 };
298 #endif // OPAL_HAS_PCSS
299 
300 
301 #if OPAL_IVR
303 {
305 public:
307 
308  virtual void GetArgumentSpec(ostream & strm) const;
309  virtual bool Initialise(PArgList & args, bool, const PString &);
310 
311 #if P_CLI
312  virtual void AddCommands(PCLI &);
313 #endif // P_CLI
314 };
315 #endif // OPAL_IVR
316 
317 
318 #if OPAL_HAS_MIXER
320 {
322 public:
324 
325  virtual void GetArgumentSpec(ostream & strm) const;
326  virtual bool Initialise(PArgList & args, bool, const PString &);
327 
328 #if P_CLI
329  virtual void AddCommands(PCLI &);
330 #endif // P_CLI
331 };
332 #endif // OPAL_HAS_MIXER
333 
334 
341 {
342  PCLASSINFO(OpalConsoleManager, OpalManager);
343 
344  public:
346  const char * endpointPrefixes = OPAL_CONSOLE_PREFIXES
347  );
349 
350  virtual PString GetArgumentSpec() const;
351  virtual void Usage(ostream & strm, const PArgList & args);
352 
353  bool PreInitialise(PArgList & args, bool verbose = false);
354 
355  virtual bool Initialise(
356  PArgList & args,
357  bool verbose = false,
358  const PString & defaultRoute = PString::Empty()
359  );
360  virtual void Run();
361  virtual void EndRun(bool interrupt = false);
362  virtual void Broadcast(const PString & msg);
363 
364  virtual bool OnLocalOutgoingCall(const OpalLocalConnection & connection);
365  virtual void OnEstablishedCall(OpalCall & call);
366  virtual void OnHold(OpalConnection & connection, bool fromRemote, bool onHold);
367  virtual bool OnChangedPresentationRole(OpalConnection & connection, const PString & newChairURI, bool request);
368  virtual void OnStartMediaPatch(OpalConnection & connection, OpalMediaPatch & patch);
369  virtual void OnClosedMediaStream(const OpalMediaStream & stream);
370  virtual void OnFailedMediaStream(OpalConnection & connection, bool fromRemote, const PString & reason);
371  virtual void OnUserInputString(OpalConnection & connection, const PString & value);
372  virtual void OnClearedCall(OpalCall & call);
373 
374  class LockedStream : PWaitAndSignal
375  {
376  protected:
377  ostream & m_stream;
378  public:
380  : PWaitAndSignal(mgr.m_outputMutex)
381  , m_stream(*mgr.m_outputStream)
382  {
383  }
384 
385  ostream & operator *() const { return m_stream; }
386  operator ostream & () const { return m_stream; }
387  };
388  friend class LockedStream;
389  __inline LockedStream LockedOutput() const { return *this; }
390 
391 
392  bool GetCallFromArgs(PCLI::Arguments & args, PSafePtr<OpalCall> & call) const;
393 
394  template <class CONTYPE> bool GetConnectionFromArgs(PCLI::Arguments & args, PSafePtr<CONTYPE> & connection) const
395  {
396  PSafePtr<OpalCall> call;
397  if (!GetCallFromArgs(args, call))
398  return false;
399 
400  if ((connection = call->GetConnectionAs<CONTYPE>(0)) != NULL)
401  return true;
402 
403  args.WriteError("Not a suitable call for operation.");
404  return false;
405  }
406 
407  bool GetStreamFromArgs(
408  PCLI::Arguments & args,
409  const OpalMediaType & mediaType,
410  bool source,
411  PSafePtr<OpalMediaStream> & stream
412  ) const;
413 
414  protected:
415  OpalConsoleEndPoint * GetConsoleEndPoint(const PString & prefix);
416 
417 #if OPAL_SIP
419 #endif
420 #if OPAL_H323
422 #endif
423 #if OPAL_SKINNY
424  virtual OpalConsoleSkinnyEndPoint * CreateSkinnyEndPoint();
425 #endif
426 #if OPAL_LID
428 #endif
429 #if OPAL_CAPI
430  virtual OpalConsoleCapiEndPoint * CreateCapiEndPoint();
431 #endif
432 
433 #if OPAL_HAS_PCSS
435 #endif
436 #if OPAL_IVR
438 #endif
439 #if OPAL_HAS_MIXER
441 #endif
442 
443  PStringArray m_endpointPrefixes;
444 
445  PSyncPoint m_endRun;
447  bool m_verbose;
448  ostream * m_outputStream;
450 
451 #if OPAL_STATISTICS
452  PTimeInterval m_statsPeriod;
453  PFilePath m_statsFile;
454  typedef map<PString, OpalMediaStatistics> StatsMap;
456  PMutex m_statsMutex;
457  virtual bool OutputStatistics();
458  virtual bool OutputStatistics(ostream & strm);
459  virtual bool OutputCallStatistics(ostream & strm, OpalCall & call);
460  virtual bool OutputStreamStatistics(ostream & strm, const OpalMediaStream & stream);
461 #endif
462 };
463 
465 
466 #if P_CLI
467 
474 class OpalManagerCLI : public OpalConsoleManager
475 {
476  PCLASSINFO(OpalManagerCLI, OpalConsoleManager);
477 
478  public:
479  OpalManagerCLI(
480  const char * endpointPrefixes = OPAL_CONSOLE_PREFIXES
481  );
482  ~OpalManagerCLI();
483 
484  // Overrides from OpalConsoleManager
485  virtual PString GetArgumentSpec() const;
486  virtual bool Initialise(
487  PArgList & args,
488  bool verbose,
489  const PString & defaultRoute = PString::Empty()
490  );
491  virtual void Run();
492  virtual void EndRun(bool interrupt);
493  virtual void Broadcast(const PString & msg);
494 
495  protected:
496  PCLI * CreateCLIStandard();
497 #if P_TELNET
498  PCLITelnet * CreateCLITelnet(WORD port);
499 #endif
500 #if P_CURSES
501  PCLICurses * CreateCLICurses();
502 #endif
503 
504 #if P_NAT
505  PDECLARE_NOTIFIER(PCLI::Arguments, OpalManagerCLI, CmdNatList);
506  PDECLARE_NOTIFIER(PCLI::Arguments, OpalManagerCLI, CmdNatAddress);
507 #endif
508 
509 #if PTRACING
510  PDECLARE_NOTIFIER(PCLI::Arguments, OpalManagerCLI, CmdTrace);
511 #endif
512 
513 #if OPAL_STATISTICS
514  PDECLARE_NOTIFIER(PCLI::Arguments, OpalManagerCLI, CmdStatistics);
515 #endif
516 
517 #if OPAL_HAS_H281
518  PDECLARE_NOTIFIER(PCLI::Arguments, OpalManagerCLI, CmdFarEndCamera);
519 #endif
520 
521  PDECLARE_NOTIFIER(PCLI::Arguments, OpalManagerCLI, CmdAudioCodec);
522 #if OPAL_VIDEO
523  PDECLARE_NOTIFIER(PCLI::Arguments, OpalManagerCLI, CmdVideoCodec);
524  PDECLARE_NOTIFIER(PCLI::Arguments, OpalManagerCLI, CmdVideoDefault);
525  PDECLARE_NOTIFIER(PCLI::Arguments, OpalManagerCLI, CmdVideoTransmit);
526  PDECLARE_NOTIFIER(PCLI::Arguments, OpalManagerCLI, CmdVideoReceive);
527  PDECLARE_NOTIFIER(PCLI::Arguments, OpalManagerCLI, CmdPresentationToken);
528 #endif // OPAL_VIDEO
529 
530  PDECLARE_NOTIFIER(PCLI::Arguments, OpalManagerCLI, CmdSilenceDetect);
531  PDECLARE_NOTIFIER(PCLI::Arguments, OpalManagerCLI, CmdAutoStart);
532  PDECLARE_NOTIFIER(PCLI::Arguments, OpalManagerCLI, CmdCodecList);
533  PDECLARE_NOTIFIER(PCLI::Arguments, OpalManagerCLI, CmdCodecOrder);
534  PDECLARE_NOTIFIER(PCLI::Arguments, OpalManagerCLI, CmdCodecMask);
535  PDECLARE_NOTIFIER(PCLI::Arguments, OpalManagerCLI, CmdCodecOption);
536  PDECLARE_NOTIFIER(PCLI::Arguments, OpalManagerCLI, CmdShowCalls);
537  PDECLARE_NOTIFIER(PCLI::Arguments, OpalManagerCLI, CmdSendUserInput);
538  PDECLARE_NOTIFIER(PCLI::Arguments, OpalManagerCLI, CmdHangUp);
539  PDECLARE_NOTIFIER(PCLI::Arguments, OpalManagerCLI, CmdDelay);
540  PDECLARE_NOTIFIER(PCLI::Arguments, OpalManagerCLI, CmdVersion);
541  PDECLARE_NOTIFIER(PCLI::Arguments, OpalManagerCLI, CmdQuit);
542  PDECLARE_NOTIFIER(PCLI::Arguments, OpalManagerCLI, CmdShutDown);
543 
544  PCLI * m_cli;
545 };
546 
547 #endif // P_CLI
548 
549 
552 template <class Manager,
553  const char Manuf[],
554  const char Name[],
555  WORD MajorVersion = OPAL_MAJOR,
556  WORD MinorVersion = OPAL_MINOR,
557  PProcess::CodeStatus Status = PProcess::ReleaseCode,
558  WORD BuildNumber = OPAL_BUILD,
559  bool Verbose = true>
560 class OpalConsoleProcess : public PProcess
561 {
562  PCLASSINFO(OpalConsoleProcess, PProcess)
563  public:
565  : PProcess(Manuf, Name, MajorVersion, MinorVersion, Status, BuildNumber)
566  , m_manager(NULL)
567  {
568  }
569 
571  {
572  delete this->m_manager;
573  }
574 
575  virtual void Main()
576  {
577  this->SetTerminationValue(1);
578  this->m_manager = new Manager;
579  if (this->m_manager->Initialise(this->GetArguments(), Verbose)) {
580  this->SetTerminationValue(0);
581  this->m_manager->Run();
582  }
583  }
584 
585  virtual bool OnInterrupt(bool)
586  {
587  if (this->m_manager == NULL)
588  return false;
589 
590  this->m_manager->EndRun(true);
591  return true;
592  }
593 
594  private:
595  Manager * m_manager;
596 };
597 
598 
599 #endif // OPAL_OPAL_CONSOLE_MGR_H
600 
601