VR-Link API Documentation for HLA 1516
vlInetSocketMgr.h
Go to the documentation of this file.
00001 /********************************************************************
00002 ** Copyright (c) 1992-2010 VT MAK
00003 ** All rights reserved.
00004 *********************************************************************/
00008 #pragma once
00009 
00010 #include <vlutil/vlInet.h>
00011 #include <vlutil/vlInetSocket.h>
00012 #include <vlutil/vlInetEndpoint.h>
00013 #include <list>
00014 #include <vector>
00015 #include <map>
00016 
00017 #ifdef DtUSE_UTILITIES_NAMESPACE
00018 namespace DtUSE_UTILITIES_NAMESPACE
00019 {
00020 #endif
00021 
00022 class DtInetTcpSocket;
00023 class DtInetUdpSocket;
00024 
00025 typedef std::multimap<DtInetEndpoint, DtInetSocket*> DtInetSocketList;
00026 typedef std::vector<DtInetEndpoint*>                 DtInetDestList;
00027 
00028 // Forward declaration to facilitate declaration of socket creation callback
00029 // prototype
00030 class DtInetSocketMgr;
00031 
00033 typedef DtInetSocket* (*DtSocketCreationCallback)(void* creator, DtInetSocketMgr * mgr);
00034 
00035 typedef bool (*DtInetSocketAdditionCallback)(DtInetSocket* sock, void* usr);
00036 typedef DtInetSocketAdditionCallback DtInetSocketRemovalCallback;
00037 class DtInetSocketCbInfo
00038 {
00039 public:
00040 
00041    DtInetSocketCbInfo(DtInetSocketAdditionCallback cb, void* usr, int order)
00042    {
00043       myCb = cb;
00044       myUsr = usr;
00045       myCallOrder = order;
00046    }
00047 
00048    DtInetSocketAdditionCallback myCb;
00049    void* myUsr;
00050    int   myCallOrder;
00051 };
00052 
00053 class DT_DLL_VLUTIL DtInetSocketMgr
00054 {
00055 public:
00059    DtInetSocketMgr( DtU32 connectionFlags = DtDefaultSockOpts );
00060 
00085    DtInetSocketMgr( DtInetEndpoint& serverEndpoint,
00086       DtInetDevice* hostIf = NULL,
00087       DtU32 serverFlags = (DtDefaultSockOpts | DtSockOptNonBlocking), 
00088       DtU32 connectionFlags = DtDefaultSockOpts,
00089       DtInetUtils::DtInetAddrFamily family = DtInetUtils::DtInetAddrFamily_IPv4);
00090 
00092    virtual ~DtInetSocketMgr();
00093 
00100    virtual int processConnections();
00101 
00112    virtual DtInetSocket* addConnection( const DtInetEndpoint& peerEp,
00113                                         DtU16 localPort = 0,
00114                                         DtInetDevice* hostIf = NULL,
00115                                         bool openImmediately = true,
00116                                         bool connectUdpSocket = false );
00117 
00122    virtual DtInetSocket* addConnection( const DtInetSocket* socket );
00124 
00134    virtual bool removeConnection( const DtInetEndpoint& peerEndpoint );
00135    virtual bool removeConnection( const DtInetSocket* socket );
00137 
00140    virtual DtInetSocket* serverSocket() const;
00141 
00146    virtual const DtInetSocketList& socketList() const;
00147 
00157    virtual DtInetSocket* peerSocket( const DtInetEndpoint& peer ) const;
00158    
00167    virtual int sendTo( caddr_t buff, int buffSize, DtInetDestList& dest, 
00168                        DtU32 flags = 0 );
00169    virtual int sendTo( DtInetBufferChain packets, DtInetDestList& dest, 
00170                        DtU32 flags = 0 );
00172 
00189    virtual DtInetSockRcvStatus recvFrom( caddr_t buff, size_t buffSize,
00190                                          DtInetEndpoint& peer,
00191                                          DtU32 flags = 0 );
00192    virtual DtInetSockRcvStatus recvToChainFrom( DtInetBufferChain& packets,
00193                                                 DtInetEndpoint& peer,
00194                                                 DtU32 flags = 0 );
00196 
00205    virtual void addSocketAdditionCallback( DtInetSocketAdditionCallback cb,
00206                                            void* usr, int order );
00207    virtual void removeSocketAdditionCallback( DtInetSocketAdditionCallback cb, 
00208                                               void* usr );
00210    
00219    virtual void addSocketRemovalCallback( DtInetSocketRemovalCallback cb, 
00220                                           void* usr, int order );
00221    virtual void removeSocketRemovalCallback( DtInetSocketRemovalCallback cb, 
00222                                              void* usr);
00224 
00227    virtual DtU32 getServerFlags() const;
00228    virtual DtU32 getConnectionFlags() const;
00230 
00233    virtual int      getLastError();
00234    virtual DtString getLastErrorString();
00235    virtual void     clearError();
00237 
00242    virtual void addSocketCreationCallback( DtSocketCreationCallback cb, 
00243                                            void* socketCreator );
00244 
00245 protected:
00247    DtInetSocketMgr(const DtInetSocketMgr&);
00248 
00250    DtInetSocketMgr& operator=(const DtInetSocketMgr &);
00251 
00252    virtual int processNewTcpConnections();
00253    virtual int processNewUdpConnections();
00254 
00255    virtual DtInetSocket* removeByKey( const DtInetEndpoint& key, 
00256                                       DtInetSocketList& list );
00257    virtual bool removeByItem( const DtInetSocket* item, 
00258                               DtInetSocketList& list );
00259 
00260 protected:
00261    DtInetSocket*    myServerSocket;
00262    DtInetTcpSocket* myTcpServerSocket;
00263    DtInetUdpSocket* myUdpServerSocket;
00264    DtInetSocketList mySockets;
00265 
00266    std::pair<DtInetEndpoint, DtInetSocket*> myLastSocketReadFrom;
00267 
00268    std::map<int, DtInetSocketCbInfo*> myAdditionCallbacks;
00269    std::map<int, DtInetSocketCbInfo*> myRemovalCallbacks;
00270 
00271    DtSocketCreationCallback mySocketCreateCallback;
00272    void * mySocketCreator;
00273 
00274    DtU32 myServerFlags;
00275    DtU32 myConnectionFlags;
00276 
00277    int      myErrorCode;
00278    DtString myErrorString;
00279 
00281    DtInetTcpSocket* myPeerSocket;
00282 };
00283 
00284 #ifdef DtUSE_UTILITIES_NAMESPACE
00285 } 
00286 #endif
00287 
00288 

Document ID: Generated on Mon May 14 08:06:18 EDT 2012 from SVN revision 114750
Copyright © 2005-2012 VT MÄK Inc. All Rights Reserved (www.mak.com)