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: 21788 $
00030  * $Author: rjongbloed $
00031  * $Date: 2008-12-11 23:42:13 -0600 (Thu, 11 Dec 2008) $
00032  */
00033 
00034 #include <ptlib/sockets.h>
00035 
00036 #ifndef PTLIB_PNAT_H
00037 #define PTLIB_PNAT_H
00038 
00039 #include <ptlib/plugin.h>
00040 #include <ptlib/pluginmgr.h>
00041 
00049 class PNatMethod  : public PObject
00050 {
00051     PCLASSINFO(PNatMethod,PObject);
00052 
00053   public:
00058     PNatMethod();
00059 
00062     ~PNatMethod();
00064 
00065 
00068     virtual void PrintOn(
00069       ostream & strm
00070     ) const;
00072 
00073 
00078     static PNatMethod * Create(
00079       const PString & name,        
00080       PPluginManager * pluginMgr = NULL   
00081     );
00082 
00085     virtual PString GetName() const = 0;
00086 
00090     virtual PString GetServer() const;
00091 
00094     virtual bool GetServerAddress(
00095       PIPSocket::Address & address,   
00096       WORD & port                     
00097     ) const = 0;
00098 
00102     virtual PBoolean GetExternalAddress(
00103       PIPSocket::Address & externalAddress, 
00104       const PTimeInterval & maxAge = 1000   
00105     ) = 0;
00106 
00109     virtual bool GetInterfaceAddress(
00110       PIPSocket::Address & internalAddress
00111     ) const = 0;
00112 
00126     virtual PBoolean CreateSocket(
00127       PUDPSocket * & socket,
00128       const PIPSocket::Address & binding = PIPSocket::GetDefaultIpAny(),
00129       WORD localPort = 0
00130     ) = 0;
00131 
00145     virtual PBoolean CreateSocketPair(
00146       PUDPSocket * & socket1,
00147       PUDPSocket * & socket2,
00148       const PIPSocket::Address & binding = PIPSocket::GetDefaultIpAny()
00149     ) = 0;
00150 
00158     virtual bool IsAvailable(
00159       const PIPSocket::Address & binding = PIPSocket::GetDefaultIpAny()  
00160     ) = 0;
00161 
00162     enum RTPSupportTypes {
00163       RTPSupported,
00164       RTPIfSendMedia,
00165       RTPUnsupported,
00166       RTPUnknown,
00167       NumRTPSupportTypes
00168     };
00169 
00173     virtual RTPSupportTypes GetRTPSupport(
00174       PBoolean force = PFalse    
00175     ) = 0;
00176 
00187     virtual void SetPortRanges(
00188       WORD portBase,          
00189       WORD portMax = 0,       
00190       WORD portPairBase = 0,  
00191       WORD portPairMax = 0    
00192     );
00194 
00195   protected:
00196     struct PortInfo {
00197       PortInfo(WORD port = 0)
00198         : basePort(port)
00199         , maxPort(port)
00200         , currentPort(port)
00201       {
00202       }
00203 
00204       PMutex mutex;
00205       WORD   basePort;
00206       WORD   maxPort;
00207       WORD   currentPort;
00208     } singlePortInfo, pairedPortInfo;
00209 };
00210 
00212 
00213 PLIST(PNatList, PNatMethod);
00214 
00216 
00222 class PNatStrategy : public PObject
00223 {
00224   PCLASSINFO(PNatStrategy,PObject);
00225 
00226 public :
00227 
00232   PNatStrategy();
00233 
00236   ~PNatStrategy();
00238 
00246   void AddMethod(PNatMethod * method);
00247 
00253   PNatMethod * GetMethod();
00254 
00255 
00259   PBoolean RemoveMethod(const PString & meth);
00260 
00271     void SetPortRanges(
00272       WORD portBase,          
00273       WORD portMax = 0,       
00274       WORD portPairBase = 0,  
00275       WORD portPairMax = 0    
00276     );
00277 
00280     PNatList GetNATList() {  return natlist; };
00281 
00282         PNatMethod * LoadNatMethod(const PString & name);
00283 
00284     PStringList GetRegisteredList();
00285 
00287 
00288 private:
00289   PNatList natlist;
00290 };
00291 
00293 //
00294 // declare macros and structures needed for NAT plugins
00295 //
00296 
00297 typedef PFactory<PNatMethod> NatFactory;
00298 
00299 template <class className> class PNatMethodServiceDescriptor : public PDevicePluginServiceDescriptor
00300 {
00301   public:
00302     virtual PObject *    CreateInstance(int /*userData*/) const { return new className; }
00303     virtual PStringArray GetDeviceNames(int /*userData*/) const { return className::GetNatMethodName(); }
00304 };
00305 
00306 #define PCREATE_NAT_PLUGIN(name) \
00307   static PNatMethodServiceDescriptor<PNatMethod_##name> PNatMethod_##name##_descriptor; \
00308   PCREATE_PLUGIN(name, PNatMethod, &PNatMethod_##name##_descriptor)
00309 
00310 
00311 #endif // PTLIB_PNAT_H
00312 
00313 
00314 // End Of File ///////////////////////////////////////////////////////////////

Generated on Thu May 27 01:36:48 2010 for PTLib by  doxygen 1.4.7