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 #ifndef RTI13Ambassador_hxx
19 #define RTI13Ambassador_hxx
28 #ifndef RTI_USES_STD_FSTREAM
29 #define RTI_USES_STD_FSTREAM
35 #include <simgear/debug/logstream.hxx>
36 #include <simgear/structure/SGWeakReferenced.hxx>
37 #include <simgear/structure/SGSharedPtr.hxx>
38 #include <simgear/structure/SGWeakPtr.hxx>
39 #include <simgear/timing/timestamp.hxx>
41 #include "RTIObjectClass.hxx"
42 #include "RTIData.hxx"
43 #include "RTI13Federate.hxx"
44 #include "RTI13ObjectInstance.hxx"
50 class RTI13Ambassador : public SGReferenced {
55 void createFederationExecution(const std::string& name, const std::string& objectModel)
56 { _rtiAmbassador.createFederationExecution(name.c_str(), objectModel.c_str()); }
57 void destroyFederationExecution(const std::string& name)
58 { _rtiAmbassador.destroyFederationExecution(name.c_str()); }
60 RTI::FederateHandle joinFederationExecution(const std::string& federate, const std::string& federation, RTI::FederateAmbassador* federateAmbassador)
61 { return _rtiAmbassador.joinFederationExecution(federate.c_str(), federation.c_str(), federateAmbassador); }
62 void resignFederationExecution()
63 { _rtiAmbassador.resignFederationExecution(RTI::DELETE_OBJECTS_AND_RELEASE_ATTRIBUTES); }
65 void registerFederationSynchronizationPoint(const std::string& label, const RTIData& tag)
66 { _rtiAmbassador.registerFederationSynchronizationPoint(label.c_str(), tag.data()); }
67 void synchronizationPointAchieved(const std::string& label)
68 { _rtiAmbassador.synchronizationPointAchieved(label.c_str()); }
70 void publishObjectClass(const RTI::ObjectClassHandle& handle, const RTI::AttributeHandleSet& attributeHandleSet)
71 { _rtiAmbassador.publishObjectClass(handle, attributeHandleSet); }
72 void unpublishObjectClass(const RTI::ObjectClassHandle& handle)
73 { _rtiAmbassador.unpublishObjectClass(handle); }
75 void publishInteractionClass(const RTI::InteractionClassHandle& handle)
76 { _rtiAmbassador.publishInteractionClass(handle); }
77 void unpublishInteractionClass(const RTI::InteractionClassHandle& handle)
78 { _rtiAmbassador.unpublishInteractionClass(handle); }
80 void subscribeObjectClassAttributes(const RTI::ObjectClassHandle& handle, const RTI::AttributeHandleSet& attributeHandleSet, bool active)
81 { _rtiAmbassador.subscribeObjectClassAttributes(handle, attributeHandleSet, active ? RTI::RTI_TRUE : RTI::RTI_FALSE); }
82 void unsubscribeObjectClass(const RTI::ObjectClassHandle& handle)
83 { _rtiAmbassador.unsubscribeObjectClass(handle); }
85 void subscribeInteractionClass(const RTI::InteractionClassHandle& handle, bool active)
86 { _rtiAmbassador.subscribeInteractionClass(handle, active ? RTI::RTI_TRUE : RTI::RTI_FALSE); }
87 void unsubscribeInteractionClass(const RTI::InteractionClassHandle& handle)
88 { _rtiAmbassador.unsubscribeInteractionClass(handle); }
90 RTI::ObjectHandle registerObjectInstance(const RTI::ObjectClassHandle& handle)
91 { return _rtiAmbassador.registerObjectInstance(handle); }
92 void updateAttributeValues(const RTI::ObjectHandle& objectHandle, const RTI::AttributeHandleValuePairSet& attributeValues,
93 const SGTimeStamp& timeStamp, const RTIData& tag)
94 { _rtiAmbassador.updateAttributeValues(objectHandle, attributeValues, toFedTime(timeStamp), tag.data()); }
95 void updateAttributeValues(const RTI::ObjectHandle& objectHandle, const RTI::AttributeHandleValuePairSet& attributeValues, const RTIData& tag)
96 { _rtiAmbassador.updateAttributeValues(objectHandle, attributeValues, tag.data()); }
98 // RTI::EventRetractionHandle sendInteraction(RTI::InteractionClassHandle interactionClassHandle, const RTI::ParameterHandleValuePairSet& parameters, const RTI::FedTime& fedTime, const RTIData& tag)
99 // { return _rtiAmbassador.sendInteraction(interactionClassHandle, parameters, fedTime, tag.data()); }
100 // void sendInteraction(RTI::InteractionClassHandle interactionClassHandle, const RTI::ParameterHandleValuePairSet& parameters, const RTIData& tag)
101 // { _rtiAmbassador.sendInteraction(interactionClassHandle, parameters, tag.data()); }
103 void deleteObjectInstance(const RTI::ObjectHandle& objectHandle, const SGTimeStamp& timeStamp, const RTIData& tag)
104 { /* RTI::EventRetractionHandle h = */ _rtiAmbassador.deleteObjectInstance(objectHandle, toFedTime(timeStamp), tag.data()); }
105 void deleteObjectInstance(const RTI::ObjectHandle& objectHandle, const RTIData& tag)
106 { _rtiAmbassador.deleteObjectInstance(objectHandle, tag.data()); }
107 void localDeleteObjectInstance(const RTI::ObjectHandle& objectHandle)
108 { _rtiAmbassador.localDeleteObjectInstance(objectHandle); }
110 void requestObjectAttributeValueUpdate(const RTI::ObjectHandle& handle, const RTI::AttributeHandleSet& attributeHandleSet)
111 { _rtiAmbassador.requestObjectAttributeValueUpdate(handle, attributeHandleSet); }
112 void requestClassAttributeValueUpdate(const RTI::ObjectClassHandle& handle, const RTI::AttributeHandleSet& attributeHandleSet)
113 { _rtiAmbassador.requestClassAttributeValueUpdate(handle, attributeHandleSet); }
115 // Ownership Management -------------------
117 // bool unconditionalAttributeOwnershipDivestiture(const RTIHandle& objectHandle, const RTIHandleSet& attributeHandles)
120 // std::auto_ptr<RTI::AttributeHandleSet> attributeHandleSet(RTI::AttributeHandleSetFactory::create(attributeHandles.size()));
121 // for (RTIHandleSet::const_iterator i = attributeHandles.begin(); i != attributeHandles.end(); ++i)
122 // attributeHandleSet->add(*i);
123 // _rtiAmbassador.unconditionalAttributeOwnershipDivestiture(objectHandle, *attributeHandleSet);
125 // } catch (RTI::ObjectNotKnown& e) {
126 // } catch (RTI::AttributeNotDefined& e) {
127 // } catch (RTI::AttributeNotOwned& e) {
128 // } catch (RTI::FederateNotExecutionMember& e) {
129 // } catch (RTI::ConcurrentAccessAttempted& e) {
130 // } catch (RTI::SaveInProgress& e) {
131 // } catch (RTI::RestoreInProgress& e) {
132 // } catch (RTI::RTIinternalError& e) {
136 // bool negotiatedAttributeOwnershipDivestiture(const RTIHandle& objectHandle, const RTIHandleSet& attributeHandles, const RTIData& tag)
139 // std::auto_ptr<RTI::AttributeHandleSet> attributeHandleSet(RTI::AttributeHandleSetFactory::create(attributeHandles.size()));
140 // for (RTIHandleSet::const_iterator i = attributeHandles.begin(); i != attributeHandles.end(); ++i)
141 // attributeHandleSet->add(*i);
142 // _rtiAmbassador.negotiatedAttributeOwnershipDivestiture(objectHandle, *attributeHandleSet, tag.data());
144 // } catch (RTI::ObjectNotKnown& e) {
145 // } catch (RTI::AttributeNotDefined& e) {
146 // } catch (RTI::AttributeNotOwned& e) {
147 // } catch (RTI::AttributeAlreadyBeingDivested& e) {
148 // } catch (RTI::FederateNotExecutionMember& e) {
149 // } catch (RTI::ConcurrentAccessAttempted& e) {
150 // } catch (RTI::SaveInProgress& e) {
151 // } catch (RTI::RestoreInProgress& e) {
152 // } catch (RTI::RTIinternalError& e) {
156 // bool attributeOwnershipAcquisition(const RTIHandle& objectHandle, const RTIHandleSet& attributeHandles, const RTIData& tag)
159 // std::auto_ptr<RTI::AttributeHandleSet> attributeHandleSet(RTI::AttributeHandleSetFactory::create(attributeHandles.size()));
160 // for (RTIHandleSet::const_iterator i = attributeHandles.begin(); i != attributeHandles.end(); ++i)
161 // attributeHandleSet->add(*i);
162 // _rtiAmbassador.attributeOwnershipAcquisition(objectHandle, *attributeHandleSet, tag.data());
164 // } catch (RTI::ObjectNotKnown& e) {
165 // } catch (RTI::ObjectClassNotPublished& e) {
166 // } catch (RTI::AttributeNotDefined& e) {
167 // } catch (RTI::AttributeNotPublished& e) {
168 // } catch (RTI::FederateOwnsAttributes& e) {
169 // } catch (RTI::FederateNotExecutionMember& e) {
170 // } catch (RTI::ConcurrentAccessAttempted& e) {
171 // } catch (RTI::SaveInProgress& e) {
172 // } catch (RTI::RestoreInProgress& e) {
173 // } catch (RTI::RTIinternalError& e) {
177 // bool attributeOwnershipAcquisitionIfAvailable(const RTIHandle& objectHandle, const RTIHandleSet& attributeHandles)
180 // std::auto_ptr<RTI::AttributeHandleSet> attributeHandleSet(RTI::AttributeHandleSetFactory::create(attributeHandles.size()));
181 // for (RTIHandleSet::const_iterator i = attributeHandles.begin(); i != attributeHandles.end(); ++i)
182 // attributeHandleSet->add(*i);
183 // _rtiAmbassador.attributeOwnershipAcquisitionIfAvailable(objectHandle, *attributeHandleSet);
185 // } catch (RTI::ObjectNotKnown& e) {
186 // } catch (RTI::ObjectClassNotPublished& e) {
187 // } catch (RTI::AttributeNotDefined& e) {
188 // } catch (RTI::AttributeNotPublished& e) {
189 // } catch (RTI::FederateOwnsAttributes& e) {
190 // } catch (RTI::AttributeAlreadyBeingAcquired& e) {
191 // } catch (RTI::FederateNotExecutionMember& e) {
192 // } catch (RTI::ConcurrentAccessAttempted& e) {
193 // } catch (RTI::SaveInProgress& e) {
194 // } catch (RTI::RestoreInProgress& e) {
195 // } catch (RTI::RTIinternalError& e) {
199 // RTIHandleSet attributeOwnershipReleaseResponse(const RTIHandle& objectHandle, const RTIHandleSet& attributeHandles)
202 // std::auto_ptr<RTI::AttributeHandleSet> attributeHandleSet(RTI::AttributeHandleSetFactory::create(attributeHandles.size()));
203 // for (RTIHandleSet::const_iterator i = attributeHandles.begin(); i != attributeHandles.end(); ++i)
204 // attributeHandleSet->add(*i);
205 // attributeHandleSet.reset(_rtiAmbassador.attributeOwnershipReleaseResponse(objectHandle, *attributeHandleSet));
206 // RTIHandleSet handleSet;
207 // RTI::ULong numAttribs = attributeHandleSet->size();
208 // for (RTI::ULong i = 0; i < numAttribs; ++i)
209 // handleSet.insert(attributeHandleSet->getHandle(i));
211 // } catch (RTI::ObjectNotKnown& e) {
212 // } catch (RTI::AttributeNotDefined& e) {
213 // } catch (RTI::AttributeNotOwned& e) {
214 // } catch (RTI::FederateWasNotAskedToReleaseAttribute& e) {
215 // } catch (RTI::FederateNotExecutionMember& e) {
216 // } catch (RTI::ConcurrentAccessAttempted& e) {
217 // } catch (RTI::SaveInProgress& e) {
218 // } catch (RTI::RestoreInProgress& e) {
219 // } catch (RTI::RTIinternalError& e) {
221 // return RTIHandleSet();
223 // bool cancelNegotiatedAttributeOwnershipDivestiture(const RTIHandle& objectHandle, const RTIHandleSet& attributeHandles)
226 // std::auto_ptr<RTI::AttributeHandleSet> attributeHandleSet(RTI::AttributeHandleSetFactory::create(attributeHandles.size()));
227 // for (RTIHandleSet::const_iterator i = attributeHandles.begin(); i != attributeHandles.end(); ++i)
228 // attributeHandleSet->add(*i);
229 // _rtiAmbassador.cancelNegotiatedAttributeOwnershipDivestiture(objectHandle, *attributeHandleSet);
231 // } catch (RTI::ObjectNotKnown& e) {
232 // } catch (RTI::AttributeNotDefined& e) {
233 // } catch (RTI::AttributeNotOwned& e) {
234 // } catch (RTI::AttributeDivestitureWasNotRequested& e) {
235 // } catch (RTI::FederateNotExecutionMember& e) {
236 // } catch (RTI::ConcurrentAccessAttempted& e) {
237 // } catch (RTI::SaveInProgress& e) {
238 // } catch (RTI::RestoreInProgress& e) {
239 // } catch (RTI::RTIinternalError& e) {
243 // bool cancelAttributeOwnershipAcquisition(const RTIHandle& objectHandle, const RTIHandleSet& attributeHandles)
246 // std::auto_ptr<RTI::AttributeHandleSet> attributeHandleSet(RTI::AttributeHandleSetFactory::create(attributeHandles.size()));
247 // for (RTIHandleSet::const_iterator i = attributeHandles.begin(); i != attributeHandles.end(); ++i)
248 // attributeHandleSet->add(*i);
249 // _rtiAmbassador.cancelAttributeOwnershipAcquisition(objectHandle, *attributeHandleSet);
251 // } catch (RTI::ObjectNotKnown& e) {
252 // } catch (RTI::AttributeNotDefined& e) {
253 // } catch (RTI::AttributeAlreadyOwned& e) {
254 // } catch (RTI::AttributeAcquisitionWasNotRequested& e) {
255 // } catch (RTI::FederateNotExecutionMember& e) {
256 // } catch (RTI::ConcurrentAccessAttempted& e) {
257 // } catch (RTI::SaveInProgress& e) {
258 // } catch (RTI::RestoreInProgress& e) {
259 // } catch (RTI::RTIinternalError& e) {
263 // bool queryAttributeOwnership(const RTIHandle& objectHandle, const RTIHandle& attributeHandle)
266 // _rtiAmbassador.queryAttributeOwnership(objectHandle, attributeHandle);
268 // } catch (RTI::ObjectNotKnown& e) {
269 // } catch (RTI::AttributeNotDefined& e) {
270 // } catch (RTI::FederateNotExecutionMember& e) {
271 // } catch (RTI::ConcurrentAccessAttempted& e) {
272 // } catch (RTI::SaveInProgress& e) {
273 // } catch (RTI::RestoreInProgress& e) {
274 // } catch (RTI::RTIinternalError& e) {
278 bool isAttributeOwnedByFederate(const RTI::ObjectHandle& objectHandle, const RTI::AttributeHandle& attributeHandle)
279 { return _rtiAmbassador.isAttributeOwnedByFederate(objectHandle, attributeHandle); }
283 void enableTimeRegulation(const SGTimeStamp& lookahead)
285 RTIfedTime federateTime;
286 federateTime.setZero();
287 _rtiAmbassador.enableTimeRegulation(federateTime, toFedTime(lookahead));
289 void disableTimeRegulation()
290 { _rtiAmbassador.disableTimeRegulation();}
292 void enableTimeConstrained()
293 { _rtiAmbassador.enableTimeConstrained(); }
294 void disableTimeConstrained()
295 { _rtiAmbassador.disableTimeConstrained(); }
297 void timeAdvanceRequest(const SGTimeStamp& time)
298 { _rtiAmbassador.timeAdvanceRequest(toFedTime(time)); }
299 void timeAdvanceRequestAvailable(const SGTimeStamp& time)
300 { _rtiAmbassador.timeAdvanceRequestAvailable(toFedTime(time)); }
301 void flushQueueRequest(const SGTimeStamp& time)
302 { _rtiAmbassador.flushQueueRequest(toFedTime(time)); }
304 bool queryGALT(SGTimeStamp& timeStamp)
307 fedTime.setPositiveInfinity();
308 _rtiAmbassador.queryLBTS(fedTime);
309 if (fedTime.isPositiveInfinity())
311 timeStamp = toTimeStamp(fedTime);
314 bool queryLITS(SGTimeStamp& timeStamp)
317 fedTime.setPositiveInfinity();
318 _rtiAmbassador.queryMinNextEventTime(fedTime);
319 if (fedTime.isPositiveInfinity())
321 timeStamp = toTimeStamp(fedTime);
324 void queryFederateTime(SGTimeStamp& timeStamp)
327 _rtiAmbassador.queryFederateTime(fedTime);
328 timeStamp = toTimeStamp(fedTime);
330 void modifyLookahead(const SGTimeStamp& timeStamp)
331 { _rtiAmbassador.modifyLookahead(toFedTime(timeStamp)); }
332 void queryLookahead(SGTimeStamp& timeStamp)
335 _rtiAmbassador.queryLookahead(fedTime);
336 timeStamp = toTimeStamp(fedTime);
339 RTI::ObjectClassHandle getObjectClassHandle(const std::string& name)
340 { return _rtiAmbassador.getObjectClassHandle(name.c_str()); }
341 std::string getObjectClassName(const RTI::ObjectClassHandle& handle)
342 { return rtiToStdString(_rtiAmbassador.getObjectClassName(handle)); }
344 RTI::AttributeHandle getAttributeHandle(const std::string& attributeName, const RTI::ObjectClassHandle& objectClassHandle)
345 { return _rtiAmbassador.getAttributeHandle(attributeName.c_str(), objectClassHandle); }
346 std::string getAttributeName(const RTI::AttributeHandle& attributeHandle, const RTI::ObjectClassHandle& objectClassHandle)
347 { return rtiToStdString(_rtiAmbassador.getAttributeName(attributeHandle, objectClassHandle)); }
349 RTI::InteractionClassHandle getInteractionClassHandle(const std::string& name)
350 { return _rtiAmbassador.getInteractionClassHandle(name.c_str()); }
351 std::string getInteractionClassName(const RTI::InteractionClassHandle& handle)
352 { return rtiToStdString(_rtiAmbassador.getInteractionClassName(handle)); }
354 RTI::ParameterHandle getParameterHandle(const std::string& parameterName, const RTI::InteractionClassHandle& interactionClassHandle)
355 { return _rtiAmbassador.getParameterHandle(parameterName.c_str(), interactionClassHandle); }
356 std::string getParameterName(const RTI::ParameterHandle& parameterHandle, const RTI::InteractionClassHandle& interactionClassHandle)
357 { return rtiToStdString(_rtiAmbassador.getParameterName(parameterHandle, interactionClassHandle)); }
359 RTI::ObjectHandle getObjectInstanceHandle(const std::string& name)
360 { return _rtiAmbassador.getObjectInstanceHandle(name.c_str()); }
361 std::string getObjectInstanceName(const RTI::ObjectHandle& objectHandle)
362 { return rtiToStdString(_rtiAmbassador.getObjectInstanceName(objectHandle)); }
364 // RTIHandle getRoutingSpaceHandle(const std::string& routingSpaceName)
367 // return _rtiAmbassador.getRoutingSpaceHandle(routingSpaceName.c_str());
368 // } catch (RTI::NameNotFound& e) {
369 // } catch (RTI::FederateNotExecutionMember& e) {
370 // } catch (RTI::ConcurrentAccessAttempted& e) {
371 // } catch (RTI::RTIinternalError& e) {
373 // return RTIHandle(-1);
375 // std::string getRoutingSpaceName(const RTIHandle& routingSpaceHandle)
377 // std::string routingSpaceName;
379 // rtiToStdString(routingSpaceName, _rtiAmbassador.wgetRoutingSpaceName(routingSpaceHandle));
380 // } catch (RTI::SpaceNotDefined& e) {
381 // } catch (RTI::FederateNotExecutionMember& e) {
382 // } catch (RTI::ConcurrentAccessAttempted& e) {
383 // } catch (RTI::RTIinternalError& e) {
385 // return routingSpaceName;
388 void enableClassRelevanceAdvisorySwitch()
389 { _rtiAmbassador.enableClassRelevanceAdvisorySwitch(); }
390 void disableClassRelevanceAdvisorySwitch()
391 { _rtiAmbassador.disableClassRelevanceAdvisorySwitch(); }
393 void enableAttributeRelevanceAdvisorySwitch()
394 { _rtiAmbassador.enableAttributeRelevanceAdvisorySwitch(); }
395 void disableAttributeRelevanceAdvisorySwitch()
396 { _rtiAmbassador.disableAttributeRelevanceAdvisorySwitch(); }
398 void enableAttributeScopeAdvisorySwitch()
399 { _rtiAmbassador.enableAttributeScopeAdvisorySwitch(); }
400 void disableAttributeScopeAdvisorySwitch()
401 { _rtiAmbassador.disableAttributeScopeAdvisorySwitch(); }
403 void enableInteractionRelevanceAdvisorySwitch()
404 { _rtiAmbassador.enableInteractionRelevanceAdvisorySwitch(); }
405 void disableInteractionRelevanceAdvisorySwitch()
406 { _rtiAmbassador.disableInteractionRelevanceAdvisorySwitch(); }
410 { return _rtiAmbassador.tick(); }
411 bool tick(double minimum, double maximum)
412 { return _rtiAmbassador.tick(minimum, maximum); }
415 static SGTimeStamp toTimeStamp(const RTI::FedTime& fedTime)
417 RTIfedTime referenceTime(fedTime);
418 return SGTimeStamp::fromSec(referenceTime.getTime() + 0.5e-9);
421 static RTIfedTime toFedTime(const SGTimeStamp& timeStamp)
423 RTIfedTime referenceTime;
424 referenceTime.setZero();
425 referenceTime += timeStamp.toSecs();
426 return referenceTime;
429 static std::string rtiToStdString(char* n)
432 return std::string();
439 // The connection class
440 RTI::RTIambassador _rtiAmbassador;
441 SGWeakPtr<RTI13Federate> _federate;
444 } // namespace simgear