// 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 <cstdlib>
#include <list>
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<std::string>::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); }
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()); }
// { _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); }
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)
// {
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)
// 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)
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<RTIObjectInstance> objectInstance, const RTIData& tag) :
- _objectInstance(objectInstance),
- _tag(tag)
- { }
- virtual void operator()()
- {
- _objectInstance->removeInstance(_tag);
- }
- private:
- SGSharedPtr<RTIObjectInstance> _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<RTI13ObjectInstance> 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)
{
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<std::string> _pendingSyncLabels;
- std::set<std::string> _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<SGSharedPtr<QueueCallback> > 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<SGSharedPtr<RTIObjectInstance> > ObjectInstanceSet;
- ObjectInstanceSet _objectInstancePendingCallbackList;
-
- // Top level information for dispatching federate object attribute updates
- typedef std::map<RTI::ObjectHandle, SGSharedPtr<RTI13ObjectInstance> > ObjectInstanceMap;
- // Map of all available objects
- ObjectInstanceMap _objectInstanceMap;
-
- // Top level information for dispatching creation of federate objects
- typedef std::map<RTI::ObjectClassHandle, SGSharedPtr<RTI13ObjectClass> > ObjectClassMap;
- ObjectClassMap _objectClassMap;
-
- bool _timeRegulationEnabled;
- bool _timeConstrainedEnabled;
- bool _timeAdvancePending;
- SGTimeStamp _federateTime;
+ SGWeakPtr<RTI13Federate> _federate;
};
} // namespace simgear
-// 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
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<RTI13ObjectInstance> 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<std::string>::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<RTIObjectClass> objectClass, SGSharedPtr<RTIObjectInstance> objectInstance, const RTIData& tag) :
+ _objectClass(objectClass),
+ _objectInstance(objectInstance),
+ _tag(tag)
+ { }
+ virtual void operator()()
+ {
+ _objectClass->discoverInstance(_objectInstance.get(), _tag);
+ _objectInstance->requestObjectAttributeValueUpdate();
+ }
+ private:
+ SGSharedPtr<RTIObjectClass> _objectClass;
+ SGSharedPtr<RTIObjectInstance> _objectInstance;
+ RTIData _tag;
+ };
+ class RemoveObjectCallback : public QueueCallback {
+ public:
+ RemoveObjectCallback(SGSharedPtr<RTIObjectInstance> objectInstance, const RTIData& tag) :
+ _objectInstance(objectInstance),
+ _tag(tag)
+ { }
+ virtual void operator()()
+ {
+ _objectInstance->removeInstance(_tag);
+ }
+ private:
+ SGSharedPtr<RTIObjectInstance> _objectInstance;
+ RTIData _tag;
+ };
+
+ // The rtiambassador to issue requests
+ SGSharedPtr<RTI13Ambassador> _rtiAmbassador;
+
+ // All the sync labels we got an announcement for
+ std::set<std::string> _pendingSyncLabels;
+ std::set<std::string> _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<SGSharedPtr<QueueCallback> > QueueCallbackList;
+ QueueCallbackList _queueCallbackList;
+
+ // Top level information for dispatching federate object attribute updates
+ typedef std::map<RTI::ObjectHandle, SGSharedPtr<RTI13ObjectInstance> > ObjectInstanceMap;
+ // Map of all available objects
+ ObjectInstanceMap _objectInstanceMap;
+
+ // Top level information for dispatching creation of federate objects
+ typedef std::map<RTI::ObjectClassHandle, SGSharedPtr<RTI13ObjectClass> > 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<std::string>& 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!");
}
RTI13Federate::~RTI13Federate()
{
+ if (_joined)
+ _ambassador->resignFederationExecution();
+ delete _federateAmbassador;
}
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);
try {
_ambassador->resignFederationExecution();
SG_LOG(SG_NETWORK, SG_INFO, "RTI: Resigned from federation.");
+ _joined = false;
_federateHandle = -1;
return true;
} catch (RTI::FederateOwnsAttributes& e) {
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;
}
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;
}
return false;
}
- if (_ambassador->getTimeConstrainedEnabled()) {
+ if (_federateAmbassador->_timeConstrainedEnabled) {
SG_LOG(SG_NETWORK, SG_WARN, "RTI: Time constrained is already enabled.");
return false;
}
return false;
}
- while (!_ambassador->getTimeConstrainedEnabled()) {
+ while (!_federateAmbassador->_timeConstrainedEnabled) {
_ambassador->tick(_tickTimeout, 0);
- _ambassador->processQueues();
+ _federateAmbassador->processQueues();
}
return true;
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;
return false;
}
- if (_ambassador->getTimeRegulationEnabled()) {
+ if (_federateAmbassador->_timeRegulationEnabled) {
SG_LOG(SG_NETWORK, SG_WARN, "RTI: Time regulation already enabled.");
return false;
}
return false;
}
- while (!_ambassador->getTimeRegulationEnabled()) {
+ while (!_federateAmbassador->_timeRegulationEnabled) {
_ambassador->tick(_tickTimeout, 0);
- _ambassador->processQueues();
+ _federateAmbassador->processQueues();
}
return true;
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;
return false;
}
- SGTimeStamp fedTime = _ambassador->getCurrentLogicalTime() + dt;
+ SGTimeStamp fedTime = _federateAmbassador->_federateTime + dt;
return timeAdvanceRequest(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;
return false;
}
- while (_ambassador->getTimeAdvancePending()) {
+ while (_federateAmbassador->_timeAdvancePending) {
_ambassador->tick(_tickTimeout, 0);
- _ambassador->processQueues();
+ _federateAmbassador->processQueues();
}
return true;
RTI13Federate::tick()
{
bool result = _ambassador->tick();
- _ambassador->processQueues();
+ _federateAmbassador->processQueues();
return result;
}
RTI13Federate::tick(const double& minimum, const double& maximum)
{
bool result = _ambassador->tick(minimum, maximum);
- _ambassador->processQueues();
+ _federateAmbassador->processQueues();
return result;
}
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;
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;
}
}
+void
+RTI13Federate::insertObjectInstance(RTI13ObjectInstance* objectInstance)
+{
+ _federateAmbassador->_objectInstanceMap[objectInstance->getHandle()] = objectInstance;
+}
+
}
-// 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
virtual RTI13ObjectClass* createObjectClass(const std::string& name, HLAObjectClass* hlaObjectClass);
virtual RTI13ObjectInstance* getObjectInstance(const std::string& name);
+ void insertObjectInstance(RTI13ObjectInstance* objectInstance);
private:
RTI13Federate(const RTI13Federate&);
/// 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
/// RTI connection
SGSharedPtr<RTI13Ambassador> _ambassador;
+
+ /// Callbacks from the rti are handled here.
+ struct FederateAmbassador;
+ FederateAmbassador* _federateAmbassador;
};
}
std::string
RTI13ObjectClass::getName() const
{
- SGSharedPtr<RTI13Ambassador> 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
unsigned
RTI13ObjectClass::getAttributeIndex(const std::string& name) const
{
- SGSharedPtr<RTI13Ambassador> 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())
unsigned
RTI13ObjectClass::getOrCreateAttributeIndex(const std::string& name)
{
- SGSharedPtr<RTI13Ambassador> 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())
bool
RTI13ObjectClass::publish(const std::set<unsigned>& indexSet)
{
- SGSharedPtr<RTI13Ambassador> ambassador = _ambassador.lock();
- if (!ambassador.valid()) {
+ if (!_ambassador.valid()) {
SG_LOG(SG_NETWORK, SG_WARN, "Error: Ambassador is zero.");
return false;
}
attributeHandleSet->add(_attributeHandleVector[*i]);
}
- ambassador->publishObjectClass(_handle, *attributeHandleSet);
+ _ambassador->publishObjectClass(_handle, *attributeHandleSet);
for (unsigned i = 0; i < getNumAttributes(); ++i) {
_attributeDataVector[i]._published = true;
bool
RTI13ObjectClass::unpublish()
{
- SGSharedPtr<RTI13Ambassador> 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;
bool
RTI13ObjectClass::subscribe(const std::set<unsigned>& indexSet, bool active)
{
- SGSharedPtr<RTI13Ambassador> ambassador = _ambassador.lock();
- if (!ambassador.valid()) {
+ if (!_ambassador.valid()) {
SG_LOG(SG_NETWORK, SG_WARN, "Error: Ambassador is zero.");
return false;
}
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;
bool
RTI13ObjectClass::unsubscribe()
{
- SGSharedPtr<RTI13Ambassador> 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;
RTIObjectInstance*
RTI13ObjectClass::registerObjectInstance(HLAObjectInstance* hlaObjectInstance)
{
- SGSharedPtr<RTI13Ambassador> ambassador = _ambassador.lock();
- if (!ambassador.valid()) {
+ if (!_ambassador.valid()) {
SG_LOG(SG_NETWORK, SG_WARN, "Error: Ambassador is zero.");
return 0;
}
+ SGSharedPtr<RTI13Federate> 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;
private:
RTI::ObjectClassHandle _handle;
- SGWeakPtr<RTI13Ambassador> _ambassador;
+ SGSharedPtr<RTI13Ambassador> _ambassador;
typedef std::map<RTI::AttributeHandle, unsigned> AttributeHandleIndexMap;
AttributeHandleIndexMap _attributeHandleIndexMap;
std::string
RTI13ObjectInstance::getName() const
{
- SGSharedPtr<RTI13Ambassador> 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();
}
void
-RTI13ObjectInstance::addToRequestQueue()
+RTI13ObjectInstance::deleteObjectInstance(const RTIData& tag)
{
- SGSharedPtr<RTI13Ambassador> 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<RTI13Ambassador> ambassador = _ambassador.lock();
- if (!ambassador.valid()) {
- SG_LOG(SG_NETWORK, SG_WARN, "Error: Ambassador is zero.");
+ SGSharedPtr<RTI13Federate> 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) {
void
RTI13ObjectInstance::deleteObjectInstance(const SGTimeStamp& timeStamp, const RTIData& tag)
{
- SGSharedPtr<RTI13Ambassador> ambassador = _ambassador.lock();
- if (!ambassador.valid()) {
+ if (!_ambassador.valid()) {
SG_LOG(SG_NETWORK, SG_WARN, "Error: Ambassador is zero.");
return;
}
+ SGSharedPtr<RTI13Federate> 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) {
void
RTI13ObjectInstance::localDeleteObjectInstance()
{
- SGSharedPtr<RTI13Ambassador> ambassador = _ambassador.lock();
- if (!ambassador.valid()) {
+ if (!_ambassador.valid()) {
SG_LOG(SG_NETWORK, SG_WARN, "Error: Ambassador is zero.");
return;
}
+ SGSharedPtr<RTI13Federate> 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) {
void
RTI13ObjectInstance::requestObjectAttributeValueUpdate()
{
- SGSharedPtr<RTI13Ambassador> ambassador = _ambassador.lock();
- if (!ambassador.valid()) {
+ if (!_ambassador.valid()) {
SG_LOG(SG_NETWORK, SG_WARN, "Error: Ambassador is zero.");
return;
}
if (!attributeHandleSet->size())
return;
- ambassador->requestObjectAttributeValueUpdate(_handle, *attributeHandleSet);
+ _ambassador->requestObjectAttributeValueUpdate(_handle, *attributeHandleSet);
for (unsigned i = 0; i < numAttributes; ++i)
setRequestAttributeUpdate(i, false);
void
RTI13ObjectInstance::updateAttributeValues(const RTIData& tag)
{
- SGSharedPtr<RTI13Ambassador> ambassador = _ambassador.lock();
- if (!ambassador.valid()) {
+ if (!_ambassador.valid()) {
SG_LOG(SG_NETWORK, SG_WARN, "Error: Ambassador is zero.");
return;
}
if (!_attributeValuePairSet->size())
return;
- ambassador->updateAttributeValues(_handle, *_attributeValuePairSet, tag);
+ _ambassador->updateAttributeValues(_handle, *_attributeValuePairSet, tag);
for (unsigned i = 0; i < numAttributes; ++i) {
setAttributeUpdated(i);
void
RTI13ObjectInstance::updateAttributeValues(const SGTimeStamp& timeStamp, const RTIData& tag)
{
- SGSharedPtr<RTI13Ambassador> ambassador = _ambassador.lock();
- if (!ambassador.valid()) {
+ if (!_ambassador.valid()) {
SG_LOG(SG_NETWORK, SG_WARN, "Error: Ambassador is zero.");
return;
}
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);
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();
private:
RTI::ObjectHandle _handle;
SGSharedPtr<const RTI13ObjectClass> _objectClass;
- SGWeakPtr<RTI13Ambassador> _ambassador;
+ SGSharedPtr<RTI13Ambassador> _ambassador;
// cached storage for updates
std::auto_ptr<RTI::AttributeHandleValuePairSet> _attributeValuePairSet;
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;
if (request) {
if (!_pendingAttributeUpdateRequest) {
_pendingAttributeUpdateRequest = true;
- addToRequestQueue();
}
}
}