1 // Copyright (C) 2009 - 2010 Mathias Froehlich - Mathias.Froehlich@web.de
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Library General Public
5 // License as published by the Free Software Foundation; either
6 // version 2 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Library General Public License for more details.
13 // You should have received a copy of the GNU General Public License
14 // along with this program; if not, write to the Free Software
15 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 #include "HLAObjectClass.hxx"
20 #include "RTIFederate.hxx"
21 #include "RTIObjectClass.hxx"
22 #include "RTIObjectInstance.hxx"
23 #include "HLADataType.hxx"
24 #include "HLAFederate.hxx"
25 #include "HLAObjectInstance.hxx"
29 HLAObjectClass::InstanceCallback::~InstanceCallback()
34 HLAObjectClass::InstanceCallback::discoverInstance(const HLAObjectClass&, HLAObjectInstance& objectInstance, const RTIData& tag)
39 HLAObjectClass::InstanceCallback::removeInstance(const HLAObjectClass&, HLAObjectInstance& objectInstance, const RTIData& tag)
44 HLAObjectClass::InstanceCallback::registerInstance(const HLAObjectClass&, HLAObjectInstance& objectInstance)
49 HLAObjectClass::InstanceCallback::deleteInstance(const HLAObjectClass&, HLAObjectInstance& objectInstance)
53 HLAObjectClass::RegistrationCallback::~RegistrationCallback()
57 HLAObjectClass::HLAObjectClass(const std::string& name, HLAFederate& federate) :
60 _rtiObjectClass = federate._rtiFederate->createObjectClass(name, this);
61 if (!_rtiObjectClass.valid())
62 SG_LOG(SG_NETWORK, SG_WARN, "HLAObjectClass::HLAObjectClass(): No RTIObjectClass found for \"" << name << "\"!");
65 HLAObjectClass::~HLAObjectClass()
70 HLAObjectClass::getNumAttributes() const
72 if (!_rtiObjectClass.valid()) {
73 SG_LOG(SG_NETWORK, SG_WARN, "HLAObjectClass::getAttributeIndex(): No RTIObject class for object class \"" << getName() << "\"!");
76 return _rtiObjectClass->getNumAttributes();
80 HLAObjectClass::getAttributeIndex(const std::string& name) const
82 if (!_rtiObjectClass.valid()) {
83 SG_LOG(SG_NETWORK, SG_WARN, "HLAObjectClass::getAttributeIndex(): No RTIObject class for object class \"" << getName() << "\"!");
86 return _rtiObjectClass->getOrCreateAttributeIndex(name);
90 HLAObjectClass::getAttributeName(unsigned index) const
92 if (!_rtiObjectClass.valid()) {
93 SG_LOG(SG_NETWORK, SG_WARN, "HLAObjectClass::getAttributeIndex(): No RTIObject class for object class \"" << getName() << "\"!");
96 return _rtiObjectClass->getAttributeName(index);
100 HLAObjectClass::getAttributeDataType(unsigned index) const
102 if (!_rtiObjectClass.valid()) {
103 SG_LOG(SG_NETWORK, SG_WARN, "HLAObjectClass::getAttributeDataType(): No RTIObject class for object class \"" << getName() << "\"!");
106 return _rtiObjectClass->getAttributeDataType(index);
110 HLAObjectClass::setAttributeDataType(unsigned index, const HLADataType* dataType)
112 if (!_rtiObjectClass.valid()) {
113 SG_LOG(SG_NETWORK, SG_WARN, "HLAObjectClass::setAttributeDataType(): No RTIObject class for object class \"" << getName() << "\"!");
116 _rtiObjectClass->setAttributeDataType(index, dataType);
120 HLAObjectClass::getAttributeUpdateType(unsigned index) const
122 if (!_rtiObjectClass.valid()) {
123 SG_LOG(SG_NETWORK, SG_WARN, "HLAObjectClass::getAttributeUpdateType(): No RTIObject class for object class \"" << getName() << "\"!");
124 return HLAUndefinedUpdate;
126 return _rtiObjectClass->getAttributeUpdateType(index);
130 HLAObjectClass::setAttributeUpdateType(unsigned index, HLAUpdateType updateType)
132 if (!_rtiObjectClass.valid()) {
133 SG_LOG(SG_NETWORK, SG_WARN, "HLAObjectClass::setAttributeUpdateType(): "
134 "No RTIObject class for object class \"" << getName() << "\"!");
137 _rtiObjectClass->setAttributeUpdateType(index, updateType);
140 HLADataElement::IndexPathPair
141 HLAObjectClass::getIndexPathPair(const HLADataElement::AttributePathPair& attributePathPair) const
143 unsigned index = getAttributeIndex(attributePathPair.first);
144 if (getNumAttributes() <= index) {
145 SG_LOG(SG_NETWORK, SG_ALERT, "HLAObjectClass::getIndexPathPair(\""
146 << HLADataElement::toString(attributePathPair)
147 << "\"): Could not resolve attribute \"" << attributePathPair.first
148 << "\" for object class \"" << getName() << "\"!");
150 return HLADataElement::IndexPathPair(index, attributePathPair.second);
153 HLADataElement::IndexPathPair
154 HLAObjectClass::getIndexPathPair(const std::string& path) const
156 return getIndexPathPair(HLADataElement::toAttributePathPair(path));
160 HLAObjectClass::subscribe(const std::set<unsigned>& indexSet, bool active)
162 if (!_rtiObjectClass.valid()) {
163 SG_LOG(SG_NETWORK, SG_WARN, "HLAObjectClass::subscribe(): No RTIObject class for object class \"" << getName() << "\"!");
166 return _rtiObjectClass->subscribe(indexSet, active);
170 HLAObjectClass::unsubscribe()
172 if (!_rtiObjectClass.valid()) {
173 SG_LOG(SG_NETWORK, SG_WARN, "HLAObjectClass::unsubscribe(): No RTIObject class for object class \"" << getName() << "\"!");
176 return _rtiObjectClass->unsubscribe();
180 HLAObjectClass::publish(const std::set<unsigned>& indexSet)
182 if (!_rtiObjectClass.valid()) {
183 SG_LOG(SG_NETWORK, SG_WARN, "HLAObjectClass::publish(): No RTIObject class for object class \"" << getName() << "\"!");
186 return _rtiObjectClass->publish(indexSet);
190 HLAObjectClass::unpublish()
192 if (!_rtiObjectClass.valid()) {
193 SG_LOG(SG_NETWORK, SG_WARN, "HLAObjectClass::unpublish(): No RTIObject class for object class \"" << getName() << "\"!");
196 return _rtiObjectClass->unpublish();
200 HLAObjectClass::startRegistration() const
205 HLAObjectClass::stopRegistration() const
210 HLAObjectClass::createObjectInstance(RTIObjectInstance* rtiObjectInstance)
212 return new HLAObjectInstance(this, rtiObjectInstance);
216 HLAObjectClass::discoverInstance(RTIObjectInstance* objectInstance, const RTIData& tag)
218 SGSharedPtr<HLAObjectInstance> hlaObjectInstance = createObjectInstance(objectInstance);
219 if (hlaObjectInstance.valid()) {
220 SG_LOG(SG_NETWORK, SG_INFO, "RTI: create new object instance for discovered \""
221 << hlaObjectInstance->getName() << "\" object");
222 _objectInstanceSet.insert(hlaObjectInstance);
223 discoverInstanceCallback(*hlaObjectInstance, tag);
225 SG_LOG(SG_NETWORK, SG_INFO, "RTI: local delete of \"" << objectInstance->getName() << "\"");
226 objectInstance->localDeleteObjectInstance();
231 HLAObjectClass::removeInstance(HLAObjectInstance& hlaObjectInstance, const RTIData& tag)
233 SG_LOG(SG_NETWORK, SG_INFO, "RTI: remove object instance \"" << hlaObjectInstance.getName() << "\"");
234 removeInstanceCallback(hlaObjectInstance, tag);
235 _objectInstanceSet.erase(&hlaObjectInstance);
239 HLAObjectClass::registerInstance(HLAObjectInstance& objectInstance)
241 _objectInstanceSet.insert(&objectInstance);
242 registerInstanceCallback(objectInstance);
246 HLAObjectClass::deleteInstance(HLAObjectInstance& objectInstance)
248 deleteInstanceCallback(objectInstance);
249 _objectInstanceSet.erase(&objectInstance);
253 HLAObjectClass::discoverInstanceCallback(HLAObjectInstance& objectInstance, const RTIData& tag) const
255 if (!_instanceCallback.valid())
257 _instanceCallback->discoverInstance(*this, objectInstance, tag);
261 HLAObjectClass::removeInstanceCallback(HLAObjectInstance& objectInstance, const RTIData& tag) const
263 if (!_instanceCallback.valid())
265 _instanceCallback->removeInstance(*this, objectInstance, tag);
269 HLAObjectClass::registerInstanceCallback(HLAObjectInstance& objectInstance) const
271 if (!_instanceCallback.valid())
273 _instanceCallback->registerInstance(*this, objectInstance);
277 HLAObjectClass::deleteInstanceCallback(HLAObjectInstance& objectInstance) const
279 if (!_instanceCallback.valid())
281 _instanceCallback->deleteInstance(*this, objectInstance);
285 HLAObjectClass::startRegistrationCallback()
287 if (_registrationCallback.valid())
288 _registrationCallback->startRegistration(*this);
294 HLAObjectClass::stopRegistrationCallback()
296 if (_registrationCallback.valid())
297 _registrationCallback->stopRegistration(*this);
302 } // namespace simgear