From: Mathias Froehlich Date: Sat, 24 Nov 2012 08:54:21 +0000 (+0100) Subject: hla: Route failures in message processing into the HLA layer. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=3c749d4774a6c4eb924b1975f4257c9785559d4f;p=simgear.git hla: Route failures in message processing into the HLA layer. --- diff --git a/simgear/hla/HLAFederate.cxx b/simgear/hla/HLAFederate.cxx index d52dbcca..8e590be4 100644 --- a/simgear/hla/HLAFederate.cxx +++ b/simgear/hla/HLAFederate.cxx @@ -541,7 +541,10 @@ HLAFederate::enableTimeConstrained() } while (!_rtiFederate->getTimeConstrainedEnabled()) { - _rtiFederate->processMessage(); + if (RTIFederate::ProcessMessageFatal == _rtiFederate->processMessage()) { + SG_LOG(SG_NETWORK, SG_WARN, "HLA: Fatal error on processing messages!"); + return false; + } } return true; @@ -584,7 +587,10 @@ HLAFederate::enableTimeRegulation(const SGTimeStamp& lookahead) } while (!_rtiFederate->getTimeRegulationEnabled()) { - _rtiFederate->processMessage(); + if (RTIFederate::ProcessMessageFatal == _rtiFederate->processMessage()) { + SG_LOG(SG_NETWORK, SG_WARN, "HLA: Fatal error on processing messages!"); + return false; + } } return true; @@ -708,7 +714,12 @@ HLAFederate::processMessage() SG_LOG(SG_NETWORK, SG_WARN, "HLA: Accessing unconnected federate!"); return false; } - return _rtiFederate->processMessage(); + + if (RTIFederate::ProcessMessageFatal == _rtiFederate->processMessage()) { + SG_LOG(SG_NETWORK, SG_WARN, "HLA: Fatal error on processing messages!"); + return false; + } + return true; } bool @@ -718,7 +729,12 @@ HLAFederate::processMessage(const SGTimeStamp& timeout) SG_LOG(SG_NETWORK, SG_WARN, "HLA: Accessing unconnected federate!"); return false; } - return _rtiFederate->processMessages(timeout.toSecs(), 0); + + if (RTIFederate::ProcessMessageFatal == _rtiFederate->processMessages(timeout.toSecs(), 0)) { + SG_LOG(SG_NETWORK, SG_WARN, "HLA: Fatal error on processing messages!"); + return false; + } + return true; } bool @@ -730,7 +746,10 @@ HLAFederate::processMessages() } while (_rtiFederate->getTimeAdvancePending()) { - _rtiFederate->processMessage(); + if (RTIFederate::ProcessMessageFatal == _rtiFederate->processMessage()) { + SG_LOG(SG_NETWORK, SG_WARN, "HLA: Fatal error on processing messages!"); + return false; + } } if (_timeConstrainedByLocalClock) { @@ -744,12 +763,23 @@ HLAFederate::processMessages() double rest = (systemTime - SGTimeStamp::now()).toSecs(); if (rest < 0) break; - _rtiFederate->processMessages(rest, rest); + if (RTIFederate::ProcessMessageFatal == _rtiFederate->processMessages(rest, rest)) { + SG_LOG(SG_NETWORK, SG_WARN, "HLA: Fatal error on processing messages!"); + return false; + } } } // Now flush just what is left - while (_rtiFederate->processMessages(0, 0)); + while (true) { + RTIFederate::ProcessMessageResult result = _rtiFederate->processMessages(0, 0); + if (RTIFederate::ProcessMessageLast == result) + break; + if (RTIFederate::ProcessMessageFatal == result) { + SG_LOG(SG_NETWORK, SG_WARN, "HLA: Fatal error on processing messages!"); + return false; + } + } return true; } diff --git a/simgear/hla/RTI13Federate.cxx b/simgear/hla/RTI13Federate.cxx index 1a46cfdb..9ceb8283 100644 --- a/simgear/hla/RTI13Federate.cxx +++ b/simgear/hla/RTI13Federate.cxx @@ -1563,73 +1563,77 @@ RTI13Federate::queryLITS(SGTimeStamp& timeStamp) return true; } -bool +RTI13Federate::ProcessMessageResult RTI13Federate::processMessage() { - bool result = _tick(); + ProcessMessageResult result = _tick(); _federateAmbassador->processQueues(); return result; } -bool +RTI13Federate::ProcessMessageResult RTI13Federate::processMessages(const double& minimum, const double& maximum) { - bool result = _tick(minimum, 0); + ProcessMessageResult result = _tick(minimum, 0); _federateAmbassador->processQueues(); - if (!result) - return false; + if (result != ProcessMessagePending) + return result; SGTimeStamp timeStamp = SGTimeStamp::now() + SGTimeStamp::fromSec(maximum); do { result = _tick(0, 0); _federateAmbassador->processQueues(); - } while (result && SGTimeStamp::now() <= timeStamp); + } while (result == ProcessMessagePending && SGTimeStamp::now() <= timeStamp); return result; } -bool +RTI13Federate::ProcessMessageResult RTI13Federate::_tick() { if (!_ambassador.valid()) { SG_LOG(SG_NETWORK, SG_WARN, "RTI: Ambassador is zero while calling _tick()."); - return false; + return ProcessMessageFatal; } try { - return _ambassador->tick(); + if (_ambassador->tick()) + return ProcessMessagePending; + return ProcessMessageLast; } catch (RTI::SpecifiedSaveLabelDoesNotExist& e) { SG_LOG(SG_NETWORK, SG_WARN, "RTI: Specified save label does not exist: " << e._name << " " << e._reason); - return false; + return ProcessMessageFatal; } catch (RTI::ConcurrentAccessAttempted& e) { SG_LOG(SG_NETWORK, SG_WARN, "RTI: Concurrent access attempted: " << e._name << " " << e._reason); - return false; + return ProcessMessageFatal; } catch (RTI::RTIinternalError& e) { SG_LOG(SG_NETWORK, SG_WARN, "RTI: Internal error: " << e._name << " " << e._reason); - return false; + return ProcessMessageFatal; } - return false; + return ProcessMessageFatal; } -bool +RTI13Federate::ProcessMessageResult RTI13Federate::_tick(const double& minimum, const double& maximum) { if (!_ambassador.valid()) { SG_LOG(SG_NETWORK, SG_WARN, "RTI: Ambassador is zero while calling _tick()."); - return false; + return ProcessMessageFatal; } try { - return _ambassador->tick(minimum, maximum); + if (_ambassador->tick(minimum, maximum)) + return ProcessMessagePending; + return ProcessMessageLast; } catch (RTI::SpecifiedSaveLabelDoesNotExist& e) { SG_LOG(SG_NETWORK, SG_WARN, "RTI: Specified save label does not exist: " << e._name << " " << e._reason); - return false; + return ProcessMessageFatal; } catch (RTI::ConcurrentAccessAttempted& e) { SG_LOG(SG_NETWORK, SG_WARN, "RTI: Concurrent access attempted: " << e._name << " " << e._reason); - return false; + return ProcessMessageFatal; } catch (RTI::RTIinternalError& e) { SG_LOG(SG_NETWORK, SG_WARN, "RTI: Internal error: " << e._name << " " << e._reason); - return false; + return ProcessMessageFatal; } - return false; + return ProcessMessageFatal; } diff --git a/simgear/hla/RTI13Federate.hxx b/simgear/hla/RTI13Federate.hxx index ac6c5855..9f637371 100644 --- a/simgear/hla/RTI13Federate.hxx +++ b/simgear/hla/RTI13Federate.hxx @@ -75,12 +75,12 @@ public: virtual bool queryLITS(SGTimeStamp& timeStamp); /// Process messages - virtual bool processMessage(); - virtual bool processMessages(const double& minimum, const double& maximum); + virtual ProcessMessageResult processMessage(); + virtual ProcessMessageResult processMessages(const double& minimum, const double& maximum); // helper functions for the above - bool _tick(); - bool _tick(const double& minimum, const double& maximum); + ProcessMessageResult _tick(); + ProcessMessageResult _tick(const double& minimum, const double& maximum); virtual RTI13ObjectClass* createObjectClass(const std::string& name, HLAObjectClass* hlaObjectClass); virtual RTI13InteractionClass* createInteractionClass(const std::string& name, HLAInteractionClass* interactionClass); diff --git a/simgear/hla/RTIFederate.hxx b/simgear/hla/RTIFederate.hxx index 002e22b2..7372ee6a 100644 --- a/simgear/hla/RTIFederate.hxx +++ b/simgear/hla/RTIFederate.hxx @@ -75,9 +75,15 @@ public: virtual bool queryGALT(SGTimeStamp& timeStamp) = 0; virtual bool queryLITS(SGTimeStamp& timeStamp) = 0; + enum ProcessMessageResult { + ProcessMessagePending, + ProcessMessageLast, + ProcessMessageFatal + }; + /// Process messages - virtual bool processMessage() = 0; - virtual bool processMessages(const double& minimum, const double& maximum) = 0; + virtual ProcessMessageResult processMessage() = 0; + virtual ProcessMessageResult processMessages(const double& minimum, const double& maximum) = 0; virtual RTIObjectClass* createObjectClass(const std::string& name, HLAObjectClass* hlaObjectClass) = 0; virtual RTIInteractionClass* createInteractionClass(const std::string& name, HLAInteractionClass* interactionClass) = 0;