![]() |
VR-Forces 4.0.4 Class Documentation
|
00001 /******************************************************************************* 00002 ** Copyright (c) 2006 MAK Technologies, Inc. 00003 ** All rights reserved. 00004 *******************************************************************************/ 00005 /******************************************************************************* 00006 ** $RCSfile: hTimeMgmtControl.h,v $ $Revision: 1.5 $ $State: Exp $ 00007 *******************************************************************************/ 00008 00009 // \file hTimeMgmtControl.h 00010 // \brief DtHlaTimeManagementControl provides controls for enabling/disabling 00011 // HLA time constrained/time regulating mode, and the means to advance federate 00012 // (logical) time. 00013 00014 #ifndef hTimeMgmtControl_H_ 00015 #define hTimeMgmtControl_H_ 00016 00017 #if DtHLA 00018 00019 #if !DtHLA_1516 00020 #include "fedtime.hh" 00021 #include <vl/vrlRtiAmb13.h> 00022 #else 00023 #if DtHLA_1516_EVOLVED 00024 #include "RTI/LogicalTime.h" 00025 #include "RTI/LogicalTimeInterval.h" 00026 #include "RTI/RTIambassador.h" 00027 #else 00028 #include "RTI/LogicalTime.h" 00029 #include "RTI/logicalTimeImpl.h" 00030 #include "RTI/logicalTimeIntervalImpl.h" 00031 #include "RTI/RTIambassador.h" 00032 #endif 00033 #endif 00034 #include <vl/hExerciseConn.h> 00035 #include <vl/vrlFedAmb.h> 00036 #include <vrfExtObjects/vrfExtObjectsDefines.h> 00037 #include <list> 00038 00039 class DtHlaTimeManagementControl; 00040 00041 // Signature for time advance grant callback functions. 00042 typedef void (*DtTimeAdvanceGrantedCb)(DtHlaTimeManagementControl* tmControl, 00043 void* usr); 00044 00045 typedef struct DtTimeAdvanceGrantedCbData 00046 { 00047 DtTimeAdvanceGrantedCb func; 00048 void* usr; 00049 } DtTimeAdvanceGrantedCbData; 00050 00051 00052 // DtHlaTimeManagementControl provides controls for enabling/disabling 00053 // the HLA Time Management time-constrained mode for a federate. 00054 class DT_DLL_vrfExtObjects DtHlaTimeManagementControl 00055 { 00056 public: 00057 00058 // constructor 00059 DtHlaTimeManagementControl(DtExerciseConn& exConn); 00060 00061 // destructor 00062 virtual ~DtHlaTimeManagementControl(); 00063 00064 // ------------------------------------------------------------------------- 00065 // Time Constrained Interface----------------------------------------------- 00066 // ------------------------------------------------------------------------- 00067 00068 // Enables HLA time constrained mode for the federate. You must call 00069 // this before making any calls to advanceFedTime(). This call will repeatedly 00070 // call drainInput on the exConn until time constrained status is granted. 00071 virtual bool enableTimeConstrained(); 00072 00073 // Disable HLA time constrained mode. Federate is free to advance time 00074 // indepenedent of the federation. This call will repeatedly 00075 // call drainInput on the exConn until time constrained status is disabled. 00076 virtual bool disableTimeConstrained(); 00077 00078 // Is federate currently time constrained? 00079 virtual bool isTimeConstrained() const; 00080 00081 // ------------------------------------------------------------------------- 00082 // Time Regulating Interface------------------------------------------------ 00083 // ------------------------------------------------------------------------- 00084 00085 // Enable time regulating mode. 00086 // \param exerciseConn 00087 // \param lookaheadInterval Time interval when added to current logical 00088 // time represents the earliest time the federate will send out any 00089 // TSO (time stamp ordered) events. 00090 #if !DtHLA_1516 00091 virtual bool enableTimeRegulation( 00092 const RTI::FedTime& requestedFederationTime, 00093 const RTI::FedTime& lookahead, 00094 RTI::FedTime& federationTime); 00095 #else 00096 virtual bool enableTimeRegulation( 00097 const RTI::LogicalTime& requestedFederationTime, 00098 const RTI::LogicalTimeInterval& lookahead, 00099 RTI::LogicalTime& federationTime); 00100 #endif 00101 00102 // Set new value for lookahead (assuming time regulating mode is already 00103 // enabled) and returns true. Otherwise prints warning and returns false. 00104 #if !DtHLA_1516 00105 virtual bool modifyLookahead( 00106 const RTI::FedTime& lookahead); 00107 #else 00108 virtual bool modifyLookahead( 00109 const RTI::LogicalTimeInterval& lookahead); 00110 #endif 00111 00112 // Disable time regulating mode. 00113 virtual bool disableTimeRegulation(); 00114 00115 // \return Is this federate in time regulating mode? 00116 virtual bool isTimeRegulating() const; 00117 00118 // ------------------------------------------------------------------------- 00119 // Advancing Time----------------------------------------------------------- 00120 // ------------------------------------------------------------------------- 00121 00122 // \param Request an advance to given federation time. Federation time 00123 // may be different than requested time following this call, even if 00124 // blockUntilAdvanceIsGranted is true (federation time may exceed requested 00125 // time). 00126 // If blockUntilAdvanceIsGranted is true, call will not return until 00127 // actualTime exceeds requestedTime. 00128 // \param requestedFederationTime Desired federation time to advance to. 00129 // \param blockUntilAdvanceIsGranted Indicates whether this function should 00130 // wait until request is granted. 00131 #if !DtHLA_1516 00132 virtual bool timeAdvanceRequest( 00133 const RTI::FedTime& requestedFederateTime, 00134 bool blockUntilAdvanceIsGranted = true); 00135 #else 00136 virtual bool timeAdvanceRequest( 00137 const RTI::LogicalTime& requestedFederateTime, 00138 bool blockUntilAdvanceIsGranted = true); 00139 #endif 00140 00141 // Add/remove callbacks to be executed immediately following a time advance 00142 // request grant. 00143 virtual void addTimeAdvanceGrantedCallback(DtTimeAdvanceGrantedCb cb, void *usr); 00144 virtual void removeTimeAdvanceGrantedCallback(DtTimeAdvanceGrantedCb cb, void *usr); 00145 00146 // ------------------------------------------------------------------------- 00147 // Querying Time------------------------------------------------------------ 00148 // ------------------------------------------------------------------------- 00149 00150 // Get the lower bound time stamp (LBTS) 00151 // \param Returns current LBTS for the federate 00152 // \return true if call is successful, false otherwise 00153 #if !DtHLA_1516 00154 virtual bool queryLBTS(RTI::FedTime& federateTime) const; 00155 #else 00156 virtual bool queryLBTS(RTI::LogicalTime& federateTime) const; 00157 #endif 00158 00159 // Get the current federation (logical) time 00160 // \param Returns current federation time for the federate 00161 // \return true if call is successful, false otherwise 00162 #if !DtHLA_1516 00163 virtual bool queryFederateTime(RTI::FedTime& federateTime) const; 00164 #else 00165 virtual bool queryFederateTime(RTI::LogicalTime& federateTime) const; 00166 #endif 00167 00168 public: 00169 00170 // Callbacks registered with federate ambassador to advance federation time, 00171 // enable time constrained mode, and enable time regulating mode. 00172 // timeAdvanceRequestCb calls processTimeAdvanceRequest to actually perform 00173 // the work in the callback. 00174 #if !DtHLA_1516 00175 static void timeAdvanceRequestCb( const RTI::FedTime&, void* ); 00176 static void timeConstrainedEnableCb( const RTI::FedTime&, void* ); 00177 static void timeRegulationEnableCb( const RTI::FedTime&, void* ); 00178 #else 00179 static void timeAdvanceRequestCb( const RTI::LogicalTime&, void* ); 00180 static void timeConstrainedEnableCb( const RTI::LogicalTime&, void* ); 00181 static void timeRegulationEnableCb( const RTI::LogicalTime&, void* ); 00182 #endif 00183 00184 protected: 00185 00186 // \return The exercise connection this class has been handed in to use. 00187 virtual DtExerciseConn& exerciseConn() const; 00188 00189 // \return New instance of a federation time object. 00190 #if !DtHLA_1516 00191 virtual RTI::FedTime* createFederationTime() const; 00192 #else 00193 virtual RTI::LogicalTime* createFederationTime() const; 00194 #endif 00195 00196 // Sets myFederationTime to the new time given by the RTI and sets 00197 // myTimeAdvanceGrantPending to false. 00198 #if !DtHLA_1516 00199 virtual void processTimeAdvanceRequest( const RTI::FedTime& fTime ); 00200 #else 00201 virtual void processTimeAdvanceRequest( const RTI::LogicalTime& fTime ); 00202 #endif 00203 00204 virtual void invokeTimeAdvanceGrantedCallbacks(); 00205 00206 void removeAllTimeAdvanceGrantedCallbacks(); 00207 00208 private: 00209 00210 // copy constructor - not implemented 00211 DtHlaTimeManagementControl(const DtHlaTimeManagementControl& orig); 00212 00213 // assignment operator - not implemented 00214 DtHlaTimeManagementControl& operator=(const DtHlaTimeManagementControl& orig); 00215 00216 protected: 00217 00218 DtExerciseConn& myExerciseConn; 00219 00220 // Used in callback functions 00221 bool myTimeAdvanceGrantPending; 00222 bool myIsTimeConstrained; 00223 bool myIsTimeRegulating; 00224 bool myNeedToRegisterTimeAdvanceGrant; 00225 00226 #if !DtHLA_1516 00227 RTI::FedTime* myFederationTime; 00228 #else 00229 RTI::LogicalTime* myFederationTime; 00230 #endif 00231 00232 std::list<DtTimeAdvanceGrantedCbData> myTimeAdvanceGrantedCbs; 00233 }; 00234 00235 #endif // DtHLA 00236 00237 #endif