OPAL  Version 3.12.9
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: 29995 $
27  * $Author: rjongbloed $
28  * $Date: 2013-06-19 16:43:18 +1000 (Wed, 19 Jun 2013) $
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/manager.h>
39 #include <ptclib/cli.h>
40 
41 #if P_CLI
42 
43 class SIPEndPoint;
44 class H323EndPoint;
45 class OpalLineEndPoint;
46 class OpalCapiEndPoint;
47 
48 
54 class OpalManagerConsole : public OpalManager
55 {
56  PCLASSINFO(OpalManagerConsole, OpalManager);
57 
58  public:
59  OpalManagerConsole();
60 
61  virtual PString GetArgumentSpec() const;
62  virtual void Usage(ostream & strm, const PArgList & args);
63 
64  virtual bool Initialise(
65  PArgList & args,
66  bool verbose,
67  const PString & defaultRoute = PString::Empty()
68  );
69  virtual void Run();
70  virtual void EndRun(bool interrupt = false);
71 
72  void OnEstablishedCall(OpalCall & call);
73  void OnHold(OpalConnection & connection, bool fromRemote, bool onHold);
74  PBoolean OnOpenMediaStream(OpalConnection & connection, OpalMediaStream & stream);
75  void OnClosedMediaStream(const OpalMediaStream & stream);
76  virtual void OnClearedCall(OpalCall & call);
77 
78  protected:
79 #if OPAL_SIP
80  SIPEndPoint * CreateSIPEndPoint();
81 #endif
82 #if OPAL_H323
83  H323EndPoint * CreateH323EndPoint();
84 #endif
85 #if OPAL_LID
86  OpalLineEndPoint * CreateLineEndPoint();
87 #endif
88 #if OPAL_CAPI
89  OpalCapiEndPoint * CreateCapiEndPoint();
90 #endif
91 
92  PSyncPoint m_endRun;
93  bool m_interrupted;
94  bool m_verbose;
95 };
96 
97 
104 class OpalManagerCLI : public OpalManagerConsole
105 {
106  PCLASSINFO(OpalManagerCLI, OpalManagerConsole);
107 
108  public:
109  OpalManagerCLI();
110  ~OpalManagerCLI();
111 
112  virtual PString GetArgumentSpec() const;
113  virtual bool Initialise(
114  PArgList & args,
115  bool verbose,
116  const PString & defaultRoute = PString::Empty()
117  );
118  virtual void Run();
119  virtual void EndRun(bool interrupt);
120 
121  protected:
122  PCLI * CreatePCLI(
123 #if P_TELNET
124  WORD port
125 #endif
126  );
127 
128 #if OPAL_SIP
129  PDECLARE_NOTIFIER(PCLI::Arguments, OpalManagerCLI, CmdRegister);
130 #endif
131 
132 #if P_NAT
133  PDECLARE_NOTIFIER(PCLI::Arguments, OpalManagerCLI, CmdNat);
134 #endif
135 
136 #if PTRACING
137  PDECLARE_NOTIFIER(PCLI::Arguments, OpalManagerCLI, CmdTrace);
138 #endif
139 
140  PDECLARE_NOTIFIER(PCLI::Arguments, OpalManagerCLI, CmdListCodecs);
141  PDECLARE_NOTIFIER(PCLI::Arguments, OpalManagerCLI, CmdDelay);
142  PDECLARE_NOTIFIER(PCLI::Arguments, OpalManagerCLI, CmdVersion);
143  PDECLARE_NOTIFIER(PCLI::Arguments, OpalManagerCLI, CmdQuit);
144  PDECLARE_NOTIFIER(PCLI::Arguments, OpalManagerCLI, CmdShutDown);
145 
146  PCLI * m_cli;
147 };
148 
149 
152 template <class Manager,
153  const char Manuf[],
154  const char Name[],
155  WORD MajorVersion = OPAL_MAJOR,
156  WORD MinorVersion = OPAL_MINOR,
157  PProcess::CodeStatus Status = PProcess::ReleaseCode,
158  WORD BuildNumber = OPAL_BUILD,
159  bool Verbose = true>
160 class OpalConsoleProcess : public PProcess
161 {
162  PCLASSINFO(OpalConsoleProcess, PProcess)
163  public:
164  OpalConsoleProcess()
165  : PProcess(Manuf, Name, MajorVersion, MinorVersion, Status, BuildNumber)
166  , m_manager(NULL)
167  {
168  }
169 
170  ~OpalConsoleProcess()
171  {
172  delete this->m_manager;
173  }
174 
175  virtual void Main()
176  {
177  this->SetTerminationValue(1);
178  this->m_manager = new Manager;
179  if (this->m_manager->Initialise(this->GetArguments(), Verbose)) {
180  this->SetTerminationValue(0);
181  this->m_manager->Run();
182  }
183  }
184 
185  virtual bool OnInterrupt(bool)
186  {
187  if (this->m_manager == NULL)
188  return false;
189 
190  this->m_manager->EndRun(true);
191  return true;
192  }
193 
194  private:
195  Manager * m_manager;
196 };
197 
198 
199 #endif // P_CLI
200 
201 #endif // OPAL_OPAL_CONSOLE_MGR_H
202 
203