VR-Forces 4.7 Class Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
timeManagementControlHLA.h
Go to the documentation of this file.
1 /****************************************************************************
2  * Copyright (c) 2017 VT MAK
3  * All rights reserved.
4  ****************************************************************************/
5 
9 
10 #pragma once
11 
12 #if DtHLA
13 
14 #if !DtHLA_1516
15 #include "fedtime.hh"
16 #include <vl/vrlRtiAmbassador13.h>
17 #else
18 #if DtHLA_1516_EVOLVED
19  #include "RTI/LogicalTime.h"
20  #include "RTI/LogicalTimeInterval.h"
21  #include "RTI/LogicalTimeFactory.h"
22  #include "RTI/RTIambassador.h"
23 #else
24  #include "RTI/LogicalTime.h"
25  #include "RTI/logicalTimeImpl.h"
26  #include "RTI/logicalTimeIntervalImpl.h"
27  #include "RTI/RTIambassador.h"
28 #endif
29 #endif
30 #include <vl/exerciseConnHLA.h>
31 #include <vl/vrlFederateAmbassador.h>
33 #include <list>
34 
36 
37 // Signature for time advance grant callback functions.
39  void* usr);
40 
42 {
44  void* usr;
46 
47 
48 // DtTimeManagementControl provides controls for enabling/disabling
49 // the HLA Time Management time-constrained mode for a federate.
51 {
52 public:
53 
54  // constructor
55  DtTimeManagementControl(DtExerciseConn& exConn);
56 
57  // destructor
58  virtual ~DtTimeManagementControl();
59 
60  // -------------------------------------------------------------------------
61  // Time Constrained Interface-----------------------------------------------
62  // -------------------------------------------------------------------------
63 
64  // Enables HLA time constrained mode for the federate. You must call
65  // this before making any calls to advanceFedTime(). This call will repeatedly
66  // call drainInput on the exConn until time constrained status is granted.
67  virtual bool enableTimeConstrained();
68 
69  // Disable HLA time constrained mode. Federate is free to advance time
70  // indepenedent of the federation. This call will repeatedly
71  // call drainInput on the exConn until time constrained status is disabled.
72  virtual bool disableTimeConstrained();
73 
74  // Is federate currently time constrained?
75  virtual bool isTimeConstrained() const;
76 
77  // -------------------------------------------------------------------------
78  // Time Regulating Interface------------------------------------------------
79  // -------------------------------------------------------------------------
80 
81  // Enable time regulating mode.
82  // \param exerciseConn
83  // \param lookaheadInterval Time interval when added to current logical
84  // time represents the earliest time the federate will send out any
85  // TSO (time stamp ordered) events.
86 #if !DtHLA_1516
87  virtual bool enableTimeRegulation(
88  const RTI::FedTime& requestedFederationTime,
89  const RTI::FedTime& lookahead,
90  RTI::FedTime& federationTime);
91 #else
92  virtual bool enableTimeRegulation(
93  const RTI::LogicalTime& requestedFederationTime,
94  const RTI::LogicalTimeInterval& lookahead,
95  RTI::LogicalTime& federationTime);
96 #endif
97 
98  // Set new value for lookahead (assuming time regulating mode is already
99  // enabled) and returns true. Otherwise prints warning and returns false.
100 #if !DtHLA_1516
101  virtual bool modifyLookahead(
102  const RTI::FedTime& lookahead);
103 #else
104  virtual bool modifyLookahead(
105  const RTI::LogicalTimeInterval& lookahead);
106 #endif
107 
108  // Disable time regulating mode.
109  virtual bool disableTimeRegulation();
110 
111  // \return Is this federate in time regulating mode?
112  virtual bool isTimeRegulating() const;
113 
114  // -------------------------------------------------------------------------
115  // Advancing Time-----------------------------------------------------------
116  // -------------------------------------------------------------------------
117 
118  // \param Request an advance to given federation time. Federation time
119  // may be different than requested time following this call, even if
120  // blockUntilAdvanceIsGranted is true (federation time may exceed requested
121  // time).
122  // If blockUntilAdvanceIsGranted is true, call will not return until
123  // actualTime exceeds requestedTime.
124  // \param requestedFederationTime Desired federation time to advance to.
125  // \param blockUntilAdvanceIsGranted Indicates whether this function should
126  // wait until request is granted.
127 #if !DtHLA_1516
128  virtual bool timeAdvanceRequest(
129  const RTI::FedTime& requestedFederateTime,
130  bool blockUntilAdvanceIsGranted = true);
131 #else
132  virtual bool timeAdvanceRequest(
133  const RTI::LogicalTime& requestedFederateTime,
134  bool blockUntilAdvanceIsGranted = true);
135 #endif
136 
137  // Add/remove callbacks to be executed immediately following a time advance
138  // request grant.
139  virtual void addTimeAdvanceGrantedCallback(DtTimeAdvanceGrantedCb cb, void *usr);
140  virtual void removeTimeAdvanceGrantedCallback(DtTimeAdvanceGrantedCb cb, void *usr);
141 
142  // -------------------------------------------------------------------------
143  // Querying Time------------------------------------------------------------
144  // -------------------------------------------------------------------------
145 
146  // Get the lower bound time stamp (LBTS)
147  // \param Returns current LBTS for the federate
148  // \return true if call is successful, false otherwise
149 #if !DtHLA_1516
150  virtual bool queryLBTS(RTI::FedTime& federateTime) const;
151 #else
152  virtual bool queryLBTS(RTI::LogicalTime& federateTime) const;
153 #endif
154 
155  // Get the current federation (logical) time
156  // \param Returns current federation time for the federate
157  // \return true if call is successful, false otherwise
158 #if !DtHLA_1516
159  virtual bool queryFederateTime(RTI::FedTime& federateTime) const;
160 #else
161  virtual bool queryFederateTime(RTI::LogicalTime& federateTime) const;
162 #endif
163 
164 public:
165 
166  // Callbacks registered with federate ambassador to advance federation time,
167  // enable time constrained mode, and enable time regulating mode.
168  // timeAdvanceRequestCb calls processTimeAdvanceRequest to actually perform
169  // the work in the callback.
170 #if !DtHLA_1516
171  static void timeAdvanceRequestCb( const RTI::FedTime&, void* );
172  static void timeConstrainedEnableCb( const RTI::FedTime&, void* );
173  static void timeRegulationEnableCb( const RTI::FedTime&, void* );
174 #else
175  static void timeAdvanceRequestCb( const RTI::LogicalTime&, void* );
176  static void timeConstrainedEnableCb( const RTI::LogicalTime&, void* );
177  static void timeRegulationEnableCb( const RTI::LogicalTime&, void* );
178 #endif
179 
180 protected:
181 
182  // \return The exercise connection this class has been handed in to use.
183  virtual DtExerciseConn& exerciseConn() const;
184 
185  // \return New instance of a federation time object.
186 #if !DtHLA_1516
187  virtual RTI::FedTime* createFederationTime() const;
188 #else
189  virtual RTI::LogicalTime* createFederationTime() const;
190 #endif
191 
192  // Sets myFederationTime to the new time given by the RTI and sets
193  // myTimeAdvanceGrantPending to false.
194 #if !DtHLA_1516
195  virtual void processTimeAdvanceRequest( const RTI::FedTime& fTime );
196 #else
197  virtual void processTimeAdvanceRequest( const RTI::LogicalTime& fTime );
198 #endif
199 
200  virtual void invokeTimeAdvanceGrantedCallbacks();
201 
202  void removeAllTimeAdvanceGrantedCallbacks();
203 
204 private:
205 
206  // copy constructor - not implemented
208 
209  // assignment operator - not implemented
210  DtTimeManagementControl& operator=(const DtTimeManagementControl& orig);
211 
212 protected:
213 
214  DtExerciseConn& myExerciseConn;
215 
216  // Used in callback functions
221 
222 #if !DtHLA_1516
223  RTI::FedTime* myFederationTime;
224 #else
225  RTI::LogicalTime* myFederationTime;
226 #endif
227 
228  std::list<DtTimeAdvanceGrantedCbData> myTimeAdvanceGrantedCbs;
229 
230 };
231 
232 #endif // DtHLA

Document ID: Generated on Fri Apr 26 21:53:14 EDT 2019 from SVN revision 197883
Copyright © 2005-2019 VT MAK. All Rights Reserved (www.mak.com)