hla: Introduce backend factory infrastructure.
Not finally ready, but provide a factory infrastructure to improove plugability of different rti backend implementations.
This commit is contained in:
@@ -57,6 +57,7 @@ if(RTI_FOUND)
|
|||||||
RTI13ObjectClass.cxx
|
RTI13ObjectClass.cxx
|
||||||
RTI13ObjectInstance.cxx
|
RTI13ObjectInstance.cxx
|
||||||
RTI13Federate.cxx
|
RTI13Federate.cxx
|
||||||
|
RTI13FederateFactory.cxx
|
||||||
)
|
)
|
||||||
simgear_component(rti13 hla "${RTI13_SOURCES}" "")
|
simgear_component(rti13 hla "${RTI13_SOURCES}" "")
|
||||||
set_property(TARGET sgrti13 APPEND PROPERTY COMPILE_FLAGS "-I${RTI_INCLUDE_DIR}")
|
set_property(TARGET sgrti13 APPEND PROPERTY COMPILE_FLAGS "-I${RTI_INCLUDE_DIR}")
|
||||||
@@ -66,5 +67,7 @@ set(RTI_SOURCES
|
|||||||
RTIObjectClass.cxx
|
RTIObjectClass.cxx
|
||||||
RTIObjectInstance.cxx
|
RTIObjectInstance.cxx
|
||||||
RTIFederate.cxx
|
RTIFederate.cxx
|
||||||
|
RTIFederateFactory.cxx
|
||||||
|
RTIFederateFactoryRegistry.cxx
|
||||||
)
|
)
|
||||||
simgear_component(rti hla "${RTI_SOURCES}" "")
|
simgear_component(rti hla "${RTI_SOURCES}" "")
|
||||||
|
|||||||
+19
-28
@@ -17,8 +17,11 @@
|
|||||||
|
|
||||||
#include "HLAFederate.hxx"
|
#include "HLAFederate.hxx"
|
||||||
|
|
||||||
#include "RTI13Federate.hxx"
|
#include "simgear/debug/logstream.hxx"
|
||||||
|
|
||||||
#include "RTIFederate.hxx"
|
#include "RTIFederate.hxx"
|
||||||
|
#include "RTIFederateFactoryRegistry.hxx"
|
||||||
|
#include "RTI13FederateFactory.hxx"
|
||||||
#include "RTIInteractionClass.hxx"
|
#include "RTIInteractionClass.hxx"
|
||||||
#include "RTIObjectClass.hxx"
|
#include "RTIObjectClass.hxx"
|
||||||
#include "HLADataElement.hxx"
|
#include "HLADataElement.hxx"
|
||||||
@@ -35,6 +38,8 @@ HLAFederate::HLAFederate() :
|
|||||||
_timeConstrainedByLocalClock(false),
|
_timeConstrainedByLocalClock(false),
|
||||||
_done(false)
|
_done(false)
|
||||||
{
|
{
|
||||||
|
// For now instantiate the current only available factory here explicitly
|
||||||
|
RTI13FederateFactory::instance();
|
||||||
}
|
}
|
||||||
|
|
||||||
HLAFederate::~HLAFederate()
|
HLAFederate::~HLAFederate()
|
||||||
@@ -159,28 +164,9 @@ HLAFederate::setFederateName(const std::string& federateName)
|
|||||||
bool
|
bool
|
||||||
HLAFederate::connect(Version version, const std::list<std::string>& stringList)
|
HLAFederate::connect(Version version, const std::list<std::string>& stringList)
|
||||||
{
|
{
|
||||||
if (_rtiFederate.valid()) {
|
_version = version;
|
||||||
SG_LOG(SG_NETWORK, SG_WARN, "HLA: Trying to connect to already connected federate!");
|
_connectArguments = stringList;
|
||||||
return false;
|
return connect();
|
||||||
}
|
|
||||||
switch (version) {
|
|
||||||
case RTI13:
|
|
||||||
_rtiFederate = new RTI13Federate(stringList);
|
|
||||||
_version = version;
|
|
||||||
_connectArguments = 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
|
bool
|
||||||
@@ -190,17 +176,22 @@ HLAFederate::connect()
|
|||||||
SG_LOG(SG_NETWORK, SG_WARN, "HLA: Trying to connect to already connected federate!");
|
SG_LOG(SG_NETWORK, SG_WARN, "HLA: Trying to connect to already connected federate!");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SGSharedPtr<RTIFederateFactoryRegistry> registry = RTIFederateFactoryRegistry::instance();
|
||||||
|
if (!registry) {
|
||||||
|
SG_LOG(SG_NETWORK, SG_ALERT, "HLA: RTIFederateFactoryRegistry is no longer available!");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
switch (_version) {
|
switch (_version) {
|
||||||
case RTI13:
|
case RTI13:
|
||||||
_rtiFederate = new RTI13Federate(_connectArguments);
|
_rtiFederate = registry->create("RTI13", _connectArguments);
|
||||||
break;
|
break;
|
||||||
case RTI1516:
|
case RTI1516:
|
||||||
SG_LOG(SG_IO, SG_ALERT, "HLA version RTI1516 not yet(!?) supported.");
|
_rtiFederate = registry->create("RTI1516", _connectArguments);
|
||||||
// _rtiFederate = new RTI1516Federate(_connectArguments);
|
|
||||||
break;
|
break;
|
||||||
case RTI1516E:
|
case RTI1516E:
|
||||||
SG_LOG(SG_IO, SG_ALERT, "HLA version RTI1516E not yet(!?) supported.");
|
_rtiFederate = registry->create("RTI1516E", _connectArguments);
|
||||||
// _rtiFederate = new RTI1516eFederate(_connectArguments);
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
SG_LOG(SG_NETWORK, SG_WARN, "HLA: Unknown rti version in connect!");
|
SG_LOG(SG_NETWORK, SG_WARN, "HLA: Unknown rti version in connect!");
|
||||||
|
|||||||
@@ -0,0 +1,49 @@
|
|||||||
|
// Copyright (C) 2011 - 2012 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 "RTI13FederateFactory.hxx"
|
||||||
|
|
||||||
|
#include "RTI13Federate.hxx"
|
||||||
|
|
||||||
|
namespace simgear {
|
||||||
|
|
||||||
|
RTI13FederateFactory::RTI13FederateFactory()
|
||||||
|
{
|
||||||
|
_registerAtFactory();
|
||||||
|
}
|
||||||
|
|
||||||
|
RTI13FederateFactory::~RTI13FederateFactory()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
RTIFederate*
|
||||||
|
RTI13FederateFactory::create(const std::string& name, const std::list<std::string>& stringList) const
|
||||||
|
{
|
||||||
|
if (name != "RTI13")
|
||||||
|
return 0;
|
||||||
|
return new RTI13Federate(stringList);
|
||||||
|
}
|
||||||
|
|
||||||
|
const SGSharedPtr<RTI13FederateFactory>&
|
||||||
|
RTI13FederateFactory::instance()
|
||||||
|
{
|
||||||
|
static SGSharedPtr<RTI13FederateFactory> federateFactory = new RTI13FederateFactory;
|
||||||
|
return federateFactory;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
// Copyright (C) 2011 - 2012 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 RTI13FederateFactory_hxx
|
||||||
|
#define RTI13FederateFactory_hxx
|
||||||
|
|
||||||
|
#include "RTIFederateFactory.hxx"
|
||||||
|
|
||||||
|
#include "simgear/structure/SGSharedPtr.hxx"
|
||||||
|
|
||||||
|
namespace simgear {
|
||||||
|
|
||||||
|
class RTI13FederateFactory : public RTIFederateFactory {
|
||||||
|
public:
|
||||||
|
RTI13FederateFactory();
|
||||||
|
virtual ~RTI13FederateFactory();
|
||||||
|
|
||||||
|
virtual RTIFederate* create(const std::string& name, const std::list<std::string>& stringList) const;
|
||||||
|
|
||||||
|
static const SGSharedPtr<RTI13FederateFactory>& instance();
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
// Copyright (C) 2011 - 2012 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 "RTIFederateFactory.hxx"
|
||||||
|
|
||||||
|
#include "RTIFederateFactoryRegistry.hxx"
|
||||||
|
|
||||||
|
namespace simgear {
|
||||||
|
|
||||||
|
RTIFederateFactory::~RTIFederateFactory()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
RTIFederateFactory::_registerAtFactory()
|
||||||
|
{
|
||||||
|
SGSharedPtr<RTIFederateFactoryRegistry> registry = RTIFederateFactoryRegistry::instance();
|
||||||
|
if (!registry.valid())
|
||||||
|
return;
|
||||||
|
registry->registerFactory(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
// Copyright (C) 2011 - 2012 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 RTIFederateFactory_hxx
|
||||||
|
#define RTIFederateFactory_hxx
|
||||||
|
|
||||||
|
#include <list>
|
||||||
|
#include <string>
|
||||||
|
#include "simgear/structure/SGReferenced.hxx"
|
||||||
|
|
||||||
|
namespace simgear {
|
||||||
|
|
||||||
|
class RTIFederate;
|
||||||
|
|
||||||
|
class RTIFederateFactory : public SGReferenced {
|
||||||
|
public:
|
||||||
|
virtual ~RTIFederateFactory();
|
||||||
|
virtual RTIFederate* create(const std::string& name, const std::list<std::string>& stringList) const = 0;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void _registerAtFactory();
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
// Copyright (C) 2011 - 2012 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 "RTIFederateFactoryRegistry.hxx"
|
||||||
|
|
||||||
|
#include "simgear/threads/SGGuard.hxx"
|
||||||
|
#include "RTIFederate.hxx"
|
||||||
|
|
||||||
|
namespace simgear {
|
||||||
|
|
||||||
|
RTIFederateFactoryRegistry::RTIFederateFactoryRegistry()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
RTIFederateFactoryRegistry::~RTIFederateFactoryRegistry()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
SGSharedPtr<RTIFederate>
|
||||||
|
RTIFederateFactoryRegistry::create(const std::string& name, const std::list<std::string>& stringList) const
|
||||||
|
{
|
||||||
|
SGGuard<SGMutex> guard(_mutex);
|
||||||
|
for (FederateFactoryList::const_iterator i = _federateFactoryList.begin(); i != _federateFactoryList.end(); ++i) {
|
||||||
|
SGSharedPtr<RTIFederate> federate = (*i)->create(name, stringList);
|
||||||
|
if (!federate.valid())
|
||||||
|
continue;
|
||||||
|
return federate;
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
RTIFederateFactoryRegistry::registerFactory(RTIFederateFactory* factory)
|
||||||
|
{
|
||||||
|
SGGuard<SGMutex> guard(_mutex);
|
||||||
|
_federateFactoryList.push_back(factory);
|
||||||
|
}
|
||||||
|
|
||||||
|
const SGSharedPtr<RTIFederateFactoryRegistry>&
|
||||||
|
RTIFederateFactoryRegistry::instance()
|
||||||
|
{
|
||||||
|
static SGSharedPtr<RTIFederateFactoryRegistry> registry = new RTIFederateFactoryRegistry;
|
||||||
|
return registry;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
// Copyright (C) 2011 - 2012 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 RTIFederateFactoryRegistry_hxx
|
||||||
|
#define RTIFederateFactoryRegistry_hxx
|
||||||
|
|
||||||
|
#include <list>
|
||||||
|
#include <string>
|
||||||
|
#include "simgear/structure/SGReferenced.hxx"
|
||||||
|
#include "simgear/structure/SGSharedPtr.hxx"
|
||||||
|
#include "RTIFederateFactory.hxx"
|
||||||
|
|
||||||
|
#include "simgear/threads/SGThread.hxx"
|
||||||
|
|
||||||
|
namespace simgear {
|
||||||
|
|
||||||
|
class RTIFederateFactoryRegistry : public SGReferenced {
|
||||||
|
public:
|
||||||
|
~RTIFederateFactoryRegistry();
|
||||||
|
|
||||||
|
SGSharedPtr<RTIFederate> create(const std::string& name, const std::list<std::string>& stringList) const;
|
||||||
|
|
||||||
|
void registerFactory(RTIFederateFactory* factory);
|
||||||
|
|
||||||
|
static const SGSharedPtr<RTIFederateFactoryRegistry>& instance();
|
||||||
|
|
||||||
|
private:
|
||||||
|
RTIFederateFactoryRegistry();
|
||||||
|
|
||||||
|
RTIFederateFactoryRegistry(const RTIFederateFactoryRegistry&);
|
||||||
|
RTIFederateFactoryRegistry& operator=(const RTIFederateFactoryRegistry&);
|
||||||
|
|
||||||
|
mutable SGMutex _mutex;
|
||||||
|
typedef std::list<SGSharedPtr<RTIFederateFactory> > FederateFactoryList;
|
||||||
|
FederateFactoryList _federateFactoryList;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
Reference in New Issue
Block a user