]> git.mxchange.org Git - simgear.git/blobdiff - simgear/hla/HLAFederate.cxx
cppbind: automatic conversion of SGReferenced derived pointers.
[simgear.git] / simgear / hla / HLAFederate.cxx
index 8cd173ad53ec0f1abb99d465dd7d8bdbb9a1b46e..462351cc1d6c620ad07023b24ce1508a0ffdef9e 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,101 +763,31 @@ 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));
-
-    return true;
-}
-
-bool
-HLAFederate::tick(const double& minimum, const double& maximum)
-{
-    if (!_rtiFederate.valid()) {
-        SG_LOG(SG_NETWORK, SG_WARN, "HLA: Accessing unconnected federate!");
-        return false;
-    }
-    return _rtiFederate->processMessages(minimum, maximum);
-}
-
-bool
-HLAFederate::readObjectModelTemplate(const std::string& objectModel,
-                                     HLAFederate::ObjectModelFactory& objectModelFactory)
-{
-    // The XML version of the federate object model.
-    // This one covers the generic attributes, parameters and data types.
-    HLAOMTXmlVisitor omtXmlVisitor;
-    try {
-        readXML(objectModel, omtXmlVisitor);
-    } catch (const sg_throwable& e) {
-        SG_LOG(SG_IO, SG_ALERT, "Could not open HLA XML object model file: "
-               << e.getMessage());
-        return false;
-    } catch (...) {
-        SG_LOG(SG_IO, SG_ALERT, "Could not open HLA XML object model file");
-        return false;
-    }
-
-    omtXmlVisitor.setDataTypesToFederate(*this);
-
-    unsigned numObjectClasses = omtXmlVisitor.getNumObjectClasses();
-    for (unsigned i = 0; i < numObjectClasses; ++i) {
-        const HLAOMTXmlVisitor::ObjectClass* objectClass = omtXmlVisitor.getObjectClass(i);
-        std::string objectClassName = objectClass->getName();
-
-        SGSharedPtr<HLAObjectClass> hlaObjectClass = objectModelFactory.createObjectClass(objectClassName, *this);
-        if (!hlaObjectClass.valid()) {
-            SG_LOG(SG_IO, SG_INFO, "Ignoring object class \"" << objectClassName << "\".");
-            continue;
-        }
-
-        bool publish = objectModelFactory.publishObjectClass(objectClassName, objectClass->getSharing());
-        bool subscribe = objectModelFactory.subscribeObjectClass(objectClassName, objectClass->getSharing());
-
-        // process the attributes
-        for (unsigned j = 0; j < objectClass->getNumAttributes(); ++j) {
-            const simgear::HLAOMTXmlVisitor::Attribute* attribute;
-            attribute = objectClass->getAttribute(j);
-
-            std::string attributeName = attribute->getName();
-            unsigned index = hlaObjectClass->addAttribute(attributeName);
-
-            if (index == ~0u) {
-                SG_LOG(SG_IO, SG_WARN, "RTI does not know the \"" << attributeName << "\" attribute!");
-                continue;
-            }
-
-            // the attributes datatype
-            SGSharedPtr<const HLADataType> dataType = getDataType(attribute->getDataType());
-            if (!dataType.valid()) {
-                SG_LOG(SG_IO, SG_WARN, "Could not find data type for attribute \""
-                       << attributeName << "\" in object class \"" << objectClassName << "\"!");
-            }
-            hlaObjectClass->setAttributeDataType(index, dataType);
-            hlaObjectClass->setAttributeUpdateType(index, attribute->getUpdateType());
-            if (subscribe && objectModelFactory.subscribeAttribute(objectClassName, attributeName, attribute->_sharing))
-                hlaObjectClass->setAttributeSubscriptionType(index, attribute->getSubscriptionType());
-            if (publish && objectModelFactory.publishAttribute(objectClassName, attributeName, attribute->_sharing))
-                hlaObjectClass->setAttributePublicationType(index, attribute->getPublicationType());
+    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;
         }
-
-        if (publish)
-            hlaObjectClass->publish();
-        if (subscribe)
-            hlaObjectClass->subscribe();
-
     }
 
-    return resolveObjectModel();
+    return true;
 }
 
 bool
 HLAFederate::readRTI13ObjectModelTemplate(const std::string& objectModel)
 {
-    SG_LOG(SG_IO, SG_ALERT, "HLA version RTI13 not yet(!?) supported.");
+    SG_LOG(SG_IO, SG_WARN, "HLA version RTI13 not yet(!?) supported.");
     return false;
 }
 
@@ -867,7 +816,7 @@ HLAFederate::readRTI1516ObjectModelTemplate(const std::string& objectModel)
 bool
 HLAFederate::readRTI1516EObjectModelTemplate(const std::string& objectModel)
 {
-    SG_LOG(SG_IO, SG_ALERT, "HLA version RTI1516E not yet(!?) supported.");
+    SG_LOG(SG_IO, SG_WARN, "HLA version RTI1516E not yet(!?) supported.");
     return false;
 }
 
@@ -1150,7 +1099,10 @@ HLAFederate::init()
 bool
 HLAFederate::update()
 {
-    return timeAdvanceBy(_timeIncrement);
+    if (_timeIncrement <= SGTimeStamp::fromSec(0))
+        return processMessages();
+    else
+        return timeAdvanceBy(_timeIncrement);
 }
 
 bool
@@ -1207,9 +1159,9 @@ HLAFederate::_clearRTI()
 }
 
 bool
-HLAFederate::_insertInteractionClass(const SGSharedPtr<HLAInteractionClass>& interactionClass)
+HLAFederate::_insertInteractionClass(HLAInteractionClass* interactionClass)
 {
-    if (!interactionClass.valid())
+    if (!interactionClass)
         return false;
     if (_interactionClassMap.find(interactionClass->getName()) != _interactionClassMap.end()) {
         SG_LOG(SG_IO, SG_ALERT, "HLA: _insertInteractionClass: object instance with name \""
@@ -1221,9 +1173,9 @@ HLAFederate::_insertInteractionClass(const SGSharedPtr<HLAInteractionClass>& int
 }
 
 bool
-HLAFederate::_insertObjectClass(const SGSharedPtr<HLAObjectClass>& objectClass)
+HLAFederate::_insertObjectClass(HLAObjectClass* objectClass)
 {
-    if (!objectClass.valid())
+    if (!objectClass)
         return false;
     if (_objectClassMap.find(objectClass->getName()) != _objectClassMap.end()) {
         SG_LOG(SG_IO, SG_ALERT, "HLA: _insertObjectClass: object instance with name \""
@@ -1235,9 +1187,9 @@ HLAFederate::_insertObjectClass(const SGSharedPtr<HLAObjectClass>& objectClass)
 }
 
 bool
-HLAFederate::_insertObjectInstance(const SGSharedPtr<HLAObjectInstance>& objectInstance)
+HLAFederate::_insertObjectInstance(HLAObjectInstance* objectInstance)
 {
-    if (!objectInstance.valid())
+    if (!objectInstance)
         return false;
     if (objectInstance->getName().empty()) {
         SG_LOG(SG_IO, SG_ALERT, "HLA: _insertObjectInstance: trying to insert object instance with empty name!");