MAK RTIspy API Documentation for HLA Evolved
rtiMessageForwarder.h
Go to the documentation of this file.
00001 /*********************************************************************
00002 ** Copyright (c) 1992, 1997 MaK Technologies, Inc.
00003 ** All rights reserved.
00004 *********************************************************************/
00005 /*********************************************************************
00006 ** $RCSfile: rtiMessageForwarder.h,v $ $Revision: 1.19 $ $State: Exp $
00007 *********************************************************************/
00008 #ifndef DtRtiMsgForwarder_H_
00009 #define DtRtiMsgForwarder_H_
00010 
00014 
00015 #include "rtiMsConfig.h"
00016 #include "RIDparams.h"
00017 #include "multicastDiscoveryMgr.h"
00018 #include "rtiVersion.h"
00019 #include <vlutil/vlRunnable.h>
00020 #include <vlutil/vlThreadSafe.h>
00021 //#include "execThreadEvents.h"
00022 
00023 #include <vlutil/vlSelectParamW.h>
00024 #include <vlutil/vlSmartPointers.h>
00025 #include <vlutil/vlInetAddr.h>
00026 
00027 #include <utility>
00028 #include <deque>
00029 
00032 class DtRtiMsg;
00033 class DtRtiMsgForwarder;
00034 class DtFilteredTcpForwarder;
00035 class DtMessageFilter;
00036 class DtRtiExecTrackingFilter;
00037 class DtRoutePrinterFilter;
00038 class DtUpdateInterRoutingFilter;
00039 class DtFedexMsgFilter;
00040 class DtMulitcastDiscoveryMgr;
00041 class DtMsgFwdrFunctor;
00042 class DtRtiMsgForwarder;
00043 class DtConnectConfirmFilter;
00044 class DtDeleteSocketFilter;
00045 class DtTcpMsgSocket;
00046 class DtTcpMsgSocketMgr;
00047 
00049 typedef DtRtiMsgForwarder* (*DtRtiMsgFwderCreator)( unsigned long, const DtRIDParameters& params );
00050 
00056 class DT_DLL_FORWARDER DtRtiMsgForwarder : public DtRunnable
00057 {
00058 protected:
00060    DtRtiMsgForwarder( unsigned long id, const DtRIDParameters& params );
00061 
00062 public:
00063    
00064    struct DT_DLL_FORWARDER ConnectionInfo
00065    {
00066       ConnectionInfo( unsigned long connId, DtTcpMsgSocket* socket,
00067          const MAKRti::DtInetAddr& ipAddr, int port, 
00068          unsigned long federateHandle = 0,
00069          const MAKRti::DtString& federateName = "",
00070          const MAKRti::DtString& federateType = "",
00071          const MAKRti::DtString& fedexName = "",
00072          DtHlaVersionId hlaVersion = DtHla13,
00073          const MAKRti::DtInetAddr& webServerAddr = MAKRti::DtInetAddr(), 
00074          int webServerPort = 0 );
00075 
00077       bool operator==( const ConnectionInfo& rhs );
00078       bool operator<( const ConnectionInfo& rhs );
00079 
00081       void setFederateInfo( unsigned long fedexHandle, unsigned long handle,
00082          const MAKRti::DtString& name, const MAKRti::DtString& type,
00083          const MAKRti::DtString& fedexName, DtHlaVersionId hlaVersion );
00084       void setConnectionId( unsigned long connId );
00085 
00087       void setWebServerAddr( const MAKRti::DtInetAddr& ip );
00088       void setWebServerPort( int port );
00089 
00090       unsigned long myConnId;
00091       unsigned long myFederationHandle;
00092       unsigned long myHandle;
00093       unsigned long myProcessID;
00094       MAKRti::DtInetAddr myIp;
00095       int                myPort;
00096       MAKRti::DtString   myName;
00097       MAKRti::DtString   myType;
00098       MAKRti::DtString   myFederationName;
00099       MAKRti::DtString   myProcessName;
00100       MAKRti::DtString   myCommandArgs;
00101       MAKRti::DtInetAddr myWebServerAddr;
00102       int                myWebServerPort;
00103       DtHlaVersionId     myHlaVersion;
00104       const DtTcpMsgSocket*  mySocket;
00105       
00106 
00108       DtBitMask myFedIdMask;
00109    };
00110 
00111    typedef DtBoost::shared_ptr<ConnectionInfo> ConnectionInfoSP;
00112    typedef DtBoost::weak_ptr<ConnectionInfo>   ConnectionInfoWP;
00113    typedef std::map< const DtTcpMsgSocket*, ConnectionInfoSP >  SocketToConnInfoMap;
00114    
00115 
00116 public:
00117 
00119    virtual ~DtRtiMsgForwarder();
00120 
00122    virtual void init();
00123 
00125    virtual bool hasExec() const;
00126 
00130    virtual void run();
00131 
00133 
00135    virtual void setEnableBundling( unsigned int maxBundleSize );
00136 
00138    virtual void setUseSmartForwarding( bool yesNo );
00139 
00141    virtual void setRouteFedexMessages( bool yesNo );
00142 
00143 
00146    virtual void addPacketFilter( DtMessageFilter* filter );
00147    virtual void removePacketFilter( DtMessageFilter* filter );
00148 
00150    virtual inline unsigned long forwarderId() const;
00151 
00153    virtual void setForwarderId(unsigned long newId);
00154 
00156    void updateTcpForwarderQueuedSockets();
00157 
00158 public:
00159 
00162 
00164    virtual inline const DtRtiMsgForwarder::SocketToConnInfoMap& getConnToConnInfoMap() const;
00165 
00167    virtual ConnectionInfoSP getConnectionInfoByConnId( unsigned long connId ) const;
00168 
00170    virtual ConnectionInfoSP getConnectionInfoByHandle( unsigned long federateHandle ) const;
00171 
00173    virtual ConnectionInfoSP getConnectionInfoBySocket( const DtTcpMsgSocket* sock ) const;
00174 
00176    virtual std::pair< bool, unsigned long > rtiExecConnected() const;
00177 
00179    virtual void sendMessage( const DtRtiMsg& msg, const DtTcpMsgSocket* src = 0 );
00180 
00184    virtual void requestCloseAllConnections();   
00185 
00191    virtual void requestKillSingleConnection( const DtTcpMsgSocket* sock );
00192 
00197    virtual void markConnectionAsAboutToBeDeleted(DtTcpMsgSocket const* socket, unsigned int connectionId);
00198 
00200    virtual bool isConnectionMarkedForDeletion(unsigned int connectionId) const;
00201 
00205    virtual void removeOldConnection(unsigned int connectionId);
00206 
00209    virtual void shutdownRequestedByExec();
00210 
00214    virtual bool updateFederateConnectionId( unsigned long orig, unsigned long final );
00215 
00217    virtual bool updateFederateWebServer( unsigned long connId, MAKRti::DtInetAddr ip, int port );
00218 
00220    virtual void updateConnectionProcessParameters( unsigned long connId, unsigned long processId, MAKRti::DtString processName, MAKRti::DtString commandArgs );
00221 
00223    virtual bool shouldStop();
00224 
00225 public:
00226 
00228    static DtRtiMsgForwarder* create( unsigned long id, const DtRIDParameters& params );
00229 
00233    static void setCreatorFunction(DtRtiMsgFwderCreator fn);
00234 
00236    static void tcpSocketAdditionCb(DtTcpMsgSocket* sock, void* usr);
00237    static void tcpSocketRemovalCb(DtTcpMsgSocket* sock, void* usr);
00238 
00239 protected:
00240 
00241    virtual void performMcastDiscovery();
00242 
00245    virtual void applyRegisteredFilters();
00246    virtual void disableRegisteredFilters();
00247 
00250    virtual void waitForIo();
00251 
00252 
00253    virtual void tcpSocketAdditionCb(DtTcpMsgSocket* sock);
00254    virtual void tcpSocketRemovalCb(DtTcpMsgSocket* sock);
00255 
00257    virtual unsigned long consumeConnId();
00258 
00262    virtual void preRunLoopEvent() {};
00263    virtual void runLoopEvent() {};
00264    virtual void postRunLoopEvent() {};
00265 
00266 
00267    virtual bool populateConnectionInformation(
00268       unsigned int& numForwarderToForwarderConns,
00269       std::vector<MAKRti::DtString>& forwarderIdentifiers,
00270       std::vector<MAKRti::DtString>& forwarderConnectionHostNames,
00271       std::vector<MAKRti::DtInetAddr>& forwarderConnectionAddrs,
00272       unsigned int& numForwarderClientConns,
00273       std::vector<MAKRti::DtString>& clientConnectionHostNames,
00274       std::vector<MAKRti::DtInetAddr>& clientConnectionAddrs) const;
00275 
00277    virtual void closeAllConnectionsIfRequested();
00278 
00280    DtRtiMsgForwarder( const DtRtiMsgForwarder& orig );
00281    DtRtiMsgForwarder& operator=( const DtRtiMsgForwarder& orig );
00282 
00283 protected:
00284 
00286 
00289    unsigned long myForwarderId;
00290 
00292    MAKRti::DtInetAddr myForwarderAddr;
00293 
00295    bool myCloseAllConnectionsRequested;
00296 
00298    DtFilteredTcpForwarder* myTcpForwarder;
00299 
00301    DtTcpMsgSocketMgr* mySocketMgr;
00302 
00304    int myPort;
00305    int myTcpNoDelay;
00306 
00309    unsigned long myNextConnectionIdOffset;
00310 
00312    unsigned int myPacketBundleSize;
00313 
00315    DtRtiExecTrackingFilter*    myRtiExecMonitor;
00316 
00318    DtRoutePrinterFilter*       myRoutePrinter;
00319    DtUpdateInterRoutingFilter* myDmMsgRouter;
00320 
00322    DtFedexMsgFilter*           myFedexMsgRouter;
00323 
00325    DtConnectConfirmFilter* myConnectConfirmFilter;
00326 
00329    DtDeleteSocketFilter* mySocketMonitor;
00330 
00332    const DtRIDParameters& myParams;
00333 
00334    DtMulitcastDiscoveryMgr myMcastDiscoveryMgr;
00335    DtThreadSafe< std::deque<DtMsgFwdrFunctor*> > myPendingProxyCommands;
00336 
00338    std::vector< DtMessageFilter* > myRegisteredFilters;
00339 
00344    SocketToConnInfoMap myConnToConnInfoMap;
00345 
00347    std::set<DtTcpMsgSocket const*> myConnectionsAboutToBeDeleted;
00348 
00349    MAKRti::DtSelectParamWithWrite mySelectParams;
00350 
00352    bool myShouldStop;
00353 
00354 protected:
00355 
00356    static DtRtiMsgFwderCreator      theCreator;
00357 };
00358 
00359 
00360 
00361 inline const DtRtiMsgForwarder::SocketToConnInfoMap& DtRtiMsgForwarder::getConnToConnInfoMap() const
00362 {
00363    return myConnToConnInfoMap;
00364 }
00365 
00366 inline unsigned long DtRtiMsgForwarder::forwarderId() const
00367 {
00368    return myForwarderId;
00369 }
00370 
00371 
00372 #endif //!  DtRtiMsgForwarder_H_
00373 

Document ID: Generated on Thu Jun 14 14:15:04 EDT 2012 from SVN revision 116116
Copyright © 2005-2012 VT MÄK Inc. All Rights Reserved (www.mak.com)