From bd999ca090853e68acb7b0f4aab3d875afd8c010 Mon Sep 17 00:00:00 2001 From: Mathias Froehlich Date: Sat, 1 Oct 2011 09:10:57 +0200 Subject: [PATCH] hla: Move callbacks into the rti federate implementation. --- simgear/hla/RTI13Ambassador.hxx | 658 +--------------------------- simgear/hla/RTI13Federate.cxx | 634 ++++++++++++++++++++++++++- simgear/hla/RTI13Federate.hxx | 8 +- simgear/hla/RTI13ObjectClass.cxx | 49 ++- simgear/hla/RTI13ObjectClass.hxx | 2 +- simgear/hla/RTI13ObjectInstance.cxx | 61 ++- simgear/hla/RTI13ObjectInstance.hxx | 4 +- simgear/hla/RTIObjectInstance.hxx | 4 - 8 files changed, 694 insertions(+), 726 deletions(-) diff --git a/simgear/hla/RTI13Ambassador.hxx b/simgear/hla/RTI13Ambassador.hxx index 5446f858..2465e349 100644 --- a/simgear/hla/RTI13Ambassador.hxx +++ b/simgear/hla/RTI13Ambassador.hxx @@ -15,8 +15,8 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // -#ifndef RTIAmbassador_hxx -#define RTIAmbassador_hxx +#ifndef RTI13Ambassador_hxx +#define RTI13Ambassador_hxx #include #include @@ -45,58 +45,20 @@ namespace simgear { -class RTI13Ambassador : public SGWeakReferenced { +class RTI13Federate; + +class RTI13Ambassador : public SGReferenced { public: - RTI13Ambassador() : - _federateAmbassador(*this), - _timeRegulationEnabled(false), - _timeConstrainedEnabled(false), - _timeAdvancePending(false) - { } - virtual ~RTI13Ambassador() + ~RTI13Ambassador() { } - // processes the queues that filled up during the past - void processQueues() - { - while (!_queueCallbackList.empty()) { - (*_queueCallbackList.front())(); - _queueCallbackList.pop_front(); - } - - while (!_objectInstancePendingCallbackList.empty()) { - (*_objectInstancePendingCallbackList.begin())->flushPendingRequests(); - _objectInstancePendingCallbackList.erase(_objectInstancePendingCallbackList.begin()); - } - } - - bool getTimeRegulationEnabled() const - { return _timeRegulationEnabled; } - bool getTimeConstrainedEnabled() const - { return _timeConstrainedEnabled; } - bool getTimeAdvancePending() const - { return _timeAdvancePending; } - const SGTimeStamp& getCurrentLogicalTime() const - { return _federateTime; } - - bool getFederationSynchronizationPointAnnounced(const std::string& label) - { return _pendingSyncLabels.find(label) != _pendingSyncLabels.end(); } - bool getFederationSynchronized(const std::string& label) - { - std::set::iterator i = _syncronizedSyncLabels.find(label); - if (i == _syncronizedSyncLabels.end()) - return false; - _syncronizedSyncLabels.erase(i); - return true; - } - void createFederationExecution(const std::string& name, const std::string& objectModel) { _rtiAmbassador.createFederationExecution(name.c_str(), objectModel.c_str()); } void destroyFederationExecution(const std::string& name) { _rtiAmbassador.destroyFederationExecution(name.c_str()); } - RTI::FederateHandle joinFederationExecution(const std::string& federate, const std::string& federation) - { return _rtiAmbassador.joinFederationExecution(federate.c_str(), federation.c_str(), &_federateAmbassador); } + RTI::FederateHandle joinFederationExecution(const std::string& federate, const std::string& federation, RTI::FederateAmbassador* federateAmbassador) + { return _rtiAmbassador.joinFederationExecution(federate.c_str(), federation.c_str(), federateAmbassador); } void resignFederationExecution() { _rtiAmbassador.resignFederationExecution(RTI::DELETE_OBJECTS_AND_RELEASE_ATTRIBUTES); } @@ -114,13 +76,8 @@ public: void unsubscribeObjectClass(const RTI::ObjectClassHandle& handle) { _rtiAmbassador.unsubscribeObjectClass(handle); } - RTI13ObjectInstance* registerObjectInstance(const RTI13ObjectClass* objectClass, HLAObjectInstance* hlaObjectInstance) - { - RTI::ObjectHandle objectHandle = _rtiAmbassador.registerObjectInstance(objectClass->getHandle()); - RTI13ObjectInstance* objectInstance = new RTI13ObjectInstance(objectHandle, hlaObjectInstance, objectClass, this, true); - _objectInstanceMap[objectHandle] = objectInstance; - return objectInstance; - } + RTI::ObjectHandle registerObjectInstance(const RTI::ObjectClassHandle& handle) + { return _rtiAmbassador.registerObjectInstance(handle); } void updateAttributeValues(const RTI::ObjectHandle& objectHandle, const RTI::AttributeHandleValuePairSet& attributeValues, const SGTimeStamp& timeStamp, const RTIData& tag) { _rtiAmbassador.updateAttributeValues(objectHandle, attributeValues, toFedTime(timeStamp), tag.data()); } @@ -133,38 +90,11 @@ public: // { _rtiAmbassador.sendInteraction(interactionClassHandle, parameters, tag.data()); } void deleteObjectInstance(const RTI::ObjectHandle& objectHandle, const SGTimeStamp& timeStamp, const RTIData& tag) - { - RTI::EventRetractionHandle h = _rtiAmbassador.deleteObjectInstance(objectHandle, toFedTime(timeStamp), tag.data()); - ObjectInstanceMap::iterator i = _objectInstanceMap.find(objectHandle); - if (i == _objectInstanceMap.end()) { - SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not get object class: ObjectInstance not found."); - return; - } - _objectInstancePendingCallbackList.erase(i->second); - _objectInstanceMap.erase(i); - } + { RTI::EventRetractionHandle h = _rtiAmbassador.deleteObjectInstance(objectHandle, toFedTime(timeStamp), tag.data()); } void deleteObjectInstance(const RTI::ObjectHandle& objectHandle, const RTIData& tag) - { - _rtiAmbassador.deleteObjectInstance(objectHandle, tag.data()); - ObjectInstanceMap::iterator i = _objectInstanceMap.find(objectHandle); - if (i == _objectInstanceMap.end()) { - SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not get object class: ObjectInstance not found."); - return; - } - _objectInstancePendingCallbackList.erase(i->second); - _objectInstanceMap.erase(i); - } + { _rtiAmbassador.deleteObjectInstance(objectHandle, tag.data()); } void localDeleteObjectInstance(const RTI::ObjectHandle& objectHandle) - { - _rtiAmbassador.localDeleteObjectInstance(objectHandle); - ObjectInstanceMap::iterator i = _objectInstanceMap.find(objectHandle); - if (i == _objectInstanceMap.end()) { - SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not get object class: ObjectInstance not found."); - return; - } - _objectInstancePendingCallbackList.erase(i->second); - _objectInstanceMap.erase(i); - } + { _rtiAmbassador.localDeleteObjectInstance(objectHandle); } void requestObjectAttributeValueUpdate(const RTI::ObjectHandle& handle, const RTI::AttributeHandleSet& attributeHandleSet) { _rtiAmbassador.requestObjectAttributeValueUpdate(handle, attributeHandleSet); } @@ -354,17 +284,17 @@ public: void enableTimeRegulation(const SGTimeStamp& federateTime, const SGTimeStamp& lookahead) { _rtiAmbassador.enableTimeRegulation(toFedTime(federateTime), toFedTime(lookahead)); } void disableTimeRegulation() - { _rtiAmbassador.disableTimeRegulation(); _timeRegulationEnabled = false; } + { _rtiAmbassador.disableTimeRegulation();} void enableTimeConstrained() { _rtiAmbassador.enableTimeConstrained(); } void disableTimeConstrained() - { _rtiAmbassador.disableTimeConstrained(); _timeConstrainedEnabled = false; } + { _rtiAmbassador.disableTimeConstrained(); } void timeAdvanceRequest(const SGTimeStamp& time) - { _rtiAmbassador.timeAdvanceRequest(toFedTime(time)); _timeAdvancePending = true; } + { _rtiAmbassador.timeAdvanceRequest(toFedTime(time)); } void timeAdvanceRequestAvailable(const SGTimeStamp& time) - { _rtiAmbassador.timeAdvanceRequestAvailable(toFedTime(time)); _timeAdvancePending = true; } + { _rtiAmbassador.timeAdvanceRequestAvailable(toFedTime(time)); } // bool queryLBTS(double& time) // { @@ -396,19 +326,6 @@ public: timeStamp = toTimeStamp(fedTime); } - RTI13ObjectClass* createObjectClass(const std::string& name, HLAObjectClass* hlaObjectClass) - { - RTI::ObjectClassHandle objectClassHandle; - objectClassHandle = getObjectClassHandle(name); - if (_objectClassMap.find(objectClassHandle) != _objectClassMap.end()) { - SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not create object class, object class already exists!"); - return 0; - } - RTI13ObjectClass* rtiObjectClass; - rtiObjectClass = new RTI13ObjectClass(hlaObjectClass, objectClassHandle, this); - _objectClassMap[objectClassHandle] = rtiObjectClass; - return rtiObjectClass; - } RTI::ObjectClassHandle getObjectClassHandle(const std::string& name) { return _rtiAmbassador.getObjectClassHandle(name.c_str()); } std::string getObjectClassName(const RTI::ObjectClassHandle& handle) @@ -469,17 +386,6 @@ public: // return parameterName; // } - RTI13ObjectInstance* getObjectInstance(const std::string& name) - { - RTI::ObjectHandle objectHandle; - objectHandle = getObjectInstanceHandle(name); - ObjectInstanceMap::iterator i = _objectInstanceMap.find(objectHandle); - if (i == _objectInstanceMap.end()) { - SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not get object class: ObjectInstance not found."); - return 0; - } - return i->second; - } RTI::ObjectHandle getObjectInstanceHandle(const std::string& name) { return _rtiAmbassador.getObjectInstanceHandle(name.c_str()); } std::string getObjectInstanceName(const RTI::ObjectHandle& objectHandle) @@ -535,498 +441,6 @@ public: bool tick(double minimum, double maximum) { return _rtiAmbassador.tick(minimum, maximum); } - void addObjectInstanceForCallback(RTIObjectInstance* objectIntance) - { _objectInstancePendingCallbackList.insert(objectIntance); } - -private: - /// 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 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; - }; - - /// Just the interface class doing the callbacks into the parent class - struct FederateAmbassador : public RTI::FederateAmbassador { - FederateAmbassador(RTI13Ambassador& rtiAmbassador) : - _rtiAmbassador(rtiAmbassador) - { - } - virtual ~FederateAmbassador() - throw (RTI::FederateInternalError) - { - } - - /// RTI federate ambassador callback functions. - virtual void synchronizationPointRegistrationSucceeded(const char* label) - throw (RTI::FederateInternalError) - { - } - - virtual void synchronizationPointRegistrationFailed(const char* label) - throw (RTI::FederateInternalError) - { - } - - virtual void announceSynchronizationPoint(const char* label, const char* tag) - throw (RTI::FederateInternalError) - { - _rtiAmbassador._pendingSyncLabels.insert(toStdString(label)); - } - - virtual void federationSynchronized(const char* label) - throw (RTI::FederateInternalError) - { - std::string s = toStdString(label); - _rtiAmbassador._pendingSyncLabels.erase(s); - _rtiAmbassador._syncronizedSyncLabels.insert(s); - } - - virtual void initiateFederateSave(const char* label) - throw (RTI::UnableToPerformSave, - RTI::FederateInternalError) - { - } - - virtual void federationSaved() - throw (RTI::FederateInternalError) - { - } - - virtual void federationNotSaved() - throw (RTI::FederateInternalError) - { - } - - virtual void requestFederationRestoreSucceeded(const char* label) - throw (RTI::FederateInternalError) - { - } - - virtual void requestFederationRestoreFailed(const char* label, const char* reason) - throw (RTI::FederateInternalError) - { - } - - virtual void federationRestoreBegun() - throw (RTI::FederateInternalError) - { - } - - virtual void initiateFederateRestore(const char* label, RTI::FederateHandle federateHandle) - throw (RTI::SpecifiedSaveLabelDoesNotExist, - RTI::CouldNotRestore, - RTI::FederateInternalError) - { - } - - virtual void federationRestored() - throw (RTI::FederateInternalError) - { - } - - virtual void federationNotRestored() - throw (RTI::FederateInternalError) - { - } - - // Declaration Management - virtual void startRegistrationForObjectClass(RTI::ObjectClassHandle objectClassHandle) - throw (RTI::ObjectClassNotPublished, - RTI::FederateInternalError) - { - ObjectClassMap::iterator i = _rtiAmbassador._objectClassMap.find(objectClassHandle); - if (i == _rtiAmbassador._objectClassMap.end()) - return; - if (!i->second.valid()) - return; - i->second->startRegistration(); - } - - virtual void stopRegistrationForObjectClass(RTI::ObjectClassHandle objectClassHandle) - throw (RTI::ObjectClassNotPublished, - RTI::FederateInternalError) - { - ObjectClassMap::iterator i = _rtiAmbassador._objectClassMap.find(objectClassHandle); - if (i == _rtiAmbassador._objectClassMap.end()) - return; - if (!i->second.valid()) - return; - i->second->stopRegistration(); - } - - virtual void turnInteractionsOn(RTI::InteractionClassHandle interactionClassHandle) - throw (RTI::InteractionClassNotPublished, - RTI::FederateInternalError) - { - } - - virtual void turnInteractionsOff(RTI::InteractionClassHandle interactionClassHandle) - throw (RTI::InteractionClassNotPublished, - RTI::FederateInternalError) - { - } - - - // Object Management - virtual void discoverObjectInstance(RTI::ObjectHandle objectHandle, RTI::ObjectClassHandle objectClassHandle, const char* tag) - throw (RTI::CouldNotDiscover, - RTI::ObjectClassNotKnown, - RTI::FederateInternalError) - { - ObjectClassMap::iterator i = _rtiAmbassador._objectClassMap.find(objectClassHandle); - if (i == _rtiAmbassador._objectClassMap.end()) - throw RTI::ObjectClassNotKnown("Federate: discoverObjectInstance()!"); - if (!i->second.valid()) - return; - SGSharedPtr objectInstance = new RTI13ObjectInstance(objectHandle, 0, i->second, &_rtiAmbassador, false); - _rtiAmbassador._objectInstanceMap[objectHandle] = objectInstance; - _rtiAmbassador._objectInstancePendingCallbackList.insert(objectInstance); - i->second->discoverInstance(objectInstance.get(), tagToData(tag)); - } - - virtual void reflectAttributeValues(RTI::ObjectHandle objectHandle, const RTI::AttributeHandleValuePairSet& attributeValuePairSet, - const RTI::FedTime& fedTime, const char* tag, RTI::EventRetractionHandle eventRetractionHandle) - throw (RTI::ObjectNotKnown, - RTI::AttributeNotKnown, - RTI::FederateOwnsAttributes, - RTI::InvalidFederationTime, - RTI::FederateInternalError) - { - ObjectInstanceMap::iterator i = _rtiAmbassador._objectInstanceMap.find(objectHandle); - if (i == _rtiAmbassador._objectInstanceMap.end()) - throw RTI::ObjectNotKnown("Reflect attributes for unknown object!"); - if (!i->second.valid()) - return; - i->second->reflectAttributeValues(attributeValuePairSet, toTimeStamp(fedTime), tagToData(tag)); - } - - virtual void reflectAttributeValues(RTI::ObjectHandle objectHandle, const RTI::AttributeHandleValuePairSet& attributeValuePairSet, - const char* tag) - throw (RTI::ObjectNotKnown, - RTI::AttributeNotKnown, - RTI::FederateOwnsAttributes, - RTI::FederateInternalError) - { - ObjectInstanceMap::iterator i = _rtiAmbassador._objectInstanceMap.find(objectHandle); - if (i == _rtiAmbassador._objectInstanceMap.end()) - throw RTI::ObjectNotKnown("Reflect attributes for unknown object!"); - if (!i->second.valid()) - return; - i->second->reflectAttributeValues(attributeValuePairSet, tagToData(tag)); - } - - virtual void receiveInteraction(RTI::InteractionClassHandle interactionClassHandle, const RTI::ParameterHandleValuePairSet& parameters, - const RTI::FedTime& fedTime, const char* tag, RTI::EventRetractionHandle eventRetractionHandle) - throw (RTI::InteractionClassNotKnown, - RTI::InteractionParameterNotKnown, - RTI::InvalidFederationTime, - RTI::FederateInternalError) - { - } - - virtual void receiveInteraction(RTI::InteractionClassHandle interactionClassHandle, - const RTI::ParameterHandleValuePairSet& parameters, const char* tag) - throw (RTI::InteractionClassNotKnown, - RTI::InteractionParameterNotKnown, - RTI::FederateInternalError) - { - } - - virtual void removeObjectInstance(RTI::ObjectHandle objectHandle, const RTI::FedTime& fedTime, - const char* tag, RTI::EventRetractionHandle eventRetractionHandle) - throw (RTI::ObjectNotKnown, - RTI::InvalidFederationTime, - RTI::FederateInternalError) - { - ObjectInstanceMap::iterator i = _rtiAmbassador._objectInstanceMap.find(objectHandle); - if (i == _rtiAmbassador._objectInstanceMap.end()) - throw RTI::ObjectNotKnown("Federate: removeObjectInstance()!"); - if (i->second.valid()) - _rtiAmbassador._queueCallbackList.push_back(new RemoveObjectCallback(i->second, tagToData(tag))); - _rtiAmbassador._objectInstancePendingCallbackList.erase(i->second); - _rtiAmbassador._objectInstanceMap.erase(i); - } - - virtual void removeObjectInstance(RTI::ObjectHandle objectHandle, const char* tag) - throw (RTI::ObjectNotKnown, - RTI::FederateInternalError) - { - ObjectInstanceMap::iterator i = _rtiAmbassador._objectInstanceMap.find(objectHandle); - if (i == _rtiAmbassador._objectInstanceMap.end()) - throw RTI::ObjectNotKnown("Federate: removeObjectInstance()!"); - if (i->second.valid()) - _rtiAmbassador._queueCallbackList.push_back(new RemoveObjectCallback(i->second, tagToData(tag))); - _rtiAmbassador._objectInstancePendingCallbackList.erase(i->second); - _rtiAmbassador._objectInstanceMap.erase(i); - } - - virtual void attributesInScope(RTI::ObjectHandle objectHandle, const RTI::AttributeHandleSet& attributes) - throw (RTI::ObjectNotKnown, - RTI::AttributeNotKnown, - RTI::FederateInternalError) - { - ObjectInstanceMap::iterator i = _rtiAmbassador._objectInstanceMap.find(objectHandle); - if (i == _rtiAmbassador._objectInstanceMap.end()) - throw RTI::ObjectNotKnown("Attributes in scope for unknown object!"); - if (!i->second.valid()) - return; - i->second->attributesInScope(attributes); - } - - virtual void attributesOutOfScope(RTI::ObjectHandle objectHandle, const RTI::AttributeHandleSet& attributes) - throw (RTI::ObjectNotKnown, - RTI::AttributeNotKnown, - RTI::FederateInternalError) - { - ObjectInstanceMap::iterator i = _rtiAmbassador._objectInstanceMap.find(objectHandle); - if (i == _rtiAmbassador._objectInstanceMap.end()) - throw RTI::ObjectNotKnown("Attributes in scope for unknown object!"); - if (!i->second.valid()) - return; - i->second->attributesOutOfScope(attributes); - } - - virtual void provideAttributeValueUpdate(RTI::ObjectHandle objectHandle, const RTI::AttributeHandleSet& attributes) - throw (RTI::ObjectNotKnown, - RTI::AttributeNotKnown, - RTI::AttributeNotOwned, - RTI::FederateInternalError) - { - ObjectInstanceMap::iterator i = _rtiAmbassador._objectInstanceMap.find(objectHandle); - if (i == _rtiAmbassador._objectInstanceMap.end()) - throw RTI::ObjectNotKnown("Reflect attributes for unknown object!"); - if (!i->second.valid()) - return; - i->second->provideAttributeValueUpdate(attributes); - } - - virtual void turnUpdatesOnForObjectInstance(RTI::ObjectHandle objectHandle, const RTI::AttributeHandleSet& attributes) - throw (RTI::ObjectNotKnown, - RTI::AttributeNotOwned, - RTI::FederateInternalError) - { - ObjectInstanceMap::iterator i = _rtiAmbassador._objectInstanceMap.find(objectHandle); - if (i == _rtiAmbassador._objectInstanceMap.end()) - throw RTI::ObjectNotKnown("Turn on attributes for unknown object!"); - if (!i->second.valid()) - return; - i->second->turnUpdatesOnForObjectInstance(attributes); - } - - virtual void turnUpdatesOffForObjectInstance(RTI::ObjectHandle objectHandle, const RTI::AttributeHandleSet& attributes) - throw (RTI::ObjectNotKnown, - RTI::AttributeNotOwned, - RTI::FederateInternalError) - { - ObjectInstanceMap::iterator i = _rtiAmbassador._objectInstanceMap.find(objectHandle); - if (i == _rtiAmbassador._objectInstanceMap.end()) - throw RTI::ObjectNotKnown("Turn off attributes for unknown object!"); - if (!i->second.valid()) - return; - i->second->turnUpdatesOffForObjectInstance(attributes); - } - - // Ownership Management - virtual void requestAttributeOwnershipAssumption(RTI::ObjectHandle objectHandle, - const RTI::AttributeHandleSet& attributes, const char* tag) - throw (RTI::ObjectNotKnown, - RTI::AttributeNotKnown, - RTI::AttributeAlreadyOwned, - RTI::AttributeNotPublished, - RTI::FederateInternalError) - { - ObjectInstanceMap::iterator i = _rtiAmbassador._objectInstanceMap.find(objectHandle); - if (i == _rtiAmbassador._objectInstanceMap.end()) - throw RTI::ObjectNotKnown("requestAttributeOwnershipAssumption for unknown object!"); - if (!i->second.valid()) - return; - i->second->requestAttributeOwnershipAssumption(attributes, tagToData(tag)); - } - - virtual void attributeOwnershipDivestitureNotification(RTI::ObjectHandle objectHandle, const RTI::AttributeHandleSet& attributes) - throw (RTI::ObjectNotKnown, - RTI::AttributeNotKnown, - RTI::AttributeNotOwned, - RTI::AttributeDivestitureWasNotRequested, - RTI::FederateInternalError) - { - ObjectInstanceMap::iterator i = _rtiAmbassador._objectInstanceMap.find(objectHandle); - if (i == _rtiAmbassador._objectInstanceMap.end()) - throw RTI::ObjectNotKnown("attributeOwnershipDivestitureNotification for unknown object!"); - if (!i->second.valid()) - return; - i->second->attributeOwnershipDivestitureNotification(attributes); - } - - virtual void attributeOwnershipAcquisitionNotification(RTI::ObjectHandle objectHandle, const RTI::AttributeHandleSet& attributes) - throw (RTI::ObjectNotKnown, - RTI::AttributeNotKnown, - RTI::AttributeAcquisitionWasNotRequested, - RTI::AttributeAlreadyOwned, - RTI::AttributeNotPublished, - RTI::FederateInternalError) - { - ObjectInstanceMap::iterator i = _rtiAmbassador._objectInstanceMap.find(objectHandle); - if (i == _rtiAmbassador._objectInstanceMap.end()) - throw RTI::ObjectNotKnown("attributeOwnershipAcquisitionNotification for unknown object!"); - if (!i->second.valid()) - return; - i->second->attributeOwnershipAcquisitionNotification(attributes); - } - - virtual void attributeOwnershipUnavailable(RTI::ObjectHandle objectHandle, const RTI::AttributeHandleSet& attributes) - throw (RTI::ObjectNotKnown, - RTI::AttributeNotKnown, - RTI::AttributeAlreadyOwned, - RTI::AttributeAcquisitionWasNotRequested, - RTI::FederateInternalError) - { - ObjectInstanceMap::iterator i = _rtiAmbassador._objectInstanceMap.find(objectHandle); - if (i == _rtiAmbassador._objectInstanceMap.end()) - throw RTI::ObjectNotKnown("attributeOwnershipUnavailable for unknown object!"); - if (!i->second.valid()) - return; - i->second->attributeOwnershipUnavailable(attributes); - } - - virtual void requestAttributeOwnershipRelease(RTI::ObjectHandle objectHandle, - const RTI::AttributeHandleSet& attributes, const char* tag) - throw (RTI::ObjectNotKnown, - RTI::AttributeNotKnown, - RTI::AttributeNotOwned, - RTI::FederateInternalError) - { - ObjectInstanceMap::iterator i = _rtiAmbassador._objectInstanceMap.find(objectHandle); - if (i == _rtiAmbassador._objectInstanceMap.end()) - throw RTI::ObjectNotKnown("requestAttributeOwnershipRelease for unknown object!"); - if (!i->second.valid()) - return; - i->second->requestAttributeOwnershipRelease(attributes, tagToData(tag)); - } - - virtual void confirmAttributeOwnershipAcquisitionCancellation(RTI::ObjectHandle objectHandle, const RTI::AttributeHandleSet& attributes) - throw (RTI::ObjectNotKnown, - RTI::AttributeNotKnown, - RTI::AttributeAlreadyOwned, - RTI::AttributeAcquisitionWasNotCanceled, - RTI::FederateInternalError) - { - ObjectInstanceMap::iterator i = _rtiAmbassador._objectInstanceMap.find(objectHandle); - if (i == _rtiAmbassador._objectInstanceMap.end()) - throw RTI::ObjectNotKnown("confirmAttributeOwnershipAcquisitionCancellation for unknown object!"); - if (!i->second.valid()) - return; - i->second->confirmAttributeOwnershipAcquisitionCancellation(attributes); - } - - virtual void informAttributeOwnership(RTI::ObjectHandle objectHandle, RTI::AttributeHandle attributeHandle, - RTI::FederateHandle federateHandle) - throw (RTI::ObjectNotKnown, - RTI::AttributeNotKnown, - RTI::FederateInternalError) - { - ObjectInstanceMap::iterator i = _rtiAmbassador._objectInstanceMap.find(objectHandle); - if (i == _rtiAmbassador._objectInstanceMap.end()) - throw RTI::ObjectNotKnown("informAttributeOwnership for unknown object!"); - if (!i->second.valid()) - return; - i->second->informAttributeOwnership(attributeHandle, federateHandle); - } - - virtual void attributeIsNotOwned(RTI::ObjectHandle objectHandle, RTI::AttributeHandle attributeHandle) - throw (RTI::ObjectNotKnown, - RTI::AttributeNotKnown, - RTI::FederateInternalError) - { - ObjectInstanceMap::iterator i = _rtiAmbassador._objectInstanceMap.find(objectHandle); - if (i == _rtiAmbassador._objectInstanceMap.end()) - throw RTI::ObjectNotKnown("attributeIsNotOwned for unknown object!"); - if (!i->second.valid()) - return; - i->second->attributeIsNotOwned(attributeHandle); - } - - virtual void attributeOwnedByRTI(RTI::ObjectHandle objectHandle, RTI::AttributeHandle attributeHandle) - throw (RTI::ObjectNotKnown, - RTI::AttributeNotKnown, - RTI::FederateInternalError) - { - ObjectInstanceMap::iterator i = _rtiAmbassador._objectInstanceMap.find(objectHandle); - if (i == _rtiAmbassador._objectInstanceMap.end()) - throw RTI::ObjectNotKnown("attributeOwnedByRTI for unknown object!"); - if (!i->second.valid()) - return; - i->second->attributeOwnedByRTI(attributeHandle); - } - - // Time Management - virtual void timeRegulationEnabled(const RTI::FedTime& fedTime) - throw (RTI::InvalidFederationTime, - RTI::EnableTimeRegulationWasNotPending, - RTI::FederateInternalError) - { - _rtiAmbassador._timeRegulationEnabled = true; - _rtiAmbassador._federateTime = toTimeStamp(fedTime); - SG_LOG(SG_NETWORK, SG_INFO, "RTI: timeRegulationEnabled: " << _rtiAmbassador._federateTime); - } - - virtual void timeConstrainedEnabled(const RTI::FedTime& fedTime) - throw (RTI::InvalidFederationTime, - RTI::EnableTimeConstrainedWasNotPending, - RTI::FederateInternalError) - { - _rtiAmbassador._timeConstrainedEnabled = true; - _rtiAmbassador._federateTime = toTimeStamp(fedTime); - SG_LOG(SG_NETWORK, SG_INFO, "RTI: timeConstrainedEnabled: " << _rtiAmbassador._federateTime); - } - - virtual void timeAdvanceGrant(const RTI::FedTime& fedTime) - throw (RTI::InvalidFederationTime, - RTI::TimeAdvanceWasNotInProgress, - RTI::FederateInternalError) - { - _rtiAmbassador._federateTime = toTimeStamp(fedTime); - _rtiAmbassador._timeAdvancePending = false; - SG_LOG(SG_NETWORK, SG_INFO, "RTI: timeAdvanceGrant: " << _rtiAmbassador._federateTime); - } - - virtual void requestRetraction(RTI::EventRetractionHandle eventRetractionHandle) - throw (RTI::EventNotKnown, - RTI::FederateInternalError) - { - // No retraction concept yet - } - - private: - const RTIData& tagToData(const char* tag) - { - if (tag) - _cachedTag.setData(tag, std::strlen(tag) + 1); - else - _cachedTag.setData("", 1); - return _cachedTag; - } - RTIData _cachedTag; - - RTI13Ambassador& _rtiAmbassador; - }; static SGTimeStamp toTimeStamp(const RTI::FedTime& fedTime) { @@ -1052,45 +466,9 @@ private: return s; } - static std::string toStdString(const char* n) - { - if (!n) - return std::string(); - return std::string(n); - } - // The connection class RTI::RTIambassador _rtiAmbassador; - - // The class with all the callbacks. - FederateAmbassador _federateAmbassador; - - // All the sync labels we got an announcement for - std::set _pendingSyncLabels; - std::set _syncronizedSyncLabels; - - // All that calls back into user code is just queued. - // That is to make sure we do not call recursively into the RTI - typedef std::list > QueueCallbackList; - QueueCallbackList _queueCallbackList; - // All object instances that need to be called due to some event are noted here - // That is to make sure we do not call recursively into the RTI - typedef std::set > ObjectInstanceSet; - ObjectInstanceSet _objectInstancePendingCallbackList; - - // Top level information for dispatching federate object attribute updates - typedef std::map > ObjectInstanceMap; - // Map of all available objects - ObjectInstanceMap _objectInstanceMap; - - // Top level information for dispatching creation of federate objects - typedef std::map > ObjectClassMap; - ObjectClassMap _objectClassMap; - - bool _timeRegulationEnabled; - bool _timeConstrainedEnabled; - bool _timeAdvancePending; - SGTimeStamp _federateTime; + SGWeakPtr _federate; }; } // namespace simgear diff --git a/simgear/hla/RTI13Federate.cxx b/simgear/hla/RTI13Federate.cxx index a77fbaea..32913c23 100644 --- a/simgear/hla/RTI13Federate.cxx +++ b/simgear/hla/RTI13Federate.cxx @@ -1,4 +1,4 @@ -// Copyright (C) 2009 - 2010 Mathias Froehlich - Mathias.Froehlich@web.de +// Copyright (C) 2009 - 2011 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 @@ -21,10 +21,570 @@ namespace simgear { +static std::string toStdString(const char* n) +{ + if (!n) + return std::string(); + return std::string(n); +} + +/// Just the interface class doing the callbacks into the parent class +struct RTI13Federate::FederateAmbassador : public RTI::FederateAmbassador { + FederateAmbassador() : + _timeRegulationEnabled(false), + _timeConstrainedEnabled(false), + _timeAdvancePending(false) + { + } + virtual ~FederateAmbassador() + throw (RTI::FederateInternalError) + { + } + + /// RTI federate ambassador callback functions. + virtual void synchronizationPointRegistrationSucceeded(const char* label) + throw (RTI::FederateInternalError) + { + } + + virtual void synchronizationPointRegistrationFailed(const char* label) + throw (RTI::FederateInternalError) + { + } + + virtual void announceSynchronizationPoint(const char* label, const char* tag) + throw (RTI::FederateInternalError) + { + _pendingSyncLabels.insert(toStdString(label)); + } + + virtual void federationSynchronized(const char* label) + throw (RTI::FederateInternalError) + { + std::string s = toStdString(label); + _pendingSyncLabels.erase(s); + _syncronizedSyncLabels.insert(s); + } + + virtual void initiateFederateSave(const char* label) + throw (RTI::UnableToPerformSave, + RTI::FederateInternalError) + { + } + + virtual void federationSaved() + throw (RTI::FederateInternalError) + { + } + + virtual void federationNotSaved() + throw (RTI::FederateInternalError) + { + } + + virtual void requestFederationRestoreSucceeded(const char* label) + throw (RTI::FederateInternalError) + { + } + + virtual void requestFederationRestoreFailed(const char* label, const char* reason) + throw (RTI::FederateInternalError) + { + } + + virtual void federationRestoreBegun() + throw (RTI::FederateInternalError) + { + } + + virtual void initiateFederateRestore(const char* label, RTI::FederateHandle federateHandle) + throw (RTI::SpecifiedSaveLabelDoesNotExist, + RTI::CouldNotRestore, + RTI::FederateInternalError) + { + } + + virtual void federationRestored() + throw (RTI::FederateInternalError) + { + } + + virtual void federationNotRestored() + throw (RTI::FederateInternalError) + { + } + + // Declaration Management + virtual void startRegistrationForObjectClass(RTI::ObjectClassHandle objectClassHandle) + throw (RTI::ObjectClassNotPublished, + RTI::FederateInternalError) + { + ObjectClassMap::iterator i = _objectClassMap.find(objectClassHandle); + if (i == _objectClassMap.end()) + return; + if (!i->second.valid()) + return; + i->second->startRegistration(); + } + + virtual void stopRegistrationForObjectClass(RTI::ObjectClassHandle objectClassHandle) + throw (RTI::ObjectClassNotPublished, + RTI::FederateInternalError) + { + ObjectClassMap::iterator i = _objectClassMap.find(objectClassHandle); + if (i == _objectClassMap.end()) + return; + if (!i->second.valid()) + return; + i->second->stopRegistration(); + } + + virtual void turnInteractionsOn(RTI::InteractionClassHandle interactionClassHandle) + throw (RTI::InteractionClassNotPublished, + RTI::FederateInternalError) + { + } + + virtual void turnInteractionsOff(RTI::InteractionClassHandle interactionClassHandle) + throw (RTI::InteractionClassNotPublished, + RTI::FederateInternalError) + { + } + + + // Object Management + virtual void discoverObjectInstance(RTI::ObjectHandle objectHandle, RTI::ObjectClassHandle objectClassHandle, const char* tag) + throw (RTI::CouldNotDiscover, + RTI::ObjectClassNotKnown, + RTI::FederateInternalError) + { + ObjectClassMap::iterator i = _objectClassMap.find(objectClassHandle); + if (i == _objectClassMap.end()) + throw RTI::ObjectClassNotKnown("Federate: discoverObjectInstance()!"); + if (!i->second.valid()) + return; + SGSharedPtr objectInstance = new RTI13ObjectInstance(objectHandle, 0, i->second, _rtiAmbassador.get(), false); + _objectInstanceMap[objectHandle] = objectInstance; + _queueCallbackList.push_back(new DiscoverObjectCallback(i->second, objectInstance, tagToData(tag))); + } + + virtual void reflectAttributeValues(RTI::ObjectHandle objectHandle, const RTI::AttributeHandleValuePairSet& attributeValuePairSet, + const RTI::FedTime& fedTime, const char* tag, RTI::EventRetractionHandle eventRetractionHandle) + throw (RTI::ObjectNotKnown, + RTI::AttributeNotKnown, + RTI::FederateOwnsAttributes, + RTI::InvalidFederationTime, + RTI::FederateInternalError) + { + ObjectInstanceMap::iterator i = _objectInstanceMap.find(objectHandle); + if (i == _objectInstanceMap.end()) + throw RTI::ObjectNotKnown("Reflect attributes for unknown object!"); + if (!i->second.valid()) + return; + i->second->reflectAttributeValues(attributeValuePairSet, RTI13Ambassador::toTimeStamp(fedTime), tagToData(tag)); + } + + virtual void reflectAttributeValues(RTI::ObjectHandle objectHandle, const RTI::AttributeHandleValuePairSet& attributeValuePairSet, + const char* tag) + throw (RTI::ObjectNotKnown, + RTI::AttributeNotKnown, + RTI::FederateOwnsAttributes, + RTI::FederateInternalError) + { + ObjectInstanceMap::iterator i = _objectInstanceMap.find(objectHandle); + if (i == _objectInstanceMap.end()) + throw RTI::ObjectNotKnown("Reflect attributes for unknown object!"); + if (!i->second.valid()) + return; + i->second->reflectAttributeValues(attributeValuePairSet, tagToData(tag)); + } + + virtual void receiveInteraction(RTI::InteractionClassHandle interactionClassHandle, const RTI::ParameterHandleValuePairSet& parameters, + const RTI::FedTime& fedTime, const char* tag, RTI::EventRetractionHandle eventRetractionHandle) + throw (RTI::InteractionClassNotKnown, + RTI::InteractionParameterNotKnown, + RTI::InvalidFederationTime, + RTI::FederateInternalError) + { + } + + virtual void receiveInteraction(RTI::InteractionClassHandle interactionClassHandle, + const RTI::ParameterHandleValuePairSet& parameters, const char* tag) + throw (RTI::InteractionClassNotKnown, + RTI::InteractionParameterNotKnown, + RTI::FederateInternalError) + { + } + + virtual void removeObjectInstance(RTI::ObjectHandle objectHandle, const RTI::FedTime& fedTime, + const char* tag, RTI::EventRetractionHandle eventRetractionHandle) + throw (RTI::ObjectNotKnown, + RTI::InvalidFederationTime, + RTI::FederateInternalError) + { + ObjectInstanceMap::iterator i = _objectInstanceMap.find(objectHandle); + if (i == _objectInstanceMap.end()) + throw RTI::ObjectNotKnown("Federate: removeObjectInstance()!"); + if (i->second.valid()) + _queueCallbackList.push_back(new RemoveObjectCallback(i->second, tagToData(tag))); + _objectInstanceMap.erase(i); + } + + virtual void removeObjectInstance(RTI::ObjectHandle objectHandle, const char* tag) + throw (RTI::ObjectNotKnown, + RTI::FederateInternalError) + { + ObjectInstanceMap::iterator i = _objectInstanceMap.find(objectHandle); + if (i == _objectInstanceMap.end()) + throw RTI::ObjectNotKnown("Federate: removeObjectInstance()!"); + if (i->second.valid()) + _queueCallbackList.push_back(new RemoveObjectCallback(i->second, tagToData(tag))); + _objectInstanceMap.erase(i); + } + + virtual void attributesInScope(RTI::ObjectHandle objectHandle, const RTI::AttributeHandleSet& attributes) + throw (RTI::ObjectNotKnown, + RTI::AttributeNotKnown, + RTI::FederateInternalError) + { + ObjectInstanceMap::iterator i = _objectInstanceMap.find(objectHandle); + if (i == _objectInstanceMap.end()) + throw RTI::ObjectNotKnown("Attributes in scope for unknown object!"); + if (!i->second.valid()) + return; + i->second->attributesInScope(attributes); + } + + virtual void attributesOutOfScope(RTI::ObjectHandle objectHandle, const RTI::AttributeHandleSet& attributes) + throw (RTI::ObjectNotKnown, + RTI::AttributeNotKnown, + RTI::FederateInternalError) + { + ObjectInstanceMap::iterator i = _objectInstanceMap.find(objectHandle); + if (i == _objectInstanceMap.end()) + throw RTI::ObjectNotKnown("Attributes in scope for unknown object!"); + if (!i->second.valid()) + return; + i->second->attributesOutOfScope(attributes); + } + + virtual void provideAttributeValueUpdate(RTI::ObjectHandle objectHandle, const RTI::AttributeHandleSet& attributes) + throw (RTI::ObjectNotKnown, + RTI::AttributeNotKnown, + RTI::AttributeNotOwned, + RTI::FederateInternalError) + { + ObjectInstanceMap::iterator i = _objectInstanceMap.find(objectHandle); + if (i == _objectInstanceMap.end()) + throw RTI::ObjectNotKnown("Reflect attributes for unknown object!"); + if (!i->second.valid()) + return; + i->second->provideAttributeValueUpdate(attributes); + } + + virtual void turnUpdatesOnForObjectInstance(RTI::ObjectHandle objectHandle, const RTI::AttributeHandleSet& attributes) + throw (RTI::ObjectNotKnown, + RTI::AttributeNotOwned, + RTI::FederateInternalError) + { + ObjectInstanceMap::iterator i = _objectInstanceMap.find(objectHandle); + if (i == _objectInstanceMap.end()) + throw RTI::ObjectNotKnown("Turn on attributes for unknown object!"); + if (!i->second.valid()) + return; + i->second->turnUpdatesOnForObjectInstance(attributes); + } + + virtual void turnUpdatesOffForObjectInstance(RTI::ObjectHandle objectHandle, const RTI::AttributeHandleSet& attributes) + throw (RTI::ObjectNotKnown, + RTI::AttributeNotOwned, + RTI::FederateInternalError) + { + ObjectInstanceMap::iterator i = _objectInstanceMap.find(objectHandle); + if (i == _objectInstanceMap.end()) + throw RTI::ObjectNotKnown("Turn off attributes for unknown object!"); + if (!i->second.valid()) + return; + i->second->turnUpdatesOffForObjectInstance(attributes); + } + + // Ownership Management + virtual void requestAttributeOwnershipAssumption(RTI::ObjectHandle objectHandle, + const RTI::AttributeHandleSet& attributes, const char* tag) + throw (RTI::ObjectNotKnown, + RTI::AttributeNotKnown, + RTI::AttributeAlreadyOwned, + RTI::AttributeNotPublished, + RTI::FederateInternalError) + { + ObjectInstanceMap::iterator i = _objectInstanceMap.find(objectHandle); + if (i == _objectInstanceMap.end()) + throw RTI::ObjectNotKnown("requestAttributeOwnershipAssumption for unknown object!"); + if (!i->second.valid()) + return; + i->second->requestAttributeOwnershipAssumption(attributes, tagToData(tag)); + } + + virtual void attributeOwnershipDivestitureNotification(RTI::ObjectHandle objectHandle, const RTI::AttributeHandleSet& attributes) + throw (RTI::ObjectNotKnown, + RTI::AttributeNotKnown, + RTI::AttributeNotOwned, + RTI::AttributeDivestitureWasNotRequested, + RTI::FederateInternalError) + { + ObjectInstanceMap::iterator i = _objectInstanceMap.find(objectHandle); + if (i == _objectInstanceMap.end()) + throw RTI::ObjectNotKnown("attributeOwnershipDivestitureNotification for unknown object!"); + if (!i->second.valid()) + return; + i->second->attributeOwnershipDivestitureNotification(attributes); + } + + virtual void attributeOwnershipAcquisitionNotification(RTI::ObjectHandle objectHandle, const RTI::AttributeHandleSet& attributes) + throw (RTI::ObjectNotKnown, + RTI::AttributeNotKnown, + RTI::AttributeAcquisitionWasNotRequested, + RTI::AttributeAlreadyOwned, + RTI::AttributeNotPublished, + RTI::FederateInternalError) + { + ObjectInstanceMap::iterator i = _objectInstanceMap.find(objectHandle); + if (i == _objectInstanceMap.end()) + throw RTI::ObjectNotKnown("attributeOwnershipAcquisitionNotification for unknown object!"); + if (!i->second.valid()) + return; + i->second->attributeOwnershipAcquisitionNotification(attributes); + } + + virtual void attributeOwnershipUnavailable(RTI::ObjectHandle objectHandle, const RTI::AttributeHandleSet& attributes) + throw (RTI::ObjectNotKnown, + RTI::AttributeNotKnown, + RTI::AttributeAlreadyOwned, + RTI::AttributeAcquisitionWasNotRequested, + RTI::FederateInternalError) + { + ObjectInstanceMap::iterator i = _objectInstanceMap.find(objectHandle); + if (i == _objectInstanceMap.end()) + throw RTI::ObjectNotKnown("attributeOwnershipUnavailable for unknown object!"); + if (!i->second.valid()) + return; + i->second->attributeOwnershipUnavailable(attributes); + } + + virtual void requestAttributeOwnershipRelease(RTI::ObjectHandle objectHandle, + const RTI::AttributeHandleSet& attributes, const char* tag) + throw (RTI::ObjectNotKnown, + RTI::AttributeNotKnown, + RTI::AttributeNotOwned, + RTI::FederateInternalError) + { + ObjectInstanceMap::iterator i = _objectInstanceMap.find(objectHandle); + if (i == _objectInstanceMap.end()) + throw RTI::ObjectNotKnown("requestAttributeOwnershipRelease for unknown object!"); + if (!i->second.valid()) + return; + i->second->requestAttributeOwnershipRelease(attributes, tagToData(tag)); + } + + virtual void confirmAttributeOwnershipAcquisitionCancellation(RTI::ObjectHandle objectHandle, const RTI::AttributeHandleSet& attributes) + throw (RTI::ObjectNotKnown, + RTI::AttributeNotKnown, + RTI::AttributeAlreadyOwned, + RTI::AttributeAcquisitionWasNotCanceled, + RTI::FederateInternalError) + { + ObjectInstanceMap::iterator i = _objectInstanceMap.find(objectHandle); + if (i == _objectInstanceMap.end()) + throw RTI::ObjectNotKnown("confirmAttributeOwnershipAcquisitionCancellation for unknown object!"); + if (!i->second.valid()) + return; + i->second->confirmAttributeOwnershipAcquisitionCancellation(attributes); + } + + virtual void informAttributeOwnership(RTI::ObjectHandle objectHandle, RTI::AttributeHandle attributeHandle, + RTI::FederateHandle federateHandle) + throw (RTI::ObjectNotKnown, + RTI::AttributeNotKnown, + RTI::FederateInternalError) + { + ObjectInstanceMap::iterator i = _objectInstanceMap.find(objectHandle); + if (i == _objectInstanceMap.end()) + throw RTI::ObjectNotKnown("informAttributeOwnership for unknown object!"); + if (!i->second.valid()) + return; + i->second->informAttributeOwnership(attributeHandle, federateHandle); + } + + virtual void attributeIsNotOwned(RTI::ObjectHandle objectHandle, RTI::AttributeHandle attributeHandle) + throw (RTI::ObjectNotKnown, + RTI::AttributeNotKnown, + RTI::FederateInternalError) + { + ObjectInstanceMap::iterator i = _objectInstanceMap.find(objectHandle); + if (i == _objectInstanceMap.end()) + throw RTI::ObjectNotKnown("attributeIsNotOwned for unknown object!"); + if (!i->second.valid()) + return; + i->second->attributeIsNotOwned(attributeHandle); + } + + virtual void attributeOwnedByRTI(RTI::ObjectHandle objectHandle, RTI::AttributeHandle attributeHandle) + throw (RTI::ObjectNotKnown, + RTI::AttributeNotKnown, + RTI::FederateInternalError) + { + ObjectInstanceMap::iterator i = _objectInstanceMap.find(objectHandle); + if (i == _objectInstanceMap.end()) + throw RTI::ObjectNotKnown("attributeOwnedByRTI for unknown object!"); + if (!i->second.valid()) + return; + i->second->attributeOwnedByRTI(attributeHandle); + } + + // Time Management + virtual void timeRegulationEnabled(const RTI::FedTime& fedTime) + throw (RTI::InvalidFederationTime, + RTI::EnableTimeRegulationWasNotPending, + RTI::FederateInternalError) + { + _timeRegulationEnabled = true; + _federateTime = RTI13Ambassador::toTimeStamp(fedTime); + SG_LOG(SG_NETWORK, SG_INFO, "RTI: timeRegulationEnabled: " << _federateTime); + } + + virtual void timeConstrainedEnabled(const RTI::FedTime& fedTime) + throw (RTI::InvalidFederationTime, + RTI::EnableTimeConstrainedWasNotPending, + RTI::FederateInternalError) + { + _timeConstrainedEnabled = true; + _federateTime = RTI13Ambassador::toTimeStamp(fedTime); + SG_LOG(SG_NETWORK, SG_INFO, "RTI: timeConstrainedEnabled: " << _federateTime); + } + + virtual void timeAdvanceGrant(const RTI::FedTime& fedTime) + throw (RTI::InvalidFederationTime, + RTI::TimeAdvanceWasNotInProgress, + RTI::FederateInternalError) + { + _federateTime = RTI13Ambassador::toTimeStamp(fedTime); + _timeAdvancePending = false; + SG_LOG(SG_NETWORK, SG_INFO, "RTI: timeAdvanceGrant: " << _federateTime); + } + + virtual void requestRetraction(RTI::EventRetractionHandle eventRetractionHandle) + throw (RTI::EventNotKnown, + RTI::FederateInternalError) + { + // No retraction concept yet + } + + // processes the queues that filled up during the past + void processQueues() + { + while (!_queueCallbackList.empty()) { + (*_queueCallbackList.front())(); + _queueCallbackList.pop_front(); + } + } + + bool getFederationSynchronizationPointAnnounced(const std::string& label) + { return _pendingSyncLabels.find(label) != _pendingSyncLabels.end(); } + bool getFederationSynchronized(const std::string& label) + { + std::set::iterator i = _syncronizedSyncLabels.find(label); + if (i == _syncronizedSyncLabels.end()) + return false; + _syncronizedSyncLabels.erase(i); + 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; + + // All the sync labels we got an announcement for + std::set _pendingSyncLabels; + std::set _syncronizedSyncLabels; + + // All that calls back into user code is just queued. + // That is to make sure we do not call recursively into the RTI + typedef std::list > QueueCallbackList; + QueueCallbackList _queueCallbackList; + + // Top level information for dispatching federate object attribute updates + typedef std::map > ObjectInstanceMap; + // Map of all available objects + ObjectInstanceMap _objectInstanceMap; + + // Top level information for dispatching creation of federate objects + typedef std::map > ObjectClassMap; + ObjectClassMap _objectClassMap; + + bool _timeRegulationEnabled; + bool _timeConstrainedEnabled; + bool _timeAdvancePending; + SGTimeStamp _federateTime; + +private: + const RTIData& tagToData(const char* tag) + { + if (tag) + _cachedTag.setData(tag, std::strlen(tag) + 1); + else + _cachedTag.setData("", 1); + return _cachedTag; + } + RTIData _cachedTag; +}; + RTI13Federate::RTI13Federate(const std::list& stringList) : + _joined(false), _tickTimeout(10), - _ambassador(new RTI13Ambassador) + _ambassador(new RTI13Ambassador), + _federateAmbassador(new FederateAmbassador) { + _ambassador->_federate = this; + _federateAmbassador->_rtiAmbassador = _ambassador; if (stringList.empty()) { SG_LOG(SG_NETWORK, SG_WARN, "RTI: Ignoring non empty connect arguments while connecting to an RTI13 federation!"); } @@ -32,6 +592,9 @@ RTI13Federate::RTI13Federate(const std::list& stringList) : RTI13Federate::~RTI13Federate() { + if (_joined) + _ambassador->resignFederationExecution(); + delete _federateAmbassador; } bool @@ -80,11 +643,12 @@ bool RTI13Federate::join(const std::string& federateType, const std::string& federationName) { try { - _federateHandle = _ambassador->joinFederationExecution(federateType, federationName); + _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; } catch (RTI::FederateAlreadyExecutionMember& e) { SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not join federation execution: " << e._name << " " << e._reason); @@ -119,6 +683,7 @@ RTI13Federate::resign() try { _ambassador->resignFederationExecution(); SG_LOG(SG_NETWORK, SG_INFO, "RTI: Resigned from federation."); + _joined = false; _federateHandle = -1; return true; } catch (RTI::FederateOwnsAttributes& e) { @@ -167,9 +732,9 @@ RTI13Federate::registerFederationSynchronizationPoint(const std::string& label, bool RTI13Federate::waitForFederationSynchronizationPointAnnounced(const std::string& label) { - while (!_ambassador->getFederationSynchronizationPointAnnounced(label)) { + while (!_federateAmbassador->getFederationSynchronizationPointAnnounced(label)) { _ambassador->tick(_tickTimeout, 0); - _ambassador->processQueues(); + _federateAmbassador->processQueues(); } return true; } @@ -205,9 +770,9 @@ RTI13Federate::synchronizationPointAchieved(const std::string& label) bool RTI13Federate::waitForFederationSynchronized(const std::string& label) { - while (!_ambassador->getFederationSynchronized(label)) { + while (!_federateAmbassador->getFederationSynchronized(label)) { _ambassador->tick(_tickTimeout, 0); - _ambassador->processQueues(); + _federateAmbassador->processQueues(); } return true; } @@ -220,7 +785,7 @@ RTI13Federate::enableTimeConstrained() return false; } - if (_ambassador->getTimeConstrainedEnabled()) { + if (_federateAmbassador->_timeConstrainedEnabled) { SG_LOG(SG_NETWORK, SG_WARN, "RTI: Time constrained is already enabled."); return false; } @@ -253,9 +818,9 @@ RTI13Federate::enableTimeConstrained() return false; } - while (!_ambassador->getTimeConstrainedEnabled()) { + while (!_federateAmbassador->_timeConstrainedEnabled) { _ambassador->tick(_tickTimeout, 0); - _ambassador->processQueues(); + _federateAmbassador->processQueues(); } return true; @@ -269,13 +834,14 @@ RTI13Federate::disableTimeConstrained() return false; } - if (!_ambassador->getTimeConstrainedEnabled()) { + if (!_federateAmbassador->_timeConstrainedEnabled) { SG_LOG(SG_NETWORK, SG_WARN, "RTI: Time constrained is not enabled."); return false; } try { _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); return false; @@ -307,7 +873,7 @@ RTI13Federate::enableTimeRegulation(const SGTimeStamp& lookahead) return false; } - if (_ambassador->getTimeRegulationEnabled()) { + if (_federateAmbassador->_timeRegulationEnabled) { SG_LOG(SG_NETWORK, SG_WARN, "RTI: Time regulation already enabled."); return false; } @@ -346,9 +912,9 @@ RTI13Federate::enableTimeRegulation(const SGTimeStamp& lookahead) return false; } - while (!_ambassador->getTimeRegulationEnabled()) { + while (!_federateAmbassador->_timeRegulationEnabled) { _ambassador->tick(_tickTimeout, 0); - _ambassador->processQueues(); + _federateAmbassador->processQueues(); } return true; @@ -362,13 +928,14 @@ RTI13Federate::disableTimeRegulation() return false; } - if (!_ambassador->getTimeRegulationEnabled()) { + if (!_federateAmbassador->_timeRegulationEnabled) { SG_LOG(SG_NETWORK, SG_WARN, "RTI: Time regulation is not enabled."); return false; } try { _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); return false; @@ -400,7 +967,7 @@ RTI13Federate::timeAdvanceRequestBy(const SGTimeStamp& dt) return false; } - SGTimeStamp fedTime = _ambassador->getCurrentLogicalTime() + dt; + SGTimeStamp fedTime = _federateAmbassador->_federateTime + dt; return timeAdvanceRequest(fedTime); } @@ -414,6 +981,7 @@ RTI13Federate::timeAdvanceRequest(const SGTimeStamp& fedTime) try { _ambassador->timeAdvanceRequest(fedTime); + _federateAmbassador->_timeAdvancePending = true; } catch (RTI::InvalidFederationTime& e) { SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not resign federation execution: " << e._name << " " << e._reason); return false; @@ -446,9 +1014,9 @@ RTI13Federate::timeAdvanceRequest(const SGTimeStamp& fedTime) return false; } - while (_ambassador->getTimeAdvancePending()) { + while (_federateAmbassador->_timeAdvancePending) { _ambassador->tick(_tickTimeout, 0); - _ambassador->processQueues(); + _federateAmbassador->processQueues(); } return true; @@ -547,7 +1115,7 @@ bool RTI13Federate::tick() { bool result = _ambassador->tick(); - _ambassador->processQueues(); + _federateAmbassador->processQueues(); return result; } @@ -555,7 +1123,7 @@ bool RTI13Federate::tick(const double& minimum, const double& maximum) { bool result = _ambassador->tick(minimum, maximum); - _ambassador->processQueues(); + _federateAmbassador->processQueues(); return result; } @@ -563,7 +1131,16 @@ RTI13ObjectClass* RTI13Federate::createObjectClass(const std::string& objectClassName, HLAObjectClass* hlaObjectClass) { try { - return _ambassador->createObjectClass(objectClassName, hlaObjectClass); + RTI::ObjectClassHandle objectClassHandle; + objectClassHandle = _ambassador->getObjectClassHandle(objectClassName); + if (_federateAmbassador->_objectClassMap.find(objectClassHandle) != _federateAmbassador->_objectClassMap.end()) { + SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not create object class, object class already exists!"); + return 0; + } + RTI13ObjectClass* rtiObjectClass; + rtiObjectClass = new RTI13ObjectClass(hlaObjectClass, objectClassHandle, _ambassador.get()); + _federateAmbassador->_objectClassMap[objectClassHandle] = rtiObjectClass; + return rtiObjectClass; } catch (RTI::NameNotFound& e) { SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not get object class: " << e._name << " " << e._reason); return 0; @@ -583,7 +1160,14 @@ RTI13ObjectInstance* RTI13Federate::getObjectInstance(const std::string& objectInstanceName) { try { - return _ambassador->getObjectInstance(objectInstanceName); + RTI::ObjectHandle objectHandle; + 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."); + 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); return 0; @@ -599,4 +1183,10 @@ RTI13Federate::getObjectInstance(const std::string& objectInstanceName) } } +void +RTI13Federate::insertObjectInstance(RTI13ObjectInstance* objectInstance) +{ + _federateAmbassador->_objectInstanceMap[objectInstance->getHandle()] = objectInstance; +} + } diff --git a/simgear/hla/RTI13Federate.hxx b/simgear/hla/RTI13Federate.hxx index 839e7d50..6f3b9b03 100644 --- a/simgear/hla/RTI13Federate.hxx +++ b/simgear/hla/RTI13Federate.hxx @@ -1,4 +1,4 @@ -// Copyright (C) 2009 - 2010 Mathias Froehlich - Mathias.Froehlich@web.de +// Copyright (C) 2009 - 2011 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 @@ -71,6 +71,7 @@ public: virtual RTI13ObjectClass* createObjectClass(const std::string& name, HLAObjectClass* hlaObjectClass); virtual RTI13ObjectInstance* getObjectInstance(const std::string& name); + void insertObjectInstance(RTI13ObjectInstance* objectInstance); private: RTI13Federate(const RTI13Federate&); @@ -78,6 +79,7 @@ private: /// The federate handle RTI::FederateHandle _federateHandle; + bool _joined; /// The timeout for the single callback tick function in /// syncronous operations that need to wait for a callback @@ -85,6 +87,10 @@ private: /// RTI connection SGSharedPtr _ambassador; + + /// Callbacks from the rti are handled here. + struct FederateAmbassador; + FederateAmbassador* _federateAmbassador; }; } diff --git a/simgear/hla/RTI13ObjectClass.cxx b/simgear/hla/RTI13ObjectClass.cxx index e2ccd497..fcc41682 100644 --- a/simgear/hla/RTI13ObjectClass.cxx +++ b/simgear/hla/RTI13ObjectClass.cxx @@ -37,12 +37,11 @@ RTI13ObjectClass::~RTI13ObjectClass() std::string RTI13ObjectClass::getName() const { - SGSharedPtr ambassador = _ambassador.lock(); - if (!ambassador.valid()) { + if (!_ambassador.valid()) { SG_LOG(SG_NETWORK, SG_WARN, "Error: Ambassador is zero."); return std::string(); } - return ambassador->getObjectClassName(_handle); + return _ambassador->getObjectClassName(_handle); } unsigned @@ -54,14 +53,13 @@ RTI13ObjectClass::getNumAttributes() const unsigned RTI13ObjectClass::getAttributeIndex(const std::string& name) const { - SGSharedPtr ambassador = _ambassador.lock(); - if (!ambassador.valid()) { + if (!_ambassador.valid()) { SG_LOG(SG_NETWORK, SG_WARN, "Error: Ambassador is zero."); return ~0u; } try { - RTI::AttributeHandle attributeHandle = ambassador->getAttributeHandle(name, _handle); + RTI::AttributeHandle attributeHandle = _ambassador->getAttributeHandle(name, _handle); AttributeHandleIndexMap::const_iterator i = _attributeHandleIndexMap.find(attributeHandle); if (i != _attributeHandleIndexMap.end()) @@ -93,14 +91,13 @@ RTI13ObjectClass::getAttributeIndex(const std::string& name) const unsigned RTI13ObjectClass::getOrCreateAttributeIndex(const std::string& name) { - SGSharedPtr ambassador = _ambassador.lock(); - if (!ambassador.valid()) { + if (!_ambassador.valid()) { SG_LOG(SG_NETWORK, SG_WARN, "Error: Ambassador is zero."); return ~0u; } try { - RTI::AttributeHandle attributeHandle = ambassador->getAttributeHandle(name, _handle); + RTI::AttributeHandle attributeHandle = _ambassador->getAttributeHandle(name, _handle); AttributeHandleIndexMap::const_iterator i = _attributeHandleIndexMap.find(attributeHandle); if (i != _attributeHandleIndexMap.end()) @@ -169,8 +166,7 @@ RTI13ObjectClass::getOrCreateAttributeIndex(const std::string& name) bool RTI13ObjectClass::publish(const std::set& indexSet) { - SGSharedPtr ambassador = _ambassador.lock(); - if (!ambassador.valid()) { + if (!_ambassador.valid()) { SG_LOG(SG_NETWORK, SG_WARN, "Error: Ambassador is zero."); return false; } @@ -185,7 +181,7 @@ RTI13ObjectClass::publish(const std::set& indexSet) attributeHandleSet->add(_attributeHandleVector[*i]); } - ambassador->publishObjectClass(_handle, *attributeHandleSet); + _ambassador->publishObjectClass(_handle, *attributeHandleSet); for (unsigned i = 0; i < getNumAttributes(); ++i) { _attributeDataVector[i]._published = true; @@ -225,14 +221,13 @@ RTI13ObjectClass::publish(const std::set& indexSet) bool RTI13ObjectClass::unpublish() { - SGSharedPtr ambassador = _ambassador.lock(); - if (!ambassador.valid()) { + if (!_ambassador.valid()) { SG_LOG(SG_NETWORK, SG_WARN, "Error: Ambassador is zero."); return false; } try { - ambassador->unpublishObjectClass(_handle); + _ambassador->unpublishObjectClass(_handle); for (unsigned i = 0; i < getNumAttributes(); ++i) { _attributeDataVector[i]._published = false; @@ -272,8 +267,7 @@ RTI13ObjectClass::unpublish() bool RTI13ObjectClass::subscribe(const std::set& indexSet, bool active) { - SGSharedPtr ambassador = _ambassador.lock(); - if (!ambassador.valid()) { + if (!_ambassador.valid()) { SG_LOG(SG_NETWORK, SG_WARN, "Error: Ambassador is zero."); return false; } @@ -289,7 +283,7 @@ RTI13ObjectClass::subscribe(const std::set& indexSet, bool active) attributeHandleSet->add(_attributeHandleVector[*i]); } - ambassador->subscribeObjectClassAttributes(_handle, *attributeHandleSet, active); + _ambassador->subscribeObjectClassAttributes(_handle, *attributeHandleSet, active); for (unsigned i = 0; i < getNumAttributes(); ++i) { _attributeDataVector[i]._subscribed = true; @@ -326,14 +320,13 @@ RTI13ObjectClass::subscribe(const std::set& indexSet, bool active) bool RTI13ObjectClass::unsubscribe() { - SGSharedPtr ambassador = _ambassador.lock(); - if (!ambassador.valid()) { + if (!_ambassador.valid()) { SG_LOG(SG_NETWORK, SG_WARN, "Error: Ambassador is zero."); return 0; } try { - ambassador->unsubscribeObjectClass(_handle); + _ambassador->unsubscribeObjectClass(_handle); for (unsigned i = 0; i < getNumAttributes(); ++i) { _attributeDataVector[i]._subscribed = false; @@ -370,14 +363,22 @@ RTI13ObjectClass::unsubscribe() RTIObjectInstance* RTI13ObjectClass::registerObjectInstance(HLAObjectInstance* hlaObjectInstance) { - SGSharedPtr ambassador = _ambassador.lock(); - if (!ambassador.valid()) { + if (!_ambassador.valid()) { SG_LOG(SG_NETWORK, SG_WARN, "Error: Ambassador is zero."); return 0; } + SGSharedPtr federate = _ambassador->_federate.lock(); + if (!federate.valid()) { + SG_LOG(SG_NETWORK, SG_WARN, "Error: Federate is zero."); + return 0; + } + try { - return ambassador->registerObjectInstance(this, hlaObjectInstance); + RTI::ObjectHandle objectHandle = _ambassador->registerObjectInstance(getHandle()); + RTI13ObjectInstance* objectInstance = new RTI13ObjectInstance(objectHandle, hlaObjectInstance, this, _ambassador.get(), true); + federate->insertObjectInstance(objectInstance); + return objectInstance; } catch (RTI::ObjectClassNotDefined& e) { SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not register object instance: " << e._name << " " << e._reason); return 0; diff --git a/simgear/hla/RTI13ObjectClass.hxx b/simgear/hla/RTI13ObjectClass.hxx index e8c25cd0..c4949ca9 100644 --- a/simgear/hla/RTI13ObjectClass.hxx +++ b/simgear/hla/RTI13ObjectClass.hxx @@ -73,7 +73,7 @@ public: private: RTI::ObjectClassHandle _handle; - SGWeakPtr _ambassador; + SGSharedPtr _ambassador; typedef std::map AttributeHandleIndexMap; AttributeHandleIndexMap _attributeHandleIndexMap; diff --git a/simgear/hla/RTI13ObjectInstance.cxx b/simgear/hla/RTI13ObjectInstance.cxx index 87f6a42d..723f9b17 100644 --- a/simgear/hla/RTI13ObjectInstance.cxx +++ b/simgear/hla/RTI13ObjectInstance.cxx @@ -50,14 +50,13 @@ RTI13ObjectInstance::get13ObjectClass() const std::string RTI13ObjectInstance::getName() const { - SGSharedPtr ambassador = _ambassador.lock(); - if (!ambassador.valid()) { + if (!_ambassador.valid()) { SG_LOG(SG_NETWORK, SG_WARN, "Error: Ambassador is zero."); return std::string(); } try { - return ambassador->getObjectInstanceName(_handle); + return _ambassador->getObjectInstanceName(_handle); } catch (RTI::ObjectNotKnown& e) { SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not get object name: " << e._name << " " << e._reason); return std::string(); @@ -77,28 +76,21 @@ RTI13ObjectInstance::getName() const } void -RTI13ObjectInstance::addToRequestQueue() +RTI13ObjectInstance::deleteObjectInstance(const RTIData& tag) { - SGSharedPtr ambassador = _ambassador.lock(); - if (!ambassador.valid()) { + if (!_ambassador.valid()) { SG_LOG(SG_NETWORK, SG_WARN, "Error: Ambassador is zero."); return; } - ambassador->addObjectInstanceForCallback(this); -} - -void -RTI13ObjectInstance::deleteObjectInstance(const RTIData& tag) -{ - SGSharedPtr ambassador = _ambassador.lock(); - if (!ambassador.valid()) { - SG_LOG(SG_NETWORK, SG_WARN, "Error: Ambassador is zero."); + SGSharedPtr federate = _ambassador->_federate.lock(); + if (!federate.valid()) { + SG_LOG(SG_NETWORK, SG_WARN, "Error: Federate is zero."); return; } try { - ambassador->deleteObjectInstance(_handle, tag); + _ambassador->deleteObjectInstance(_handle, tag); } catch (RTI::ObjectNotKnown& e) { SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not delete object instance: " << e._name << " " << e._reason); } catch (RTI::DeletePrivilegeNotHeld& e) { @@ -119,14 +111,19 @@ RTI13ObjectInstance::deleteObjectInstance(const RTIData& tag) void RTI13ObjectInstance::deleteObjectInstance(const SGTimeStamp& timeStamp, const RTIData& tag) { - SGSharedPtr ambassador = _ambassador.lock(); - if (!ambassador.valid()) { + if (!_ambassador.valid()) { SG_LOG(SG_NETWORK, SG_WARN, "Error: Ambassador is zero."); return; } + SGSharedPtr federate = _ambassador->_federate.lock(); + if (!federate.valid()) { + SG_LOG(SG_NETWORK, SG_WARN, "Error: Federate is zero."); + return; + } + try { - ambassador->deleteObjectInstance(_handle, timeStamp, tag); + _ambassador->deleteObjectInstance(_handle, timeStamp, tag); } catch (RTI::ObjectNotKnown& e) { SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not delete object instance: " << e._name << " " << e._reason); } catch (RTI::DeletePrivilegeNotHeld& e) { @@ -149,14 +146,19 @@ RTI13ObjectInstance::deleteObjectInstance(const SGTimeStamp& timeStamp, const RT void RTI13ObjectInstance::localDeleteObjectInstance() { - SGSharedPtr ambassador = _ambassador.lock(); - if (!ambassador.valid()) { + if (!_ambassador.valid()) { SG_LOG(SG_NETWORK, SG_WARN, "Error: Ambassador is zero."); return; } + SGSharedPtr federate = _ambassador->_federate.lock(); + if (!federate.valid()) { + SG_LOG(SG_NETWORK, SG_WARN, "Error: Federate is zero."); + return; + } + try { - ambassador->localDeleteObjectInstance(_handle); + _ambassador->localDeleteObjectInstance(_handle); } catch (RTI::ObjectNotKnown& e) { SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not delete object instance: " << e._name << " " << e._reason); } catch (RTI::FederateOwnsAttributes& e) { @@ -221,8 +223,7 @@ RTI13ObjectInstance::reflectAttributeValues(const RTI::AttributeHandleValuePairS void RTI13ObjectInstance::requestObjectAttributeValueUpdate() { - SGSharedPtr ambassador = _ambassador.lock(); - if (!ambassador.valid()) { + if (!_ambassador.valid()) { SG_LOG(SG_NETWORK, SG_WARN, "Error: Ambassador is zero."); return; } @@ -238,7 +239,7 @@ RTI13ObjectInstance::requestObjectAttributeValueUpdate() if (!attributeHandleSet->size()) return; - ambassador->requestObjectAttributeValueUpdate(_handle, *attributeHandleSet); + _ambassador->requestObjectAttributeValueUpdate(_handle, *attributeHandleSet); for (unsigned i = 0; i < numAttributes; ++i) setRequestAttributeUpdate(i, false); @@ -285,8 +286,7 @@ RTI13ObjectInstance::provideAttributeValueUpdate(const RTI::AttributeHandleSet& void RTI13ObjectInstance::updateAttributeValues(const RTIData& tag) { - SGSharedPtr ambassador = _ambassador.lock(); - if (!ambassador.valid()) { + if (!_ambassador.valid()) { SG_LOG(SG_NETWORK, SG_WARN, "Error: Ambassador is zero."); return; } @@ -312,7 +312,7 @@ RTI13ObjectInstance::updateAttributeValues(const RTIData& tag) if (!_attributeValuePairSet->size()) return; - ambassador->updateAttributeValues(_handle, *_attributeValuePairSet, tag); + _ambassador->updateAttributeValues(_handle, *_attributeValuePairSet, tag); for (unsigned i = 0; i < numAttributes; ++i) { setAttributeUpdated(i); @@ -343,8 +343,7 @@ RTI13ObjectInstance::updateAttributeValues(const RTIData& tag) void RTI13ObjectInstance::updateAttributeValues(const SGTimeStamp& timeStamp, const RTIData& tag) { - SGSharedPtr ambassador = _ambassador.lock(); - if (!ambassador.valid()) { + if (!_ambassador.valid()) { SG_LOG(SG_NETWORK, SG_WARN, "Error: Ambassador is zero."); return; } @@ -370,7 +369,7 @@ RTI13ObjectInstance::updateAttributeValues(const SGTimeStamp& timeStamp, const R if (!_attributeValuePairSet->size()) return; - ambassador->updateAttributeValues(_handle, *_attributeValuePairSet, timeStamp, tag); + _ambassador->updateAttributeValues(_handle, *_attributeValuePairSet, timeStamp, tag); for (unsigned i = 0; i < numAttributes; ++i) { setAttributeUpdated(i); diff --git a/simgear/hla/RTI13ObjectInstance.hxx b/simgear/hla/RTI13ObjectInstance.hxx index ed73aa09..654bff92 100644 --- a/simgear/hla/RTI13ObjectInstance.hxx +++ b/simgear/hla/RTI13ObjectInstance.hxx @@ -61,8 +61,6 @@ public: virtual std::string getName() const; - virtual void addToRequestQueue(); - virtual void deleteObjectInstance(const RTIData& tag); virtual void deleteObjectInstance(const SGTimeStamp& timeStamp, const RTIData& tag); virtual void localDeleteObjectInstance(); @@ -95,7 +93,7 @@ public: private: RTI::ObjectHandle _handle; SGSharedPtr _objectClass; - SGWeakPtr _ambassador; + SGSharedPtr _ambassador; // cached storage for updates std::auto_ptr _attributeValuePairSet; diff --git a/simgear/hla/RTIObjectInstance.hxx b/simgear/hla/RTIObjectInstance.hxx index fb8f096a..3edbed60 100644 --- a/simgear/hla/RTIObjectInstance.hxx +++ b/simgear/hla/RTIObjectInstance.hxx @@ -50,9 +50,6 @@ public: unsigned getAttributeIndex(const std::string& name) const; std::string getAttributeName(unsigned index) const; - // FIXME: factor out an ambassador base - virtual void addToRequestQueue() = 0; - virtual void deleteObjectInstance(const RTIData& tag) = 0; virtual void deleteObjectInstance(const SGTimeStamp& timeStamp, const RTIData& tag) = 0; virtual void localDeleteObjectInstance() = 0; @@ -213,7 +210,6 @@ public: if (request) { if (!_pendingAttributeUpdateRequest) { _pendingAttributeUpdateRequest = true; - addToRequestQueue(); } } } -- 2.39.5