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); }
74 void subscribeObjectClassAttributes(const RTI::ObjectClassHandle& handle, const RTI::AttributeHandleSet& attributeHandleSet, bool active)
75 { _rtiAmbassador.subscribeObjectClassAttributes(handle, attributeHandleSet, active ? RTI::RTI_TRUE : RTI::RTI_FALSE); }
76 void unsubscribeObjectClass(const RTI::ObjectClassHandle& handle)
77 { _rtiAmbassador.unsubscribeObjectClass(handle); }
79 RTI::ObjectHandle registerObjectInstance(const RTI::ObjectClassHandle& handle)
80 { return _rtiAmbassador.registerObjectInstance(handle); }
81 void updateAttributeValues(const RTI::ObjectHandle& objectHandle, const RTI::AttributeHandleValuePairSet& attributeValues,
82 const SGTimeStamp& timeStamp, const RTIData& tag)
83 { _rtiAmbassador.updateAttributeValues(objectHandle, attributeValues, toFedTime(timeStamp), tag.data()); }
84 void updateAttributeValues(const RTI::ObjectHandle& objectHandle, const RTI::AttributeHandleValuePairSet& attributeValues, const RTIData& tag)
85 { _rtiAmbassador.updateAttributeValues(objectHandle, attributeValues, tag.data()); }
87 // RTI::EventRetractionHandle sendInteraction(RTI::InteractionClassHandle interactionClassHandle, const RTI::ParameterHandleValuePairSet& parameters, const RTI::FedTime& fedTime, const RTIData& tag)
88 // { return _rtiAmbassador.sendInteraction(interactionClassHandle, parameters, fedTime, tag.data()); }
89 // void sendInteraction(RTI::InteractionClassHandle interactionClassHandle, const RTI::ParameterHandleValuePairSet& parameters, const RTIData& tag)
90 // { _rtiAmbassador.sendInteraction(interactionClassHandle, parameters, tag.data()); }
92 void deleteObjectInstance(const RTI::ObjectHandle& objectHandle, const SGTimeStamp& timeStamp, const RTIData& tag)
93 { RTI::EventRetractionHandle h = _rtiAmbassador.deleteObjectInstance(objectHandle, toFedTime(timeStamp), tag.data()); }
94 void deleteObjectInstance(const RTI::ObjectHandle& objectHandle, const RTIData& tag)
95 { _rtiAmbassador.deleteObjectInstance(objectHandle, tag.data()); }
96 void localDeleteObjectInstance(const RTI::ObjectHandle& objectHandle)
97 { _rtiAmbassador.localDeleteObjectInstance(objectHandle); }
99 void requestObjectAttributeValueUpdate(const RTI::ObjectHandle& handle, const RTI::AttributeHandleSet& attributeHandleSet)
100 { _rtiAmbassador.requestObjectAttributeValueUpdate(handle, attributeHandleSet); }
101 void requestClassAttributeValueUpdate(const RTI::ObjectClassHandle& handle, const RTI::AttributeHandleSet& attributeHandleSet)
102 { _rtiAmbassador.requestClassAttributeValueUpdate(handle, attributeHandleSet); }
104 // Ownership Management -------------------
106 // bool unconditionalAttributeOwnershipDivestiture(const RTIHandle& objectHandle, const RTIHandleSet& attributeHandles)
109 // std::auto_ptr<RTI::AttributeHandleSet> attributeHandleSet(RTI::AttributeHandleSetFactory::create(attributeHandles.size()));
110 // for (RTIHandleSet::const_iterator i = attributeHandles.begin(); i != attributeHandles.end(); ++i)
111 // attributeHandleSet->add(*i);
112 // _rtiAmbassador.unconditionalAttributeOwnershipDivestiture(objectHandle, *attributeHandleSet);
114 // } catch (RTI::ObjectNotKnown& e) {
115 // } catch (RTI::AttributeNotDefined& e) {
116 // } catch (RTI::AttributeNotOwned& e) {
117 // } catch (RTI::FederateNotExecutionMember& e) {
118 // } catch (RTI::ConcurrentAccessAttempted& e) {
119 // } catch (RTI::SaveInProgress& e) {
120 // } catch (RTI::RestoreInProgress& e) {
121 // } catch (RTI::RTIinternalError& e) {
125 // bool negotiatedAttributeOwnershipDivestiture(const RTIHandle& objectHandle, const RTIHandleSet& attributeHandles, const RTIData& tag)
128 // std::auto_ptr<RTI::AttributeHandleSet> attributeHandleSet(RTI::AttributeHandleSetFactory::create(attributeHandles.size()));
129 // for (RTIHandleSet::const_iterator i = attributeHandles.begin(); i != attributeHandles.end(); ++i)
130 // attributeHandleSet->add(*i);
131 // _rtiAmbassador.negotiatedAttributeOwnershipDivestiture(objectHandle, *attributeHandleSet, tag.data());
133 // } catch (RTI::ObjectNotKnown& e) {
134 // } catch (RTI::AttributeNotDefined& e) {
135 // } catch (RTI::AttributeNotOwned& e) {
136 // } catch (RTI::AttributeAlreadyBeingDivested& e) {
137 // } catch (RTI::FederateNotExecutionMember& e) {
138 // } catch (RTI::ConcurrentAccessAttempted& e) {
139 // } catch (RTI::SaveInProgress& e) {
140 // } catch (RTI::RestoreInProgress& e) {
141 // } catch (RTI::RTIinternalError& e) {
145 // bool attributeOwnershipAcquisition(const RTIHandle& objectHandle, const RTIHandleSet& attributeHandles, const RTIData& tag)
148 // std::auto_ptr<RTI::AttributeHandleSet> attributeHandleSet(RTI::AttributeHandleSetFactory::create(attributeHandles.size()));
149 // for (RTIHandleSet::const_iterator i = attributeHandles.begin(); i != attributeHandles.end(); ++i)
150 // attributeHandleSet->add(*i);
151 // _rtiAmbassador.attributeOwnershipAcquisition(objectHandle, *attributeHandleSet, tag.data());
153 // } catch (RTI::ObjectNotKnown& e) {
154 // } catch (RTI::ObjectClassNotPublished& e) {
155 // } catch (RTI::AttributeNotDefined& e) {
156 // } catch (RTI::AttributeNotPublished& e) {
157 // } catch (RTI::FederateOwnsAttributes& e) {
158 // } catch (RTI::FederateNotExecutionMember& e) {
159 // } catch (RTI::ConcurrentAccessAttempted& e) {
160 // } catch (RTI::SaveInProgress& e) {
161 // } catch (RTI::RestoreInProgress& e) {
162 // } catch (RTI::RTIinternalError& e) {
166 // bool attributeOwnershipAcquisitionIfAvailable(const RTIHandle& objectHandle, const RTIHandleSet& attributeHandles)
169 // std::auto_ptr<RTI::AttributeHandleSet> attributeHandleSet(RTI::AttributeHandleSetFactory::create(attributeHandles.size()));
170 // for (RTIHandleSet::const_iterator i = attributeHandles.begin(); i != attributeHandles.end(); ++i)
171 // attributeHandleSet->add(*i);
172 // _rtiAmbassador.attributeOwnershipAcquisitionIfAvailable(objectHandle, *attributeHandleSet);
174 // } catch (RTI::ObjectNotKnown& e) {
175 // } catch (RTI::ObjectClassNotPublished& e) {
176 // } catch (RTI::AttributeNotDefined& e) {
177 // } catch (RTI::AttributeNotPublished& e) {
178 // } catch (RTI::FederateOwnsAttributes& e) {
179 // } catch (RTI::AttributeAlreadyBeingAcquired& e) {
180 // } catch (RTI::FederateNotExecutionMember& e) {
181 // } catch (RTI::ConcurrentAccessAttempted& e) {
182 // } catch (RTI::SaveInProgress& e) {
183 // } catch (RTI::RestoreInProgress& e) {
184 // } catch (RTI::RTIinternalError& e) {
188 // RTIHandleSet attributeOwnershipReleaseResponse(const RTIHandle& objectHandle, const RTIHandleSet& attributeHandles)
191 // std::auto_ptr<RTI::AttributeHandleSet> attributeHandleSet(RTI::AttributeHandleSetFactory::create(attributeHandles.size()));
192 // for (RTIHandleSet::const_iterator i = attributeHandles.begin(); i != attributeHandles.end(); ++i)
193 // attributeHandleSet->add(*i);
194 // attributeHandleSet.reset(_rtiAmbassador.attributeOwnershipReleaseResponse(objectHandle, *attributeHandleSet));
195 // RTIHandleSet handleSet;
196 // RTI::ULong numAttribs = attributeHandleSet->size();
197 // for (RTI::ULong i = 0; i < numAttribs; ++i)
198 // handleSet.insert(attributeHandleSet->getHandle(i));
200 // } catch (RTI::ObjectNotKnown& e) {
201 // } catch (RTI::AttributeNotDefined& e) {
202 // } catch (RTI::AttributeNotOwned& e) {
203 // } catch (RTI::FederateWasNotAskedToReleaseAttribute& e) {
204 // } catch (RTI::FederateNotExecutionMember& e) {
205 // } catch (RTI::ConcurrentAccessAttempted& e) {
206 // } catch (RTI::SaveInProgress& e) {
207 // } catch (RTI::RestoreInProgress& e) {
208 // } catch (RTI::RTIinternalError& e) {
210 // return RTIHandleSet();
212 // bool cancelNegotiatedAttributeOwnershipDivestiture(const RTIHandle& objectHandle, const RTIHandleSet& attributeHandles)
215 // std::auto_ptr<RTI::AttributeHandleSet> attributeHandleSet(RTI::AttributeHandleSetFactory::create(attributeHandles.size()));
216 // for (RTIHandleSet::const_iterator i = attributeHandles.begin(); i != attributeHandles.end(); ++i)
217 // attributeHandleSet->add(*i);
218 // _rtiAmbassador.cancelNegotiatedAttributeOwnershipDivestiture(objectHandle, *attributeHandleSet);
220 // } catch (RTI::ObjectNotKnown& e) {
221 // } catch (RTI::AttributeNotDefined& e) {
222 // } catch (RTI::AttributeNotOwned& e) {
223 // } catch (RTI::AttributeDivestitureWasNotRequested& e) {
224 // } catch (RTI::FederateNotExecutionMember& e) {
225 // } catch (RTI::ConcurrentAccessAttempted& e) {
226 // } catch (RTI::SaveInProgress& e) {
227 // } catch (RTI::RestoreInProgress& e) {
228 // } catch (RTI::RTIinternalError& e) {
232 // bool cancelAttributeOwnershipAcquisition(const RTIHandle& objectHandle, const RTIHandleSet& attributeHandles)
235 // std::auto_ptr<RTI::AttributeHandleSet> attributeHandleSet(RTI::AttributeHandleSetFactory::create(attributeHandles.size()));
236 // for (RTIHandleSet::const_iterator i = attributeHandles.begin(); i != attributeHandles.end(); ++i)
237 // attributeHandleSet->add(*i);
238 // _rtiAmbassador.cancelAttributeOwnershipAcquisition(objectHandle, *attributeHandleSet);
240 // } catch (RTI::ObjectNotKnown& e) {
241 // } catch (RTI::AttributeNotDefined& e) {
242 // } catch (RTI::AttributeAlreadyOwned& e) {
243 // } catch (RTI::AttributeAcquisitionWasNotRequested& e) {
244 // } catch (RTI::FederateNotExecutionMember& e) {
245 // } catch (RTI::ConcurrentAccessAttempted& e) {
246 // } catch (RTI::SaveInProgress& e) {
247 // } catch (RTI::RestoreInProgress& e) {
248 // } catch (RTI::RTIinternalError& e) {
252 // bool queryAttributeOwnership(const RTIHandle& objectHandle, const RTIHandle& attributeHandle)
255 // _rtiAmbassador.queryAttributeOwnership(objectHandle, attributeHandle);
257 // } catch (RTI::ObjectNotKnown& e) {
258 // } catch (RTI::AttributeNotDefined& e) {
259 // } catch (RTI::FederateNotExecutionMember& e) {
260 // } catch (RTI::ConcurrentAccessAttempted& e) {
261 // } catch (RTI::SaveInProgress& e) {
262 // } catch (RTI::RestoreInProgress& e) {
263 // } catch (RTI::RTIinternalError& e) {
267 // bool isAttributeOwnedByFederate(const RTIHandle& objectHandle, const RTIHandle& attributeHandle)
270 // return _rtiAmbassador.isAttributeOwnedByFederate(objectHandle, attributeHandle);
271 // } catch (RTI::ObjectNotKnown& e) {
272 // } catch (RTI::AttributeNotDefined& e) {
273 // } catch (RTI::FederateNotExecutionMember& e) {
274 // } catch (RTI::ConcurrentAccessAttempted& e) {
275 // } catch (RTI::SaveInProgress& e) {
276 // } catch (RTI::RestoreInProgress& e) {
277 // } catch (RTI::RTIinternalError& e) {
284 void enableTimeRegulation(const SGTimeStamp& lookahead)
286 RTIfedTime federateTime;
287 federateTime.setZero();
288 _rtiAmbassador.enableTimeRegulation(federateTime, toFedTime(lookahead));
290 void disableTimeRegulation()
291 { _rtiAmbassador.disableTimeRegulation();}
293 void enableTimeConstrained()
294 { _rtiAmbassador.enableTimeConstrained(); }
295 void disableTimeConstrained()
296 { _rtiAmbassador.disableTimeConstrained(); }
298 void timeAdvanceRequest(const SGTimeStamp& time)
299 { _rtiAmbassador.timeAdvanceRequest(toFedTime(time)); }
300 void timeAdvanceRequestAvailable(const SGTimeStamp& time)
301 { _rtiAmbassador.timeAdvanceRequestAvailable(toFedTime(time)); }
303 bool queryGALT(SGTimeStamp& timeStamp)
306 fedTime.setPositiveInfinity();
307 _rtiAmbassador.queryLBTS(fedTime);
308 if (fedTime.isPositiveInfinity())
310 timeStamp = toTimeStamp(fedTime);
313 bool queryLITS(SGTimeStamp& timeStamp)
316 fedTime.setPositiveInfinity();
317 _rtiAmbassador.queryMinNextEventTime(fedTime);
318 if (fedTime.isPositiveInfinity())
320 timeStamp = toTimeStamp(fedTime);
323 void queryFederateTime(SGTimeStamp& timeStamp)
326 _rtiAmbassador.queryFederateTime(fedTime);
327 timeStamp = toTimeStamp(fedTime);
329 void modifyLookahead(const SGTimeStamp& timeStamp)
330 { _rtiAmbassador.modifyLookahead(toFedTime(timeStamp)); }
331 void queryLookahead(SGTimeStamp& timeStamp)
334 _rtiAmbassador.queryLookahead(fedTime);
335 timeStamp = toTimeStamp(fedTime);
338 RTI::ObjectClassHandle getObjectClassHandle(const std::string& name)
339 { return _rtiAmbassador.getObjectClassHandle(name.c_str()); }
340 std::string getObjectClassName(const RTI::ObjectClassHandle& handle)
341 { return rtiToStdString(_rtiAmbassador.getObjectClassName(handle)); }
343 RTI::AttributeHandle getAttributeHandle(const std::string& attributeName, const RTI::ObjectClassHandle& objectClassHandle)
344 { return _rtiAmbassador.getAttributeHandle(attributeName.c_str(), objectClassHandle); }
345 std::string getAttributeName(const RTI::AttributeHandle& attributeHandle, const RTI::ObjectClassHandle& objectClassHandle)
346 { return rtiToStdString(_rtiAmbassador.getAttributeName(attributeHandle, objectClassHandle)); }
348 // RTIHandle getInteractionClassHandle(const std::string& name)
351 // return _rtiAmbassador.getInteractionClassHandle(name.c_str());
352 // } catch (RTI::NameNotFound& e) {
353 // } catch (RTI::FederateNotExecutionMember& e) {
354 // } catch (RTI::ConcurrentAccessAttempted& e) {
355 // } catch (RTI::RTIinternalError& e) {
357 // return RTIHandle(-1);
359 // std::string getInteractionClassName(const RTIHandle& handle)
363 // rtiToStdString(name, _rtiAmbassador.getInteractionClassName(handle));
364 // } catch (RTI::InteractionClassNotDefined& e) {
365 // } catch (RTI::FederateNotExecutionMember& e) {
366 // } catch (RTI::ConcurrentAccessAttempted& e) {
367 // } catch (RTI::RTIinternalError& e) {
372 // RTIHandle getParameterHandle(const std::string& parameterName, const RTIHandle& interactionClassHandle)
375 // return _rtiAmbassador.getParameterHandle(parameterName.c_str(), interactionClassHandle);
376 // } catch (RTI::InteractionClassNotDefined& e) {
377 // } catch (RTI::NameNotFound& e) {
378 // } catch (RTI::FederateNotExecutionMember& e) {
379 // } catch (RTI::ConcurrentAccessAttempted& e) {
380 // } catch (RTI::RTIinternalError& e) {
382 // return RTIHandle(-1);
384 // std::string getParameterName(const RTIHandle& parameterHandle, const RTIHandle& interactionClassHandle)
386 // std::string parameterName;
388 // rtiToStdString(parameterName, _rtiAmbassador.getParameterName(parameterHandle, interactionClassHandle));
389 // } catch (RTI::InteractionClassNotDefined& e) {
390 // } catch (RTI::InteractionParameterNotDefined& e) {
391 // } catch (RTI::FederateNotExecutionMember& e) {
392 // } catch (RTI::ConcurrentAccessAttempted& e) {
393 // } catch (RTI::RTIinternalError& e) {
395 // return parameterName;
398 RTI::ObjectHandle getObjectInstanceHandle(const std::string& name)
399 { return _rtiAmbassador.getObjectInstanceHandle(name.c_str()); }
400 std::string getObjectInstanceName(const RTI::ObjectHandle& objectHandle)
401 { return rtiToStdString(_rtiAmbassador.getObjectInstanceName(objectHandle)); }
403 // RTIHandle getRoutingSpaceHandle(const std::string& routingSpaceName)
406 // return _rtiAmbassador.getRoutingSpaceHandle(routingSpaceName.c_str());
407 // } catch (RTI::NameNotFound& e) {
408 // } catch (RTI::FederateNotExecutionMember& e) {
409 // } catch (RTI::ConcurrentAccessAttempted& e) {
410 // } catch (RTI::RTIinternalError& e) {
412 // return RTIHandle(-1);
414 // std::string getRoutingSpaceName(const RTIHandle& routingSpaceHandle)
416 // std::string routingSpaceName;
418 // rtiToStdString(routingSpaceName, _rtiAmbassador.wgetRoutingSpaceName(routingSpaceHandle));
419 // } catch (RTI::SpaceNotDefined& e) {
420 // } catch (RTI::FederateNotExecutionMember& e) {
421 // } catch (RTI::ConcurrentAccessAttempted& e) {
422 // } catch (RTI::RTIinternalError& e) {
424 // return routingSpaceName;
427 void enableClassRelevanceAdvisorySwitch()
428 { _rtiAmbassador.enableClassRelevanceAdvisorySwitch(); }
429 void disableClassRelevanceAdvisorySwitch()
430 { _rtiAmbassador.disableClassRelevanceAdvisorySwitch(); }
432 void enableAttributeRelevanceAdvisorySwitch()
433 { _rtiAmbassador.enableAttributeRelevanceAdvisorySwitch(); }
434 void disableAttributeRelevanceAdvisorySwitch()
435 { _rtiAmbassador.disableAttributeRelevanceAdvisorySwitch(); }
437 void enableAttributeScopeAdvisorySwitch()
438 { _rtiAmbassador.enableAttributeScopeAdvisorySwitch(); }
439 void disableAttributeScopeAdvisorySwitch()
440 { _rtiAmbassador.disableAttributeScopeAdvisorySwitch(); }
442 void enableInteractionRelevanceAdvisorySwitch()
443 { _rtiAmbassador.enableInteractionRelevanceAdvisorySwitch(); }
444 void disableInteractionRelevanceAdvisorySwitch()
445 { _rtiAmbassador.disableInteractionRelevanceAdvisorySwitch(); }
449 { return _rtiAmbassador.tick(); }
450 bool tick(double minimum, double maximum)
451 { return _rtiAmbassador.tick(minimum, maximum); }
454 static SGTimeStamp toTimeStamp(const RTI::FedTime& fedTime)
456 RTIfedTime referenceTime(fedTime);
457 return SGTimeStamp::fromSec(referenceTime.getTime() + 0.5e-9);
460 static RTIfedTime toFedTime(const SGTimeStamp& timeStamp)
462 RTIfedTime referenceTime;
463 referenceTime.setZero();
464 referenceTime += timeStamp.toSecs();
465 return referenceTime;
468 static std::string rtiToStdString(char* n)
471 return std::string();
478 // The connection class
479 RTI::RTIambassador _rtiAmbassador;
480 SGWeakPtr<RTI13Federate> _federate;
483 } // namespace simgear