X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=simgear%2Fhla%2FRTI13Federate.cxx;h=9ceb828332938cfdb4b77f56f651a779f615ef5b;hb=6672a1212cfccb2a08be21ff5271eae9b6f91b2a;hp=32913c233f28055c2a91971e128ca2a52c4b2850;hpb=bd999ca090853e68acb7b0f4aab3d875afd8c010;p=simgear.git diff --git a/simgear/hla/RTI13Federate.cxx b/simgear/hla/RTI13Federate.cxx index 32913c23..9ceb8283 100644 --- a/simgear/hla/RTI13Federate.cxx +++ b/simgear/hla/RTI13Federate.cxx @@ -1,4 +1,4 @@ -// Copyright (C) 2009 - 2011 Mathias Froehlich - Mathias.Froehlich@web.de +// Copyright (C) 2009 - 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 @@ -15,6 +15,12 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // +#ifdef HAVE_CONFIG_H +# include +#endif + +#include + #include "RTI13Federate.hxx" #include "RTI13Ambassador.hxx" @@ -41,6 +47,27 @@ struct RTI13Federate::FederateAmbassador : public RTI::FederateAmbassador { { } + /// Generic callback to execute some notification on objects in a way that they are not prone to + /// ConcurrentAccess exceptions. + class QueueCallback : public SGReferenced { + public: + virtual ~QueueCallback() {} + virtual void operator()(FederateAmbassador& self) = 0; + }; + class TagQueueCallback : public QueueCallback { + public: + TagQueueCallback(const char* tag) + { + if (tag) + _tag.setData(tag, std::strlen(tag) + 1); + else + _tag.setData("", 1); + } + virtual ~TagQueueCallback() + { } + RTIData _tag; + }; + /// RTI federate ambassador callback functions. virtual void synchronizationPointRegistrationSucceeded(const char* label) throw (RTI::FederateInternalError) @@ -115,9 +142,21 @@ struct RTI13Federate::FederateAmbassador : public RTI::FederateAmbassador { } // Declaration Management + class StartRegistrationForObjectClassCallback : public QueueCallback { + public: + StartRegistrationForObjectClassCallback(RTI::ObjectClassHandle objectClassHandle) : + _objectClassHandle(objectClassHandle) + { } + virtual void operator()(FederateAmbassador& self) + { self.startRegistrationForObjectClassCallback(_objectClassHandle); } + private: + RTI::ObjectClassHandle _objectClassHandle; + }; virtual void startRegistrationForObjectClass(RTI::ObjectClassHandle objectClassHandle) throw (RTI::ObjectClassNotPublished, RTI::FederateInternalError) + { _queueCallbackList.push_back(new StartRegistrationForObjectClassCallback(objectClassHandle)); } + void startRegistrationForObjectClassCallback(RTI::ObjectClassHandle objectClassHandle) { ObjectClassMap::iterator i = _objectClassMap.find(objectClassHandle); if (i == _objectClassMap.end()) @@ -127,9 +166,21 @@ struct RTI13Federate::FederateAmbassador : public RTI::FederateAmbassador { i->second->startRegistration(); } + class StopRegistrationForObjectClassCallback : public QueueCallback { + public: + StopRegistrationForObjectClassCallback(RTI::ObjectClassHandle objectClassHandle) : + _objectClassHandle(objectClassHandle) + { } + virtual void operator()(FederateAmbassador& self) + { self.stopRegistrationForObjectClassCallback(_objectClassHandle); } + private: + RTI::ObjectClassHandle _objectClassHandle; + }; virtual void stopRegistrationForObjectClass(RTI::ObjectClassHandle objectClassHandle) throw (RTI::ObjectClassNotPublished, RTI::FederateInternalError) + { _queueCallbackList.push_back(new StopRegistrationForObjectClassCallback(objectClassHandle)); } + void stopRegistrationForObjectClassCallback(RTI::ObjectClassHandle objectClassHandle) { ObjectClassMap::iterator i = _objectClassMap.find(objectClassHandle); if (i == _objectClassMap.end()) @@ -151,23 +202,58 @@ struct RTI13Federate::FederateAmbassador : public RTI::FederateAmbassador { { } - // Object Management + class DiscoverObjectCallback : public TagQueueCallback { + public: + DiscoverObjectCallback(RTI::ObjectHandle objectHandle, RTI::ObjectClassHandle objectClassHandle, const char *tag) : + TagQueueCallback(tag), + _objectHandle(objectHandle), + _objectClassHandle(objectClassHandle) + { } + virtual void operator()(FederateAmbassador& self) + { self.discoverObjectInstanceCallback(_objectHandle, _objectClassHandle, _tag); } + private: + RTI::ObjectHandle _objectHandle; + RTI::ObjectClassHandle _objectClassHandle; + }; virtual void discoverObjectInstance(RTI::ObjectHandle objectHandle, RTI::ObjectClassHandle objectClassHandle, const char* tag) throw (RTI::CouldNotDiscover, RTI::ObjectClassNotKnown, RTI::FederateInternalError) + { _queueCallbackList.push_back(new DiscoverObjectCallback(objectHandle, objectClassHandle, tag)); } + void discoverObjectInstanceCallback(RTI::ObjectHandle objectHandle, RTI::ObjectClassHandle objectClassHandle, const RTIData& tag) { ObjectClassMap::iterator i = _objectClassMap.find(objectClassHandle); if (i == _objectClassMap.end()) - throw RTI::ObjectClassNotKnown("Federate: discoverObjectInstance()!"); + return; if (!i->second.valid()) return; - SGSharedPtr objectInstance = new RTI13ObjectInstance(objectHandle, 0, i->second, _rtiAmbassador.get(), false); + SGSharedPtr objectInstance = new RTI13ObjectInstance(objectHandle, 0, i->second, _rtiAmbassador.get()); _objectInstanceMap[objectHandle] = objectInstance; - _queueCallbackList.push_back(new DiscoverObjectCallback(i->second, objectInstance, tagToData(tag))); + i->second->discoverInstance(objectInstance.get(), tag); } + class ReflectAttributeValuesTimestampCallback : public TagQueueCallback { + public: + ReflectAttributeValuesTimestampCallback(RTI::ObjectHandle objectHandle, + RTI13AttributeHandleDataPairList& attributeHandleDataPairList, + const SGTimeStamp& timeStamp, const char *tag) : + TagQueueCallback(tag), + _objectHandle(objectHandle), + _timeStamp(timeStamp) + { + _attributeHandleDataPairList.swap(attributeHandleDataPairList); + } + virtual void operator()(FederateAmbassador& self) + { + self.reflectAttributeValuesCallback(_objectHandle, _attributeHandleDataPairList, _timeStamp, _tag); + self.freeAttributeHandleDataPairList(_attributeHandleDataPairList); + } + private: + RTI::ObjectHandle _objectHandle; + RTI13AttributeHandleDataPairList _attributeHandleDataPairList; + SGTimeStamp _timeStamp; + }; virtual void reflectAttributeValues(RTI::ObjectHandle objectHandle, const RTI::AttributeHandleValuePairSet& attributeValuePairSet, const RTI::FedTime& fedTime, const char* tag, RTI::EventRetractionHandle eventRetractionHandle) throw (RTI::ObjectNotKnown, @@ -175,28 +261,79 @@ struct RTI13Federate::FederateAmbassador : public RTI::FederateAmbassador { RTI::FederateOwnsAttributes, RTI::InvalidFederationTime, RTI::FederateInternalError) + { + RTI13AttributeHandleDataPairList attributeHandleDataPairList; + + RTI::ULong numAttribs = attributeValuePairSet.size(); + for (RTI::ULong i = 0; i < numAttribs; ++i) { + appendAttributeHandleDataPair(attributeHandleDataPairList); + attributeHandleDataPairList.back().first = attributeValuePairSet.getHandle(i); + RTI::ULong length = attributeValuePairSet.getValueLength(i); + attributeHandleDataPairList.back().second.resize(length); + attributeValuePairSet.getValue(i, attributeHandleDataPairList.back().second.data(), length); + } + + _queueCallbackList.push_back(new ReflectAttributeValuesTimestampCallback(objectHandle, attributeHandleDataPairList, + RTI13Ambassador::toTimeStamp(fedTime), tag)); + } + void reflectAttributeValuesCallback(RTI::ObjectHandle objectHandle, RTI13AttributeHandleDataPairList& attributeHandleDataPairList, + const SGTimeStamp& timeStamp, const RTIData& tag) { ObjectInstanceMap::iterator i = _objectInstanceMap.find(objectHandle); if (i == _objectInstanceMap.end()) - throw RTI::ObjectNotKnown("Reflect attributes for unknown object!"); + return; if (!i->second.valid()) return; - i->second->reflectAttributeValues(attributeValuePairSet, RTI13Ambassador::toTimeStamp(fedTime), tagToData(tag)); + i->second->reflectAttributeValues(attributeHandleDataPairList, timeStamp, tag, _indexPool); } + class ReflectAttributeValuesCallback : public TagQueueCallback { + public: + ReflectAttributeValuesCallback(RTI::ObjectHandle objectHandle, RTI13AttributeHandleDataPairList& attributeHandleDataPairList, + const char *tag) : + TagQueueCallback(tag), + _objectHandle(objectHandle) + { + _attributeHandleDataPairList.swap(attributeHandleDataPairList); + } + virtual void operator()(FederateAmbassador& self) + { + self.reflectAttributeValuesCallback(_objectHandle, _attributeHandleDataPairList, _tag); + self.freeAttributeHandleDataPairList(_attributeHandleDataPairList); + } + private: + RTI::ObjectHandle _objectHandle; + RTI13AttributeHandleDataPairList _attributeHandleDataPairList; + }; virtual void reflectAttributeValues(RTI::ObjectHandle objectHandle, const RTI::AttributeHandleValuePairSet& attributeValuePairSet, const char* tag) throw (RTI::ObjectNotKnown, RTI::AttributeNotKnown, RTI::FederateOwnsAttributes, RTI::FederateInternalError) + { + RTI13AttributeHandleDataPairList attributeHandleDataPairList; + + RTI::ULong numAttribs = attributeValuePairSet.size(); + for (RTI::ULong i = 0; i < numAttribs; ++i) { + appendAttributeHandleDataPair(attributeHandleDataPairList); + attributeHandleDataPairList.back().first = attributeValuePairSet.getHandle(i); + RTI::ULong length = attributeValuePairSet.getValueLength(i); + attributeHandleDataPairList.back().second.resize(length); + attributeValuePairSet.getValue(i, attributeHandleDataPairList.back().second.data(), length); + } + + _queueCallbackList.push_back(new ReflectAttributeValuesCallback(objectHandle, attributeHandleDataPairList, tag)); + } + void reflectAttributeValuesCallback(RTI::ObjectHandle objectHandle, RTI13AttributeHandleDataPairList& attributeHandleDataPairList, + const RTIData& tag) { ObjectInstanceMap::iterator i = _objectInstanceMap.find(objectHandle); if (i == _objectInstanceMap.end()) - throw RTI::ObjectNotKnown("Reflect attributes for unknown object!"); + return; if (!i->second.valid()) return; - i->second->reflectAttributeValues(attributeValuePairSet, tagToData(tag)); + i->second->reflectAttributeValues(attributeHandleDataPairList, tag, _indexPool); } virtual void receiveInteraction(RTI::InteractionClassHandle interactionClassHandle, const RTI::ParameterHandleValuePairSet& parameters, @@ -216,99 +353,202 @@ struct RTI13Federate::FederateAmbassador : public RTI::FederateAmbassador { { } + class RemoveObjectTimestampCallback : public TagQueueCallback { + public: + RemoveObjectTimestampCallback(RTI::ObjectHandle objectHandle, const SGTimeStamp& timeStamp, const char* tag) : + TagQueueCallback(tag), + _objectHandle(objectHandle), + _timeStamp(timeStamp) + { } + virtual void operator()(FederateAmbassador& self) + { self.removeObjectInstanceCallback(_objectHandle, _timeStamp, _tag); } + private: + RTI::ObjectHandle _objectHandle; + SGTimeStamp _timeStamp; + }; virtual void removeObjectInstance(RTI::ObjectHandle objectHandle, const RTI::FedTime& fedTime, const char* tag, RTI::EventRetractionHandle eventRetractionHandle) throw (RTI::ObjectNotKnown, RTI::InvalidFederationTime, RTI::FederateInternalError) + { _queueCallbackList.push_back(new RemoveObjectTimestampCallback(objectHandle, RTI13Ambassador::toTimeStamp(fedTime), tag)); } + void removeObjectInstanceCallback(RTI::ObjectHandle objectHandle, const SGTimeStamp& timeStamp, const RTIData& tag) { ObjectInstanceMap::iterator i = _objectInstanceMap.find(objectHandle); if (i == _objectInstanceMap.end()) - throw RTI::ObjectNotKnown("Federate: removeObjectInstance()!"); + return; if (i->second.valid()) - _queueCallbackList.push_back(new RemoveObjectCallback(i->second, tagToData(tag))); + i->second->removeInstance(tag); _objectInstanceMap.erase(i); } + class RemoveObjectCallback : public TagQueueCallback { + public: + RemoveObjectCallback(RTI::ObjectHandle objectHandle, const char* tag) : + TagQueueCallback(tag), + _objectHandle(objectHandle) + { } + virtual void operator()(FederateAmbassador& self) + { self.removeObjectInstanceCallback(_objectHandle, _tag); } + private: + RTI::ObjectHandle _objectHandle; + }; virtual void removeObjectInstance(RTI::ObjectHandle objectHandle, const char* tag) throw (RTI::ObjectNotKnown, RTI::FederateInternalError) + { _queueCallbackList.push_back(new RemoveObjectCallback(objectHandle, tag)); } + void removeObjectInstanceCallback(RTI::ObjectHandle objectHandle, const RTIData& tag) { ObjectInstanceMap::iterator i = _objectInstanceMap.find(objectHandle); if (i == _objectInstanceMap.end()) - throw RTI::ObjectNotKnown("Federate: removeObjectInstance()!"); + return; if (i->second.valid()) - _queueCallbackList.push_back(new RemoveObjectCallback(i->second, tagToData(tag))); + i->second->removeInstance(tag); _objectInstanceMap.erase(i); } + class AttributeHandleSetCallback : public QueueCallback { + public: + AttributeHandleSetCallback(RTI::ObjectHandle objectHandle, const RTI::AttributeHandleSet& attributeHandleSet) : + _objectHandle(objectHandle) + { + RTI::ULong numAttribs = attributeHandleSet.size(); + _attributes.reserve(numAttribs); + for (RTI::ULong i = 0; i < numAttribs; ++i) + _attributes.push_back(attributeHandleSet.getHandle(i)); + } + protected: + RTI::ObjectHandle _objectHandle; + std::vector _attributes; + }; + class AttributesInScopeCallback : public AttributeHandleSetCallback { + public: + AttributesInScopeCallback(RTI::ObjectHandle objectHandle, const RTI::AttributeHandleSet& attributes) : + AttributeHandleSetCallback(objectHandle, attributes) + { } + virtual void operator()(FederateAmbassador& self) + { self.attributesInScopeCallback(_objectHandle, _attributes); } + }; virtual void attributesInScope(RTI::ObjectHandle objectHandle, const RTI::AttributeHandleSet& attributes) throw (RTI::ObjectNotKnown, RTI::AttributeNotKnown, RTI::FederateInternalError) + { _queueCallbackList.push_back(new AttributesInScopeCallback(objectHandle, attributes)); } + void attributesInScopeCallback(RTI::ObjectHandle objectHandle, const std::vector& attributes) { ObjectInstanceMap::iterator i = _objectInstanceMap.find(objectHandle); if (i == _objectInstanceMap.end()) - throw RTI::ObjectNotKnown("Attributes in scope for unknown object!"); + return; if (!i->second.valid()) return; i->second->attributesInScope(attributes); } + class AttributesOutOfScopeCallback : public AttributeHandleSetCallback { + public: + AttributesOutOfScopeCallback(RTI::ObjectHandle objectHandle, const RTI::AttributeHandleSet& attributes) : + AttributeHandleSetCallback(objectHandle, attributes) + { } + virtual void operator()(FederateAmbassador& self) + { self.attributesOutOfScopeCallback(_objectHandle, _attributes); } + }; virtual void attributesOutOfScope(RTI::ObjectHandle objectHandle, const RTI::AttributeHandleSet& attributes) throw (RTI::ObjectNotKnown, RTI::AttributeNotKnown, RTI::FederateInternalError) + { _queueCallbackList.push_back(new AttributesOutOfScopeCallback(objectHandle, attributes)); } + void attributesOutOfScopeCallback(RTI::ObjectHandle objectHandle, const std::vector& attributes) { ObjectInstanceMap::iterator i = _objectInstanceMap.find(objectHandle); if (i == _objectInstanceMap.end()) - throw RTI::ObjectNotKnown("Attributes in scope for unknown object!"); + return; if (!i->second.valid()) return; i->second->attributesOutOfScope(attributes); } + class ProvideAttributeValueUpdateCallback : public AttributeHandleSetCallback { + public: + ProvideAttributeValueUpdateCallback(RTI::ObjectHandle objectHandle, const RTI::AttributeHandleSet& attributes) : + AttributeHandleSetCallback(objectHandle, attributes) + { } + virtual void operator()(FederateAmbassador& self) + { self.provideAttributeValueUpdateCallback(_objectHandle, _attributes); } + }; virtual void provideAttributeValueUpdate(RTI::ObjectHandle objectHandle, const RTI::AttributeHandleSet& attributes) throw (RTI::ObjectNotKnown, RTI::AttributeNotKnown, RTI::AttributeNotOwned, RTI::FederateInternalError) + { _queueCallbackList.push_back(new ProvideAttributeValueUpdateCallback(objectHandle, attributes)); } + void provideAttributeValueUpdateCallback(RTI::ObjectHandle objectHandle, const std::vector& attributes) { ObjectInstanceMap::iterator i = _objectInstanceMap.find(objectHandle); if (i == _objectInstanceMap.end()) - throw RTI::ObjectNotKnown("Reflect attributes for unknown object!"); + return; if (!i->second.valid()) return; i->second->provideAttributeValueUpdate(attributes); } + class TurnUpdatesOnForObjectInstanceCallback : public AttributeHandleSetCallback { + public: + TurnUpdatesOnForObjectInstanceCallback(RTI::ObjectHandle objectHandle, const RTI::AttributeHandleSet& attributes) : + AttributeHandleSetCallback(objectHandle, attributes) + { } + virtual void operator()(FederateAmbassador& self) + { self.turnUpdatesOnForObjectInstanceCallback(_objectHandle, _attributes); } + }; virtual void turnUpdatesOnForObjectInstance(RTI::ObjectHandle objectHandle, const RTI::AttributeHandleSet& attributes) throw (RTI::ObjectNotKnown, RTI::AttributeNotOwned, RTI::FederateInternalError) + { _queueCallbackList.push_back(new TurnUpdatesOnForObjectInstanceCallback(objectHandle, attributes)); } + void turnUpdatesOnForObjectInstanceCallback(RTI::ObjectHandle objectHandle, const std::vector& attributes) { ObjectInstanceMap::iterator i = _objectInstanceMap.find(objectHandle); if (i == _objectInstanceMap.end()) - throw RTI::ObjectNotKnown("Turn on attributes for unknown object!"); + return; if (!i->second.valid()) return; i->second->turnUpdatesOnForObjectInstance(attributes); } + class TurnUpdatesOffForObjectInstanceCallback : public AttributeHandleSetCallback { + public: + TurnUpdatesOffForObjectInstanceCallback(RTI::ObjectHandle objectHandle, const RTI::AttributeHandleSet& attributes) : + AttributeHandleSetCallback(objectHandle, attributes) + { } + virtual void operator()(FederateAmbassador& self) + { self.turnUpdatesOffForObjectInstanceCallback(_objectHandle, _attributes); } + }; virtual void turnUpdatesOffForObjectInstance(RTI::ObjectHandle objectHandle, const RTI::AttributeHandleSet& attributes) throw (RTI::ObjectNotKnown, RTI::AttributeNotOwned, RTI::FederateInternalError) + { _queueCallbackList.push_back(new TurnUpdatesOffForObjectInstanceCallback(objectHandle, attributes)); } + void turnUpdatesOffForObjectInstanceCallback(RTI::ObjectHandle objectHandle, const std::vector& attributes) { ObjectInstanceMap::iterator i = _objectInstanceMap.find(objectHandle); if (i == _objectInstanceMap.end()) - throw RTI::ObjectNotKnown("Turn off attributes for unknown object!"); + return; if (!i->second.valid()) return; i->second->turnUpdatesOffForObjectInstance(attributes); } // Ownership Management + class RequestAttributeOwnershipAssumptionCallback : public AttributeHandleSetCallback { + public: + RequestAttributeOwnershipAssumptionCallback(RTI::ObjectHandle objectHandle, const RTI::AttributeHandleSet& attributes, const RTIData& tag) : + AttributeHandleSetCallback(objectHandle, attributes), + _tag(tag) + { } + virtual void operator()(FederateAmbassador& self) + { self.requestAttributeOwnershipAssumptionCallback(_objectHandle, _attributes, _tag); } + protected: + RTIData _tag; + }; virtual void requestAttributeOwnershipAssumption(RTI::ObjectHandle objectHandle, const RTI::AttributeHandleSet& attributes, const char* tag) throw (RTI::ObjectNotKnown, @@ -316,30 +556,50 @@ struct RTI13Federate::FederateAmbassador : public RTI::FederateAmbassador { RTI::AttributeAlreadyOwned, RTI::AttributeNotPublished, RTI::FederateInternalError) + { _queueCallbackList.push_back(new RequestAttributeOwnershipAssumptionCallback(objectHandle, attributes, tagToData(tag))); } + void requestAttributeOwnershipAssumptionCallback(RTI::ObjectHandle objectHandle, std::vector& attributes, const RTIData& tag) { ObjectInstanceMap::iterator i = _objectInstanceMap.find(objectHandle); if (i == _objectInstanceMap.end()) - throw RTI::ObjectNotKnown("requestAttributeOwnershipAssumption for unknown object!"); + return; if (!i->second.valid()) return; - i->second->requestAttributeOwnershipAssumption(attributes, tagToData(tag)); + i->second->requestAttributeOwnershipAssumption(attributes, tag); } + class AttributeOwnershipDivestitureNotificationCallback : public AttributeHandleSetCallback { + public: + AttributeOwnershipDivestitureNotificationCallback(RTI::ObjectHandle objectHandle, const RTI::AttributeHandleSet& attributes) : + AttributeHandleSetCallback(objectHandle, attributes) + { } + virtual void operator()(FederateAmbassador& self) + { self.attributeOwnershipDivestitureNotificationCallback(_objectHandle, _attributes); } + }; virtual void attributeOwnershipDivestitureNotification(RTI::ObjectHandle objectHandle, const RTI::AttributeHandleSet& attributes) throw (RTI::ObjectNotKnown, RTI::AttributeNotKnown, RTI::AttributeNotOwned, RTI::AttributeDivestitureWasNotRequested, RTI::FederateInternalError) + { _queueCallbackList.push_back(new AttributeOwnershipDivestitureNotificationCallback(objectHandle, attributes)); } + void attributeOwnershipDivestitureNotificationCallback(RTI::ObjectHandle objectHandle, const std::vector& attributes) { ObjectInstanceMap::iterator i = _objectInstanceMap.find(objectHandle); if (i == _objectInstanceMap.end()) - throw RTI::ObjectNotKnown("attributeOwnershipDivestitureNotification for unknown object!"); + return; if (!i->second.valid()) return; i->second->attributeOwnershipDivestitureNotification(attributes); } + class AttributeOwnershipAcquisitionNotificationCallback : public AttributeHandleSetCallback { + public: + AttributeOwnershipAcquisitionNotificationCallback(RTI::ObjectHandle objectHandle, const RTI::AttributeHandleSet& attributes) : + AttributeHandleSetCallback(objectHandle, attributes) + { } + virtual void operator()(FederateAmbassador& self) + { self.attributeOwnershipAcquisitionNotificationCallback(_objectHandle, _attributes); } + }; virtual void attributeOwnershipAcquisitionNotification(RTI::ObjectHandle objectHandle, const RTI::AttributeHandleSet& attributes) throw (RTI::ObjectNotKnown, RTI::AttributeNotKnown, @@ -347,95 +607,174 @@ struct RTI13Federate::FederateAmbassador : public RTI::FederateAmbassador { RTI::AttributeAlreadyOwned, RTI::AttributeNotPublished, RTI::FederateInternalError) + { _queueCallbackList.push_back(new AttributeOwnershipAcquisitionNotificationCallback(objectHandle, attributes)); } + void attributeOwnershipAcquisitionNotificationCallback(RTI::ObjectHandle objectHandle, const std::vector& attributes) { ObjectInstanceMap::iterator i = _objectInstanceMap.find(objectHandle); if (i == _objectInstanceMap.end()) - throw RTI::ObjectNotKnown("attributeOwnershipAcquisitionNotification for unknown object!"); + return; if (!i->second.valid()) return; i->second->attributeOwnershipAcquisitionNotification(attributes); } + class AttributeOwnershipUnavailableCallback : public AttributeHandleSetCallback { + public: + AttributeOwnershipUnavailableCallback(RTI::ObjectHandle objectHandle, const RTI::AttributeHandleSet& attributes) : + AttributeHandleSetCallback(objectHandle, attributes) + { } + virtual void operator()(FederateAmbassador& self) + { self.attributeOwnershipUnavailableCallback(_objectHandle, _attributes); } + }; virtual void attributeOwnershipUnavailable(RTI::ObjectHandle objectHandle, const RTI::AttributeHandleSet& attributes) throw (RTI::ObjectNotKnown, RTI::AttributeNotKnown, RTI::AttributeAlreadyOwned, RTI::AttributeAcquisitionWasNotRequested, RTI::FederateInternalError) + { _queueCallbackList.push_back(new AttributeOwnershipUnavailableCallback(objectHandle, attributes)); } + void attributeOwnershipUnavailableCallback(RTI::ObjectHandle objectHandle, const std::vector& attributes) { ObjectInstanceMap::iterator i = _objectInstanceMap.find(objectHandle); if (i == _objectInstanceMap.end()) - throw RTI::ObjectNotKnown("attributeOwnershipUnavailable for unknown object!"); + return; if (!i->second.valid()) return; i->second->attributeOwnershipUnavailable(attributes); } + class RequestAttributeOwnershipReleaseCallback : public AttributeHandleSetCallback { + public: + RequestAttributeOwnershipReleaseCallback(RTI::ObjectHandle objectHandle, const RTI::AttributeHandleSet& attributes, const RTIData& tag) : + AttributeHandleSetCallback(objectHandle, attributes), + _tag(tag) + { } + virtual void operator()(FederateAmbassador& self) + { self.requestAttributeOwnershipReleaseCallback(_objectHandle, _attributes, _tag); } + protected: + RTIData _tag; + }; virtual void requestAttributeOwnershipRelease(RTI::ObjectHandle objectHandle, const RTI::AttributeHandleSet& attributes, const char* tag) throw (RTI::ObjectNotKnown, RTI::AttributeNotKnown, RTI::AttributeNotOwned, RTI::FederateInternalError) + { _queueCallbackList.push_back(new RequestAttributeOwnershipReleaseCallback(objectHandle, attributes, tagToData(tag))); } + void requestAttributeOwnershipReleaseCallback(RTI::ObjectHandle objectHandle, std::vector& attributes, const RTIData& tag) { ObjectInstanceMap::iterator i = _objectInstanceMap.find(objectHandle); if (i == _objectInstanceMap.end()) - throw RTI::ObjectNotKnown("requestAttributeOwnershipRelease for unknown object!"); + return; if (!i->second.valid()) return; - i->second->requestAttributeOwnershipRelease(attributes, tagToData(tag)); + i->second->requestAttributeOwnershipRelease(attributes, tag); } + class ConfirmAttributeOwnershipAcquisitionCancellationCallback : public AttributeHandleSetCallback { + public: + ConfirmAttributeOwnershipAcquisitionCancellationCallback(RTI::ObjectHandle objectHandle, const RTI::AttributeHandleSet& attributes) : + AttributeHandleSetCallback(objectHandle, attributes) + { } + virtual void operator()(FederateAmbassador& self) + { self.confirmAttributeOwnershipAcquisitionCancellationCallback(_objectHandle, _attributes); } + }; virtual void confirmAttributeOwnershipAcquisitionCancellation(RTI::ObjectHandle objectHandle, const RTI::AttributeHandleSet& attributes) throw (RTI::ObjectNotKnown, RTI::AttributeNotKnown, RTI::AttributeAlreadyOwned, RTI::AttributeAcquisitionWasNotCanceled, RTI::FederateInternalError) + { _queueCallbackList.push_back(new ConfirmAttributeOwnershipAcquisitionCancellationCallback(objectHandle, attributes)); } + void confirmAttributeOwnershipAcquisitionCancellationCallback(RTI::ObjectHandle objectHandle, const std::vector& attributes) { ObjectInstanceMap::iterator i = _objectInstanceMap.find(objectHandle); if (i == _objectInstanceMap.end()) - throw RTI::ObjectNotKnown("confirmAttributeOwnershipAcquisitionCancellation for unknown object!"); + return; if (!i->second.valid()) return; i->second->confirmAttributeOwnershipAcquisitionCancellation(attributes); } + class InformAttributeOwnershipCallback : public QueueCallback { + public: + InformAttributeOwnershipCallback(RTI::ObjectHandle objectHandle, RTI::AttributeHandle attributeHandle, RTI::FederateHandle federateHandle) : + _objectHandle(objectHandle), + _attributeHandle(attributeHandle), + _federateHandle(federateHandle) + { } + virtual void operator()(FederateAmbassador& self) + { self.informAttributeOwnershipCallback(_objectHandle, _attributeHandle, _federateHandle); } + private: + RTI::ObjectHandle _objectHandle; + RTI::AttributeHandle _attributeHandle; + RTI::FederateHandle _federateHandle; + }; virtual void informAttributeOwnership(RTI::ObjectHandle objectHandle, RTI::AttributeHandle attributeHandle, RTI::FederateHandle federateHandle) throw (RTI::ObjectNotKnown, RTI::AttributeNotKnown, RTI::FederateInternalError) + { _queueCallbackList.push_back(new InformAttributeOwnershipCallback(objectHandle, attributeHandle, federateHandle)); } + void informAttributeOwnershipCallback(RTI::ObjectHandle objectHandle, RTI::AttributeHandle attributeHandle, RTI::FederateHandle federateHandle) { ObjectInstanceMap::iterator i = _objectInstanceMap.find(objectHandle); if (i == _objectInstanceMap.end()) - throw RTI::ObjectNotKnown("informAttributeOwnership for unknown object!"); + return; if (!i->second.valid()) return; i->second->informAttributeOwnership(attributeHandle, federateHandle); } + class AttributeIsNotOwnedCallback : public QueueCallback { + public: + AttributeIsNotOwnedCallback(RTI::ObjectHandle objectHandle, RTI::AttributeHandle attributeHandle) : + _objectHandle(objectHandle), + _attributeHandle(attributeHandle) + { } + virtual void operator()(FederateAmbassador& self) + { self.attributeIsNotOwnedCallback(_objectHandle, _attributeHandle); } + private: + RTI::ObjectHandle _objectHandle; + RTI::AttributeHandle _attributeHandle; + }; virtual void attributeIsNotOwned(RTI::ObjectHandle objectHandle, RTI::AttributeHandle attributeHandle) throw (RTI::ObjectNotKnown, RTI::AttributeNotKnown, RTI::FederateInternalError) + { _queueCallbackList.push_back(new AttributeIsNotOwnedCallback(objectHandle, attributeHandle)); } + void attributeIsNotOwnedCallback(RTI::ObjectHandle objectHandle, RTI::AttributeHandle attributeHandle) { ObjectInstanceMap::iterator i = _objectInstanceMap.find(objectHandle); if (i == _objectInstanceMap.end()) - throw RTI::ObjectNotKnown("attributeIsNotOwned for unknown object!"); + return; if (!i->second.valid()) return; i->second->attributeIsNotOwned(attributeHandle); } + class AttributeOwnedByRTICallback : public QueueCallback { + public: + AttributeOwnedByRTICallback(RTI::ObjectHandle objectHandle, RTI::AttributeHandle attributeHandle) : + _objectHandle(objectHandle), + _attributeHandle(attributeHandle) + { } + virtual void operator()(FederateAmbassador& self) + { self.attributeOwnedByRTICallback(_objectHandle, _attributeHandle); } + private: + RTI::ObjectHandle _objectHandle; + RTI::AttributeHandle _attributeHandle; + }; virtual void attributeOwnedByRTI(RTI::ObjectHandle objectHandle, RTI::AttributeHandle attributeHandle) throw (RTI::ObjectNotKnown, RTI::AttributeNotKnown, RTI::FederateInternalError) + { _queueCallbackList.push_back(new AttributeOwnedByRTICallback(objectHandle, attributeHandle)); } + void attributeOwnedByRTICallback(RTI::ObjectHandle objectHandle, RTI::AttributeHandle attributeHandle) { ObjectInstanceMap::iterator i = _objectInstanceMap.find(objectHandle); if (i == _objectInstanceMap.end()) - throw RTI::ObjectNotKnown("attributeOwnedByRTI for unknown object!"); + return; if (!i->second.valid()) return; i->second->attributeOwnedByRTI(attributeHandle); @@ -448,8 +787,7 @@ struct RTI13Federate::FederateAmbassador : public RTI::FederateAmbassador { RTI::FederateInternalError) { _timeRegulationEnabled = true; - _federateTime = RTI13Ambassador::toTimeStamp(fedTime); - SG_LOG(SG_NETWORK, SG_INFO, "RTI: timeRegulationEnabled: " << _federateTime); + SG_LOG(SG_NETWORK, SG_INFO, "RTI: timeRegulationEnabled: " << RTI13Ambassador::toTimeStamp(fedTime)); } virtual void timeConstrainedEnabled(const RTI::FedTime& fedTime) @@ -458,8 +796,7 @@ struct RTI13Federate::FederateAmbassador : public RTI::FederateAmbassador { RTI::FederateInternalError) { _timeConstrainedEnabled = true; - _federateTime = RTI13Ambassador::toTimeStamp(fedTime); - SG_LOG(SG_NETWORK, SG_INFO, "RTI: timeConstrainedEnabled: " << _federateTime); + SG_LOG(SG_NETWORK, SG_INFO, "RTI: timeConstrainedEnabled: " << RTI13Ambassador::toTimeStamp(fedTime)); } virtual void timeAdvanceGrant(const RTI::FedTime& fedTime) @@ -467,9 +804,8 @@ struct RTI13Federate::FederateAmbassador : public RTI::FederateAmbassador { RTI::TimeAdvanceWasNotInProgress, RTI::FederateInternalError) { - _federateTime = RTI13Ambassador::toTimeStamp(fedTime); _timeAdvancePending = false; - SG_LOG(SG_NETWORK, SG_INFO, "RTI: timeAdvanceGrant: " << _federateTime); + // SG_LOG(SG_NETWORK, SG_INFO, "RTI: timeAdvanceGrant: " << RTI13Ambassador::toTimeStamp(fedTime)); } virtual void requestRetraction(RTI::EventRetractionHandle eventRetractionHandle) @@ -483,7 +819,8 @@ struct RTI13Federate::FederateAmbassador : public RTI::FederateAmbassador { void processQueues() { while (!_queueCallbackList.empty()) { - (*_queueCallbackList.front())(); + (*_queueCallbackList.front())(*this); + // _queueCallbackListPool.splice(); _queueCallbackList.pop_front(); } } @@ -499,46 +836,6 @@ struct RTI13Federate::FederateAmbassador : public RTI::FederateAmbassador { return true; } - /// Generic callback to execute some notification on objects in a way that they are not prone to - /// ConcurrentAccess exceptions. - class QueueCallback : public SGReferenced { - public: - virtual ~QueueCallback() {} - virtual void operator()() = 0; - }; - - class DiscoverObjectCallback : public QueueCallback { - public: - DiscoverObjectCallback(SGSharedPtr objectClass, SGSharedPtr objectInstance, const RTIData& tag) : - _objectClass(objectClass), - _objectInstance(objectInstance), - _tag(tag) - { } - virtual void operator()() - { - _objectClass->discoverInstance(_objectInstance.get(), _tag); - _objectInstance->requestObjectAttributeValueUpdate(); - } - private: - SGSharedPtr _objectClass; - SGSharedPtr _objectInstance; - RTIData _tag; - }; - class RemoveObjectCallback : public QueueCallback { - public: - RemoveObjectCallback(SGSharedPtr objectInstance, const RTIData& tag) : - _objectInstance(objectInstance), - _tag(tag) - { } - virtual void operator()() - { - _objectInstance->removeInstance(_tag); - } - private: - SGSharedPtr _objectInstance; - RTIData _tag; - }; - // The rtiambassador to issue requests SGSharedPtr _rtiAmbassador; @@ -550,6 +847,22 @@ struct RTI13Federate::FederateAmbassador : public RTI::FederateAmbassador { // That is to make sure we do not call recursively into the RTI typedef std::list > QueueCallbackList; QueueCallbackList _queueCallbackList; + // QueueCallbackList _queueCallbackListPool; + + RTI13AttributeHandleDataPairList _attributeHandleDataPairPool; + void appendAttributeHandleDataPair(RTI13AttributeHandleDataPairList& attributeHandleDataPairList) + { + if (_attributeHandleDataPairPool.empty()) + attributeHandleDataPairList.push_back(RTI13AttributeHandleDataPair()); + else + attributeHandleDataPairList.splice(attributeHandleDataPairList.end(), + _attributeHandleDataPairPool, _attributeHandleDataPairPool.begin()); + } + void freeAttributeHandleDataPairList(RTI13AttributeHandleDataPairList& attributeHandleDataPairList) + { _attributeHandleDataPairPool.splice(_attributeHandleDataPairPool.end(), attributeHandleDataPairList); } + + // For attribute reflection, pool or indices + HLAIndexList _indexPool; // Top level information for dispatching federate object attribute updates typedef std::map > ObjectInstanceMap; @@ -560,10 +873,13 @@ struct RTI13Federate::FederateAmbassador : public RTI::FederateAmbassador { typedef std::map > ObjectClassMap; ObjectClassMap _objectClassMap; + // Top level information for dispatching creation of federate objects + typedef std::map > InteractionClassMap; + InteractionClassMap _interactionClassMap; + bool _timeRegulationEnabled; bool _timeConstrainedEnabled; bool _timeAdvancePending; - SGTimeStamp _federateTime; private: const RTIData& tagToData(const char* tag) @@ -579,7 +895,6 @@ private: RTI13Federate::RTI13Federate(const std::list& stringList) : _joined(false), - _tickTimeout(10), _ambassador(new RTI13Ambassador), _federateAmbassador(new FederateAmbassador) { @@ -597,83 +912,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; } } @@ -704,6 +1017,12 @@ RTI13Federate::resign() } } +bool +RTI13Federate::getJoined() const +{ + return _joined; +} + bool RTI13Federate::registerFederationSynchronizationPoint(const std::string& label, const RTIData& tag) { @@ -730,13 +1049,9 @@ RTI13Federate::registerFederationSynchronizationPoint(const std::string& label, } bool -RTI13Federate::waitForFederationSynchronizationPointAnnounced(const std::string& label) +RTI13Federate::getFederationSynchronizationPointAnnounced(const std::string& label) { - while (!_federateAmbassador->getFederationSynchronizationPointAnnounced(label)) { - _ambassador->tick(_tickTimeout, 0); - _federateAmbassador->processQueues(); - } - return true; + return _federateAmbassador->getFederationSynchronizationPointAnnounced(label); } bool @@ -768,13 +1083,9 @@ RTI13Federate::synchronizationPointAchieved(const std::string& label) } bool -RTI13Federate::waitForFederationSynchronized(const std::string& label) +RTI13Federate::getFederationSynchronized(const std::string& label) { - while (!_federateAmbassador->getFederationSynchronized(label)) { - _ambassador->tick(_tickTimeout, 0); - _federateAmbassador->processQueues(); - } - return true; + return _federateAmbassador->getFederationSynchronized(label); } bool @@ -793,36 +1104,31 @@ RTI13Federate::enableTimeConstrained() try { _ambassador->enableTimeConstrained(); } catch (RTI::TimeConstrainedAlreadyEnabled& e) { - SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not resign federation execution: " << e._name << " " << e._reason); + SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not enable time constrained: " << e._name << " " << e._reason); return false; } catch (RTI::EnableTimeConstrainedPending& e) { - SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not resign federation execution: " << e._name << " " << e._reason); + SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not enable time constrained: " << e._name << " " << e._reason); return false; } catch (RTI::TimeAdvanceAlreadyInProgress& e) { - SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not resign federation execution: " << e._name << " " << e._reason); + SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not enable time constrained: " << e._name << " " << e._reason); return false; } catch (RTI::ConcurrentAccessAttempted& e) { - SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not resign federation execution: " << e._name << " " << e._reason); + SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not enable time constrained: " << e._name << " " << e._reason); return false; } catch (RTI::FederateNotExecutionMember& e) { - SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not resign federation execution: " << e._name << " " << e._reason); + SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not enable time constrained: " << e._name << " " << e._reason); return false; } catch (RTI::SaveInProgress& e) { - SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not resign federation execution: " << e._name << " " << e._reason); + SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not enable time constrained: " << e._name << " " << e._reason); return false; } catch (RTI::RestoreInProgress& e) { - SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not resign federation execution: " << e._name << " " << e._reason); + SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not enable time constrained: " << e._name << " " << e._reason); return false; } catch (RTI::RTIinternalError& e) { - SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not resign federation execution: " << e._name << " " << e._reason); + SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not enable time constrained: " << e._name << " " << e._reason); return false; } - while (!_federateAmbassador->_timeConstrainedEnabled) { - _ambassador->tick(_tickTimeout, 0); - _federateAmbassador->processQueues(); - } - return true; } @@ -843,28 +1149,34 @@ RTI13Federate::disableTimeConstrained() _ambassador->disableTimeConstrained(); _federateAmbassador->_timeConstrainedEnabled = false; } catch (RTI::TimeConstrainedWasNotEnabled& e) { - SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not resign federation execution: " << e._name << " " << e._reason); + SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not disable time constrained: " << e._name << " " << e._reason); return false; } catch (RTI::FederateNotExecutionMember& e) { - SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not resign federation execution: " << e._name << " " << e._reason); + SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not disable time constrained: " << e._name << " " << e._reason); return false; } catch (RTI::ConcurrentAccessAttempted& e) { - SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not resign federation execution: " << e._name << " " << e._reason); + SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not disable time constrained: " << e._name << " " << e._reason); return false; } catch (RTI::SaveInProgress& e) { - SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not resign federation execution: " << e._name << " " << e._reason); + SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not disable time constrained: " << e._name << " " << e._reason); return false; } catch (RTI::RestoreInProgress& e) { - SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not resign federation execution: " << e._name << " " << e._reason); + SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not disable time constrained: " << e._name << " " << e._reason); return false; } catch (RTI::RTIinternalError& e) { - SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not resign federation execution: " << e._name << " " << e._reason); + SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not disable time constrained: " << e._name << " " << e._reason); return false; } return true; } +bool +RTI13Federate::getTimeConstrainedEnabled() +{ + return _federateAmbassador->_timeConstrainedEnabled; +} + bool RTI13Federate::enableTimeRegulation(const SGTimeStamp& lookahead) { @@ -879,44 +1191,39 @@ RTI13Federate::enableTimeRegulation(const SGTimeStamp& lookahead) } try { - _ambassador->enableTimeRegulation(SGTimeStamp(), lookahead); + _ambassador->enableTimeRegulation(lookahead); } catch (RTI::TimeRegulationAlreadyEnabled& e) { - SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not resign federation execution: " << e._name << " " << e._reason); + SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not enable time regulation: " << e._name << " " << e._reason); return false; } catch (RTI::EnableTimeRegulationPending& e) { - SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not resign federation execution: " << e._name << " " << e._reason); + SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not enable time regulation: " << e._name << " " << e._reason); return false; } catch (RTI::TimeAdvanceAlreadyInProgress& e) { - SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not resign federation execution: " << e._name << " " << e._reason); + SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not enable time regulation: " << e._name << " " << e._reason); return false; } catch (RTI::InvalidFederationTime& e) { - SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not resign federation execution: " << e._name << " " << e._reason); + SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not enable time regulation: " << e._name << " " << e._reason); return false; } catch (RTI::InvalidLookahead& e) { - SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not resign federation execution: " << e._name << " " << e._reason); + SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not enable time regulation: " << e._name << " " << e._reason); return false; } catch (RTI::ConcurrentAccessAttempted& e) { - SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not resign federation execution: " << e._name << " " << e._reason); + SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not enable time regulation: " << e._name << " " << e._reason); return false; } catch (RTI::FederateNotExecutionMember& e) { - SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not resign federation execution: " << e._name << " " << e._reason); + SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not enable time regulation: " << e._name << " " << e._reason); return false; } catch (RTI::SaveInProgress& e) { - SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not resign federation execution: " << e._name << " " << e._reason); + SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not enable time regulation: " << e._name << " " << e._reason); return false; } catch (RTI::RestoreInProgress& e) { - SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not resign federation execution: " << e._name << " " << e._reason); + SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not enable time regulation: " << e._name << " " << e._reason); return false; } catch (RTI::RTIinternalError& e) { - SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not resign federation execution: " << e._name << " " << e._reason); + SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not enable time regulation: " << e._name << " " << e._reason); return false; } - while (!_federateAmbassador->_timeRegulationEnabled) { - _ambassador->tick(_tickTimeout, 0); - _federateAmbassador->processQueues(); - } - return true; } @@ -937,22 +1244,22 @@ RTI13Federate::disableTimeRegulation() _ambassador->disableTimeRegulation(); _federateAmbassador->_timeRegulationEnabled = false; } catch (RTI::TimeRegulationWasNotEnabled& e) { - SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not resign federation execution: " << e._name << " " << e._reason); + SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not disable time regulation: " << e._name << " " << e._reason); return false; } catch (RTI::ConcurrentAccessAttempted& e) { - SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not resign federation execution: " << e._name << " " << e._reason); + SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not disable time regulation: " << e._name << " " << e._reason); return false; } catch (RTI::FederateNotExecutionMember& e) { - SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not resign federation execution: " << e._name << " " << e._reason); + SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not disable time regulation: " << e._name << " " << e._reason); return false; } catch (RTI::SaveInProgress& e) { - SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not resign federation execution: " << e._name << " " << e._reason); + SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not disable time regulation: " << e._name << " " << e._reason); return false; } catch (RTI::RestoreInProgress& e) { - SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not resign federation execution: " << e._name << " " << e._reason); + SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not disable time regulation: " << e._name << " " << e._reason); return false; } catch (RTI::RTIinternalError& e) { - SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not resign federation execution: " << e._name << " " << e._reason); + SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not disable time regulation: " << e._name << " " << e._reason); return false; } @@ -960,123 +1267,210 @@ RTI13Federate::disableTimeRegulation() } bool -RTI13Federate::timeAdvanceRequestBy(const SGTimeStamp& dt) +RTI13Federate::modifyLookahead(const SGTimeStamp& timeStamp) { if (!_ambassador.valid()) { - SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not disable time regulation at unconnected federate."); + SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not modify lookahead."); + return false; + } + try { + _ambassador->modifyLookahead(timeStamp); + } catch (RTI::InvalidLookahead& e) { + SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not modify lookahead: " << e._name << " " << e._reason); + return false; + } catch (RTI::FederateNotExecutionMember& e) { + SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not modify lookahead: " << e._name << " " << e._reason); + return false; + } catch (RTI::ConcurrentAccessAttempted& e) { + SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not modify lookahead: " << e._name << " " << e._reason); + return false; + } catch (RTI::SaveInProgress& e) { + SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not modify lookahead: " << e._name << " " << e._reason); + return false; + } catch (RTI::RestoreInProgress& e) { + SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not modify lookahead: " << e._name << " " << e._reason); + return false; + } catch (RTI::RTIinternalError& e) { + SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not modify lookahead: " << e._name << " " << e._reason); return false; } + return true; +} - SGTimeStamp fedTime = _federateAmbassador->_federateTime + dt; - return timeAdvanceRequest(fedTime); +bool +RTI13Federate::getTimeRegulationEnabled() +{ + return _federateAmbassador->_timeRegulationEnabled; } bool -RTI13Federate::timeAdvanceRequest(const SGTimeStamp& fedTime) +RTI13Federate::timeAdvanceRequest(const SGTimeStamp& timeStamp) { if (!_ambassador.valid()) { - SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not disable time regulation at unconnected federate."); + SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not advance time at unconnected federate."); return false; } try { - _ambassador->timeAdvanceRequest(fedTime); + _ambassador->timeAdvanceRequest(timeStamp); _federateAmbassador->_timeAdvancePending = true; } catch (RTI::InvalidFederationTime& e) { - SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not resign federation execution: " << e._name << " " << e._reason); + SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not advance time: " << e._name << " " << e._reason); return false; } catch (RTI::FederationTimeAlreadyPassed& e) { - SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not resign federation execution: " << e._name << " " << e._reason); + SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not advance time: " << e._name << " " << e._reason); return false; } catch (RTI::TimeAdvanceAlreadyInProgress& e) { - SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not resign federation execution: " << e._name << " " << e._reason); + SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not advance time: " << e._name << " " << e._reason); return false; } catch (RTI::EnableTimeRegulationPending& e) { - SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not resign federation execution: " << e._name << " " << e._reason); + SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not advance time: " << e._name << " " << e._reason); return false; } catch (RTI::EnableTimeConstrainedPending& e) { - SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not resign federation execution: " << e._name << " " << e._reason); + SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not advance time: " << e._name << " " << e._reason); return false; } catch (RTI::FederateNotExecutionMember& e) { - SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not resign federation execution: " << e._name << " " << e._reason); + SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not advance time: " << e._name << " " << e._reason); return false; } catch (RTI::ConcurrentAccessAttempted& e) { - SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not resign federation execution: " << e._name << " " << e._reason); + SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not advance time: " << e._name << " " << e._reason); return false; } catch (RTI::SaveInProgress& e) { - SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not resign federation execution: " << e._name << " " << e._reason); + SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not advance time: " << e._name << " " << e._reason); return false; } catch (RTI::RestoreInProgress& e) { - SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not resign federation execution: " << e._name << " " << e._reason); + SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not advance time: " << e._name << " " << e._reason); return false; } catch (RTI::RTIinternalError& e) { - SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not resign federation execution: " << e._name << " " << e._reason); + SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not advance time: " << e._name << " " << e._reason); return false; } - while (_federateAmbassador->_timeAdvancePending) { - _ambassador->tick(_tickTimeout, 0); - _federateAmbassador->processQueues(); + return true; +} + +bool +RTI13Federate::timeAdvanceRequestAvailable(const SGTimeStamp& timeStamp) +{ + if (!_ambassador.valid()) { + SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not advance time at unconnected federate."); + return false; + } + + try { + _ambassador->timeAdvanceRequestAvailable(timeStamp); + _federateAmbassador->_timeAdvancePending = true; + } catch (RTI::InvalidFederationTime& e) { + SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not advance time: " << e._name << " " << e._reason); + return false; + } catch (RTI::FederationTimeAlreadyPassed& e) { + SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not advance time: " << e._name << " " << e._reason); + return false; + } catch (RTI::TimeAdvanceAlreadyInProgress& e) { + SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not advance time: " << e._name << " " << e._reason); + return false; + } catch (RTI::EnableTimeRegulationPending& e) { + SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not advance time: " << e._name << " " << e._reason); + return false; + } catch (RTI::EnableTimeConstrainedPending& e) { + SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not advance time: " << e._name << " " << e._reason); + return false; + } catch (RTI::FederateNotExecutionMember& e) { + SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not advance time: " << e._name << " " << e._reason); + return false; + } catch (RTI::ConcurrentAccessAttempted& e) { + SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not advance time: " << e._name << " " << e._reason); + return false; + } catch (RTI::SaveInProgress& e) { + SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not advance time: " << e._name << " " << e._reason); + return false; + } catch (RTI::RestoreInProgress& e) { + SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not advance time: " << e._name << " " << e._reason); + return false; + } catch (RTI::RTIinternalError& e) { + SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not advance time: " << e._name << " " << e._reason); + return false; } return true; } bool -RTI13Federate::queryFederateTime(SGTimeStamp& timeStamp) +RTI13Federate::flushQueueRequest(const SGTimeStamp& timeStamp) { if (!_ambassador.valid()) { - SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not query federate time."); + SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not flush queue at unconnected federate."); return false; } try { - _ambassador->queryFederateTime(timeStamp); + _ambassador->flushQueueRequest(timeStamp); + _federateAmbassador->_timeAdvancePending = true; + } catch (RTI::InvalidFederationTime& e) { + SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not flush queue: " << e._name << " " << e._reason); + return false; + } catch (RTI::FederationTimeAlreadyPassed& e) { + SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not flush queue: " << e._name << " " << e._reason); + return false; + } catch (RTI::TimeAdvanceAlreadyInProgress& e) { + SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not flush queue: " << e._name << " " << e._reason); + return false; + } catch (RTI::EnableTimeRegulationPending& e) { + SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not flush queue: " << e._name << " " << e._reason); + return false; + } catch (RTI::EnableTimeConstrainedPending& e) { + SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not flush queue: " << e._name << " " << e._reason); + return false; } catch (RTI::FederateNotExecutionMember& e) { - SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not query federate time: " << e._name << " " << e._reason); + SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not flush queue: " << e._name << " " << e._reason); return false; } catch (RTI::ConcurrentAccessAttempted& e) { - SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not query federate time: " << e._name << " " << e._reason); + SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not flush queue: " << e._name << " " << e._reason); return false; } catch (RTI::SaveInProgress& e) { - SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not query federate time: " << e._name << " " << e._reason); + SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not flush queue: " << e._name << " " << e._reason); return false; } catch (RTI::RestoreInProgress& e) { - SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not query federate time: " << e._name << " " << e._reason); + SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not flush queue: " << e._name << " " << e._reason); return false; } catch (RTI::RTIinternalError& e) { - SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not query federate time: " << e._name << " " << e._reason); + SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not flush queue: " << e._name << " " << e._reason); return false; } + return true; } bool -RTI13Federate::modifyLookahead(const SGTimeStamp& timeStamp) +RTI13Federate::getTimeAdvancePending() +{ + return _federateAmbassador->_timeAdvancePending; +} + +bool +RTI13Federate::queryFederateTime(SGTimeStamp& timeStamp) { if (!_ambassador.valid()) { - SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not modify lookahead."); + SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not query federate time."); return false; } + try { - _ambassador->modifyLookahead(timeStamp); - } catch (RTI::InvalidLookahead& e) { - SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not modify lookahead: " << e._name << " " << e._reason); - return false; + _ambassador->queryFederateTime(timeStamp); } catch (RTI::FederateNotExecutionMember& e) { - SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not modify lookahead: " << e._name << " " << e._reason); + SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not query federate time: " << e._name << " " << e._reason); return false; } catch (RTI::ConcurrentAccessAttempted& e) { - SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not modify lookahead: " << e._name << " " << e._reason); + SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not query federate time: " << e._name << " " << e._reason); return false; } catch (RTI::SaveInProgress& e) { - SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not modify lookahead: " << e._name << " " << e._reason); + SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not query federate time: " << e._name << " " << e._reason); return false; } catch (RTI::RestoreInProgress& e) { - SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not modify lookahead: " << e._name << " " << e._reason); + SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not query federate time: " << e._name << " " << e._reason); return false; } catch (RTI::RTIinternalError& e) { - SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not modify lookahead: " << e._name << " " << e._reason); + SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not query federate time: " << e._name << " " << e._reason); return false; } return true; @@ -1112,21 +1506,137 @@ RTI13Federate::queryLookahead(SGTimeStamp& timeStamp) } bool -RTI13Federate::tick() +RTI13Federate::queryGALT(SGTimeStamp& timeStamp) +{ + if (!_ambassador.valid()) { + SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not query GALT."); + return false; + } + + try { + return _ambassador->queryGALT(timeStamp); + } catch (RTI::FederateNotExecutionMember& e) { + SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not query GALT: " << e._name << " " << e._reason); + return false; + } catch (RTI::ConcurrentAccessAttempted& e) { + SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not query GALT: " << e._name << " " << e._reason); + return false; + } catch (RTI::SaveInProgress& e) { + SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not query GALT: " << e._name << " " << e._reason); + return false; + } catch (RTI::RestoreInProgress& e) { + SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not query GALT: " << e._name << " " << e._reason); + return false; + } catch (RTI::RTIinternalError& e) { + SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not query GALT: " << e._name << " " << e._reason); + return false; + } + return true; +} + +bool +RTI13Federate::queryLITS(SGTimeStamp& timeStamp) +{ + if (!_ambassador.valid()) { + SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not query LITS."); + return false; + } + + try { + return _ambassador->queryLITS(timeStamp); + } catch (RTI::FederateNotExecutionMember& e) { + SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not query LITS: " << e._name << " " << e._reason); + return false; + } catch (RTI::ConcurrentAccessAttempted& e) { + SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not query LITS: " << e._name << " " << e._reason); + return false; + } catch (RTI::SaveInProgress& e) { + SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not query LITS: " << e._name << " " << e._reason); + return false; + } catch (RTI::RestoreInProgress& e) { + SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not query LITS: " << e._name << " " << e._reason); + return false; + } catch (RTI::RTIinternalError& e) { + SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not query LITS: " << e._name << " " << e._reason); + return false; + } + return true; +} + +RTI13Federate::ProcessMessageResult +RTI13Federate::processMessage() { - bool result = _ambassador->tick(); + ProcessMessageResult result = _tick(); _federateAmbassador->processQueues(); return result; } -bool -RTI13Federate::tick(const double& minimum, const double& maximum) +RTI13Federate::ProcessMessageResult +RTI13Federate::processMessages(const double& minimum, const double& maximum) { - bool result = _ambassador->tick(minimum, maximum); + ProcessMessageResult result = _tick(minimum, 0); _federateAmbassador->processQueues(); + if (result != ProcessMessagePending) + return result; + SGTimeStamp timeStamp = SGTimeStamp::now() + SGTimeStamp::fromSec(maximum); + do { + result = _tick(0, 0); + _federateAmbassador->processQueues(); + } while (result == ProcessMessagePending && SGTimeStamp::now() <= timeStamp); return result; } +RTI13Federate::ProcessMessageResult +RTI13Federate::_tick() +{ + if (!_ambassador.valid()) { + SG_LOG(SG_NETWORK, SG_WARN, "RTI: Ambassador is zero while calling _tick()."); + return ProcessMessageFatal; + } + + try { + if (_ambassador->tick()) + return ProcessMessagePending; + return ProcessMessageLast; + } catch (RTI::SpecifiedSaveLabelDoesNotExist& e) { + SG_LOG(SG_NETWORK, SG_WARN, "RTI: Specified save label does not exist: " << e._name << " " << e._reason); + return ProcessMessageFatal; + } catch (RTI::ConcurrentAccessAttempted& e) { + SG_LOG(SG_NETWORK, SG_WARN, "RTI: Concurrent access attempted: " << e._name << " " << e._reason); + return ProcessMessageFatal; + } catch (RTI::RTIinternalError& e) { + SG_LOG(SG_NETWORK, SG_WARN, "RTI: Internal error: " << e._name << " " << e._reason); + return ProcessMessageFatal; + } + return ProcessMessageFatal; +} + +RTI13Federate::ProcessMessageResult +RTI13Federate::_tick(const double& minimum, const double& maximum) +{ + if (!_ambassador.valid()) { + SG_LOG(SG_NETWORK, SG_WARN, "RTI: Ambassador is zero while calling _tick()."); + return ProcessMessageFatal; + } + + try { + if (_ambassador->tick(minimum, maximum)) + return ProcessMessagePending; + return ProcessMessageLast; + } catch (RTI::SpecifiedSaveLabelDoesNotExist& e) { + SG_LOG(SG_NETWORK, SG_WARN, "RTI: Specified save label does not exist: " << e._name << " " << e._reason); + return ProcessMessageFatal; + } catch (RTI::ConcurrentAccessAttempted& e) { + SG_LOG(SG_NETWORK, SG_WARN, "RTI: Concurrent access attempted: " << e._name << " " << e._reason); + return ProcessMessageFatal; + } catch (RTI::RTIinternalError& e) { + SG_LOG(SG_NETWORK, SG_WARN, "RTI: Internal error: " << e._name << " " << e._reason); + return ProcessMessageFatal; + } + return ProcessMessageFatal; +} + + RTI13ObjectClass* RTI13Federate::createObjectClass(const std::string& objectClassName, HLAObjectClass* hlaObjectClass) { @@ -1156,6 +1666,35 @@ RTI13Federate::createObjectClass(const std::string& objectClassName, HLAObjectCl } } +RTI13InteractionClass* +RTI13Federate::createInteractionClass(const std::string& interactionClassName, HLAInteractionClass* interactionClass) +{ + try { + RTI::InteractionClassHandle interactionClassHandle; + interactionClassHandle = _ambassador->getInteractionClassHandle(interactionClassName); + if (_federateAmbassador->_interactionClassMap.find(interactionClassHandle) != _federateAmbassador->_interactionClassMap.end()) { + SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not create interaction class, interaction class already exists!"); + return 0; + } + RTI13InteractionClass* rtiInteractionClass; + rtiInteractionClass = new RTI13InteractionClass(interactionClass, interactionClassHandle, _ambassador.get()); + _federateAmbassador->_interactionClassMap[interactionClassHandle] = rtiInteractionClass; + return rtiInteractionClass; + } catch (RTI::NameNotFound& e) { + SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not get interaction class: " << e._name << " " << e._reason); + return 0; + } catch (RTI::FederateNotExecutionMember& e) { + SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not get interaction class: " << e._name << " " << e._reason); + return 0; + } catch (RTI::ConcurrentAccessAttempted& e) { + SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not get interaction class: " << e._name << " " << e._reason); + return 0; + } catch (RTI::RTIinternalError& e) { + SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not get interaction class: " << e._name << " " << e._reason); + return 0; + } +} + RTI13ObjectInstance* RTI13Federate::getObjectInstance(const std::string& objectInstanceName) { @@ -1164,21 +1703,21 @@ RTI13Federate::getObjectInstance(const std::string& objectInstanceName) objectHandle = _ambassador->getObjectInstanceHandle(objectInstanceName); FederateAmbassador::ObjectInstanceMap::iterator i = _federateAmbassador->_objectInstanceMap.find(objectHandle); if (i == _federateAmbassador->_objectInstanceMap.end()) { - SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not get object class: ObjectInstance not found."); + SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not get object instance: ObjectInstance not found."); return 0; } return i->second; } catch (RTI::ObjectNotKnown& e) { - SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not get object class: " << e._name << " " << e._reason); + SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not get object instance: " << e._name << " " << e._reason); return 0; } catch (RTI::FederateNotExecutionMember& e) { - SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not get object class: " << e._name << " " << e._reason); + SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not get object instance: " << e._name << " " << e._reason); return 0; } catch (RTI::ConcurrentAccessAttempted& e) { - SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not get object class: " << e._name << " " << e._reason); + SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not get object instance: " << e._name << " " << e._reason); return 0; } catch (RTI::RTIinternalError& e) { - SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not get object class: " << e._name << " " << e._reason); + SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not get object instance: " << e._name << " " << e._reason); return 0; } }