#include "RTIObjectClass.hxx"
#include "RTIObjectInstance.hxx"
#include "HLADataType.hxx"
+#include "HLADataTypeVisitor.hxx"
#include "HLAFederate.hxx"
#include "HLAObjectInstance.hxx"
return _rtiObjectClass->unpublish();
}
+void
+HLAObjectClass::discoverInstance(HLAObjectInstance& objectInstance, const RTIData& tag)
+{
+ if (_instanceCallback.valid())
+ _instanceCallback->discoverInstance(*this, objectInstance, tag);
+}
+
+void
+HLAObjectClass::removeInstance(HLAObjectInstance& objectInstance, const RTIData& tag)
+{
+ if (_instanceCallback.valid())
+ _instanceCallback->removeInstance(*this, objectInstance, tag);
+}
+
+void
+HLAObjectClass::registerInstance(HLAObjectInstance& objectInstance)
+{
+ if (_instanceCallback.valid())
+ _instanceCallback->registerInstance(*this, objectInstance);
+}
+
+void
+HLAObjectClass::deleteInstance(HLAObjectInstance& objectInstance)
+{
+ if (_instanceCallback.valid())
+ _instanceCallback->deleteInstance(*this, objectInstance);
+}
+
void
HLAObjectClass::startRegistration() const
{
return federate->createObjectInstance(this, name);
}
+void
+HLAObjectClass::createAttributeDataElements(HLAObjectInstance& objectInstance)
+{
+ unsigned numAttributes = getNumAttributes();
+ for (unsigned i = 0; i < numAttributes; ++i)
+ objectInstance.createAndSetAttributeDataElement(i);
+}
+
+HLADataElement*
+HLAObjectClass::createAttributeDataElement(HLAObjectInstance& objectInstance, unsigned index)
+{
+ // FIXME here we want to have a vector of factories and if this fails do the following
+ const HLADataType* dataType = getAttributeDataType(index);
+ if (!dataType)
+ return 0;
+ HLADataElementFactoryVisitor dataElementFactoryVisitor;
+ dataType->accept(dataElementFactoryVisitor);
+ return dataElementFactoryVisitor.getDataElement();
+}
+
void
HLAObjectClass::_setRTIObjectClass(RTIObjectClass* objectClass)
{
<< rtiObjectInstance->getName() << "\" object");
return;
}
- if (_instanceCallback.valid())
- _instanceCallback->discoverInstance(*this, *objectInstance, tag);
+ objectInstance->discoverInstance(tag);
+ objectInstance->createAttributeDataElements();
}
void
return;
}
SG_LOG(SG_NETWORK, SG_INFO, "RTI: remove object instance \"" << objectInstance.getName() << "\"");
- if (_instanceCallback.valid())
- _instanceCallback->removeInstance(*this, objectInstance, tag);
+ objectInstance.removeInstance(tag);
federate->_eraseObjectInstance(objectInstance.getName());
}
<< objectInstance->getName() << "\" object");
return;
}
- if (_instanceCallback.valid())
- _instanceCallback->registerInstance(*this, *objectInstance);
+ registerInstance(*objectInstance);
+ objectInstance->createAttributeDataElements();
}
void
SG_LOG(SG_NETWORK, SG_ALERT, "RTI: could not find parent federate while deleting object instance");
return;
}
- if (_instanceCallback.valid())
- _instanceCallback->deleteInstance(*this, objectInstance);
+ deleteInstance(objectInstance);
federate->_eraseObjectInstance(objectInstance.getName());
}
const SGSharedPtr<InstanceCallback>& getInstanceCallback() const
{ return _instanceCallback; }
+ virtual void discoverInstance(HLAObjectInstance& objectInstance, const RTIData& tag);
+ virtual void removeInstance(HLAObjectInstance& objectInstance, const RTIData& tag);
+ virtual void registerInstance(HLAObjectInstance& objectInstance);
+ virtual void deleteInstance(HLAObjectInstance& objectInstance);
+
// Is called by the default registration callback if installed
// Should register the already known object instances of this class.
virtual void startRegistration() const;
/// Create a new instance of this class.
virtual HLAObjectInstance* createObjectInstance(const std::string& name);
+ virtual void createAttributeDataElements(HLAObjectInstance& objectInstance);
+ virtual HLADataElement* createAttributeDataElement(HLAObjectInstance& objectInstance, unsigned index);
+
private:
HLAObjectClass(const HLAObjectClass&);
HLAObjectClass& operator=(const HLAObjectClass&);
}
}
+void
+HLAObjectInstance::discoverInstance(const RTIData& tag)
+{
+ HLAObjectClass* objectClass = getObjectClass().get();
+ if (!objectClass) {
+ SG_LOG(SG_IO, SG_ALERT, "Could not discover instance of unknown object class!");
+ return;
+ }
+ objectClass->discoverInstance(*this, tag);
+}
+
+void
+HLAObjectInstance::removeInstance(const RTIData& tag)
+{
+ HLAObjectClass* objectClass = getObjectClass().get();
+ if (!objectClass) {
+ SG_LOG(SG_IO, SG_ALERT, "Could not remove instance of unknown object class!");
+ return;
+ }
+ objectClass->removeInstance(*this, tag);
+}
+
void
HLAObjectInstance::registerInstance()
{
_rtiObjectInstance->deleteObjectInstance(tag);
}
+void
+HLAObjectInstance::createAttributeDataElements()
+{
+ HLAObjectClass* objectClass = getObjectClass().get();
+ if (!objectClass) {
+ SG_LOG(SG_IO, SG_ALERT, "Could not create data elements for instance of unknown object class!");
+ return;
+ }
+ objectClass->createAttributeDataElements(*this);
+}
+
+void
+HLAObjectInstance::createAndSetAttributeDataElement(unsigned index)
+{
+ if (getAttributeDataElement(index)) {
+ SG_LOG(SG_IO, SG_DEBUG, "Attribute data element for attribute \""
+ << getAttributeName(index) << "\" is already set.");
+ return;
+ }
+ SGSharedPtr<HLADataElement> dataElement = createAttributeDataElement(index);
+ setAttributeDataElement(index, dataElement);
+}
+
+HLADataElement*
+HLAObjectInstance::createAttributeDataElement(unsigned index)
+{
+ HLAObjectClass* objectClass = getObjectClass().get();
+ if (!objectClass) {
+ SG_LOG(SG_IO, SG_ALERT, "Could not create data element for instance of unknown object class!");
+ return 0;
+ }
+ return objectClass->createAttributeDataElement(*this, index);
+}
+
void
HLAObjectInstance::updateAttributeValues(const RTIData& tag)
{
void setAttribute(unsigned index, const HLAPathElementMap& pathElementMap);
void setAttributes(const HLAAttributePathElementMap& attributePathElementMap);
+ /// Gets called on discovering this object instance.
+ virtual void discoverInstance(const RTIData& tag);
+ /// Gets called on remove this object instance.
+ virtual void removeInstance(const RTIData& tag);
+
+ /// Call this to register the object instance at the rti and assign the object class to it.
void registerInstance();
- void registerInstance(HLAObjectClass* objectClass);
- void deleteInstance(const RTIData& tag);
+ virtual void registerInstance(HLAObjectClass* objectClass);
+ /// Call this to delete the object instance from the rti.
+ virtual void deleteInstance(const RTIData& tag);
+
+ /// Is called when the instance is either registered or discovered.
+ /// It creates data elements for each element that is not yet set and that has a data type attached.
+ /// the default calls back into the object class createAttributeDataElements method.
+ virtual void createAttributeDataElements();
+ /// Create and set the data element with index. Called somewhere in the above callchain.
+ void createAndSetAttributeDataElement(unsigned index);
+ /// Create an individual data element, the default calls back into the object class
+ /// createAttributeDataElement method.
+ virtual HLADataElement* createAttributeDataElement(unsigned index);
// Push the current values into the RTI
virtual void updateAttributeValues(const RTIData& tag);