+bool
+HLAFederate::createJoinFederationExecution()
+{
+ if (!_rtiFederate.valid()) {
+ SG_LOG(SG_NETWORK, SG_WARN, "HLA: Accessing unconnected federate!");
+ return false;
+ }
+
+ for (;;) {
+ // Try to join.
+ RTIFederate::FederationManagementResult joinResult;
+ joinResult = _rtiFederate->join(_federateType, _federationExecutionName);
+ switch (joinResult) {
+ case RTIFederate::FederationManagementSuccess:
+ // Fast return on success
+ return true;
+ case RTIFederate::FederationManagementFatal:
+ // Abort on fatal errors
+ return false;
+ default:
+ break;
+ };
+
+ // If not already joinable, try to create the requested federation
+ RTIFederate::FederationManagementResult createResult;
+ createResult = _rtiFederate->createFederationExecution(_federationExecutionName, _federationObjectModel);
+ switch (createResult) {
+ case RTIFederate::FederationManagementFatal:
+ // Abort on fatal errors
+ return false;
+ default:
+ // Try again to join
+ break;
+ }
+ }
+}
+
+bool
+HLAFederate::resignDestroyFederationExecution()
+{
+ if (!_rtiFederate.valid()) {
+ SG_LOG(SG_NETWORK, SG_WARN, "HLA: Accessing unconnected federate!");
+ return false;
+ }
+
+ // Resign ourselves
+ bool success = _rtiFederate->resign();
+
+ // and try to destroy, non fatal if still some federates joined
+ if (_rtiFederate->destroyFederationExecution(_federationExecutionName) == RTIFederate::FederationManagementFatal)
+ success = false;
+
+ return success;
+}
+
+bool
+HLAFederate::getTimeConstrained() const
+{
+ return _timeConstrained;
+}
+
+bool
+HLAFederate::setTimeConstrained(bool timeConstrained)
+{
+ _timeConstrained = timeConstrained;
+
+ if (_rtiFederate.valid() && _rtiFederate->getJoined()) {
+ if (_timeConstrained && !_rtiFederate->getTimeConstrainedEnabled()) {
+ if (!enableTimeConstrained())
+ return false;
+ } else if (!_timeConstrained && _rtiFederate->getTimeConstrainedEnabled()) {
+ if (!disableTimeConstrained())
+ return false;
+ }
+
+ }
+
+ return true;
+}
+
+bool
+HLAFederate::getTimeConstrainedByLocalClock() const
+{
+ return _timeConstrainedByLocalClock;
+}
+
+bool
+HLAFederate::setTimeConstrainedByLocalClock(bool timeConstrainedByLocalClock)
+{
+ _timeConstrainedByLocalClock = timeConstrainedByLocalClock;
+
+ if (_rtiFederate.valid() && _rtiFederate->getJoined()) {
+ if (_timeConstrainedByLocalClock) {
+ if (!enableTimeConstrainedByLocalClock())
+ return false;
+ }
+ }
+
+ return true;
+}
+
+bool
+HLAFederate::getTimeRegulating() const
+{
+ return _timeRegulating;
+}
+
+bool
+HLAFederate::setTimeRegulating(bool timeRegulating)
+{
+ _timeRegulating = timeRegulating;
+
+ if (_rtiFederate.valid() && _rtiFederate->getJoined()) {
+ if (_timeRegulating && !_rtiFederate->getTimeRegulationEnabled()) {
+ if (!enableTimeRegulation())
+ return false;
+ } else if (!_timeRegulating && _rtiFederate->getTimeRegulationEnabled()) {
+ if (!disableTimeRegulation())
+ return false;
+ }
+
+ }
+ return true;
+}
+
+bool
+HLAFederate::setLeadTime(const SGTimeStamp& leadTime)
+{
+ if (leadTime < SGTimeStamp::fromSec(0)) {
+ SG_LOG(SG_NETWORK, SG_WARN, "Ignoring negative lead time!");
+ return false;
+ }
+
+ _leadTime = leadTime;
+
+ if (_rtiFederate.valid() && _rtiFederate->getJoined()) {
+ if (!modifyLookahead(_leadTime + SGTimeStamp::fromSec(_timeIncrement.toSecs()*0.9))) {
+ SG_LOG(SG_NETWORK, SG_WARN, "Cannot modify lookahead!");
+ return false;
+ }
+ }
+
+ return true;
+}
+
+const SGTimeStamp&
+HLAFederate::getLeadTime() const
+{
+ return _leadTime;
+}
+
+bool
+HLAFederate::setTimeIncrement(const SGTimeStamp& timeIncrement)
+{
+ if (timeIncrement < SGTimeStamp::fromSec(0)) {
+ SG_LOG(SG_NETWORK, SG_WARN, "Ignoring negative time increment!");
+ return false;
+ }
+
+ _timeIncrement = timeIncrement;
+
+ if (_rtiFederate.valid() && _rtiFederate->getJoined()) {
+ if (!modifyLookahead(_leadTime + SGTimeStamp::fromSec(_timeIncrement.toSecs()*0.9))) {
+ SG_LOG(SG_NETWORK, SG_WARN, "Cannot modify lookahead!");
+ return false;
+ }
+ }
+
+ return true;
+}
+
+const SGTimeStamp&
+HLAFederate::getTimeIncrement() const
+{
+ return _timeIncrement;
+}
+