From 29faf13afda0032b7f70bdde6092158c067c5da4 Mon Sep 17 00:00:00 2001 From: Mathias Froehlich Date: Tue, 30 Aug 2011 21:52:40 +0200 Subject: [PATCH] Move the decision which rti to use into HLAFederate. --- simgear/hla/CMakeLists.txt | 20 +++--- simgear/hla/HLA13Federate.cxx | 33 ---------- simgear/hla/HLA13Federate.hxx | 33 ---------- simgear/hla/HLAFederate.cxx | 115 ++++++++++++++++++++++++++++++++-- simgear/hla/HLAFederate.hxx | 18 ++++-- simgear/hla/Makefile.am | 25 ++++---- simgear/hla/RTI13Federate.cxx | 5 +- simgear/hla/RTI13Federate.hxx | 2 +- 8 files changed, 151 insertions(+), 100 deletions(-) delete mode 100644 simgear/hla/HLA13Federate.cxx delete mode 100644 simgear/hla/HLA13Federate.hxx diff --git a/simgear/hla/CMakeLists.txt b/simgear/hla/CMakeLists.txt index bae6eb73..207210ab 100644 --- a/simgear/hla/CMakeLists.txt +++ b/simgear/hla/CMakeLists.txt @@ -26,9 +26,6 @@ set(HLA_HEADERS ) set(HLA_SOURCES - RTIObjectClass.cxx - RTIObjectInstance.cxx - RTIFederate.cxx HLAArrayDataElement.cxx HLAArrayDataType.cxx HLABasicDataElement.cxx @@ -51,15 +48,18 @@ set(HLA_SOURCES simgear_component(hla hla "${HLA_SOURCES}" "${HLA_HEADERS}") if(RTI_FOUND) - set(HLA13_HEADERS - HLA13Federate.hxx - ) - set(HLA13_SOURCES + set(RTI13_SOURCES RTI13ObjectClass.cxx RTI13ObjectInstance.cxx RTI13Federate.cxx - HLA13Federate.cxx ) - simgear_component(hla13 hla "${HLA13_SOURCES}" "${HLA13_HEADERS}") - set_property(TARGET sghla13 APPEND PROPERTY COMPILE_FLAGS "-I${RTI_INCLUDE_DIR}") + simgear_component(rti13 hla "${RTI13_SOURCES}" "") + set_property(TARGET sgrti13 APPEND PROPERTY COMPILE_FLAGS "-I${RTI_INCLUDE_DIR}") endif() + +set(RTI_SOURCES + RTIObjectClass.cxx + RTIObjectInstance.cxx + RTIFederate.cxx + ) +simgear_component(rti hla "${RTI_SOURCES}" "") diff --git a/simgear/hla/HLA13Federate.cxx b/simgear/hla/HLA13Federate.cxx deleted file mode 100644 index 4f78344c..00000000 --- a/simgear/hla/HLA13Federate.cxx +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright (C) 2009 - 2010 Mathias Froehlich - Mathias.Froehlich@web.de -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Library General Public -// License as published by the Free Software Foundation; either -// version 2 of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Library General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// - -#include "HLA13Federate.hxx" - -#include "RTI13Federate.hxx" - -namespace simgear { - -HLA13Federate::HLA13Federate() : - HLAFederate(new RTI13Federate) -{ -} - -HLA13Federate::~HLA13Federate() -{ -} - -} // namespace simgear diff --git a/simgear/hla/HLA13Federate.hxx b/simgear/hla/HLA13Federate.hxx deleted file mode 100644 index dc3fa0b6..00000000 --- a/simgear/hla/HLA13Federate.hxx +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright (C) 2009 - 2010 Mathias Froehlich - Mathias.Froehlich@web.de -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Library General Public -// License as published by the Free Software Foundation; either -// version 2 of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Library General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// - -#ifndef HLA13Federate_hxx -#define HLA13Federate_hxx - -#include "HLAFederate.hxx" - -namespace simgear { - -class HLA13Federate : public HLAFederate { -public: - HLA13Federate(); - virtual ~HLA13Federate(); -}; - -} // namespace simgear - -#endif diff --git a/simgear/hla/HLAFederate.cxx b/simgear/hla/HLAFederate.cxx index d16494c9..59a5f4b0 100644 --- a/simgear/hla/HLAFederate.cxx +++ b/simgear/hla/HLAFederate.cxx @@ -17,6 +17,7 @@ #include "HLAFederate.hxx" +#include "RTI13Federate.hxx" #include "RTIFederate.hxx" #include "RTIInteractionClass.hxx" #include "RTIObjectClass.hxx" @@ -26,8 +27,7 @@ namespace simgear { -HLAFederate::HLAFederate(const SGSharedPtr& rtiFederate) : - _rtiFederate(rtiFederate) +HLAFederate::HLAFederate() { } @@ -35,105 +35,209 @@ HLAFederate::~HLAFederate() { } -const std::string& +std::string HLAFederate::getFederateType() const { + if (!_rtiFederate.valid()) { + SG_LOG(SG_NETWORK, SG_WARN, "HLA: Accessing unconnected federate!"); + return std::string(); + } return _rtiFederate->getFederateType(); } -const std::string& +std::string HLAFederate::getFederationName() const { + if (!_rtiFederate.valid()) { + SG_LOG(SG_NETWORK, SG_WARN, "HLA: Accessing unconnected federate!"); + return std::string(); + } return _rtiFederate->getFederationName(); } +bool +HLAFederate::connect(Version version, const std::list& stringList) +{ + if (_rtiFederate.valid()) { + SG_LOG(SG_NETWORK, SG_WARN, "HLA: Trying to connect to already connected federate!"); + return false; + } + switch (version) { + case RTI13: + _rtiFederate = new RTI13Federate(stringList); + break; + case RTI1516: + SG_LOG(SG_IO, SG_ALERT, "HLA version RTI1516 not yet(!?) supported."); + // _rtiFederate = new RTI1516Federate(stringList); + break; + case RTI1516E: + SG_LOG(SG_IO, SG_ALERT, "HLA version RTI1516E not yet(!?) supported."); + // _rtiFederate = new RTI1516eFederate(stringList); + break; + default: + SG_LOG(SG_NETWORK, SG_WARN, "HLA: Unknown rti version in connect!"); + } + return _rtiFederate.valid(); +} + +bool +HLAFederate::disconnect() +{ + if (!_rtiFederate.valid()) { + SG_LOG(SG_NETWORK, SG_WARN, "HLA: Accessing unconnected federate!"); + return false; + } + _rtiFederate = 0; + return true; +} + bool HLAFederate::createFederationExecution(const std::string& federation, const std::string& objectModel) { + if (!_rtiFederate.valid()) { + SG_LOG(SG_NETWORK, SG_WARN, "HLA: Accessing unconnected federate!"); + return false; + } return _rtiFederate->createFederationExecution(federation, objectModel); } bool HLAFederate::destroyFederationExecution(const std::string& federation) { + if (!_rtiFederate.valid()) { + SG_LOG(SG_NETWORK, SG_WARN, "HLA: Accessing unconnected federate!"); + return false; + } return _rtiFederate->destroyFederationExecution(federation); } bool HLAFederate::join(const std::string& federateType, const std::string& federation) { + if (!_rtiFederate.valid()) { + SG_LOG(SG_NETWORK, SG_WARN, "HLA: Accessing unconnected federate!"); + return false; + } return _rtiFederate->join(federateType, federation); } bool HLAFederate::resign() { + if (!_rtiFederate.valid()) { + SG_LOG(SG_NETWORK, SG_WARN, "HLA: Accessing unconnected federate!"); + return false; + } return _rtiFederate->resign(); } bool HLAFederate::enableTimeConstrained() { + if (!_rtiFederate.valid()) { + SG_LOG(SG_NETWORK, SG_WARN, "HLA: Accessing unconnected federate!"); + return false; + } return _rtiFederate->enableTimeConstrained(); } bool HLAFederate::disableTimeConstrained() { + if (!_rtiFederate.valid()) { + SG_LOG(SG_NETWORK, SG_WARN, "HLA: Accessing unconnected federate!"); + return false; + } return _rtiFederate->disableTimeConstrained(); } bool HLAFederate::enableTimeRegulation(const SGTimeStamp& lookahead) { + if (!_rtiFederate.valid()) { + SG_LOG(SG_NETWORK, SG_WARN, "HLA: Accessing unconnected federate!"); + return false; + } return _rtiFederate->enableTimeRegulation(lookahead); } bool HLAFederate::disableTimeRegulation() { + if (!_rtiFederate.valid()) { + SG_LOG(SG_NETWORK, SG_WARN, "HLA: Accessing unconnected federate!"); + return false; + } return _rtiFederate->disableTimeRegulation(); } bool HLAFederate::timeAdvanceRequestBy(const SGTimeStamp& dt) { + if (!_rtiFederate.valid()) { + SG_LOG(SG_NETWORK, SG_WARN, "HLA: Accessing unconnected federate!"); + return false; + } return _rtiFederate->timeAdvanceRequestBy(dt); } bool HLAFederate::timeAdvanceRequest(const SGTimeStamp& dt) { + if (!_rtiFederate.valid()) { + SG_LOG(SG_NETWORK, SG_WARN, "HLA: Accessing unconnected federate!"); + return false; + } return _rtiFederate->timeAdvanceRequest(dt); } bool HLAFederate::queryFederateTime(SGTimeStamp& timeStamp) { + if (!_rtiFederate.valid()) { + SG_LOG(SG_NETWORK, SG_WARN, "HLA: Accessing unconnected federate!"); + return false; + } return _rtiFederate->queryFederateTime(timeStamp); } bool HLAFederate::modifyLookahead(const SGTimeStamp& timeStamp) { + if (!_rtiFederate.valid()) { + SG_LOG(SG_NETWORK, SG_WARN, "HLA: Accessing unconnected federate!"); + return false; + } return _rtiFederate->modifyLookahead(timeStamp); } bool HLAFederate::queryLookahead(SGTimeStamp& timeStamp) { + if (!_rtiFederate.valid()) { + SG_LOG(SG_NETWORK, SG_WARN, "HLA: Accessing unconnected federate!"); + return false; + } return _rtiFederate->queryLookahead(timeStamp); } bool HLAFederate::tick() { + if (!_rtiFederate.valid()) { + SG_LOG(SG_NETWORK, SG_WARN, "HLA: Accessing unconnected federate!"); + return false; + } return _rtiFederate->tick(); } 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->tick(minimum, maximum); } @@ -142,8 +246,7 @@ HLAFederate::readObjectModelTemplate(const std::string& objectModel, HLAFederate::ObjectModelFactory& objectModelFactory) { if (!_rtiFederate.valid()) { - SG_LOG(SG_IO, SG_ALERT, "Could not process HLA XML object model file: " - "No rti federate available!"); + SG_LOG(SG_NETWORK, SG_WARN, "HLA: Accessing unconnected federate!"); return false; } diff --git a/simgear/hla/HLAFederate.hxx b/simgear/hla/HLAFederate.hxx index 7376540e..5af83396 100644 --- a/simgear/hla/HLAFederate.hxx +++ b/simgear/hla/HLAFederate.hxx @@ -32,11 +32,22 @@ class RTIFederate; class HLAFederate : public SGWeakReferenced { public: + enum Version { + RTI13, + RTI1516, + RTI1516E + }; + + HLAFederate(); virtual ~HLAFederate(); + /// connect to an rti + bool connect(Version version, const std::list& stringList); + bool disconnect(); + /// Get the name of the joined federate/federation - const std::string& getFederateType() const; - const std::string& getFederationName() const; + std::string getFederateType() const; + std::string getFederationName() const; /// Create a federation execution /// Semantically this methods should be static, @@ -94,9 +105,6 @@ public: HLAInteractionClass* getInteractionClass(const std::string& name); const HLAInteractionClass* getInteractionClass(const std::string& name) const; -protected: - HLAFederate(const SGSharedPtr& rtiFederate); - private: SGSharedPtr _rtiFederate; diff --git a/simgear/hla/Makefile.am b/simgear/hla/Makefile.am index e4af1531..67542ddb 100644 --- a/simgear/hla/Makefile.am +++ b/simgear/hla/Makefile.am @@ -29,9 +29,6 @@ libsghla_a_HEADERS = \ HLAVariantDataType.hxx libsghla_a_SOURCES = \ - RTIObjectClass.cxx \ - RTIObjectInstance.cxx \ - RTIFederate.cxx \ HLAArrayDataElement.cxx \ HLAArrayDataType.cxx \ HLABasicDataElement.cxx \ @@ -53,17 +50,23 @@ libsghla_a_SOURCES = \ if ENABLE_HLA13 -lib_LIBRARIES += libsghla13.a - -libsghla13_adir = @includedir@/hla +lib_LIBRARIES += libsgrti13.a -libsghla13_a_HEADERS = \ - HLA13Federate.hxx +libsgrti13_adir = @includedir@/hla -libsghla13_a_SOURCES = \ +libsgrti13_a_SOURCES = \ RTI13ObjectClass.cxx \ RTI13ObjectInstance.cxx \ - RTI13Federate.cxx \ - HLA13Federate.cxx + RTI13Federate.cxx endif + +lib_LIBRARIES += libsgrti.a + +libsgrti_adir = @includedir@/hla + +libsgrti_a_SOURCES = \ + RTIObjectClass.cxx \ + RTIObjectInstance.cxx \ + RTIFederate.cxx + diff --git a/simgear/hla/RTI13Federate.cxx b/simgear/hla/RTI13Federate.cxx index 649a9f58..a77fbaea 100644 --- a/simgear/hla/RTI13Federate.cxx +++ b/simgear/hla/RTI13Federate.cxx @@ -21,10 +21,13 @@ namespace simgear { -RTI13Federate::RTI13Federate() : +RTI13Federate::RTI13Federate(const std::list& stringList) : _tickTimeout(10), _ambassador(new RTI13Ambassador) { + if (stringList.empty()) { + SG_LOG(SG_NETWORK, SG_WARN, "RTI: Ignoring non empty connect arguments while connecting to an RTI13 federation!"); + } } RTI13Federate::~RTI13Federate() diff --git a/simgear/hla/RTI13Federate.hxx b/simgear/hla/RTI13Federate.hxx index 8ace9e58..839e7d50 100644 --- a/simgear/hla/RTI13Federate.hxx +++ b/simgear/hla/RTI13Federate.hxx @@ -34,7 +34,7 @@ class RTI13Ambassador; class RTI13Federate : public RTIFederate { public: - RTI13Federate(); + RTI13Federate(const std::list& stringList); virtual ~RTI13Federate(); virtual bool createFederationExecution(const std::string& federation, const std::string& objectModel); -- 2.39.5