]> git.mxchange.org Git - simgear.git/blob - simgear/hla/RTI13Ambassador.hxx
Add an initial implementation of a rti/hla dispatcher.
[simgear.git] / simgear / hla / RTI13Ambassador.hxx
1 // Copyright (C) 2009 - 2010  Mathias Froehlich - Mathias.Froehlich@web.de
2 //
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.
7 //
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.
12 //
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.
16 //
17
18 #ifndef RTIAmbassador_hxx
19 #define RTIAmbassador_hxx
20
21 #include <cstdlib>
22 #include <list>
23 #include <memory>
24 #include <vector>
25 #include <map>
26 #include <set>
27
28 #ifndef RTI_USES_STD_FSTREAM
29 #define RTI_USES_STD_FSTREAM
30 #endif
31
32 #include <RTI.hh>
33 #include <fedtime.hh>
34
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>
40
41 #include "RTIObjectClass.hxx"
42 #include "RTIData.hxx"
43 #include "RTI13Federate.hxx"
44 #include "RTI13ObjectInstance.hxx"
45
46 namespace simgear {
47
48 class RTI13Ambassador : public SGWeakReferenced {
49 public:
50     RTI13Ambassador() :
51         _federateAmbassador(*this),
52         _timeRegulationEnabled(false),
53         _timeConstrainedEnabled(false),
54         _timeAdvancePending(false)
55     { }
56     virtual ~RTI13Ambassador()
57     { }
58
59     // processes the queues that filled up during the past
60     void processQueues()
61     {
62         while (!_queueCallbackList.empty()) {
63             (*_queueCallbackList.front())();
64             _queueCallbackList.pop_front();
65         }
66
67         while (!_objectInstancePendingCallbackList.empty()) {
68             (*_objectInstancePendingCallbackList.begin())->flushPendingRequests();
69             _objectInstancePendingCallbackList.erase(_objectInstancePendingCallbackList.begin());
70         }
71     }
72
73     bool getTimeRegulationEnabled() const
74     { return _timeRegulationEnabled; }
75     bool getTimeConstrainedEnabled() const
76     { return _timeConstrainedEnabled; }
77     bool getTimeAdvancePending() const
78     { return _timeAdvancePending; }
79     const SGTimeStamp& getCurrentLogicalTime() const
80     { return _federateTime; }
81
82     bool getFederationSynchronizationPointAnnounced(const std::string& label)
83     { return _pendingSyncLabels.find(label) != _pendingSyncLabels.end(); }
84     bool getFederationSynchronized(const std::string& label)
85     {
86         std::set<std::string>::iterator i = _syncronizedSyncLabels.find(label);
87         if (i == _syncronizedSyncLabels.end())
88             return false;
89         _syncronizedSyncLabels.erase(i);
90         return true;
91     }
92
93     void createFederationExecution(const std::string& name, const std::string& objectModel)
94     { _rtiAmbassador.createFederationExecution(name.c_str(), objectModel.c_str()); }
95     void destroyFederationExecution(const std::string& name)
96     { _rtiAmbassador.destroyFederationExecution(name.c_str()); }
97
98     RTI::FederateHandle joinFederationExecution(const std::string& federate, const std::string& federation)
99     { return _rtiAmbassador.joinFederationExecution(federate.c_str(), federation.c_str(), &_federateAmbassador); }
100     void resignFederationExecution()
101     { _rtiAmbassador.resignFederationExecution(RTI::DELETE_OBJECTS_AND_RELEASE_ATTRIBUTES); }
102
103     void registerFederationSynchronizationPoint(const std::string& label, const RTIData& tag)
104     { _rtiAmbassador.registerFederationSynchronizationPoint(label.c_str(), tag.data()); }
105     void synchronizationPointAchieved(const std::string& label)
106     { _rtiAmbassador.synchronizationPointAchieved(label.c_str()); }
107
108     void publishObjectClass(const RTI::ObjectClassHandle& handle, const RTI::AttributeHandleSet& attributeHandleSet)
109     { _rtiAmbassador.publishObjectClass(handle, attributeHandleSet); }
110     void unpublishObjectClass(const RTI::ObjectClassHandle& handle)
111     { _rtiAmbassador.unpublishObjectClass(handle); }
112     void subscribeObjectClassAttributes(const RTI::ObjectClassHandle& handle, const RTI::AttributeHandleSet& attributeHandleSet, bool active)
113     { _rtiAmbassador.subscribeObjectClassAttributes(handle, attributeHandleSet, active ? RTI::RTI_TRUE : RTI::RTI_FALSE); }
114     void unsubscribeObjectClass(const RTI::ObjectClassHandle& handle)
115     { _rtiAmbassador.unsubscribeObjectClass(handle); }
116
117     RTI13ObjectInstance* registerObjectInstance(const RTI13ObjectClass* objectClass, HLAObjectInstance* hlaObjectInstance)
118     {
119         RTI::ObjectHandle objectHandle = _rtiAmbassador.registerObjectInstance(objectClass->getHandle());
120         RTI13ObjectInstance* objectInstance = new RTI13ObjectInstance(objectHandle, hlaObjectInstance, objectClass, this, true);
121         _objectInstanceMap[objectHandle] = objectInstance;
122         return objectInstance;
123     }
124     void updateAttributeValues(const RTI::ObjectHandle& objectHandle, const RTI::AttributeHandleValuePairSet& attributeValues,
125                                const SGTimeStamp& timeStamp, const RTIData& tag)
126     { _rtiAmbassador.updateAttributeValues(objectHandle, attributeValues, toFedTime(timeStamp), tag.data()); }
127     void updateAttributeValues(const RTI::ObjectHandle& objectHandle, const RTI::AttributeHandleValuePairSet& attributeValues, const RTIData& tag)
128     { _rtiAmbassador.updateAttributeValues(objectHandle, attributeValues, tag.data()); }
129
130     // RTI::EventRetractionHandle sendInteraction(RTI::InteractionClassHandle interactionClassHandle, const RTI::ParameterHandleValuePairSet& parameters, const RTI::FedTime& fedTime, const RTIData& tag)
131     // { return _rtiAmbassador.sendInteraction(interactionClassHandle, parameters, fedTime, tag.data()); }
132     // void sendInteraction(RTI::InteractionClassHandle interactionClassHandle, const RTI::ParameterHandleValuePairSet& parameters, const RTIData& tag)
133     // { _rtiAmbassador.sendInteraction(interactionClassHandle, parameters, tag.data()); }
134
135     void deleteObjectInstance(const RTI::ObjectHandle& objectHandle, const SGTimeStamp& timeStamp, const RTIData& tag)
136     {
137         RTI::EventRetractionHandle h = _rtiAmbassador.deleteObjectInstance(objectHandle, toFedTime(timeStamp), tag.data());
138         ObjectInstanceMap::iterator i = _objectInstanceMap.find(objectHandle);
139         if (i == _objectInstanceMap.end()) {
140             SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not get object class: ObjectInstance not found.");
141             return;
142         }
143         _objectInstancePendingCallbackList.erase(i->second);
144         _objectInstanceMap.erase(i);
145     }
146     void deleteObjectInstance(const RTI::ObjectHandle& objectHandle, const RTIData& tag)
147     {
148         _rtiAmbassador.deleteObjectInstance(objectHandle, tag.data());
149         ObjectInstanceMap::iterator i = _objectInstanceMap.find(objectHandle);
150         if (i == _objectInstanceMap.end()) {
151             SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not get object class: ObjectInstance not found.");
152             return;
153         }
154         _objectInstancePendingCallbackList.erase(i->second);
155         _objectInstanceMap.erase(i);
156     }
157     void localDeleteObjectInstance(const RTI::ObjectHandle& objectHandle)
158     {
159         _rtiAmbassador.localDeleteObjectInstance(objectHandle);
160         ObjectInstanceMap::iterator i = _objectInstanceMap.find(objectHandle);
161         if (i == _objectInstanceMap.end()) {
162             SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not get object class: ObjectInstance not found.");
163             return;
164         }
165         _objectInstancePendingCallbackList.erase(i->second);
166         _objectInstanceMap.erase(i);
167     }
168
169     void requestObjectAttributeValueUpdate(const RTI::ObjectHandle& handle, const RTI::AttributeHandleSet& attributeHandleSet)
170     { _rtiAmbassador.requestObjectAttributeValueUpdate(handle, attributeHandleSet); }
171     void requestClassAttributeValueUpdate(const RTI::ObjectClassHandle& handle, const RTI::AttributeHandleSet& attributeHandleSet)
172     { _rtiAmbassador.requestClassAttributeValueUpdate(handle, attributeHandleSet); }
173
174     // Ownership Management -------------------
175
176     // bool unconditionalAttributeOwnershipDivestiture(const RTIHandle& objectHandle, const RTIHandleSet& attributeHandles)
177     // {
178     //     try {
179     //         std::auto_ptr<RTI::AttributeHandleSet> attributeHandleSet(RTI::AttributeHandleSetFactory::create(attributeHandles.size()));
180     //         for (RTIHandleSet::const_iterator i = attributeHandles.begin(); i != attributeHandles.end(); ++i)
181     //             attributeHandleSet->add(*i);
182     //         _rtiAmbassador.unconditionalAttributeOwnershipDivestiture(objectHandle, *attributeHandleSet);
183     //         return true;
184     //     } catch (RTI::ObjectNotKnown& e) {
185     //     } catch (RTI::AttributeNotDefined& e) {
186     //     } catch (RTI::AttributeNotOwned& e) {
187     //     } catch (RTI::FederateNotExecutionMember& e) {
188     //     } catch (RTI::ConcurrentAccessAttempted& e) {
189     //     } catch (RTI::SaveInProgress& e) {
190     //     } catch (RTI::RestoreInProgress& e) {
191     //     } catch (RTI::RTIinternalError& e) {
192     //     }
193     //     return false;
194     // }
195     // bool negotiatedAttributeOwnershipDivestiture(const RTIHandle& objectHandle, const RTIHandleSet& attributeHandles, const RTIData& tag)
196     // {
197     //     try {
198     //         std::auto_ptr<RTI::AttributeHandleSet> attributeHandleSet(RTI::AttributeHandleSetFactory::create(attributeHandles.size()));
199     //         for (RTIHandleSet::const_iterator i = attributeHandles.begin(); i != attributeHandles.end(); ++i)
200     //             attributeHandleSet->add(*i);
201     //         _rtiAmbassador.negotiatedAttributeOwnershipDivestiture(objectHandle, *attributeHandleSet, tag.data());
202     //         return true;
203     //     } catch (RTI::ObjectNotKnown& e) {
204     //     } catch (RTI::AttributeNotDefined& e) {
205     //     } catch (RTI::AttributeNotOwned& e) {
206     //     } catch (RTI::AttributeAlreadyBeingDivested& e) {
207     //     } catch (RTI::FederateNotExecutionMember& e) {
208     //     } catch (RTI::ConcurrentAccessAttempted& e) {
209     //     } catch (RTI::SaveInProgress& e) {
210     //     } catch (RTI::RestoreInProgress& e) {
211     //     } catch (RTI::RTIinternalError& e) {
212     //     }
213     //     return false;
214     // }
215     // bool attributeOwnershipAcquisition(const RTIHandle& objectHandle, const RTIHandleSet& attributeHandles, const RTIData& tag)
216     // {
217     //     try {
218     //         std::auto_ptr<RTI::AttributeHandleSet> attributeHandleSet(RTI::AttributeHandleSetFactory::create(attributeHandles.size()));
219     //         for (RTIHandleSet::const_iterator i = attributeHandles.begin(); i != attributeHandles.end(); ++i)
220     //             attributeHandleSet->add(*i);
221     //         _rtiAmbassador.attributeOwnershipAcquisition(objectHandle, *attributeHandleSet, tag.data());
222     //         return true;
223     //     } catch (RTI::ObjectNotKnown& e) {
224     //     } catch (RTI::ObjectClassNotPublished& e) {
225     //     } catch (RTI::AttributeNotDefined& e) {
226     //     } catch (RTI::AttributeNotPublished& e) {
227     //     } catch (RTI::FederateOwnsAttributes& e) {
228     //     } catch (RTI::FederateNotExecutionMember& e) {
229     //     } catch (RTI::ConcurrentAccessAttempted& e) {
230     //     } catch (RTI::SaveInProgress& e) {
231     //     } catch (RTI::RestoreInProgress& e) {
232     //     } catch (RTI::RTIinternalError& e) {
233     //     }
234     //     return false;
235     // }
236     // bool attributeOwnershipAcquisitionIfAvailable(const RTIHandle& objectHandle, const RTIHandleSet& attributeHandles)
237     // {
238     //     try {
239     //         std::auto_ptr<RTI::AttributeHandleSet> attributeHandleSet(RTI::AttributeHandleSetFactory::create(attributeHandles.size()));
240     //         for (RTIHandleSet::const_iterator i = attributeHandles.begin(); i != attributeHandles.end(); ++i)
241     //             attributeHandleSet->add(*i);
242     //         _rtiAmbassador.attributeOwnershipAcquisitionIfAvailable(objectHandle, *attributeHandleSet);
243     //         return true;
244     //     } catch (RTI::ObjectNotKnown& e) {
245     //     } catch (RTI::ObjectClassNotPublished& e) {
246     //     } catch (RTI::AttributeNotDefined& e) {
247     //     } catch (RTI::AttributeNotPublished& e) {
248     //     } catch (RTI::FederateOwnsAttributes& e) {
249     //     } catch (RTI::AttributeAlreadyBeingAcquired& e) {
250     //     } catch (RTI::FederateNotExecutionMember& e) {
251     //     } catch (RTI::ConcurrentAccessAttempted& e) {
252     //     } catch (RTI::SaveInProgress& e) {
253     //     } catch (RTI::RestoreInProgress& e) {
254     //     } catch (RTI::RTIinternalError& e) {
255     //     }
256     //     return false;
257     // }
258     // RTIHandleSet attributeOwnershipReleaseResponse(const RTIHandle& objectHandle, const RTIHandleSet& attributeHandles)
259     // {
260     //     try {
261     //         std::auto_ptr<RTI::AttributeHandleSet> attributeHandleSet(RTI::AttributeHandleSetFactory::create(attributeHandles.size()));
262     //         for (RTIHandleSet::const_iterator i = attributeHandles.begin(); i != attributeHandles.end(); ++i)
263     //             attributeHandleSet->add(*i);
264     //         attributeHandleSet.reset(_rtiAmbassador.attributeOwnershipReleaseResponse(objectHandle, *attributeHandleSet));
265     //         RTIHandleSet handleSet;
266     //         RTI::ULong numAttribs = attributeHandleSet->size();
267     //         for (RTI::ULong i = 0; i < numAttribs; ++i)
268     //             handleSet.insert(attributeHandleSet->getHandle(i));
269     //         return handleSet;
270     //     } catch (RTI::ObjectNotKnown& e) {
271     //     } catch (RTI::AttributeNotDefined& e) {
272     //     } catch (RTI::AttributeNotOwned& e) {
273     //     } catch (RTI::FederateWasNotAskedToReleaseAttribute& e) {
274     //     } catch (RTI::FederateNotExecutionMember& e) {
275     //     } catch (RTI::ConcurrentAccessAttempted& e) {
276     //     } catch (RTI::SaveInProgress& e) {
277     //     } catch (RTI::RestoreInProgress& e) {
278     //     } catch (RTI::RTIinternalError& e) {
279     //     }
280     //     return RTIHandleSet();
281     // }
282     // bool cancelNegotiatedAttributeOwnershipDivestiture(const RTIHandle& objectHandle, const RTIHandleSet& attributeHandles)
283     // {
284     //     try {
285     //         std::auto_ptr<RTI::AttributeHandleSet> attributeHandleSet(RTI::AttributeHandleSetFactory::create(attributeHandles.size()));
286     //         for (RTIHandleSet::const_iterator i = attributeHandles.begin(); i != attributeHandles.end(); ++i)
287     //             attributeHandleSet->add(*i);
288     //         _rtiAmbassador.cancelNegotiatedAttributeOwnershipDivestiture(objectHandle, *attributeHandleSet);
289     //         return true;
290     //     } catch (RTI::ObjectNotKnown& e) {
291     //     } catch (RTI::AttributeNotDefined& e) {
292     //     } catch (RTI::AttributeNotOwned& e) {
293     //     } catch (RTI::AttributeDivestitureWasNotRequested& e) {
294     //     } catch (RTI::FederateNotExecutionMember& e) {
295     //     } catch (RTI::ConcurrentAccessAttempted& e) {
296     //     } catch (RTI::SaveInProgress& e) {
297     //     } catch (RTI::RestoreInProgress& e) {
298     //     } catch (RTI::RTIinternalError& e) {
299     //     }
300     //     return false;
301     // }
302     // bool cancelAttributeOwnershipAcquisition(const RTIHandle& objectHandle, const RTIHandleSet& attributeHandles)
303     // {
304     //     try {
305     //         std::auto_ptr<RTI::AttributeHandleSet> attributeHandleSet(RTI::AttributeHandleSetFactory::create(attributeHandles.size()));
306     //         for (RTIHandleSet::const_iterator i = attributeHandles.begin(); i != attributeHandles.end(); ++i)
307     //             attributeHandleSet->add(*i);
308     //         _rtiAmbassador.cancelAttributeOwnershipAcquisition(objectHandle, *attributeHandleSet);
309     //         return true;
310     //     } catch (RTI::ObjectNotKnown& e) {
311     //     } catch (RTI::AttributeNotDefined& e) {
312     //     } catch (RTI::AttributeAlreadyOwned& e) {
313     //     } catch (RTI::AttributeAcquisitionWasNotRequested& e) {
314     //     } catch (RTI::FederateNotExecutionMember& e) {
315     //     } catch (RTI::ConcurrentAccessAttempted& e) {
316     //     } catch (RTI::SaveInProgress& e) {
317     //     } catch (RTI::RestoreInProgress& e) {
318     //     } catch (RTI::RTIinternalError& e) {
319     //     }
320     //     return false;
321     // }
322     // bool queryAttributeOwnership(const RTIHandle& objectHandle, const RTIHandle& attributeHandle)
323     // {
324     //     try {
325     //         _rtiAmbassador.queryAttributeOwnership(objectHandle, attributeHandle);
326     //         return true;
327     //     } catch (RTI::ObjectNotKnown& e) {
328     //     } catch (RTI::AttributeNotDefined& e) {
329     //     } catch (RTI::FederateNotExecutionMember& e) {
330     //     } catch (RTI::ConcurrentAccessAttempted& e) {
331     //     } catch (RTI::SaveInProgress& e) {
332     //     } catch (RTI::RestoreInProgress& e) {
333     //     } catch (RTI::RTIinternalError& e) {
334     //     }
335     //     return false;
336     // }
337     // bool isAttributeOwnedByFederate(const RTIHandle& objectHandle, const RTIHandle& attributeHandle)
338     // {
339     //     try {
340     //         return _rtiAmbassador.isAttributeOwnedByFederate(objectHandle, attributeHandle);
341     //     } catch (RTI::ObjectNotKnown& e) {
342     //     } catch (RTI::AttributeNotDefined& e) {
343     //     } catch (RTI::FederateNotExecutionMember& e) {
344     //     } catch (RTI::ConcurrentAccessAttempted& e) {
345     //     } catch (RTI::SaveInProgress& e) {
346     //     } catch (RTI::RestoreInProgress& e) {
347     //     } catch (RTI::RTIinternalError& e) {
348     //     }
349     //     return false;
350     // }
351
352     /// Time Management
353
354     void enableTimeRegulation(const SGTimeStamp& federateTime, const SGTimeStamp& lookahead)
355     { _rtiAmbassador.enableTimeRegulation(toFedTime(federateTime), toFedTime(lookahead)); }
356     void disableTimeRegulation()
357     { _rtiAmbassador.disableTimeRegulation(); _timeRegulationEnabled = false; }
358
359     void enableTimeConstrained()
360     { _rtiAmbassador.enableTimeConstrained(); }
361     void disableTimeConstrained()
362     { _rtiAmbassador.disableTimeConstrained(); _timeConstrainedEnabled = false; }
363
364     void timeAdvanceRequest(const SGTimeStamp& time)
365     { _rtiAmbassador.timeAdvanceRequest(toFedTime(time)); _timeAdvancePending = true; }
366     void timeAdvanceRequestAvailable(const SGTimeStamp& time)
367     { _rtiAmbassador.timeAdvanceRequestAvailable(toFedTime(time)); _timeAdvancePending = true; }
368
369     // bool queryLBTS(double& time)
370     // {
371     //     try {
372     //         RTIfedTime fedTime;
373     //         _rtiAmbassador.queryLBTS(fedTime);
374     //         time = fedTime.getTime();
375     //         return true;
376     //     } catch (RTI::FederateNotExecutionMember& e) {
377     //     } catch (RTI::ConcurrentAccessAttempted& e) {
378     //     } catch (RTI::SaveInProgress& e) {
379     //     } catch (RTI::RestoreInProgress& e) {
380     //     } catch (RTI::RTIinternalError& e) {
381     //     }
382     //     return false;
383     // }
384     // bool queryFederateTime(double& time)
385     // {
386     //     try {
387     //         RTIfedTime fedTime;
388     //         _rtiAmbassador.queryFederateTime(fedTime);
389     //         time = fedTime.getTime();
390     //         return true;
391     //     } catch (RTI::FederateNotExecutionMember& e) {
392     //     } catch (RTI::ConcurrentAccessAttempted& e) {
393     //     } catch (RTI::SaveInProgress& e) {
394     //     } catch (RTI::RestoreInProgress& e) {
395     //     } catch (RTI::RTIinternalError& e) {
396     //     }
397     //     return false;
398     // }
399
400     // bool queryLookahead(double& time)
401     // {
402     //     try {
403     //         RTIfedTime fedTime;
404     //         _rtiAmbassador.queryLookahead(fedTime);
405     //         time = fedTime.getTime();
406     //         return true;
407     //     } catch (RTI::FederateNotExecutionMember& e) {
408     //     } catch (RTI::ConcurrentAccessAttempted& e) {
409     //     } catch (RTI::SaveInProgress& e) {
410     //     } catch (RTI::RestoreInProgress& e) {
411     //     } catch (RTI::RTIinternalError& e) {
412     //     }
413     //     return false;
414     // }
415
416     RTI13ObjectClass* createObjectClass(const std::string& name, HLAObjectClass* hlaObjectClass)
417     {
418         RTI::ObjectClassHandle objectClassHandle;
419         objectClassHandle = getObjectClassHandle(name);
420         if (_objectClassMap.find(objectClassHandle) != _objectClassMap.end()) {
421             SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not create object class, object class already exists!");
422             return 0;
423         }
424         RTI13ObjectClass* rtiObjectClass;
425         rtiObjectClass = new RTI13ObjectClass(hlaObjectClass, objectClassHandle, this);
426         _objectClassMap[objectClassHandle] = rtiObjectClass;
427         return rtiObjectClass;
428     }
429     RTI::ObjectClassHandle getObjectClassHandle(const std::string& name)
430     { return _rtiAmbassador.getObjectClassHandle(name.c_str()); }
431     std::string getObjectClassName(const RTI::ObjectClassHandle& handle)
432     { return rtiToStdString(_rtiAmbassador.getObjectClassName(handle)); }
433
434     RTI::AttributeHandle getAttributeHandle(const std::string& attributeName, const RTI::ObjectClassHandle& objectClassHandle)
435     { return _rtiAmbassador.getAttributeHandle(attributeName.c_str(), objectClassHandle); }
436     std::string getAttributeName(const RTI::AttributeHandle& attributeHandle, const RTI::ObjectClassHandle& objectClassHandle)
437     { return rtiToStdString(_rtiAmbassador.getAttributeName(attributeHandle, objectClassHandle)); }
438
439     // RTIHandle getInteractionClassHandle(const std::string& name)
440     // {
441     //     try {
442     //         return _rtiAmbassador.getInteractionClassHandle(name.c_str());
443     //     } catch (RTI::NameNotFound& e) {
444     //     } catch (RTI::FederateNotExecutionMember& e) {
445     //     } catch (RTI::ConcurrentAccessAttempted& e) {
446     //     } catch (RTI::RTIinternalError& e) {
447     //     }
448     //     return RTIHandle(-1);
449     // }
450     // std::string getInteractionClassName(const RTIHandle& handle)
451     // {
452     //     std::string name;
453     //     try {
454     //         rtiToStdString(name, _rtiAmbassador.getInteractionClassName(handle));
455     //     } catch (RTI::InteractionClassNotDefined& e) {
456     //     } catch (RTI::FederateNotExecutionMember& e) {
457     //     } catch (RTI::ConcurrentAccessAttempted& e) {
458     //     } catch (RTI::RTIinternalError& e) {
459     //     }
460     //     return name;
461     // }
462
463     // RTIHandle getParameterHandle(const std::string& parameterName, const RTIHandle& interactionClassHandle)
464     // {
465     //     try {
466     //         return _rtiAmbassador.getParameterHandle(parameterName.c_str(), interactionClassHandle);
467     //     } catch (RTI::InteractionClassNotDefined& e) {
468     //     } catch (RTI::NameNotFound& e) {
469     //     } catch (RTI::FederateNotExecutionMember& e) {
470     //     } catch (RTI::ConcurrentAccessAttempted& e) {
471     //     } catch (RTI::RTIinternalError& e) {
472     //     }
473     //     return RTIHandle(-1);
474     // }
475     // std::string getParameterName(const RTIHandle& parameterHandle, const RTIHandle& interactionClassHandle)
476     // {
477     //     std::string parameterName;
478     //     try {
479     //         rtiToStdString(parameterName, _rtiAmbassador.getParameterName(parameterHandle, interactionClassHandle));
480     //     } catch (RTI::InteractionClassNotDefined& e) {
481     //     } catch (RTI::InteractionParameterNotDefined& e) {
482     //     } catch (RTI::FederateNotExecutionMember& e) {
483     //     } catch (RTI::ConcurrentAccessAttempted& e) {
484     //     } catch (RTI::RTIinternalError& e) {
485     //     }
486     //     return parameterName;
487     // }
488
489     RTI13ObjectInstance* getObjectInstance(const std::string& name)
490     {
491         RTI::ObjectHandle objectHandle;
492         objectHandle = getObjectInstanceHandle(name);
493         ObjectInstanceMap::iterator i = _objectInstanceMap.find(objectHandle);
494         if (i == _objectInstanceMap.end()) {
495             SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not get object class: ObjectInstance not found.");
496             return 0;
497         }
498         return i->second;
499     }
500     RTI::ObjectHandle getObjectInstanceHandle(const std::string& name)
501     { return _rtiAmbassador.getObjectInstanceHandle(name.c_str()); }
502     std::string getObjectInstanceName(const RTI::ObjectHandle& objectHandle)
503     { return rtiToStdString(_rtiAmbassador.getObjectInstanceName(objectHandle)); }
504
505     // RTIHandle getRoutingSpaceHandle(const std::string& routingSpaceName)
506     // {
507     //     try {
508     //         return _rtiAmbassador.getRoutingSpaceHandle(routingSpaceName.c_str());
509     //     } catch (RTI::NameNotFound& e) {
510     //     } catch (RTI::FederateNotExecutionMember& e) {
511     //     } catch (RTI::ConcurrentAccessAttempted& e) {
512     //     } catch (RTI::RTIinternalError& e) {
513     //     }
514     //     return RTIHandle(-1);
515     // }
516     // std::string getRoutingSpaceName(const RTIHandle& routingSpaceHandle)
517     // {
518     //     std::string routingSpaceName;
519     //     try {
520     //         rtiToStdString(routingSpaceName, _rtiAmbassador.wgetRoutingSpaceName(routingSpaceHandle));
521     //     } catch (RTI::SpaceNotDefined& e) {
522     //     } catch (RTI::FederateNotExecutionMember& e) {
523     //     } catch (RTI::ConcurrentAccessAttempted& e) {
524     //     } catch (RTI::RTIinternalError& e) {
525     //     }
526     //     return routingSpaceName;
527     // }
528
529     void enableClassRelevanceAdvisorySwitch()
530     { _rtiAmbassador.enableClassRelevanceAdvisorySwitch(); }
531     void disableClassRelevanceAdvisorySwitch()
532     { _rtiAmbassador.disableClassRelevanceAdvisorySwitch(); }
533
534     void enableAttributeRelevanceAdvisorySwitch()
535     { _rtiAmbassador.enableAttributeRelevanceAdvisorySwitch(); }
536     void disableAttributeRelevanceAdvisorySwitch()
537     { _rtiAmbassador.disableAttributeRelevanceAdvisorySwitch(); }
538
539     void enableAttributeScopeAdvisorySwitch()
540     { _rtiAmbassador.enableAttributeScopeAdvisorySwitch(); }
541     void disableAttributeScopeAdvisorySwitch()
542     { _rtiAmbassador.disableAttributeScopeAdvisorySwitch(); }
543
544     void enableInteractionRelevanceAdvisorySwitch()
545     { _rtiAmbassador.enableInteractionRelevanceAdvisorySwitch(); }
546     void disableInteractionRelevanceAdvisorySwitch()
547     { _rtiAmbassador.disableInteractionRelevanceAdvisorySwitch(); }
548
549
550     bool tick()
551     { return _rtiAmbassador.tick(); }
552     bool tick(double minimum, double maximum)
553     { return _rtiAmbassador.tick(minimum, maximum); }
554
555     void addObjectInstanceForCallback(RTIObjectInstance* objectIntance)
556     { _objectInstancePendingCallbackList.insert(objectIntance); }
557
558 private:
559     /// Generic callback to execute some notification on objects in a way that they are not prone to
560     /// ConcurrentAccess exceptions.
561     class QueueCallback : public SGReferenced {
562     public:
563         virtual ~QueueCallback() {}
564         virtual void operator()() = 0;
565     };
566
567     class RemoveObjectCallback : public QueueCallback {
568     public:
569         RemoveObjectCallback(SGSharedPtr<RTIObjectInstance> objectInstance, const RTIData& tag) :
570             _objectInstance(objectInstance),
571             _tag(tag)
572         { }
573         virtual void operator()()
574         {
575             _objectInstance->removeInstance(_tag);
576         }
577     private:
578         SGSharedPtr<RTIObjectInstance> _objectInstance;
579         RTIData _tag;
580     };
581
582     /// Just the interface class doing the callbacks into the parent class
583     struct FederateAmbassador : public RTI::FederateAmbassador {
584         FederateAmbassador(RTI13Ambassador& rtiAmbassador) :
585             _rtiAmbassador(rtiAmbassador)
586         {
587         }
588         virtual ~FederateAmbassador()
589         throw (RTI::FederateInternalError)
590         {
591         }
592
593         /// RTI federate ambassador callback functions.
594         virtual void synchronizationPointRegistrationSucceeded(const char* label)
595             throw (RTI::FederateInternalError)
596         {
597         }
598
599         virtual void synchronizationPointRegistrationFailed(const char* label)
600             throw (RTI::FederateInternalError)
601         {
602         }
603
604         virtual void announceSynchronizationPoint(const char* label, const char* tag)
605             throw (RTI::FederateInternalError)
606         {
607             _rtiAmbassador._pendingSyncLabels.insert(toStdString(label));
608         }
609
610         virtual void federationSynchronized(const char* label)
611             throw (RTI::FederateInternalError)
612         {
613             std::string s = toStdString(label);
614             _rtiAmbassador._pendingSyncLabels.erase(s);
615             _rtiAmbassador._syncronizedSyncLabels.insert(s);
616         }
617
618         virtual void initiateFederateSave(const char* label)
619             throw (RTI::UnableToPerformSave,
620                    RTI::FederateInternalError)
621         {
622         }
623
624         virtual void federationSaved()
625             throw (RTI::FederateInternalError)
626         {
627         }
628
629         virtual void federationNotSaved()
630             throw (RTI::FederateInternalError)
631         {
632         }
633
634         virtual void requestFederationRestoreSucceeded(const char* label)
635             throw (RTI::FederateInternalError)
636         {
637         }
638
639         virtual void requestFederationRestoreFailed(const char* label, const char* reason)
640             throw (RTI::FederateInternalError)
641         {
642         }
643
644         virtual void federationRestoreBegun()
645             throw (RTI::FederateInternalError)
646         {
647         }
648
649         virtual void initiateFederateRestore(const char* label, RTI::FederateHandle federateHandle)
650             throw (RTI::SpecifiedSaveLabelDoesNotExist,
651                    RTI::CouldNotRestore,
652                    RTI::FederateInternalError)
653         {
654         }
655
656         virtual void federationRestored()
657             throw (RTI::FederateInternalError)
658         {
659         }
660
661         virtual void federationNotRestored()
662             throw (RTI::FederateInternalError)
663         {
664         }
665
666         // Declaration Management
667         virtual void startRegistrationForObjectClass(RTI::ObjectClassHandle objectClassHandle)
668             throw (RTI::ObjectClassNotPublished,
669                    RTI::FederateInternalError)
670         {
671             ObjectClassMap::iterator i = _rtiAmbassador._objectClassMap.find(objectClassHandle);
672             if (i == _rtiAmbassador._objectClassMap.end())
673                 return;
674             if (!i->second.valid())
675                 return;
676             i->second->startRegistration();
677         }
678
679         virtual void stopRegistrationForObjectClass(RTI::ObjectClassHandle objectClassHandle)
680             throw (RTI::ObjectClassNotPublished,
681                    RTI::FederateInternalError)
682         {
683             ObjectClassMap::iterator i = _rtiAmbassador._objectClassMap.find(objectClassHandle);
684             if (i == _rtiAmbassador._objectClassMap.end())
685                 return;
686             if (!i->second.valid())
687                 return;
688             i->second->stopRegistration();
689         }
690
691         virtual void turnInteractionsOn(RTI::InteractionClassHandle interactionClassHandle)
692             throw (RTI::InteractionClassNotPublished,
693                    RTI::FederateInternalError)
694         {
695         }
696
697         virtual void turnInteractionsOff(RTI::InteractionClassHandle interactionClassHandle)
698             throw (RTI::InteractionClassNotPublished,
699                    RTI::FederateInternalError)
700         {
701         }
702
703
704         // Object Management
705         virtual void discoverObjectInstance(RTI::ObjectHandle objectHandle, RTI::ObjectClassHandle objectClassHandle, const char* tag)
706             throw (RTI::CouldNotDiscover,
707                    RTI::ObjectClassNotKnown,
708                    RTI::FederateInternalError)
709         {
710             ObjectClassMap::iterator i = _rtiAmbassador._objectClassMap.find(objectClassHandle);
711             if (i == _rtiAmbassador._objectClassMap.end())
712                 throw RTI::ObjectClassNotKnown("Federate: discoverObjectInstance()!");
713             if (!i->second.valid())
714                 return;
715             SGSharedPtr<RTI13ObjectInstance> objectInstance = new RTI13ObjectInstance(objectHandle, 0, i->second, &_rtiAmbassador, false);
716             _rtiAmbassador._objectInstanceMap[objectHandle] = objectInstance;
717             _rtiAmbassador._objectInstancePendingCallbackList.insert(objectInstance);
718             i->second->discoverInstance(objectInstance.get(), tagToData(tag));
719         }
720
721         virtual void reflectAttributeValues(RTI::ObjectHandle objectHandle, const RTI::AttributeHandleValuePairSet& attributeValuePairSet,
722                                             const RTI::FedTime& fedTime, const char* tag, RTI::EventRetractionHandle eventRetractionHandle)
723             throw (RTI::ObjectNotKnown,
724                    RTI::AttributeNotKnown,
725                    RTI::FederateOwnsAttributes,
726                    RTI::InvalidFederationTime,
727                    RTI::FederateInternalError)
728         {
729             ObjectInstanceMap::iterator i = _rtiAmbassador._objectInstanceMap.find(objectHandle);
730             if (i == _rtiAmbassador._objectInstanceMap.end())
731                 throw RTI::ObjectNotKnown("Reflect attributes for unknown object!");
732             if (!i->second.valid())
733                 return;
734             i->second->reflectAttributeValues(attributeValuePairSet, toTimeStamp(fedTime), tagToData(tag));
735         }
736
737         virtual void reflectAttributeValues(RTI::ObjectHandle objectHandle, const RTI::AttributeHandleValuePairSet& attributeValuePairSet,
738                                             const char* tag)
739             throw (RTI::ObjectNotKnown,
740                    RTI::AttributeNotKnown,
741                    RTI::FederateOwnsAttributes,
742                    RTI::FederateInternalError)
743         {
744             ObjectInstanceMap::iterator i = _rtiAmbassador._objectInstanceMap.find(objectHandle);
745             if (i == _rtiAmbassador._objectInstanceMap.end())
746                 throw RTI::ObjectNotKnown("Reflect attributes for unknown object!");
747             if (!i->second.valid())
748                 return;
749             i->second->reflectAttributeValues(attributeValuePairSet, tagToData(tag));
750         }
751
752         virtual void receiveInteraction(RTI::InteractionClassHandle interactionClassHandle, const RTI::ParameterHandleValuePairSet& parameters,
753                                         const RTI::FedTime& fedTime, const char* tag, RTI::EventRetractionHandle eventRetractionHandle)
754             throw (RTI::InteractionClassNotKnown,
755                    RTI::InteractionParameterNotKnown,
756                    RTI::InvalidFederationTime,
757                    RTI::FederateInternalError)
758         {
759         }
760
761         virtual void receiveInteraction(RTI::InteractionClassHandle interactionClassHandle,
762                                         const RTI::ParameterHandleValuePairSet& parameters, const char* tag)
763             throw (RTI::InteractionClassNotKnown,
764                    RTI::InteractionParameterNotKnown,
765                    RTI::FederateInternalError)
766         {
767         }
768
769         virtual void removeObjectInstance(RTI::ObjectHandle objectHandle, const RTI::FedTime& fedTime,
770                                           const char* tag, RTI::EventRetractionHandle eventRetractionHandle)
771             throw (RTI::ObjectNotKnown,
772                    RTI::InvalidFederationTime,
773                    RTI::FederateInternalError)
774         {
775             ObjectInstanceMap::iterator i = _rtiAmbassador._objectInstanceMap.find(objectHandle);
776             if (i == _rtiAmbassador._objectInstanceMap.end())
777                 throw RTI::ObjectNotKnown("Federate: removeObjectInstance()!");
778             if (i->second.valid())
779                 _rtiAmbassador._queueCallbackList.push_back(new RemoveObjectCallback(i->second, tagToData(tag)));
780             _rtiAmbassador._objectInstancePendingCallbackList.erase(i->second);
781             _rtiAmbassador._objectInstanceMap.erase(i);
782         }
783
784         virtual void removeObjectInstance(RTI::ObjectHandle objectHandle, const char* tag)
785             throw (RTI::ObjectNotKnown,
786                    RTI::FederateInternalError)
787         {
788             ObjectInstanceMap::iterator i = _rtiAmbassador._objectInstanceMap.find(objectHandle);
789             if (i == _rtiAmbassador._objectInstanceMap.end())
790                 throw RTI::ObjectNotKnown("Federate: removeObjectInstance()!");
791             if (i->second.valid())
792                 _rtiAmbassador._queueCallbackList.push_back(new RemoveObjectCallback(i->second, tagToData(tag)));
793             _rtiAmbassador._objectInstancePendingCallbackList.erase(i->second);
794             _rtiAmbassador._objectInstanceMap.erase(i);
795         }
796
797         virtual void attributesInScope(RTI::ObjectHandle objectHandle, const RTI::AttributeHandleSet& attributes)
798             throw (RTI::ObjectNotKnown,
799                    RTI::AttributeNotKnown,
800                    RTI::FederateInternalError)
801         {
802             ObjectInstanceMap::iterator i = _rtiAmbassador._objectInstanceMap.find(objectHandle);
803             if (i == _rtiAmbassador._objectInstanceMap.end())
804                 throw RTI::ObjectNotKnown("Attributes in scope for unknown object!");
805             if (!i->second.valid())
806                 return;
807             i->second->attributesInScope(attributes);
808         }
809
810         virtual void attributesOutOfScope(RTI::ObjectHandle objectHandle, const RTI::AttributeHandleSet& attributes)
811             throw (RTI::ObjectNotKnown,
812                    RTI::AttributeNotKnown,
813                    RTI::FederateInternalError)
814         {
815             ObjectInstanceMap::iterator i = _rtiAmbassador._objectInstanceMap.find(objectHandle);
816             if (i == _rtiAmbassador._objectInstanceMap.end())
817                 throw RTI::ObjectNotKnown("Attributes in scope for unknown object!");
818             if (!i->second.valid())
819                 return;
820             i->second->attributesOutOfScope(attributes);
821         }
822
823         virtual void provideAttributeValueUpdate(RTI::ObjectHandle objectHandle, const RTI::AttributeHandleSet& attributes)
824             throw (RTI::ObjectNotKnown,
825                    RTI::AttributeNotKnown,
826                    RTI::AttributeNotOwned,
827                    RTI::FederateInternalError)
828         {
829             ObjectInstanceMap::iterator i = _rtiAmbassador._objectInstanceMap.find(objectHandle);
830             if (i == _rtiAmbassador._objectInstanceMap.end())
831                 throw RTI::ObjectNotKnown("Reflect attributes for unknown object!");
832             if (!i->second.valid())
833                 return;
834             i->second->provideAttributeValueUpdate(attributes);
835         }
836
837         virtual void turnUpdatesOnForObjectInstance(RTI::ObjectHandle objectHandle, const RTI::AttributeHandleSet& attributes)
838             throw (RTI::ObjectNotKnown,
839                    RTI::AttributeNotOwned,
840                    RTI::FederateInternalError)
841         {
842             ObjectInstanceMap::iterator i = _rtiAmbassador._objectInstanceMap.find(objectHandle);
843             if (i == _rtiAmbassador._objectInstanceMap.end())
844                 throw RTI::ObjectNotKnown("Turn on attributes for unknown object!");
845             if (!i->second.valid())
846                 return;
847             i->second->turnUpdatesOnForObjectInstance(attributes);
848         }
849
850         virtual void turnUpdatesOffForObjectInstance(RTI::ObjectHandle objectHandle, const RTI::AttributeHandleSet& attributes)
851             throw (RTI::ObjectNotKnown,
852                    RTI::AttributeNotOwned,
853                    RTI::FederateInternalError)
854         {
855             ObjectInstanceMap::iterator i = _rtiAmbassador._objectInstanceMap.find(objectHandle);
856             if (i == _rtiAmbassador._objectInstanceMap.end())
857                 throw RTI::ObjectNotKnown("Turn off attributes for unknown object!");
858             if (!i->second.valid())
859                 return;
860             i->second->turnUpdatesOffForObjectInstance(attributes);
861         }
862
863         // Ownership Management
864         virtual void requestAttributeOwnershipAssumption(RTI::ObjectHandle objectHandle,
865                                                          const RTI::AttributeHandleSet& attributes, const char* tag)
866             throw (RTI::ObjectNotKnown,
867                    RTI::AttributeNotKnown,
868                    RTI::AttributeAlreadyOwned,
869                    RTI::AttributeNotPublished,
870                    RTI::FederateInternalError)
871         {
872             ObjectInstanceMap::iterator i = _rtiAmbassador._objectInstanceMap.find(objectHandle);
873             if (i == _rtiAmbassador._objectInstanceMap.end())
874                 throw RTI::ObjectNotKnown("requestAttributeOwnershipAssumption for unknown object!");
875             if (!i->second.valid())
876                 return;
877             i->second->requestAttributeOwnershipAssumption(attributes, tagToData(tag));
878         }
879
880         virtual void attributeOwnershipDivestitureNotification(RTI::ObjectHandle objectHandle, const RTI::AttributeHandleSet& attributes)
881             throw (RTI::ObjectNotKnown,
882                    RTI::AttributeNotKnown,
883                    RTI::AttributeNotOwned,
884                    RTI::AttributeDivestitureWasNotRequested,
885                    RTI::FederateInternalError)
886         {
887             ObjectInstanceMap::iterator i = _rtiAmbassador._objectInstanceMap.find(objectHandle);
888             if (i == _rtiAmbassador._objectInstanceMap.end())
889                 throw RTI::ObjectNotKnown("attributeOwnershipDivestitureNotification for unknown object!");
890             if (!i->second.valid())
891                 return;
892             i->second->attributeOwnershipDivestitureNotification(attributes);
893         }
894
895         virtual void attributeOwnershipAcquisitionNotification(RTI::ObjectHandle objectHandle, const RTI::AttributeHandleSet& attributes)
896             throw (RTI::ObjectNotKnown,
897                    RTI::AttributeNotKnown,
898                    RTI::AttributeAcquisitionWasNotRequested,
899                    RTI::AttributeAlreadyOwned,
900                    RTI::AttributeNotPublished,
901                    RTI::FederateInternalError)
902         {
903             ObjectInstanceMap::iterator i = _rtiAmbassador._objectInstanceMap.find(objectHandle);
904             if (i == _rtiAmbassador._objectInstanceMap.end())
905                 throw RTI::ObjectNotKnown("attributeOwnershipAcquisitionNotification for unknown object!");
906             if (!i->second.valid())
907                 return;
908             i->second->attributeOwnershipAcquisitionNotification(attributes);
909         }
910
911         virtual void attributeOwnershipUnavailable(RTI::ObjectHandle objectHandle, const RTI::AttributeHandleSet& attributes)
912             throw (RTI::ObjectNotKnown,
913                    RTI::AttributeNotKnown,
914                    RTI::AttributeAlreadyOwned,
915                    RTI::AttributeAcquisitionWasNotRequested,
916                    RTI::FederateInternalError)
917         {
918             ObjectInstanceMap::iterator i = _rtiAmbassador._objectInstanceMap.find(objectHandle);
919             if (i == _rtiAmbassador._objectInstanceMap.end())
920                 throw RTI::ObjectNotKnown("attributeOwnershipUnavailable for unknown object!");
921             if (!i->second.valid())
922                 return;
923             i->second->attributeOwnershipUnavailable(attributes);
924         }
925
926         virtual void requestAttributeOwnershipRelease(RTI::ObjectHandle objectHandle,
927                                                       const RTI::AttributeHandleSet& attributes, const char* tag)
928             throw (RTI::ObjectNotKnown,
929                    RTI::AttributeNotKnown,
930                    RTI::AttributeNotOwned,
931                    RTI::FederateInternalError)
932         {
933             ObjectInstanceMap::iterator i = _rtiAmbassador._objectInstanceMap.find(objectHandle);
934             if (i == _rtiAmbassador._objectInstanceMap.end())
935                 throw RTI::ObjectNotKnown("requestAttributeOwnershipRelease for unknown object!");
936             if (!i->second.valid())
937                 return;
938             i->second->requestAttributeOwnershipRelease(attributes, tagToData(tag));
939         }
940
941         virtual void confirmAttributeOwnershipAcquisitionCancellation(RTI::ObjectHandle objectHandle, const RTI::AttributeHandleSet& attributes)
942             throw (RTI::ObjectNotKnown,
943                    RTI::AttributeNotKnown,
944                    RTI::AttributeAlreadyOwned,
945                    RTI::AttributeAcquisitionWasNotCanceled,
946                    RTI::FederateInternalError)
947         {
948             ObjectInstanceMap::iterator i = _rtiAmbassador._objectInstanceMap.find(objectHandle);
949             if (i == _rtiAmbassador._objectInstanceMap.end())
950                 throw RTI::ObjectNotKnown("confirmAttributeOwnershipAcquisitionCancellation for unknown object!");
951             if (!i->second.valid())
952                 return;
953             i->second->confirmAttributeOwnershipAcquisitionCancellation(attributes);
954         }
955
956         virtual void informAttributeOwnership(RTI::ObjectHandle objectHandle, RTI::AttributeHandle attributeHandle,
957                                               RTI::FederateHandle federateHandle)
958             throw (RTI::ObjectNotKnown,
959                    RTI::AttributeNotKnown,
960                    RTI::FederateInternalError)
961         {
962             ObjectInstanceMap::iterator i = _rtiAmbassador._objectInstanceMap.find(objectHandle);
963             if (i == _rtiAmbassador._objectInstanceMap.end())
964                 throw RTI::ObjectNotKnown("informAttributeOwnership for unknown object!");
965             if (!i->second.valid())
966                 return;
967             i->second->informAttributeOwnership(attributeHandle, federateHandle);
968         }
969
970         virtual void attributeIsNotOwned(RTI::ObjectHandle objectHandle, RTI::AttributeHandle attributeHandle)
971             throw (RTI::ObjectNotKnown,
972                    RTI::AttributeNotKnown,
973                    RTI::FederateInternalError)
974         {
975             ObjectInstanceMap::iterator i = _rtiAmbassador._objectInstanceMap.find(objectHandle);
976             if (i == _rtiAmbassador._objectInstanceMap.end())
977                 throw RTI::ObjectNotKnown("attributeIsNotOwned for unknown object!");
978             if (!i->second.valid())
979                 return;
980             i->second->attributeIsNotOwned(attributeHandle);
981         }
982
983         virtual void attributeOwnedByRTI(RTI::ObjectHandle objectHandle, RTI::AttributeHandle attributeHandle)
984             throw (RTI::ObjectNotKnown,
985                    RTI::AttributeNotKnown,
986                    RTI::FederateInternalError)
987         {
988             ObjectInstanceMap::iterator i = _rtiAmbassador._objectInstanceMap.find(objectHandle);
989             if (i == _rtiAmbassador._objectInstanceMap.end())
990                 throw RTI::ObjectNotKnown("attributeOwnedByRTI for unknown object!");
991             if (!i->second.valid())
992                 return;
993             i->second->attributeOwnedByRTI(attributeHandle);
994         }
995
996         // Time Management
997         virtual void timeRegulationEnabled(const RTI::FedTime& fedTime)
998             throw (RTI::InvalidFederationTime,
999                    RTI::EnableTimeRegulationWasNotPending,
1000                    RTI::FederateInternalError)
1001         {
1002             _rtiAmbassador._timeRegulationEnabled = true;
1003             _rtiAmbassador._federateTime = toTimeStamp(fedTime);
1004             SG_LOG(SG_NETWORK, SG_INFO, "RTI: timeRegulationEnabled: " << _rtiAmbassador._federateTime);
1005         }
1006
1007         virtual void timeConstrainedEnabled(const RTI::FedTime& fedTime)
1008             throw (RTI::InvalidFederationTime,
1009                    RTI::EnableTimeConstrainedWasNotPending,
1010                    RTI::FederateInternalError)
1011         {
1012             _rtiAmbassador._timeConstrainedEnabled = true;
1013             _rtiAmbassador._federateTime = toTimeStamp(fedTime);
1014             SG_LOG(SG_NETWORK, SG_INFO, "RTI: timeConstrainedEnabled: " << _rtiAmbassador._federateTime);
1015         }
1016
1017         virtual void timeAdvanceGrant(const RTI::FedTime& fedTime)
1018             throw (RTI::InvalidFederationTime,
1019                    RTI::TimeAdvanceWasNotInProgress,
1020                    RTI::FederateInternalError)
1021         {
1022             _rtiAmbassador._federateTime = toTimeStamp(fedTime);
1023             _rtiAmbassador._timeAdvancePending = false;
1024             SG_LOG(SG_NETWORK, SG_INFO, "RTI: timeAdvanceGrant: " << _rtiAmbassador._federateTime);
1025         }
1026
1027         virtual void requestRetraction(RTI::EventRetractionHandle eventRetractionHandle)
1028             throw (RTI::EventNotKnown,
1029                    RTI::FederateInternalError)
1030         {
1031             // No retraction concept yet
1032         }
1033
1034     private:
1035         const RTIData& tagToData(const char* tag)
1036         {
1037             if (tag)
1038                 _cachedTag.setData(tag, std::strlen(tag) + 1);
1039             else
1040                 _cachedTag.setData("", 1);
1041             return _cachedTag;
1042         }
1043         RTIData _cachedTag;
1044
1045         RTI13Ambassador& _rtiAmbassador;
1046     };
1047
1048     static SGTimeStamp toTimeStamp(const RTI::FedTime& fedTime)
1049     {
1050         RTIfedTime referenceTime(fedTime);
1051         return SGTimeStamp::fromSec(referenceTime.getTime() + 0.5e-9);
1052     }
1053
1054     static RTIfedTime toFedTime(const SGTimeStamp& timeStamp)
1055     {
1056         RTIfedTime referenceTime;
1057         referenceTime.setZero();
1058         referenceTime += timeStamp.toSecs();
1059         return referenceTime;
1060     }
1061
1062     static std::string rtiToStdString(char* n)
1063     {
1064         if (!n)
1065             return std::string();
1066         std::string s;
1067         s.assign(n);
1068         delete[] n;
1069         return s;
1070     }
1071
1072     static std::string toStdString(const char* n)
1073     {
1074         if (!n)
1075             return std::string();
1076         return std::string(n);
1077     }
1078
1079     // The connection class
1080     RTI::RTIambassador _rtiAmbassador;
1081
1082     // The class with all the callbacks.
1083     FederateAmbassador _federateAmbassador;
1084
1085     // All the sync labels we got an announcement for
1086     std::set<std::string> _pendingSyncLabels;
1087     std::set<std::string> _syncronizedSyncLabels;
1088
1089     // All that calls back into user code is just queued.
1090     // That is to make sure we do not call recursively into the RTI
1091     typedef std::list<SGSharedPtr<QueueCallback> > QueueCallbackList;
1092     QueueCallbackList _queueCallbackList;
1093     // All object instances that need to be called due to some event are noted here
1094     // That is to make sure we do not call recursively into the RTI
1095     typedef std::set<SGSharedPtr<RTIObjectInstance> > ObjectInstanceSet;
1096     ObjectInstanceSet _objectInstancePendingCallbackList;
1097
1098     // Top level information for dispatching federate object attribute updates
1099     typedef std::map<RTI::ObjectHandle, SGSharedPtr<RTI13ObjectInstance> > ObjectInstanceMap;
1100     // Map of all available objects
1101     ObjectInstanceMap _objectInstanceMap;
1102
1103     // Top level information for dispatching creation of federate objects
1104     typedef std::map<RTI::ObjectClassHandle, SGSharedPtr<RTI13ObjectClass> > ObjectClassMap;
1105     ObjectClassMap _objectClassMap;
1106
1107     bool _timeRegulationEnabled;
1108     bool _timeConstrainedEnabled;
1109     bool _timeAdvancePending;
1110     SGTimeStamp _federateTime;
1111 };
1112
1113 } // namespace simgear
1114
1115 #endif