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: 20385 $
00030  * $Author: rjongbloed $
00031  * $Date: 2008-06-04 10:40:38 +0000 (Wed, 04 Jun 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:
00062     PNatMethod();
00063 
00066     ~PNatMethod();
00068 
00069 
00074     static PNatMethod * Create(
00075       const PString & name,        
00076       PPluginManager * pluginMgr = NULL   
00077     );
00078 
00081     virtual PString GetName() const = 0;
00082 
00086     virtual PString GetServer() const;
00087 
00090     virtual bool GetServerAddress(
00091       PIPSocket::Address & address,   
00092       WORD & port                     
00093     ) const = 0;
00094 
00098     virtual PBoolean GetExternalAddress(
00099       PIPSocket::Address & externalAddress, 
00100       const PTimeInterval & maxAge = 1000   
00101     ) = 0;
00102 
00105     virtual bool GetInterfaceAddress(
00106       PIPSocket::Address & internalAddress
00107     ) const = 0;
00108 
00122     virtual PBoolean CreateSocket(
00123       PUDPSocket * & socket,
00124       const PIPSocket::Address & binding = PIPSocket::GetDefaultIpAny(),
00125       WORD localPort = 0
00126     ) = 0;
00127 
00141     virtual PBoolean CreateSocketPair(
00142       PUDPSocket * & socket1,
00143       PUDPSocket * & socket2,
00144       const PIPSocket::Address & binding = PIPSocket::GetDefaultIpAny()
00145     ) = 0;
00146 
00154     virtual bool IsAvailable(
00155       const PIPSocket::Address & binding = PIPSocket::GetDefaultIpAny()  
00156     ) = 0;
00157 
00158     enum RTPSupportTypes {
00159       RTPSupported,
00160       RTPIfSendMedia,
00161       RTPUnsupported,
00162       RTPUnknown,
00163       NumRTPSupportTypes
00164     };
00165 
00169     virtual RTPSupportTypes GetRTPSupport(
00170       PBoolean force = PFalse    
00171     ) = 0;
00172 
00183     virtual void SetPortRanges(
00184       WORD portBase,          
00185       WORD portMax = 0,       
00186       WORD portPairBase = 0,  
00187       WORD portPairMax = 0    
00188     );
00190 
00191   protected:
00192     struct PortInfo {
00193       PortInfo(WORD port = 0)
00194         : basePort(port)
00195         , maxPort(port)
00196         , currentPort(port)
00197       {
00198       }
00199 
00200       PMutex mutex;
00201       WORD   basePort;
00202       WORD   maxPort;
00203       WORD   currentPort;
00204     } singlePortInfo, pairedPortInfo;
00205 };
00206 
00208 
00209 PLIST(PNatList, PNatMethod);
00210 
00212 
00218 class PNatStrategy : public PObject
00219 {
00220   PCLASSINFO(PNatStrategy,PObject);
00221 
00222 public :
00223 
00228   PNatStrategy();
00229 
00232   ~PNatStrategy();
00234 
00242   void AddMethod(PNatMethod * method);
00243 
00249   PNatMethod * GetMethod();
00250 
00251 
00255   PBoolean RemoveMethod(const PString & meth);
00256 
00267     void SetPortRanges(
00268       WORD portBase,          
00269       WORD portMax = 0,       
00270       WORD portPairBase = 0,  
00271       WORD portPairMax = 0    
00272     );
00273 
00276     PNatList GetNATList() {  return natlist; };
00277 
00278         PNatMethod * LoadNatMethod(const PString & name);
00279 
00280     PStringList GetRegisteredList();
00281 
00283 
00284 private:
00285   PNatList natlist;
00286 };
00287 
00289 //
00290 // declare macros and structures needed for NAT plugins
00291 //
00292 
00293 typedef PFactory<PNatMethod> NatFactory;
00294 
00295 template <class className> class PNatMethodServiceDescriptor : public PDevicePluginServiceDescriptor
00296 {
00297   public:
00298     virtual PObject *    CreateInstance(int /*userData*/) const { return new className; }
00299     virtual PStringArray GetDeviceNames(int /*userData*/) const { return className::GetNatMethodName(); }
00300 };
00301 
00302 #define PCREATE_NAT_PLUGIN(name) \
00303   static PNatMethodServiceDescriptor<PNatMethod_##name> PNatMethod_##name##_descriptor; \
00304   PCREATE_PLUGIN(name, PNatMethod, &PNatMethod_##name##_descriptor)
00305 
00306 #endif

Generated on Mon Sep 15 01:21:35 2008 for PTLib by  doxygen 1.5.1