From c5ddd7b1f39a78d04c6748de122ede13ee12c847 Mon Sep 17 00:00:00 2001 From: Mathias Froehlich <Mathias.Froehlich@web.de> Date: Sat, 18 Feb 2012 13:35:17 +0100 Subject: [PATCH] hla: Avoid using deprecated readObjectModelTemplate. Avoid using the now deprecated readObjectModelTemplate() method in HLAFederate. Make more use of the available general initialization functions in HLAFederate. --- src/Network/HLA/hla.cxx | 34 +++++++++++++--------------------- src/Network/HLA/hla.hxx | 3 ++- 2 files changed, 15 insertions(+), 22 deletions(-) diff --git a/src/Network/HLA/hla.cxx b/src/Network/HLA/hla.cxx index 5f8d15731..493f2ee30 100644 --- a/src/Network/HLA/hla.cxx +++ b/src/Network/HLA/hla.cxx @@ -843,8 +843,16 @@ private: sg::HLADataElement::IndexPathPair _mpPropertiesIndexPathPair; }; +class FGHLA::Federate : public sg::HLAFederate { +public: + virtual ~Federate() + { } + virtual bool readObjectModel() + { return readRTI1516ObjectModelTemplate(getFederationObjectModel()); } +}; + FGHLA::FGHLA(const std::vector<std::string>& tokens) : - _hlaFederate(new simgear::HLAFederate) + _hlaFederate(new Federate) { if (1 < tokens.size() && !tokens[1].empty()) set_direction(tokens[1]); @@ -959,27 +967,15 @@ FGHLA::open() _hlaFederate->setFederationObjectModel(objectModel); _hlaFederate->setFederateType(_federate); - // Now that it is paramtrized, connect - if (!_hlaFederate->connect()) { - SG_LOG(SG_IO, SG_ALERT, "Could not connect to rti."); - return false; - } - - // Try to create and join the new federation execution - if (!_hlaFederate->createJoinFederationExecution()) { - SG_LOG(SG_IO, SG_ALERT, "Could not join federation"); + // Now that it is paramtrized, connect/join + if (!_hlaFederate->init()) { + SG_LOG(SG_IO, SG_ALERT, "Could not init the hla/rti connect."); return false; } // bool publish = get_direction() & SG_IO_OUT; // bool subscribe = get_direction() & SG_IO_IN; - sg::HLAFederate::ObjectModelFactory objectModelFactory; - if (!_hlaFederate->readObjectModelTemplate(objectModel, objectModelFactory)) { - SG_LOG(SG_IO, SG_ALERT, "Could not read omt file \"" << objectModel << "\"!"); - return false; - } - // This should be configured form a file XMLConfigReader::ObjectClassConfigList::const_iterator i; for (i = configReader.getObjectClassConfigList().begin(); @@ -1284,11 +1280,7 @@ FGHLA::close() } // Leave the federation and try to destroy the federation execution. - // Only works if no federate is joined - _hlaFederate->resignDestroyFederationExecution(); - - // throw away the HLAFederate - _hlaFederate->disconnect(); + _hlaFederate->shutdown(); set_enabled(false); diff --git a/src/Network/HLA/hla.hxx b/src/Network/HLA/hla.hxx index b1f6d4269..d843160c2 100644 --- a/src/Network/HLA/hla.hxx +++ b/src/Network/HLA/hla.hxx @@ -45,6 +45,7 @@ public: private: /// All the utility classes we need currently class XMLConfigReader; + class Federate; /// The configuration parameters extracted from the tokens in the constructor std::string _objectModelConfig; @@ -52,7 +53,7 @@ private: std::string _federate; /// The toplevel rti class - SGSharedPtr<simgear::HLAFederate> _hlaFederate; + SGSharedPtr<Federate> _hlaFederate; /// This class that is used to send register the local instance SGSharedPtr<simgear::HLAObjectClass> _localAircraftClass; /// The local aircraft instance