pnat.h

Go to the documentation of this file.
00001 /*
00002  * pnat.h
00003  *
00004  * NAT Strategy support for Portable Windows Library.
00005  *
00006  * Virteos is a Trade Mark of ISVO (Asia) Pte Ltd.
00007  *
00008  * Copyright (c) 2004 ISVO (Asia) Pte Ltd. All Rights Reserved.
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  *
00021  * The Original Code is derived from and used in conjunction with the 
00022  * OpenH323 Project (www.openh323.org/)
00023  *
00024  * The Initial Developer of the Original Code is ISVO (Asia) Pte Ltd.
00025  *
00026  *
00027  * Contributor(s): ______________________________________.
00028  *
00029  * $Revision: 19931 $
00030  * $Author: rjongbloed $
00031  * $Date: 2008-04-08 06:23:08 +0000 (Tue, 08 Apr 2008) $
00032  */
00033 
00034 #ifndef _PTLIB_H
00035 #include <ptlib.h>
00036 #endif
00037 
00038 #include <ptlib/sockets.h>
00039 
00040 #ifndef P_NATMETHOD
00041 #define P_NATMETHOD
00042 
00043 #include <ptlib/plugin.h>
00044 #include <ptlib/pluginmgr.h>
00045 
00053 class PNatMethod  : public PObject
00054 {
00055   PCLASSINFO(PNatMethod,PObject);
00056 
00057 public:
00058 
00063   PNatMethod();
00064 
00067   ~PNatMethod();
00069 
00070 
00073     static PNatMethod * Create(
00074       const PString & name,        
00075       PPluginManager * pluginMgr = NULL   
00076     );
00077 
00080 
00084    virtual PBoolean GetExternalAddress(
00085       PIPSocket::Address & externalAddress, 
00086       const PTimeInterval & maxAge = 1000   
00087    ) = 0;
00088 
00092    virtual PBoolean CreateSocketPair(
00093       PUDPSocket * & socket1,
00094       PUDPSocket * & socket2,
00095       const PIPSocket::Address & binding = PIPSocket::GetDefaultIpAny()
00096    ) = 0;
00097 
00105    virtual bool IsAvailable(
00106       const PIPSocket::Address & binding = PIPSocket::GetDefaultIpAny()  
00107    ) = 0;
00108 
00119    virtual void SetPortRanges(
00120       WORD portBase,          
00121       WORD portMax = 0,       
00122       WORD portPairBase = 0,  
00123       WORD portPairMax = 0    
00124    );
00125 
00128    static PStringList GetNatMethodName() { return PStringList(); };
00129 
00130    virtual PStringList GetName() const
00131       { return GetNatMethodName(); }
00132 
00134 
00135 protected:
00136   struct PortInfo {
00137       PortInfo(WORD port = 0)
00138         : basePort(port)
00139         , maxPort(port)
00140         , currentPort(port)
00141       {
00142       }
00143 
00144       PMutex mutex;
00145       WORD   basePort;
00146       WORD   maxPort;
00147       WORD   currentPort;
00148     } singlePortInfo, pairedPortInfo;
00149 
00150 };
00151 
00153 
00154 PLIST(PNatList, PNatMethod);
00155 
00157 
00163 class PNatStrategy : public PObject
00164 {
00165   PCLASSINFO(PNatStrategy,PObject);
00166 
00167 public :
00168 
00173   PNatStrategy();
00174 
00177   ~PNatStrategy();
00179 
00187   void AddMethod(PNatMethod * method);
00188 
00194   PNatMethod * GetMethod();
00195 
00196 
00200   PBoolean RemoveMethod(const PString & meth);
00201 
00212     void SetPortRanges(
00213       WORD portBase,          
00214       WORD portMax = 0,       
00215       WORD portPairBase = 0,  
00216       WORD portPairMax = 0    
00217     );
00218 
00221     PNatList GetNATList() {  return natlist; };
00222 
00223         PNatMethod * LoadNatMethod(const PString & name);
00224 
00225     PStringList GetRegisteredList();
00226 
00228 
00229 private:
00230   PNatList natlist;
00231 };
00232 
00234 //
00235 // declare macros and structures needed for NAT plugins
00236 //
00237 
00238 typedef PFactory<PNatMethod> NatFactory;
00239 
00240 template <class className> class PNatMethodServiceDescriptor : public PDevicePluginServiceDescriptor
00241 {
00242   public:
00243     virtual PObject *    CreateInstance(int /*userData*/) const { return new className; }
00244     virtual PStringArray GetDeviceNames(int /*userData*/) const { return className::GetNatMethodName(); }
00245 };
00246 
00247 #define PCREATE_NAT_PLUGIN(name) \
00248   static PNatMethodServiceDescriptor<PNatMethod_##name> PNatMethod_##name##_descriptor; \
00249   PCREATE_PLUGIN(name, PNatMethod, &PNatMethod_##name##_descriptor)
00250 
00251 #endif

Generated on Wed May 7 00:47:56 2008 for PTLib by  doxygen 1.5.1