// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//
+#ifdef HAVE_CONFIG_H
+# include <simgear_config.h>
+#endif
+
+#include <simgear/compiler.h>
+
#include "HLAObjectClass.hxx"
#include "simgear/debug/logstream.hxx"
#include "RTIObjectClass.hxx"
#include "RTIObjectInstance.hxx"
#include "HLADataType.hxx"
+#include "HLADataTypeVisitor.hxx"
#include "HLAFederate.hxx"
#include "HLAObjectInstance.hxx"
return _name;
}
+const SGWeakPtr<HLAFederate>&
+HLAObjectClass::getFederate() const
+{
+ return _federate;
+}
+
unsigned
HLAObjectClass::getNumAttributes() const
{
_attributeVector[index]._publicationType = publicationType;
}
-HLADataElement::IndexPathPair
-HLAObjectClass::getIndexPathPair(const HLADataElement::StringPathPair& stringPathPair) const
+bool
+HLAObjectClass::getDataElementIndex(HLADataElementIndex& dataElementIndex, const std::string& path) const
{
- unsigned index = getAttributeIndex(stringPathPair.first);
+ if (path.empty()) {
+ SG_LOG(SG_NETWORK, SG_ALERT, "HLAObjectClass: failed to parse empty element path!");
+ return false;
+ }
+ std::string::size_type len = std::min(path.find_first_of("[."), path.size());
+ unsigned index = 0;
+ while (index < getNumAttributes()) {
+ if (path.compare(0, len, getAttributeName(index)) == 0)
+ break;
+ ++index;
+ }
if (getNumAttributes() <= index) {
- SG_LOG(SG_NETWORK, SG_ALERT, "HLAObjectClass::getIndexPathPair(\""
- << HLADataElement::toString(stringPathPair)
- << "\"): Could not resolve attribute \"" << stringPathPair.first
- << "\" for object class \"" << getName() << "\"!");
+ SG_LOG(SG_NETWORK, SG_ALERT, "HLAObjectClass: faild to parse data element index \"" << path << "\":\n"
+ << "Attribute \"" << path.substr(0, len) << "\" not found in object class \""
+ << getName() << "\"!");
+ return false;
+ }
+ if (!getAttributeDataType(index)) {
+ SG_LOG(SG_NETWORK, SG_ALERT, "HLAObjectClass: faild to parse data element index \"" << path << "\":\n"
+ << "Undefined attribute data type in variant record data type \""
+ << getAttributeName(index) << "\"!");
+ return false;
}
- return HLADataElement::IndexPathPair(index, stringPathPair.second);
+ dataElementIndex.push_back(index);
+ return getAttributeDataType(index)->getDataElementIndex(dataElementIndex, path, len);
}
-HLADataElement::IndexPathPair
-HLAObjectClass::getIndexPathPair(const std::string& path) const
+HLADataElementIndex
+HLAObjectClass::getDataElementIndex(const std::string& path) const
{
- return getIndexPathPair(HLADataElement::toStringPathPair(path));
+ HLADataElementIndex dataElementIndex;
+ getDataElementIndex(dataElementIndex, path);
+ return dataElementIndex;
}
bool
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
{
HLAObjectInstance*
HLAObjectClass::createObjectInstance(const std::string& name)
{
- HLAObjectInstance* objectInstance = createObjectInstance();
- if (objectInstance)
- return objectInstance;
SGSharedPtr<HLAFederate> federate = _federate.lock();
if (!federate.valid())
return 0;
return federate->createObjectInstance(this, name);
}
-HLAObjectInstance*
-HLAObjectClass::createObjectInstance()
+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)
{
- return 0;
+ // 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
<< 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());
}