console_mgr.h

Go to the documentation of this file.
00001 /*
00002  * console_mgs.h
00003  *
00004  * An OpalManager derived class for use in a console application, providing
00005  * a standard set of command line arguments for configuring many system
00006  * parameters. Used by the sample applications such as faxopal, ovropal etc.
00007  *
00008  * Copyright (c) 2010 Vox Lucida Pty. Ltd.
00009  *
00010  * The contents of this file are subject to the Mozilla Public License
00011  * Version 1.0 (the "License"); you may not use this file except in
00012  * compliance with the License. You may obtain a copy of the License at
00013  * http://www.mozilla.org/MPL/
00014  *
00015  * Software distributed under the License is distributed on an "AS IS"
00016  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
00017  * the License for the specific language governing rights and limitations
00018  * under the License.
00019  *
00020  * The Original Code is Open Phone Abstraction Library.
00021  *
00022  * The Initial Developer of the Original Code is Vox Lucida Pty. Ltd.
00023  *
00024  * Contributor(s): ______________________________________.
00025  *
00026  * $Revision: 29995 $
00027  * $Author: rjongbloed $
00028  * $Date: 2013-06-19 01:43:18 -0500 (Wed, 19 Jun 2013) $
00029  */
00030 
00031 #ifndef OPAL_OPAL_CONSOLE_MGR_H
00032 #define OPAL_OPAL_CONSOLE_MGR_H
00033 
00034 #ifdef P_USE_PRAGMA
00035 #pragma interface
00036 #endif
00037 
00038 #include <opal/manager.h>
00039 #include <ptclib/cli.h>
00040 
00041 #if P_CLI
00042 
00043 class SIPEndPoint;
00044 class H323EndPoint;
00045 class OpalLineEndPoint;
00046 class OpalCapiEndPoint;
00047 
00048 
00054 class OpalManagerConsole : public OpalManager
00055 {
00056     PCLASSINFO(OpalManagerConsole, OpalManager);
00057 
00058   public:
00059     OpalManagerConsole();
00060 
00061     virtual PString GetArgumentSpec() const;
00062     virtual void Usage(ostream & strm, const PArgList & args);
00063 
00064     virtual bool Initialise(
00065       PArgList & args,
00066       bool verbose,
00067       const PString & defaultRoute = PString::Empty()
00068     );
00069     virtual void Run();
00070     virtual void EndRun(bool interrupt = false);
00071 
00072     void OnEstablishedCall(OpalCall & call);
00073     void OnHold(OpalConnection & connection, bool fromRemote, bool onHold);
00074     PBoolean OnOpenMediaStream(OpalConnection & connection, OpalMediaStream & stream);
00075     void OnClosedMediaStream(const OpalMediaStream & stream);
00076     virtual void OnClearedCall(OpalCall & call);
00077 
00078   protected:
00079 #if OPAL_SIP
00080     SIPEndPoint * CreateSIPEndPoint();
00081 #endif
00082 #if OPAL_H323
00083     H323EndPoint * CreateH323EndPoint();
00084 #endif
00085 #if OPAL_LID
00086     OpalLineEndPoint * CreateLineEndPoint();
00087 #endif
00088 #if OPAL_CAPI
00089     OpalCapiEndPoint * CreateCapiEndPoint();
00090 #endif
00091 
00092     PSyncPoint m_endRun;
00093     bool       m_interrupted;
00094     bool       m_verbose;
00095 };
00096 
00097 
00104 class OpalManagerCLI : public OpalManagerConsole
00105 {
00106     PCLASSINFO(OpalManagerCLI, OpalManagerConsole);
00107 
00108   public:
00109     OpalManagerCLI();
00110     ~OpalManagerCLI();
00111 
00112     virtual PString GetArgumentSpec() const;
00113     virtual bool Initialise(
00114       PArgList & args,
00115       bool verbose,
00116       const PString & defaultRoute = PString::Empty()
00117     );
00118     virtual void Run();
00119     virtual void EndRun(bool interrupt);
00120 
00121   protected:
00122     PCLI * CreatePCLI(
00123 #if P_TELNET
00124       WORD port 
00125 #endif
00126     );
00127 
00128 #if OPAL_SIP
00129     PDECLARE_NOTIFIER(PCLI::Arguments, OpalManagerCLI, CmdRegister);
00130 #endif
00131 
00132 #if P_NAT
00133     PDECLARE_NOTIFIER(PCLI::Arguments, OpalManagerCLI, CmdNat);
00134 #endif
00135 
00136 #if PTRACING
00137     PDECLARE_NOTIFIER(PCLI::Arguments, OpalManagerCLI, CmdTrace);
00138 #endif
00139 
00140     PDECLARE_NOTIFIER(PCLI::Arguments, OpalManagerCLI, CmdListCodecs);
00141     PDECLARE_NOTIFIER(PCLI::Arguments, OpalManagerCLI, CmdDelay);
00142     PDECLARE_NOTIFIER(PCLI::Arguments, OpalManagerCLI, CmdVersion);
00143     PDECLARE_NOTIFIER(PCLI::Arguments, OpalManagerCLI, CmdQuit);
00144     PDECLARE_NOTIFIER(PCLI::Arguments, OpalManagerCLI, CmdShutDown);
00145 
00146     PCLI * m_cli;
00147 };
00148 
00149 
00152 template <class Manager,                   
00153           const char Manuf[],              
00154           const char Name[],               
00155           WORD MajorVersion = OPAL_MAJOR,  
00156           WORD MinorVersion = OPAL_MINOR,  
00157           PProcess::CodeStatus Status = PProcess::ReleaseCode, 
00158           WORD BuildNumber = OPAL_BUILD,   
00159           bool Verbose = true>
00160 class OpalConsoleProcess : public PProcess
00161 {
00162     PCLASSINFO(OpalConsoleProcess, PProcess)
00163   public:
00164     OpalConsoleProcess()
00165       : PProcess(Manuf, Name, MajorVersion, MinorVersion, Status, BuildNumber)
00166       , m_manager(NULL)
00167     {
00168     }
00169 
00170     ~OpalConsoleProcess()
00171     {
00172       delete this->m_manager;
00173     }
00174 
00175     virtual void Main()
00176     {
00177       this->SetTerminationValue(1);
00178       this->m_manager = new Manager;
00179       if (this->m_manager->Initialise(this->GetArguments(), Verbose)) {
00180         this->SetTerminationValue(0);
00181         this->m_manager->Run();
00182       }
00183     }
00184 
00185     virtual bool OnInterrupt(bool)
00186     {
00187       if (this->m_manager == NULL)
00188         return false;
00189 
00190       this->m_manager->EndRun(true);
00191       return true;
00192     }
00193 
00194   private:
00195     Manager * m_manager;
00196 };
00197 
00198 
00199 #endif // P_CLI
00200 
00201 #endif // OPAL_OPAL_CONSOLE_MGR_H
00202 
00203 

Generated on 21 Jun 2013 for OPAL by  doxygen 1.4.7