hla: Provide createJoin and resignDestroy methods.

This commit is contained in:
Mathias Froehlich
2011-10-01 17:44:37 +02:00
parent 344f876b0a
commit 9e27511ef9
5 changed files with 322 additions and 74 deletions

View File

@@ -35,24 +35,106 @@ HLAFederate::~HLAFederate()
{
}
std::string
HLAFederate::getFederateType() const
HLAFederate::Version
HLAFederate::getVersion() const
{
if (!_rtiFederate.valid()) {
SG_LOG(SG_NETWORK, SG_WARN, "HLA: Accessing unconnected federate!");
return std::string();
}
return _rtiFederate->getFederateType();
return _version;
}
std::string
HLAFederate::getFederationName() const
bool
HLAFederate::setVersion(HLAFederate::Version version)
{
if (!_rtiFederate.valid()) {
SG_LOG(SG_NETWORK, SG_WARN, "HLA: Accessing unconnected federate!");
return std::string();
if (_rtiFederate.valid()) {
SG_LOG(SG_NETWORK, SG_ALERT, "HLA: Ignoring HLAFederate parameter setting on already connected federate!");
return false;
}
return _rtiFederate->getFederationName();
_version = version;
return true;
}
const std::list<std::string>&
HLAFederate::getConnectArguments() const
{
return _connectArguments;
}
bool
HLAFederate::setConnectArguments(const std::list<std::string>& connectArguments)
{
if (_rtiFederate.valid()) {
SG_LOG(SG_NETWORK, SG_ALERT, "HLA: Ignoring HLAFederate parameter setting on already connected federate!");
return false;
}
_connectArguments = connectArguments;
return true;
}
const std::string&
HLAFederate::getFederationExecutionName() const
{
return _federationExecutionName;
}
bool
HLAFederate::setFederationExecutionName(const std::string& federationExecutionName)
{
if (_rtiFederate.valid()) {
SG_LOG(SG_NETWORK, SG_ALERT, "HLA: Ignoring HLAFederate parameter setting on already connected federate!");
return false;
}
_federationExecutionName = federationExecutionName;
return true;
}
const std::string&
HLAFederate::getFederationObjectModel() const
{
return _federationObjectModel;
}
bool
HLAFederate::setFederationObjectModel(const std::string& federationObjectModel)
{
if (_rtiFederate.valid()) {
SG_LOG(SG_NETWORK, SG_ALERT, "HLA: Ignoring HLAFederate parameter setting on already connected federate!");
return false;
}
_federationObjectModel = federationObjectModel;
return true;
}
const std::string&
HLAFederate::getFederateType() const
{
return _federateType;
}
bool
HLAFederate::setFederateType(const std::string& federateType)
{
if (_rtiFederate.valid()) {
SG_LOG(SG_NETWORK, SG_ALERT, "HLA: Ignoring HLAFederate parameter setting on already connected federate!");
return false;
}
_federateType = federateType;
return true;
}
const std::string&
HLAFederate::getFederateName() const
{
return _federateName;
}
bool
HLAFederate::setFederateName(const std::string& federateName)
{
if (_rtiFederate.valid()) {
SG_LOG(SG_NETWORK, SG_ALERT, "HLA: Ignoring HLAFederate parameter setting on already connected federate!");
return false;
}
_federateName = federateName;
return true;
}
bool
@@ -65,6 +147,8 @@ HLAFederate::connect(Version version, const std::list<std::string>& stringList)
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.");
@@ -80,6 +164,31 @@ HLAFederate::connect(Version version, const std::list<std::string>& stringList)
return _rtiFederate.valid();
}
bool
HLAFederate::connect()
{
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(_connectArguments);
break;
case RTI1516:
SG_LOG(SG_IO, SG_ALERT, "HLA version RTI1516 not yet(!?) supported.");
// _rtiFederate = new RTI1516Federate(_connectArguments);
break;
case RTI1516E:
SG_LOG(SG_IO, SG_ALERT, "HLA version RTI1516E not yet(!?) supported.");
// _rtiFederate = new RTI1516eFederate(_connectArguments);
break;
default:
SG_LOG(SG_NETWORK, SG_WARN, "HLA: Unknown rti version in connect!");
}
return _rtiFederate.valid();
}
bool
HLAFederate::disconnect()
{
@@ -98,7 +207,15 @@ HLAFederate::createFederationExecution(const std::string& federation, const std:
SG_LOG(SG_NETWORK, SG_WARN, "HLA: Accessing unconnected federate!");
return false;
}
return _rtiFederate->createFederationExecution(federation, objectModel);
RTIFederate::FederationManagementResult createResult;
createResult = _rtiFederate->createFederationExecution(federation, objectModel);
if (createResult == RTIFederate::FederationManagementFatal)
return false;
_federationExecutionName = federation;
_federationObjectModel = objectModel;
return true;
}
bool
@@ -108,7 +225,45 @@ HLAFederate::destroyFederationExecution(const std::string& federation)
SG_LOG(SG_NETWORK, SG_WARN, "HLA: Accessing unconnected federate!");
return false;
}
return _rtiFederate->destroyFederationExecution(federation);
RTIFederate::FederationManagementResult destroyResult;
destroyResult = _rtiFederate->destroyFederationExecution(federation);
if (destroyResult == RTIFederate::FederationManagementFatal)
return false;
return true;
}
bool
HLAFederate::createFederationExecution()
{
if (!_rtiFederate.valid()) {
SG_LOG(SG_NETWORK, SG_WARN, "HLA: Accessing unconnected federate!");
return false;
}
RTIFederate::FederationManagementResult createResult;
createResult = _rtiFederate->createFederationExecution(_federationExecutionName, _federationObjectModel);
if (createResult != RTIFederate::FederationManagementSuccess)
return false;
return true;
}
bool
HLAFederate::destroyFederationExecution()
{
if (!_rtiFederate.valid()) {
SG_LOG(SG_NETWORK, SG_WARN, "HLA: Accessing unconnected federate!");
return false;
}
RTIFederate::FederationManagementResult destroyResult;
destroyResult = _rtiFederate->destroyFederationExecution(_federationExecutionName);
if (destroyResult != RTIFederate::FederationManagementSuccess)
return false;
return true;
}
bool
@@ -118,7 +273,29 @@ HLAFederate::join(const std::string& federateType, const std::string& federation
SG_LOG(SG_NETWORK, SG_WARN, "HLA: Accessing unconnected federate!");
return false;
}
return _rtiFederate->join(federateType, federation);
RTIFederate::FederationManagementResult joinResult;
joinResult = _rtiFederate->join(federateType, federation);
if (joinResult == RTIFederate::FederationManagementFatal)
return false;
return true;
}
bool
HLAFederate::join()
{
if (!_rtiFederate.valid()) {
SG_LOG(SG_NETWORK, SG_WARN, "HLA: Accessing unconnected federate!");
return false;
}
RTIFederate::FederationManagementResult joinResult;
joinResult = _rtiFederate->join(_federateType, _federationExecutionName);
if (joinResult != RTIFederate::FederationManagementSuccess)
return false;
return true;
}
bool
@@ -131,6 +308,61 @@ HLAFederate::resign()
return _rtiFederate->resign();
}
bool
HLAFederate::createJoinFederationExecution()
{
if (!_rtiFederate.valid()) {
SG_LOG(SG_NETWORK, SG_WARN, "HLA: Accessing unconnected federate!");
return false;
}
for (;;) {
// Try to join.
RTIFederate::FederationManagementResult joinResult;
joinResult = _rtiFederate->join(_federateType, _federationExecutionName);
switch (joinResult) {
case RTIFederate::FederationManagementSuccess:
// Fast return on success
return true;
case RTIFederate::FederationManagementFatal:
// Abort on fatal errors
return false;
default:
break;
};
// If not already joinable, try to create the requested federation
RTIFederate::FederationManagementResult createResult;
createResult = _rtiFederate->createFederationExecution(_federationExecutionName, _federationObjectModel);
switch (createResult) {
case RTIFederate::FederationManagementFatal:
// Abort on fatal errors
return false;
default:
// Try again to join
break;
}
}
}
bool
HLAFederate::resignDestroyFederationExecution()
{
if (!_rtiFederate.valid()) {
SG_LOG(SG_NETWORK, SG_WARN, "HLA: Accessing unconnected federate!");
return false;
}
// Resign ourselves
bool success = _rtiFederate->resign();
// and try to destroy, non fatal if still some federates joined
if (_rtiFederate->destroyFederationExecution(_federationExecutionName) == RTIFederate::FederationManagementFatal)
success = false;
return success;
}
bool
HLAFederate::enableTimeConstrained()
{

View File

@@ -32,33 +32,55 @@ class RTIFederate;
class HLAFederate : public SGWeakReferenced {
public:
HLAFederate();
virtual ~HLAFederate();
enum Version {
RTI13,
RTI1516,
RTI1516E
};
HLAFederate();
virtual ~HLAFederate();
Version getVersion() const;
bool setVersion(HLAFederate::Version version);
const std::list<std::string>& getConnectArguments() const;
bool setConnectArguments(const std::list<std::string>& connectArguments);
const std::string& getFederationExecutionName() const;
bool setFederationExecutionName(const std::string& federationExecutionName);
const std::string& getFederationObjectModel() const;
bool setFederationObjectModel(const std::string& federationObjectModel);
const std::string& getFederateType() const;
bool setFederateType(const std::string& federateType);
const std::string& getFederateName() const;
bool setFederateName(const std::string& federateName);
/// connect to an rti
bool connect(Version version, const std::list<std::string>& stringList);
bool connect();
bool disconnect();
/// Get the name of the joined federate/federation
std::string getFederateType() const;
std::string getFederationName() const;
/// Create a federation execution
/// Semantically this methods should be static,
/// but the nonstatic case could reuse the connection to the server
/// FIXME: cannot determine from the return value if we created the execution
bool createFederationExecution(const std::string& federation, const std::string& objectModel);
bool destroyFederationExecution(const std::string& federation);
bool createFederationExecution();
bool destroyFederationExecution();
/// Join with federateType the federation execution
bool join(const std::string& federateType, const std::string& federation);
bool join();
bool resign();
/// Try to create and join the federation execution.
bool createJoinFederationExecution();
bool resignDestroyFederationExecution();
bool enableTimeConstrained();
bool disableTimeConstrained();
@@ -108,6 +130,14 @@ public:
private:
SGSharedPtr<RTIFederate> _rtiFederate;
Version _version;
std::list<std::string> _connectArguments;
std::string _federationExecutionName;
std::string _federationObjectModel;
std::string _federateType;
std::string _federateName;
typedef std::map<std::string, SGSharedPtr<HLAObjectClass> > ObjectClassMap;
ObjectClassMap _objectClassMap;

View File

@@ -597,83 +597,81 @@ RTI13Federate::~RTI13Federate()
delete _federateAmbassador;
}
bool
RTI13Federate::FederationManagementResult
RTI13Federate::createFederationExecution(const std::string& federationName, const std::string& objectModel)
{
try {
_ambassador->createFederationExecution(federationName, objectModel);
return true;
return FederationManagementSuccess;
} catch (RTI::FederationExecutionAlreadyExists& e) {
return true;
return FederationManagementFail;
} catch (RTI::CouldNotOpenFED& e) {
SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not create federation execution: " << e._name << " " << e._reason);
return false;
return FederationManagementFatal;
} catch (RTI::ErrorReadingFED& e) {
SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not create federation execution: " << e._name << " " << e._reason);
return false;
return FederationManagementFatal;
} catch (RTI::ConcurrentAccessAttempted& e) {
SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not create federation execution: " << e._name << " " << e._reason);
return false;
return FederationManagementFatal;
} catch (RTI::RTIinternalError& e) {
SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not create federation execution: " << e._name << " " << e._reason);
return false;
return FederationManagementFatal;
}
}
bool
RTI13Federate::FederationManagementResult
RTI13Federate::destroyFederationExecution(const std::string& federation)
{
try {
_ambassador->destroyFederationExecution(federation);
return true;
return FederationManagementSuccess;
} catch (RTI::FederatesCurrentlyJoined& e) {
return true;
return FederationManagementFail;
} catch (RTI::FederationExecutionDoesNotExist& e) {
return true;
return FederationManagementFail;
} catch (RTI::ConcurrentAccessAttempted& e) {
SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not destroy federation execution: " << e._name << " " << e._reason);
return false;
return FederationManagementFatal;
} catch (RTI::RTIinternalError& e) {
SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not destroy federation execution: " << e._name << " " << e._reason);
return false;
return FederationManagementFatal;
}
}
bool
RTI13Federate::FederationManagementResult
RTI13Federate::join(const std::string& federateType, const std::string& federationName)
{
try {
_federateHandle = _ambassador->joinFederationExecution(federateType, federationName, _federateAmbassador);
SG_LOG(SG_NETWORK, SG_INFO, "RTI: Joined federation \""
<< federationName << "\" as \"" << federateType << "\"");
setFederateType(federateType);
setFederationName(federationName);
_joined = true;
return true;
return FederationManagementSuccess;
} catch (RTI::FederateAlreadyExecutionMember& e) {
SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not join federation execution: " << e._name << " " << e._reason);
return false;
return FederationManagementFatal;
} catch (RTI::FederationExecutionDoesNotExist& e) {
SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not join federation execution: " << e._name << " " << e._reason);
return false;
return FederationManagementFail;
} catch (RTI::CouldNotOpenFED& e) {
SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not join federation execution: " << e._name << " " << e._reason);
return false;
return FederationManagementFatal;
} catch (RTI::ErrorReadingFED& e) {
SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not join federation execution: " << e._name << " " << e._reason);
return false;
return FederationManagementFatal;
} catch (RTI::ConcurrentAccessAttempted& e) {
SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not join federation execution: " << e._name << " " << e._reason);
return false;
return FederationManagementFatal;
} catch (RTI::SaveInProgress& e) {
SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not join federation execution: " << e._name << " " << e._reason);
return false;
return FederationManagementFatal;
} catch (RTI::RestoreInProgress& e) {
SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not join federation execution: " << e._name << " " << e._reason);
return false;
return FederationManagementFatal;
} catch (RTI::RTIinternalError& e) {
SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not join federation execution: " << e._name << " " << e._reason);
return false;
return FederationManagementFatal;
}
}

View File

@@ -37,11 +37,13 @@ public:
RTI13Federate(const std::list<std::string>& stringList);
virtual ~RTI13Federate();
virtual bool createFederationExecution(const std::string& federation, const std::string& objectModel);
virtual bool destroyFederationExecution(const std::string& federation);
/// Create a federation execution
/// Semantically this methods should be static,
virtual FederationManagementResult createFederationExecution(const std::string& federation, const std::string& objectModel);
virtual FederationManagementResult destroyFederationExecution(const std::string& federation);
/// Join with federateName the federation execution federation
virtual bool join(const std::string& federateType, const std::string& federation);
virtual FederationManagementResult join(const std::string& federateType, const std::string& federation);
virtual bool resign();
/// Synchronization Point handling

View File

@@ -32,21 +32,19 @@ public:
RTIFederate();
virtual ~RTIFederate();
/// Get the name of the joined federate/federation
const std::string& getFederateType() const
{ return _federateType; }
const std::string& getFederationName() const
{ return _federationName; }
/// Create a federation execution
/// Semantically this methods should be static,
/// but the nonstatic case could reuse the connection to the server
/// FIXME: cannot determine from the return value if we created the execution
virtual bool createFederationExecution(const std::string& federation, const std::string& objectModel) = 0;
virtual bool destroyFederationExecution(const std::string& federation) = 0;
enum FederationManagementResult {
FederationManagementSuccess,
FederationManagementFail,
FederationManagementFatal
};
virtual FederationManagementResult createFederationExecution(const std::string& federation, const std::string& objectModel) = 0;
virtual FederationManagementResult destroyFederationExecution(const std::string& federation) = 0;
/// Join with federateName the federation execution federation
virtual bool join(const std::string& federateType, const std::string& federation) = 0;
virtual FederationManagementResult join(const std::string& federateType, const std::string& federation) = 0;
virtual bool resign() = 0;
/// Synchronization Point handling
@@ -81,21 +79,9 @@ public:
virtual RTIObjectInstance* getObjectInstance(const std::string& name) = 0;
protected:
void setFederateType(const std::string& federateType)
{ _federateType = federateType; }
void setFederationName(const std::string& federationName)
{ _federationName = federationName; }
private:
RTIFederate(const RTIFederate&);
RTIFederate& operator=(const RTIFederate&);
/// The federates name
std::string _federateType;
/// The federation execution name
std::string _federationName;
};
}