]> git.mxchange.org Git - simgear.git/commitdiff
hla: Route failures in message processing into the HLA layer.
authorMathias Froehlich <Mathias.Froehlich@web.de>
Sat, 24 Nov 2012 08:54:21 +0000 (09:54 +0100)
committerMathias Froehlich <Mathias.Froehlich@web.de>
Sat, 24 Nov 2012 08:55:26 +0000 (09:55 +0100)
simgear/hla/HLAFederate.cxx
simgear/hla/RTI13Federate.cxx
simgear/hla/RTI13Federate.hxx
simgear/hla/RTIFederate.hxx

index d52dbccae8f480c284e847bdd814d7beb17157c6..8e590be42afabbb5b9ad8a2f0dd89839c71377ae 100644 (file)
@@ -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;
 }
index 1a46cfdb581a599f6759759fc649065749ad0e31..9ceb828332938cfdb4b77f56f651a779f615ef5b 100644 (file)
@@ -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;
 }
 
 
index ac6c5855e47ad566e8dc1609b886d0b201414081..9f6373712c5b1cfeebf18a62f60d00ba470b6276 100644 (file)
@@ -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);
index 002e22b2201b911bf55b0298d39d92f55b3c7366..7372ee6a388aaeda65e743c99ed4ce0640d1356c 100644 (file)
@@ -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;