]> git.mxchange.org Git - simgear.git/blob - simgear/hla/RTI13Federate.cxx
hla: Fix buffer overrun in SGMath vector types.
[simgear.git] / simgear / hla / RTI13Federate.cxx
1 // Copyright (C) 2009 - 2011  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 #include "RTI13Federate.hxx"
19
20 #include "RTI13Ambassador.hxx"
21
22 namespace simgear {
23
24 static std::string toStdString(const char* n)
25 {
26     if (!n)
27         return std::string();
28     return std::string(n);
29 }
30
31 /// Just the interface class doing the callbacks into the parent class
32 struct RTI13Federate::FederateAmbassador : public RTI::FederateAmbassador {
33     FederateAmbassador() :
34         _timeRegulationEnabled(false),
35         _timeConstrainedEnabled(false),
36         _timeAdvancePending(false)
37     {
38     }
39     virtual ~FederateAmbassador()
40         throw (RTI::FederateInternalError)
41     {
42     }
43
44     /// Generic callback to execute some notification on objects in a way that they are not prone to
45     /// ConcurrentAccess exceptions.
46     class QueueCallback : public SGReferenced {
47     public:
48         virtual ~QueueCallback() {}
49         virtual void operator()(FederateAmbassador& self) = 0;
50     };
51     class TagQueueCallback : public QueueCallback {
52     public:
53         TagQueueCallback(const char* tag)
54         {
55             if (tag)
56                 _tag.setData(tag, std::strlen(tag) + 1);
57             else
58                 _tag.setData("", 1);
59         }
60         virtual ~TagQueueCallback()
61         { }
62         RTIData _tag;
63     };
64
65     /// RTI federate ambassador callback functions.
66     virtual void synchronizationPointRegistrationSucceeded(const char* label)
67         throw (RTI::FederateInternalError)
68     {
69     }
70
71     virtual void synchronizationPointRegistrationFailed(const char* label)
72         throw (RTI::FederateInternalError)
73     {
74     }
75
76     virtual void announceSynchronizationPoint(const char* label, const char* tag)
77         throw (RTI::FederateInternalError)
78     {
79         _pendingSyncLabels.insert(toStdString(label));
80     }
81
82     virtual void federationSynchronized(const char* label)
83         throw (RTI::FederateInternalError)
84     {
85         std::string s = toStdString(label);
86         _pendingSyncLabels.erase(s);
87         _syncronizedSyncLabels.insert(s);
88     }
89
90     virtual void initiateFederateSave(const char* label)
91         throw (RTI::UnableToPerformSave,
92                RTI::FederateInternalError)
93     {
94     }
95
96     virtual void federationSaved()
97         throw (RTI::FederateInternalError)
98     {
99     }
100
101     virtual void federationNotSaved()
102         throw (RTI::FederateInternalError)
103     {
104     }
105
106     virtual void requestFederationRestoreSucceeded(const char* label)
107         throw (RTI::FederateInternalError)
108     {
109     }
110
111     virtual void requestFederationRestoreFailed(const char* label, const char* reason)
112         throw (RTI::FederateInternalError)
113     {
114     }
115
116     virtual void federationRestoreBegun()
117         throw (RTI::FederateInternalError)
118     {
119     }
120
121     virtual void initiateFederateRestore(const char* label, RTI::FederateHandle federateHandle)
122         throw (RTI::SpecifiedSaveLabelDoesNotExist,
123                RTI::CouldNotRestore,
124                RTI::FederateInternalError)
125     {
126     }
127
128     virtual void federationRestored()
129         throw (RTI::FederateInternalError)
130     {
131     }
132
133     virtual void federationNotRestored()
134         throw (RTI::FederateInternalError)
135     {
136     }
137
138     // Declaration Management
139     class StartRegistrationForObjectClassCallback : public QueueCallback {
140     public:
141         StartRegistrationForObjectClassCallback(RTI::ObjectClassHandle objectClassHandle) :
142             _objectClassHandle(objectClassHandle)
143         { }
144         virtual void operator()(FederateAmbassador& self)
145         { self.startRegistrationForObjectClassCallback(_objectClassHandle); }
146     private:
147         RTI::ObjectClassHandle _objectClassHandle;
148     };
149     virtual void startRegistrationForObjectClass(RTI::ObjectClassHandle objectClassHandle)
150         throw (RTI::ObjectClassNotPublished,
151                RTI::FederateInternalError)
152     { _queueCallbackList.push_back(new StartRegistrationForObjectClassCallback(objectClassHandle)); }
153     void startRegistrationForObjectClassCallback(RTI::ObjectClassHandle objectClassHandle)
154     {
155         ObjectClassMap::iterator i = _objectClassMap.find(objectClassHandle);
156         if (i == _objectClassMap.end())
157             return;
158         if (!i->second.valid())
159             return;
160         i->second->startRegistration();
161     }
162
163     class StopRegistrationForObjectClassCallback : public QueueCallback {
164     public:
165         StopRegistrationForObjectClassCallback(RTI::ObjectClassHandle objectClassHandle) :
166             _objectClassHandle(objectClassHandle)
167         { }
168         virtual void operator()(FederateAmbassador& self)
169         { self.stopRegistrationForObjectClassCallback(_objectClassHandle); }
170     private:
171         RTI::ObjectClassHandle _objectClassHandle;
172     };
173     virtual void stopRegistrationForObjectClass(RTI::ObjectClassHandle objectClassHandle)
174         throw (RTI::ObjectClassNotPublished,
175                RTI::FederateInternalError)
176     { _queueCallbackList.push_back(new StopRegistrationForObjectClassCallback(objectClassHandle)); }
177     void stopRegistrationForObjectClassCallback(RTI::ObjectClassHandle objectClassHandle)
178     {
179         ObjectClassMap::iterator i = _objectClassMap.find(objectClassHandle);
180         if (i == _objectClassMap.end())
181             return;
182         if (!i->second.valid())
183             return;
184         i->second->stopRegistration();
185     }
186
187     virtual void turnInteractionsOn(RTI::InteractionClassHandle interactionClassHandle)
188         throw (RTI::InteractionClassNotPublished,
189                RTI::FederateInternalError)
190     {
191     }
192
193     virtual void turnInteractionsOff(RTI::InteractionClassHandle interactionClassHandle)
194         throw (RTI::InteractionClassNotPublished,
195                RTI::FederateInternalError)
196     {
197     }
198
199     // Object Management
200     class DiscoverObjectCallback : public TagQueueCallback {
201     public:
202         DiscoverObjectCallback(RTI::ObjectHandle objectHandle, RTI::ObjectClassHandle objectClassHandle, const char *tag) :
203             TagQueueCallback(tag),
204             _objectHandle(objectHandle),
205             _objectClassHandle(objectClassHandle)
206         { }
207         virtual void operator()(FederateAmbassador& self)
208         { self.discoverObjectInstanceCallback(_objectHandle, _objectClassHandle, _tag); }
209     private:
210         RTI::ObjectHandle _objectHandle;
211         RTI::ObjectClassHandle _objectClassHandle;
212     };
213     virtual void discoverObjectInstance(RTI::ObjectHandle objectHandle, RTI::ObjectClassHandle objectClassHandle, const char* tag)
214         throw (RTI::CouldNotDiscover,
215                RTI::ObjectClassNotKnown,
216                RTI::FederateInternalError)
217     { _queueCallbackList.push_back(new DiscoverObjectCallback(objectHandle, objectClassHandle, tag)); }
218     void discoverObjectInstanceCallback(RTI::ObjectHandle objectHandle, RTI::ObjectClassHandle objectClassHandle, const RTIData& tag)
219     {
220         ObjectClassMap::iterator i = _objectClassMap.find(objectClassHandle);
221         if (i == _objectClassMap.end())
222             return;
223         if (!i->second.valid())
224             return;
225         SGSharedPtr<RTI13ObjectInstance> objectInstance = new RTI13ObjectInstance(objectHandle, 0, i->second, _rtiAmbassador.get());
226         _objectInstanceMap[objectHandle] = objectInstance;
227         i->second->discoverInstance(objectInstance.get(), tag);
228     }
229
230     class ReflectAttributeValuesTimestampCallback : public TagQueueCallback {
231     public:
232         ReflectAttributeValuesTimestampCallback(RTI::ObjectHandle objectHandle,
233                                                 RTI13AttributeHandleDataPairList& attributeHandleDataPairList,
234                                                 const SGTimeStamp& timeStamp, const char *tag) :
235             TagQueueCallback(tag),
236             _objectHandle(objectHandle),
237             _timeStamp(timeStamp)
238         {
239             _attributeHandleDataPairList.swap(attributeHandleDataPairList);
240         }
241         virtual void operator()(FederateAmbassador& self)
242         {
243             self.reflectAttributeValuesCallback(_objectHandle, _attributeHandleDataPairList, _timeStamp, _tag);
244             self.freeAttributeHandleDataPairList(_attributeHandleDataPairList);
245         }
246     private:
247         RTI::ObjectHandle _objectHandle;
248         RTI13AttributeHandleDataPairList _attributeHandleDataPairList;
249         SGTimeStamp _timeStamp;
250     };
251     virtual void reflectAttributeValues(RTI::ObjectHandle objectHandle, const RTI::AttributeHandleValuePairSet& attributeValuePairSet,
252                                         const RTI::FedTime& fedTime, const char* tag, RTI::EventRetractionHandle eventRetractionHandle)
253         throw (RTI::ObjectNotKnown,
254                RTI::AttributeNotKnown,
255                RTI::FederateOwnsAttributes,
256                RTI::InvalidFederationTime,
257                RTI::FederateInternalError)
258     {
259         RTI13AttributeHandleDataPairList attributeHandleDataPairList;
260
261         RTI::ULong numAttribs = attributeValuePairSet.size();
262         for (RTI::ULong i = 0; i < numAttribs; ++i) {
263             appendAttributeHandleDataPair(attributeHandleDataPairList);
264             attributeHandleDataPairList.back().first = attributeValuePairSet.getHandle(i);
265             RTI::ULong length = attributeValuePairSet.getValueLength(i);
266             attributeHandleDataPairList.back().second.resize(length);
267             attributeValuePairSet.getValue(i, attributeHandleDataPairList.back().second.data(), length);
268         }
269
270         _queueCallbackList.push_back(new ReflectAttributeValuesTimestampCallback(objectHandle, attributeHandleDataPairList,
271                                                                                  RTI13Ambassador::toTimeStamp(fedTime), tag));
272     }
273     void reflectAttributeValuesCallback(RTI::ObjectHandle objectHandle, RTI13AttributeHandleDataPairList& attributeHandleDataPairList,
274                                         const SGTimeStamp& timeStamp, const RTIData& tag)
275     {
276         ObjectInstanceMap::iterator i = _objectInstanceMap.find(objectHandle);
277         if (i == _objectInstanceMap.end())
278             return;
279         if (!i->second.valid())
280             return;
281         i->second->reflectAttributeValues(attributeHandleDataPairList, timeStamp, tag, _indexPool);
282     }
283
284     class ReflectAttributeValuesCallback : public TagQueueCallback {
285     public:
286         ReflectAttributeValuesCallback(RTI::ObjectHandle objectHandle, RTI13AttributeHandleDataPairList& attributeHandleDataPairList,
287                                        const char *tag) :
288             TagQueueCallback(tag),
289             _objectHandle(objectHandle)
290         {
291             _attributeHandleDataPairList.swap(attributeHandleDataPairList);
292         }
293         virtual void operator()(FederateAmbassador& self)
294         {
295             self.reflectAttributeValuesCallback(_objectHandle, _attributeHandleDataPairList, _tag);
296             self.freeAttributeHandleDataPairList(_attributeHandleDataPairList);
297         }
298     private:
299         RTI::ObjectHandle _objectHandle;
300         RTI13AttributeHandleDataPairList _attributeHandleDataPairList;
301     };
302     virtual void reflectAttributeValues(RTI::ObjectHandle objectHandle, const RTI::AttributeHandleValuePairSet& attributeValuePairSet,
303                                         const char* tag)
304         throw (RTI::ObjectNotKnown,
305                RTI::AttributeNotKnown,
306                RTI::FederateOwnsAttributes,
307                RTI::FederateInternalError)
308     {
309         RTI13AttributeHandleDataPairList attributeHandleDataPairList;
310
311         RTI::ULong numAttribs = attributeValuePairSet.size();
312         for (RTI::ULong i = 0; i < numAttribs; ++i) {
313             appendAttributeHandleDataPair(attributeHandleDataPairList);
314             attributeHandleDataPairList.back().first = attributeValuePairSet.getHandle(i);
315             RTI::ULong length = attributeValuePairSet.getValueLength(i);
316             attributeHandleDataPairList.back().second.resize(length);
317             attributeValuePairSet.getValue(i, attributeHandleDataPairList.back().second.data(), length);
318         }
319
320         _queueCallbackList.push_back(new ReflectAttributeValuesCallback(objectHandle, attributeHandleDataPairList, tag));
321     }
322     void reflectAttributeValuesCallback(RTI::ObjectHandle objectHandle, RTI13AttributeHandleDataPairList& attributeHandleDataPairList,
323                                         const RTIData& tag)
324     {
325         ObjectInstanceMap::iterator i = _objectInstanceMap.find(objectHandle);
326         if (i == _objectInstanceMap.end())
327             return;
328         if (!i->second.valid())
329             return;
330         i->second->reflectAttributeValues(attributeHandleDataPairList, tag, _indexPool);
331     }
332
333     virtual void receiveInteraction(RTI::InteractionClassHandle interactionClassHandle, const RTI::ParameterHandleValuePairSet& parameters,
334                                     const RTI::FedTime& fedTime, const char* tag, RTI::EventRetractionHandle eventRetractionHandle)
335         throw (RTI::InteractionClassNotKnown,
336                RTI::InteractionParameterNotKnown,
337                RTI::InvalidFederationTime,
338                RTI::FederateInternalError)
339     {
340     }
341
342     virtual void receiveInteraction(RTI::InteractionClassHandle interactionClassHandle,
343                                     const RTI::ParameterHandleValuePairSet& parameters, const char* tag)
344         throw (RTI::InteractionClassNotKnown,
345                RTI::InteractionParameterNotKnown,
346                RTI::FederateInternalError)
347     {
348     }
349
350     class RemoveObjectTimestampCallback : public TagQueueCallback {
351     public:
352         RemoveObjectTimestampCallback(RTI::ObjectHandle objectHandle, const SGTimeStamp& timeStamp, const char* tag) :
353             TagQueueCallback(tag),
354             _objectHandle(objectHandle),
355             _timeStamp(timeStamp)
356         { }
357         virtual void operator()(FederateAmbassador& self)
358         { self.removeObjectInstanceCallback(_objectHandle, _timeStamp, _tag); }
359     private:
360         RTI::ObjectHandle _objectHandle;
361         SGTimeStamp _timeStamp;
362     };
363     virtual void removeObjectInstance(RTI::ObjectHandle objectHandle, const RTI::FedTime& fedTime,
364                                       const char* tag, RTI::EventRetractionHandle eventRetractionHandle)
365         throw (RTI::ObjectNotKnown,
366                RTI::InvalidFederationTime,
367                RTI::FederateInternalError)
368     { _queueCallbackList.push_back(new RemoveObjectTimestampCallback(objectHandle, RTI13Ambassador::toTimeStamp(fedTime), tag)); }
369     void removeObjectInstanceCallback(RTI::ObjectHandle objectHandle, const SGTimeStamp& timeStamp, const RTIData& tag)
370     {
371         ObjectInstanceMap::iterator i = _objectInstanceMap.find(objectHandle);
372         if (i == _objectInstanceMap.end())
373             return;
374         if (i->second.valid())
375             i->second->removeInstance(tag);
376         _objectInstanceMap.erase(i);
377     }
378
379     class RemoveObjectCallback : public TagQueueCallback {
380     public:
381         RemoveObjectCallback(RTI::ObjectHandle objectHandle, const char* tag) :
382             TagQueueCallback(tag),
383             _objectHandle(objectHandle)
384         { }
385         virtual void operator()(FederateAmbassador& self)
386         { self.removeObjectInstanceCallback(_objectHandle, _tag); }
387     private:
388         RTI::ObjectHandle _objectHandle;
389     };
390     virtual void removeObjectInstance(RTI::ObjectHandle objectHandle, const char* tag)
391         throw (RTI::ObjectNotKnown,
392                RTI::FederateInternalError)
393     { _queueCallbackList.push_back(new RemoveObjectCallback(objectHandle, tag)); }
394     void removeObjectInstanceCallback(RTI::ObjectHandle objectHandle, const RTIData& tag)
395     {
396         ObjectInstanceMap::iterator i = _objectInstanceMap.find(objectHandle);
397         if (i == _objectInstanceMap.end())
398             return;
399         if (i->second.valid())
400             i->second->removeInstance(tag);
401         _objectInstanceMap.erase(i);
402     }
403
404     class AttributeHandleSetCallback : public QueueCallback {
405     public:
406         AttributeHandleSetCallback(RTI::ObjectHandle objectHandle, const RTI::AttributeHandleSet& attributeHandleSet) :
407             _objectHandle(objectHandle)
408         {
409             RTI::ULong numAttribs = attributeHandleSet.size();
410             _attributes.reserve(numAttribs);
411             for (RTI::ULong i = 0; i < numAttribs; ++i)
412                 _attributes.push_back(attributeHandleSet.getHandle(i));
413         }
414     protected:
415         RTI::ObjectHandle _objectHandle;
416         std::vector<RTI::AttributeHandle> _attributes;
417     };
418     class AttributesInScopeCallback : public AttributeHandleSetCallback {
419     public:
420         AttributesInScopeCallback(RTI::ObjectHandle objectHandle, const RTI::AttributeHandleSet& attributes) :
421             AttributeHandleSetCallback(objectHandle, attributes)
422         { }
423         virtual void operator()(FederateAmbassador& self)
424         { self.attributesInScopeCallback(_objectHandle, _attributes); }
425     };
426     virtual void attributesInScope(RTI::ObjectHandle objectHandle, const RTI::AttributeHandleSet& attributes)
427         throw (RTI::ObjectNotKnown,
428                RTI::AttributeNotKnown,
429                RTI::FederateInternalError)
430     { _queueCallbackList.push_back(new AttributesInScopeCallback(objectHandle, attributes)); }
431     void attributesInScopeCallback(RTI::ObjectHandle objectHandle, const std::vector<RTI::AttributeHandle>& attributes)
432     {
433         ObjectInstanceMap::iterator i = _objectInstanceMap.find(objectHandle);
434         if (i == _objectInstanceMap.end())
435             return;
436         if (!i->second.valid())
437             return;
438         i->second->attributesInScope(attributes);
439     }
440
441     class AttributesOutOfScopeCallback : public AttributeHandleSetCallback {
442     public:
443         AttributesOutOfScopeCallback(RTI::ObjectHandle objectHandle, const RTI::AttributeHandleSet& attributes) :
444             AttributeHandleSetCallback(objectHandle, attributes)
445         { }
446         virtual void operator()(FederateAmbassador& self)
447         { self.attributesOutOfScopeCallback(_objectHandle, _attributes); }
448     };
449     virtual void attributesOutOfScope(RTI::ObjectHandle objectHandle, const RTI::AttributeHandleSet& attributes)
450         throw (RTI::ObjectNotKnown,
451                RTI::AttributeNotKnown,
452                RTI::FederateInternalError)
453     { _queueCallbackList.push_back(new AttributesOutOfScopeCallback(objectHandle, attributes)); }
454     void attributesOutOfScopeCallback(RTI::ObjectHandle objectHandle, const std::vector<RTI::AttributeHandle>& attributes)
455     {
456         ObjectInstanceMap::iterator i = _objectInstanceMap.find(objectHandle);
457         if (i == _objectInstanceMap.end())
458             return;
459         if (!i->second.valid())
460             return;
461         i->second->attributesOutOfScope(attributes);
462     }
463
464     class ProvideAttributeValueUpdateCallback : public AttributeHandleSetCallback {
465     public:
466         ProvideAttributeValueUpdateCallback(RTI::ObjectHandle objectHandle, const RTI::AttributeHandleSet& attributes) :
467             AttributeHandleSetCallback(objectHandle, attributes)
468         { }
469         virtual void operator()(FederateAmbassador& self)
470         { self.provideAttributeValueUpdateCallback(_objectHandle, _attributes); }
471     };
472     virtual void provideAttributeValueUpdate(RTI::ObjectHandle objectHandle, const RTI::AttributeHandleSet& attributes)
473         throw (RTI::ObjectNotKnown,
474                RTI::AttributeNotKnown,
475                RTI::AttributeNotOwned,
476                RTI::FederateInternalError)
477     { _queueCallbackList.push_back(new ProvideAttributeValueUpdateCallback(objectHandle, attributes)); }
478     void provideAttributeValueUpdateCallback(RTI::ObjectHandle objectHandle, const std::vector<RTI::AttributeHandle>& attributes)
479     {
480         ObjectInstanceMap::iterator i = _objectInstanceMap.find(objectHandle);
481         if (i == _objectInstanceMap.end())
482             return;
483         if (!i->second.valid())
484             return;
485         i->second->provideAttributeValueUpdate(attributes);
486     }
487
488     class TurnUpdatesOnForObjectInstanceCallback : public AttributeHandleSetCallback {
489     public:
490         TurnUpdatesOnForObjectInstanceCallback(RTI::ObjectHandle objectHandle, const RTI::AttributeHandleSet& attributes) :
491             AttributeHandleSetCallback(objectHandle, attributes)
492         { }
493         virtual void operator()(FederateAmbassador& self)
494         { self.turnUpdatesOnForObjectInstanceCallback(_objectHandle, _attributes); }
495     };
496     virtual void turnUpdatesOnForObjectInstance(RTI::ObjectHandle objectHandle, const RTI::AttributeHandleSet& attributes)
497         throw (RTI::ObjectNotKnown,
498                RTI::AttributeNotOwned,
499                RTI::FederateInternalError)
500     { _queueCallbackList.push_back(new TurnUpdatesOnForObjectInstanceCallback(objectHandle, attributes)); }
501     void turnUpdatesOnForObjectInstanceCallback(RTI::ObjectHandle objectHandle, const std::vector<RTI::AttributeHandle>& attributes)
502     {
503         ObjectInstanceMap::iterator i = _objectInstanceMap.find(objectHandle);
504         if (i == _objectInstanceMap.end())
505             return;
506         if (!i->second.valid())
507             return;
508         i->second->turnUpdatesOnForObjectInstance(attributes);
509     }
510
511     class TurnUpdatesOffForObjectInstanceCallback : public AttributeHandleSetCallback {
512     public:
513         TurnUpdatesOffForObjectInstanceCallback(RTI::ObjectHandle objectHandle, const RTI::AttributeHandleSet& attributes) :
514             AttributeHandleSetCallback(objectHandle, attributes)
515         { }
516         virtual void operator()(FederateAmbassador& self)
517         { self.turnUpdatesOffForObjectInstanceCallback(_objectHandle, _attributes); }
518     };
519     virtual void turnUpdatesOffForObjectInstance(RTI::ObjectHandle objectHandle, const RTI::AttributeHandleSet& attributes)
520         throw (RTI::ObjectNotKnown,
521                RTI::AttributeNotOwned,
522                RTI::FederateInternalError)
523     { _queueCallbackList.push_back(new TurnUpdatesOffForObjectInstanceCallback(objectHandle, attributes)); }
524     void turnUpdatesOffForObjectInstanceCallback(RTI::ObjectHandle objectHandle, const std::vector<RTI::AttributeHandle>& attributes)
525     {
526         ObjectInstanceMap::iterator i = _objectInstanceMap.find(objectHandle);
527         if (i == _objectInstanceMap.end())
528             return;
529         if (!i->second.valid())
530             return;
531         i->second->turnUpdatesOffForObjectInstance(attributes);
532     }
533
534     // Ownership Management
535     class RequestAttributeOwnershipAssumptionCallback : public AttributeHandleSetCallback {
536     public:
537         RequestAttributeOwnershipAssumptionCallback(RTI::ObjectHandle objectHandle, const RTI::AttributeHandleSet& attributes, const RTIData& tag) :
538             AttributeHandleSetCallback(objectHandle, attributes),
539             _tag(tag)
540         { }
541         virtual void operator()(FederateAmbassador& self)
542         { self.requestAttributeOwnershipAssumptionCallback(_objectHandle, _attributes, _tag); }
543     protected:
544         RTIData _tag;
545     };
546     virtual void requestAttributeOwnershipAssumption(RTI::ObjectHandle objectHandle,
547                                                      const RTI::AttributeHandleSet& attributes, const char* tag)
548         throw (RTI::ObjectNotKnown,
549                RTI::AttributeNotKnown,
550                RTI::AttributeAlreadyOwned,
551                RTI::AttributeNotPublished,
552                RTI::FederateInternalError)
553     { _queueCallbackList.push_back(new RequestAttributeOwnershipAssumptionCallback(objectHandle, attributes, tagToData(tag))); }
554     void requestAttributeOwnershipAssumptionCallback(RTI::ObjectHandle objectHandle, std::vector<RTI::AttributeHandle>& attributes, const RTIData& tag)
555     {
556         ObjectInstanceMap::iterator i = _objectInstanceMap.find(objectHandle);
557         if (i == _objectInstanceMap.end())
558             return;
559         if (!i->second.valid())
560             return;
561         i->second->requestAttributeOwnershipAssumption(attributes, tag);
562     }
563
564     class AttributeOwnershipDivestitureNotificationCallback : public AttributeHandleSetCallback {
565     public:
566         AttributeOwnershipDivestitureNotificationCallback(RTI::ObjectHandle objectHandle, const RTI::AttributeHandleSet& attributes) :
567             AttributeHandleSetCallback(objectHandle, attributes)
568         { }
569         virtual void operator()(FederateAmbassador& self)
570         { self.attributeOwnershipDivestitureNotificationCallback(_objectHandle, _attributes); }
571     };
572     virtual void attributeOwnershipDivestitureNotification(RTI::ObjectHandle objectHandle, const RTI::AttributeHandleSet& attributes)
573         throw (RTI::ObjectNotKnown,
574                RTI::AttributeNotKnown,
575                RTI::AttributeNotOwned,
576                RTI::AttributeDivestitureWasNotRequested,
577                RTI::FederateInternalError)
578     { _queueCallbackList.push_back(new AttributeOwnershipDivestitureNotificationCallback(objectHandle, attributes)); }
579     void attributeOwnershipDivestitureNotificationCallback(RTI::ObjectHandle objectHandle, const std::vector<RTI::AttributeHandle>& attributes)
580     {
581         ObjectInstanceMap::iterator i = _objectInstanceMap.find(objectHandle);
582         if (i == _objectInstanceMap.end())
583             return;
584         if (!i->second.valid())
585             return;
586         i->second->attributeOwnershipDivestitureNotification(attributes);
587     }
588
589     class AttributeOwnershipAcquisitionNotificationCallback : public AttributeHandleSetCallback {
590     public:
591         AttributeOwnershipAcquisitionNotificationCallback(RTI::ObjectHandle objectHandle, const RTI::AttributeHandleSet& attributes) :
592             AttributeHandleSetCallback(objectHandle, attributes)
593         { }
594         virtual void operator()(FederateAmbassador& self)
595         { self.attributeOwnershipAcquisitionNotificationCallback(_objectHandle, _attributes); }
596     };
597     virtual void attributeOwnershipAcquisitionNotification(RTI::ObjectHandle objectHandle, const RTI::AttributeHandleSet& attributes)
598         throw (RTI::ObjectNotKnown,
599                RTI::AttributeNotKnown,
600                RTI::AttributeAcquisitionWasNotRequested,
601                RTI::AttributeAlreadyOwned,
602                RTI::AttributeNotPublished,
603                RTI::FederateInternalError)
604     { _queueCallbackList.push_back(new AttributeOwnershipAcquisitionNotificationCallback(objectHandle, attributes)); }
605     void attributeOwnershipAcquisitionNotificationCallback(RTI::ObjectHandle objectHandle, const std::vector<RTI::AttributeHandle>& attributes)
606     {
607         ObjectInstanceMap::iterator i = _objectInstanceMap.find(objectHandle);
608         if (i == _objectInstanceMap.end())
609             return;
610         if (!i->second.valid())
611             return;
612         i->second->attributeOwnershipAcquisitionNotification(attributes);
613     }
614
615     class AttributeOwnershipUnavailableCallback : public AttributeHandleSetCallback {
616     public:
617         AttributeOwnershipUnavailableCallback(RTI::ObjectHandle objectHandle, const RTI::AttributeHandleSet& attributes) :
618             AttributeHandleSetCallback(objectHandle, attributes)
619         { }
620         virtual void operator()(FederateAmbassador& self)
621         { self.attributeOwnershipUnavailableCallback(_objectHandle, _attributes); }
622     };
623     virtual void attributeOwnershipUnavailable(RTI::ObjectHandle objectHandle, const RTI::AttributeHandleSet& attributes)
624         throw (RTI::ObjectNotKnown,
625                RTI::AttributeNotKnown,
626                RTI::AttributeAlreadyOwned,
627                RTI::AttributeAcquisitionWasNotRequested,
628                RTI::FederateInternalError)
629     { _queueCallbackList.push_back(new AttributeOwnershipUnavailableCallback(objectHandle, attributes)); }
630     void attributeOwnershipUnavailableCallback(RTI::ObjectHandle objectHandle, const std::vector<RTI::AttributeHandle>& attributes)
631     {
632         ObjectInstanceMap::iterator i = _objectInstanceMap.find(objectHandle);
633         if (i == _objectInstanceMap.end())
634             return;
635         if (!i->second.valid())
636             return;
637         i->second->attributeOwnershipUnavailable(attributes);
638     }
639
640     class RequestAttributeOwnershipReleaseCallback : public AttributeHandleSetCallback {
641     public:
642         RequestAttributeOwnershipReleaseCallback(RTI::ObjectHandle objectHandle, const RTI::AttributeHandleSet& attributes, const RTIData& tag) :
643             AttributeHandleSetCallback(objectHandle, attributes),
644             _tag(tag)
645         { }
646         virtual void operator()(FederateAmbassador& self)
647         { self.requestAttributeOwnershipReleaseCallback(_objectHandle, _attributes, _tag); }
648     protected:
649         RTIData _tag;
650     };
651     virtual void requestAttributeOwnershipRelease(RTI::ObjectHandle objectHandle,
652                                                   const RTI::AttributeHandleSet& attributes, const char* tag)
653         throw (RTI::ObjectNotKnown,
654                RTI::AttributeNotKnown,
655                RTI::AttributeNotOwned,
656                RTI::FederateInternalError)
657     { _queueCallbackList.push_back(new RequestAttributeOwnershipReleaseCallback(objectHandle, attributes, tagToData(tag))); }
658     void requestAttributeOwnershipReleaseCallback(RTI::ObjectHandle objectHandle, std::vector<RTI::AttributeHandle>& attributes, const RTIData& tag)
659     {
660         ObjectInstanceMap::iterator i = _objectInstanceMap.find(objectHandle);
661         if (i == _objectInstanceMap.end())
662             return;
663         if (!i->second.valid())
664             return;
665         i->second->requestAttributeOwnershipRelease(attributes, tag);
666     }
667
668     class ConfirmAttributeOwnershipAcquisitionCancellationCallback : public AttributeHandleSetCallback {
669     public:
670         ConfirmAttributeOwnershipAcquisitionCancellationCallback(RTI::ObjectHandle objectHandle, const RTI::AttributeHandleSet& attributes) :
671             AttributeHandleSetCallback(objectHandle, attributes)
672         { }
673         virtual void operator()(FederateAmbassador& self)
674         { self.confirmAttributeOwnershipAcquisitionCancellationCallback(_objectHandle, _attributes); }
675     };
676     virtual void confirmAttributeOwnershipAcquisitionCancellation(RTI::ObjectHandle objectHandle, const RTI::AttributeHandleSet& attributes)
677         throw (RTI::ObjectNotKnown,
678                RTI::AttributeNotKnown,
679                RTI::AttributeAlreadyOwned,
680                RTI::AttributeAcquisitionWasNotCanceled,
681                RTI::FederateInternalError)
682     { _queueCallbackList.push_back(new ConfirmAttributeOwnershipAcquisitionCancellationCallback(objectHandle, attributes)); }
683     void confirmAttributeOwnershipAcquisitionCancellationCallback(RTI::ObjectHandle objectHandle, const std::vector<RTI::AttributeHandle>& attributes)
684     {
685         ObjectInstanceMap::iterator i = _objectInstanceMap.find(objectHandle);
686         if (i == _objectInstanceMap.end())
687             return;
688         if (!i->second.valid())
689             return;
690         i->second->confirmAttributeOwnershipAcquisitionCancellation(attributes);
691     }
692
693     class InformAttributeOwnershipCallback : public QueueCallback {
694     public:
695         InformAttributeOwnershipCallback(RTI::ObjectHandle objectHandle, RTI::AttributeHandle attributeHandle, RTI::FederateHandle federateHandle) :
696             _objectHandle(objectHandle),
697             _attributeHandle(attributeHandle),
698             _federateHandle(federateHandle)
699         { }
700         virtual void operator()(FederateAmbassador& self)
701         { self.informAttributeOwnershipCallback(_objectHandle, _attributeHandle, _federateHandle); }
702     private:
703         RTI::ObjectHandle _objectHandle;
704         RTI::AttributeHandle _attributeHandle;
705         RTI::FederateHandle _federateHandle;
706     };
707     virtual void informAttributeOwnership(RTI::ObjectHandle objectHandle, RTI::AttributeHandle attributeHandle,
708                                           RTI::FederateHandle federateHandle)
709         throw (RTI::ObjectNotKnown,
710                RTI::AttributeNotKnown,
711                RTI::FederateInternalError)
712     { _queueCallbackList.push_back(new InformAttributeOwnershipCallback(objectHandle, attributeHandle, federateHandle)); }
713     void informAttributeOwnershipCallback(RTI::ObjectHandle objectHandle, RTI::AttributeHandle attributeHandle, RTI::FederateHandle federateHandle)
714     {
715         ObjectInstanceMap::iterator i = _objectInstanceMap.find(objectHandle);
716         if (i == _objectInstanceMap.end())
717             return;
718         if (!i->second.valid())
719             return;
720         i->second->informAttributeOwnership(attributeHandle, federateHandle);
721     }
722
723     class AttributeIsNotOwnedCallback : public QueueCallback {
724     public:
725         AttributeIsNotOwnedCallback(RTI::ObjectHandle objectHandle, RTI::AttributeHandle attributeHandle) :
726             _objectHandle(objectHandle),
727             _attributeHandle(attributeHandle)
728         { }
729         virtual void operator()(FederateAmbassador& self)
730         { self.attributeIsNotOwnedCallback(_objectHandle, _attributeHandle); }
731     private:
732         RTI::ObjectHandle _objectHandle;
733         RTI::AttributeHandle _attributeHandle;
734     };
735     virtual void attributeIsNotOwned(RTI::ObjectHandle objectHandle, RTI::AttributeHandle attributeHandle)
736         throw (RTI::ObjectNotKnown,
737                RTI::AttributeNotKnown,
738                RTI::FederateInternalError)
739     { _queueCallbackList.push_back(new AttributeIsNotOwnedCallback(objectHandle, attributeHandle)); }
740     void attributeIsNotOwnedCallback(RTI::ObjectHandle objectHandle, RTI::AttributeHandle attributeHandle)
741     {
742         ObjectInstanceMap::iterator i = _objectInstanceMap.find(objectHandle);
743         if (i == _objectInstanceMap.end())
744             return;
745         if (!i->second.valid())
746             return;
747         i->second->attributeIsNotOwned(attributeHandle);
748     }
749
750     class AttributeOwnedByRTICallback : public QueueCallback {
751     public:
752         AttributeOwnedByRTICallback(RTI::ObjectHandle objectHandle, RTI::AttributeHandle attributeHandle) :
753             _objectHandle(objectHandle),
754             _attributeHandle(attributeHandle)
755         { }
756         virtual void operator()(FederateAmbassador& self)
757         { self.attributeOwnedByRTICallback(_objectHandle, _attributeHandle); }
758     private:
759         RTI::ObjectHandle _objectHandle;
760         RTI::AttributeHandle _attributeHandle;
761     };
762     virtual void attributeOwnedByRTI(RTI::ObjectHandle objectHandle, RTI::AttributeHandle attributeHandle)
763         throw (RTI::ObjectNotKnown,
764                RTI::AttributeNotKnown,
765                RTI::FederateInternalError)
766     { _queueCallbackList.push_back(new AttributeOwnedByRTICallback(objectHandle, attributeHandle)); }
767     void attributeOwnedByRTICallback(RTI::ObjectHandle objectHandle, RTI::AttributeHandle attributeHandle)
768     {
769         ObjectInstanceMap::iterator i = _objectInstanceMap.find(objectHandle);
770         if (i == _objectInstanceMap.end())
771             return;
772         if (!i->second.valid())
773             return;
774         i->second->attributeOwnedByRTI(attributeHandle);
775     }
776
777     // Time Management
778     virtual void timeRegulationEnabled(const RTI::FedTime& fedTime)
779         throw (RTI::InvalidFederationTime,
780                RTI::EnableTimeRegulationWasNotPending,
781                RTI::FederateInternalError)
782     {
783         _timeRegulationEnabled = true;
784         SG_LOG(SG_NETWORK, SG_INFO, "RTI: timeRegulationEnabled: " << RTI13Ambassador::toTimeStamp(fedTime));
785     }
786
787     virtual void timeConstrainedEnabled(const RTI::FedTime& fedTime)
788         throw (RTI::InvalidFederationTime,
789                RTI::EnableTimeConstrainedWasNotPending,
790                RTI::FederateInternalError)
791     {
792         _timeConstrainedEnabled = true;
793         SG_LOG(SG_NETWORK, SG_INFO, "RTI: timeConstrainedEnabled: " << RTI13Ambassador::toTimeStamp(fedTime));
794     }
795
796     virtual void timeAdvanceGrant(const RTI::FedTime& fedTime)
797         throw (RTI::InvalidFederationTime,
798                RTI::TimeAdvanceWasNotInProgress,
799                RTI::FederateInternalError)
800     {
801         _timeAdvancePending = false;
802         // SG_LOG(SG_NETWORK, SG_INFO, "RTI: timeAdvanceGrant: " << RTI13Ambassador::toTimeStamp(fedTime));
803     }
804
805     virtual void requestRetraction(RTI::EventRetractionHandle eventRetractionHandle)
806         throw (RTI::EventNotKnown,
807                RTI::FederateInternalError)
808     {
809         // No retraction concept yet
810     }
811
812     // processes the queues that filled up during the past
813     void processQueues()
814     {
815         while (!_queueCallbackList.empty()) {
816             (*_queueCallbackList.front())(*this);
817             // _queueCallbackListPool.splice();
818             _queueCallbackList.pop_front();
819         }
820     }
821
822     bool getFederationSynchronizationPointAnnounced(const std::string& label)
823     { return _pendingSyncLabels.find(label) != _pendingSyncLabels.end(); }
824     bool getFederationSynchronized(const std::string& label)
825     {
826         std::set<std::string>::iterator i = _syncronizedSyncLabels.find(label);
827         if (i == _syncronizedSyncLabels.end())
828             return false;
829         _syncronizedSyncLabels.erase(i);
830         return true;
831     }
832
833     // The rtiambassador to issue requests
834     SGSharedPtr<RTI13Ambassador> _rtiAmbassador;
835
836     // All the sync labels we got an announcement for
837     std::set<std::string> _pendingSyncLabels;
838     std::set<std::string> _syncronizedSyncLabels;
839
840     // All that calls back into user code is just queued.
841     // That is to make sure we do not call recursively into the RTI
842     typedef std::list<SGSharedPtr<QueueCallback> > QueueCallbackList;
843     QueueCallbackList _queueCallbackList;
844     // QueueCallbackList _queueCallbackListPool;
845
846     RTI13AttributeHandleDataPairList _attributeHandleDataPairPool;
847     void appendAttributeHandleDataPair(RTI13AttributeHandleDataPairList& attributeHandleDataPairList)
848     {
849         if (_attributeHandleDataPairPool.empty())
850             attributeHandleDataPairList.push_back(RTI13AttributeHandleDataPair());
851         else
852             attributeHandleDataPairList.splice(attributeHandleDataPairList.end(),
853                                                _attributeHandleDataPairPool, _attributeHandleDataPairPool.begin());
854     }
855     void freeAttributeHandleDataPairList(RTI13AttributeHandleDataPairList& attributeHandleDataPairList)
856     { _attributeHandleDataPairPool.splice(_attributeHandleDataPairPool.end(), attributeHandleDataPairList); }
857
858     // For attribute reflection, pool or indices
859     HLAIndexList _indexPool;
860
861     // Top level information for dispatching federate object attribute updates
862     typedef std::map<RTI::ObjectHandle, SGSharedPtr<RTI13ObjectInstance> > ObjectInstanceMap;
863     // Map of all available objects
864     ObjectInstanceMap _objectInstanceMap;
865
866     // Top level information for dispatching creation of federate objects
867     typedef std::map<RTI::ObjectClassHandle, SGSharedPtr<RTI13ObjectClass> > ObjectClassMap;
868     ObjectClassMap _objectClassMap;
869
870     // Top level information for dispatching creation of federate objects
871     typedef std::map<RTI::InteractionClassHandle, SGSharedPtr<RTI13InteractionClass> > InteractionClassMap;
872     InteractionClassMap _interactionClassMap;
873
874     bool _timeRegulationEnabled;
875     bool _timeConstrainedEnabled;
876     bool _timeAdvancePending;
877
878 private:
879     const RTIData& tagToData(const char* tag)
880     {
881         if (tag)
882             _cachedTag.setData(tag, std::strlen(tag) + 1);
883         else
884             _cachedTag.setData("", 1);
885         return _cachedTag;
886     }
887     RTIData _cachedTag;
888 };
889
890 RTI13Federate::RTI13Federate(const std::list<std::string>& stringList) :
891     _joined(false),
892     _ambassador(new RTI13Ambassador),
893     _federateAmbassador(new FederateAmbassador)
894 {
895     _ambassador->_federate = this;
896     _federateAmbassador->_rtiAmbassador = _ambassador;
897     if (stringList.empty()) {
898         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Ignoring non empty connect arguments while connecting to an RTI13 federation!");
899     }
900 }
901
902 RTI13Federate::~RTI13Federate()
903 {
904     if (_joined)
905         _ambassador->resignFederationExecution();
906     delete _federateAmbassador;
907 }
908
909 RTI13Federate::FederationManagementResult
910 RTI13Federate::createFederationExecution(const std::string& federationName, const std::string& objectModel)
911 {
912     try {
913         _ambassador->createFederationExecution(federationName, objectModel);
914         return FederationManagementSuccess;
915     } catch (RTI::FederationExecutionAlreadyExists& e) {
916         return FederationManagementFail;
917     } catch (RTI::CouldNotOpenFED& e) {
918         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not create federation execution: " << e._name << " " << e._reason);
919         return FederationManagementFatal;
920     } catch (RTI::ErrorReadingFED& e) {
921         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not create federation execution: " << e._name << " " << e._reason);
922         return FederationManagementFatal;
923     } catch (RTI::ConcurrentAccessAttempted& e) {
924         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not create federation execution: " << e._name << " " << e._reason);
925         return FederationManagementFatal;
926     } catch (RTI::RTIinternalError& e) {
927         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not create federation execution: " << e._name << " " << e._reason);
928         return FederationManagementFatal;
929     }
930 }
931
932 RTI13Federate::FederationManagementResult
933 RTI13Federate::destroyFederationExecution(const std::string& federation)
934 {
935     try {
936         _ambassador->destroyFederationExecution(federation);
937         return FederationManagementSuccess;
938     } catch (RTI::FederatesCurrentlyJoined& e) {
939         return FederationManagementFail;
940     } catch (RTI::FederationExecutionDoesNotExist& e) {
941         return FederationManagementFail;
942     } catch (RTI::ConcurrentAccessAttempted& e) {
943         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not destroy federation execution: " << e._name << " " << e._reason);
944         return FederationManagementFatal;
945     } catch (RTI::RTIinternalError& e) {
946         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not destroy federation execution: " << e._name << " " << e._reason);
947         return FederationManagementFatal;
948     }
949 }
950
951 RTI13Federate::FederationManagementResult
952 RTI13Federate::join(const std::string& federateType, const std::string& federationName)
953 {
954     try {
955         _federateHandle = _ambassador->joinFederationExecution(federateType, federationName, _federateAmbassador);
956         SG_LOG(SG_NETWORK, SG_INFO, "RTI: Joined federation \""
957                << federationName << "\" as \"" << federateType << "\"");
958         _joined = true;
959         return FederationManagementSuccess;
960     } catch (RTI::FederateAlreadyExecutionMember& e) {
961         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not join federation execution: " << e._name << " " << e._reason);
962         return FederationManagementFatal;
963     } catch (RTI::FederationExecutionDoesNotExist& e) {
964         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not join federation execution: " << e._name << " " << e._reason);
965         return FederationManagementFail;
966     } catch (RTI::CouldNotOpenFED& e) {
967         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not join federation execution: " << e._name << " " << e._reason);
968         return FederationManagementFatal;
969     } catch (RTI::ErrorReadingFED& e) {
970         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not join federation execution: " << e._name << " " << e._reason);
971         return FederationManagementFatal;
972     } catch (RTI::ConcurrentAccessAttempted& e) {
973         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not join federation execution: " << e._name << " " << e._reason);
974         return FederationManagementFatal;
975     } catch (RTI::SaveInProgress& e) {
976         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not join federation execution: " << e._name << " " << e._reason);
977         return FederationManagementFatal;
978     } catch (RTI::RestoreInProgress& e) {
979         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not join federation execution: " << e._name << " " << e._reason);
980         return FederationManagementFatal;
981     } catch (RTI::RTIinternalError& e) {
982         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not join federation execution: " << e._name << " " << e._reason);
983         return FederationManagementFatal;
984     }
985 }
986
987 bool
988 RTI13Federate::resign()
989 {
990     try {
991         _ambassador->resignFederationExecution();
992         SG_LOG(SG_NETWORK, SG_INFO, "RTI: Resigned from federation.");
993         _joined = false;
994         _federateHandle = -1;
995         return true;
996     } catch (RTI::FederateOwnsAttributes& e) {
997         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not resign federation execution: " << e._name << " " << e._reason);
998         return false;
999     } catch (RTI::FederateNotExecutionMember& e) {
1000         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not resign federation execution: " << e._name << " " << e._reason);
1001         return false;
1002     } catch (RTI::InvalidResignAction& e) {
1003         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not resign federation execution: " << e._name << " " << e._reason);
1004         return false;
1005     } catch (RTI::ConcurrentAccessAttempted& e) {
1006         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not resign federation execution: " << e._name << " " << e._reason);
1007         return false;
1008     } catch (RTI::RTIinternalError& e) {
1009         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not resign federation execution: " << e._name << " " << e._reason);
1010         return false;
1011     }
1012 }
1013
1014 bool
1015 RTI13Federate::getJoined() const
1016 {
1017     return _joined;
1018 }
1019
1020 bool
1021 RTI13Federate::registerFederationSynchronizationPoint(const std::string& label, const RTIData& tag)
1022 {
1023     try {
1024         _ambassador->registerFederationSynchronizationPoint(label, tag);
1025         SG_LOG(SG_NETWORK, SG_INFO, "RTI: registerFederationSynchronizationPoint(" << label << ", tag )");
1026         return true;
1027     } catch (RTI::FederateNotExecutionMember& e) {
1028         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not register federation synchronization point: " << e._name << " " << e._reason);
1029         return false;
1030     } catch (RTI::ConcurrentAccessAttempted& e) {
1031         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not register federation synchronization point: " << e._name << " " << e._reason);
1032         return false;
1033     } catch (RTI::SaveInProgress& e) {
1034         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not register federation synchronization point: " << e._name << " " << e._reason);
1035         return false;
1036     } catch (RTI::RestoreInProgress& e) {
1037         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not register federation synchronization point: " << e._name << " " << e._reason);
1038         return false;
1039     } catch (RTI::RTIinternalError& e) {
1040         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not register federation synchronization point: " << e._name << " " << e._reason);
1041         return false;
1042     }
1043 }
1044
1045 bool
1046 RTI13Federate::getFederationSynchronizationPointAnnounced(const std::string& label)
1047 {
1048     return _federateAmbassador->getFederationSynchronizationPointAnnounced(label);
1049 }
1050
1051 bool
1052 RTI13Federate::synchronizationPointAchieved(const std::string& label)
1053 {
1054     try {
1055         _ambassador->synchronizationPointAchieved(label);
1056         SG_LOG(SG_NETWORK, SG_INFO, "RTI: synchronizationPointAchieved(" << label << ")");
1057         return true;
1058     } catch (RTI::SynchronizationPointLabelWasNotAnnounced& e) {
1059         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not signal synchronization point: " << e._name << " " << e._reason);
1060         return false;
1061     } catch (RTI::FederateNotExecutionMember& e) {
1062         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not signal synchronization point: " << e._name << " " << e._reason);
1063         return false;
1064     } catch (RTI::ConcurrentAccessAttempted& e) {
1065         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not signal synchronization point: " << e._name << " " << e._reason);
1066         return false;
1067     } catch (RTI::SaveInProgress& e) {
1068         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not signal synchronization point: " << e._name << " " << e._reason);
1069         return false;
1070     } catch (RTI::RestoreInProgress& e) {
1071         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not signal synchronization point: " << e._name << " " << e._reason);
1072         return false;
1073     } catch (RTI::RTIinternalError& e) {
1074         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not signal synchronization point: " << e._name << " " << e._reason);
1075         return false;
1076     }
1077 }
1078
1079 bool
1080 RTI13Federate::getFederationSynchronized(const std::string& label)
1081 {
1082     return _federateAmbassador->getFederationSynchronized(label);
1083 }
1084
1085 bool
1086 RTI13Federate::enableTimeConstrained()
1087 {
1088     if (!_ambassador.valid()) {
1089         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not enable time constrained at unconnected federate.");
1090         return false;
1091     }
1092
1093     if (_federateAmbassador->_timeConstrainedEnabled) {
1094         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Time constrained is already enabled.");
1095         return false;
1096     }
1097
1098     try {
1099         _ambassador->enableTimeConstrained();
1100     } catch (RTI::TimeConstrainedAlreadyEnabled& e) {
1101         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not enable time constrained: " << e._name << " " << e._reason);
1102         return false;
1103     } catch (RTI::EnableTimeConstrainedPending& e) {
1104         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not enable time constrained: " << e._name << " " << e._reason);
1105         return false;
1106     } catch (RTI::TimeAdvanceAlreadyInProgress& e) {
1107         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not enable time constrained: " << e._name << " " << e._reason);
1108         return false;
1109     } catch (RTI::ConcurrentAccessAttempted& e) {
1110         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not enable time constrained: " << e._name << " " << e._reason);
1111         return false;
1112     } catch (RTI::FederateNotExecutionMember& e) {
1113         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not enable time constrained: " << e._name << " " << e._reason);
1114         return false;
1115     } catch (RTI::SaveInProgress& e) {
1116         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not enable time constrained: " << e._name << " " << e._reason);
1117         return false;
1118     } catch (RTI::RestoreInProgress& e) {
1119         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not enable time constrained: " << e._name << " " << e._reason);
1120         return false;
1121     } catch (RTI::RTIinternalError& e) {
1122         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not enable time constrained: " << e._name << " " << e._reason);
1123         return false;
1124     }
1125
1126     return true;
1127 }
1128
1129 bool
1130 RTI13Federate::disableTimeConstrained()
1131 {
1132     if (!_ambassador.valid()) {
1133         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not disable time constrained at unconnected federate.");
1134         return false;
1135     }
1136
1137     if (!_federateAmbassador->_timeConstrainedEnabled) {
1138         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Time constrained is not enabled.");
1139         return false;
1140     }
1141
1142     try {
1143         _ambassador->disableTimeConstrained();
1144         _federateAmbassador->_timeConstrainedEnabled = false;
1145     } catch (RTI::TimeConstrainedWasNotEnabled& e) {
1146         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not disable time constrained: " << e._name << " " << e._reason);
1147         return false;
1148     } catch (RTI::FederateNotExecutionMember& e) {
1149         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not disable time constrained: " << e._name << " " << e._reason);
1150         return false;
1151     } catch (RTI::ConcurrentAccessAttempted& e) {
1152         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not disable time constrained: " << e._name << " " << e._reason);
1153         return false;
1154     } catch (RTI::SaveInProgress& e) {
1155         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not disable time constrained: " << e._name << " " << e._reason);
1156         return false;
1157     } catch (RTI::RestoreInProgress& e) {
1158         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not disable time constrained: " << e._name << " " << e._reason);
1159         return false;
1160     } catch (RTI::RTIinternalError& e) {
1161         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not disable time constrained: " << e._name << " " << e._reason);
1162         return false;
1163     }
1164
1165     return true;
1166 }
1167
1168 bool
1169 RTI13Federate::getTimeConstrainedEnabled()
1170 {
1171     return _federateAmbassador->_timeConstrainedEnabled;
1172 }
1173
1174 bool
1175 RTI13Federate::enableTimeRegulation(const SGTimeStamp& lookahead)
1176 {
1177     if (!_ambassador.valid()) {
1178         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not enable time regulation at unconnected federate.");
1179         return false;
1180     }
1181
1182     if (_federateAmbassador->_timeRegulationEnabled) {
1183         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Time regulation already enabled.");
1184         return false;
1185     }
1186
1187     try {
1188         _ambassador->enableTimeRegulation(lookahead);
1189     } catch (RTI::TimeRegulationAlreadyEnabled& e) {
1190         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not enable time regulation: " << e._name << " " << e._reason);
1191         return false;
1192     } catch (RTI::EnableTimeRegulationPending& e) {
1193         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not enable time regulation: " << e._name << " " << e._reason);
1194         return false;
1195     } catch (RTI::TimeAdvanceAlreadyInProgress& e) {
1196         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not enable time regulation: " << e._name << " " << e._reason);
1197         return false;
1198     } catch (RTI::InvalidFederationTime& e) {
1199         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not enable time regulation: " << e._name << " " << e._reason);
1200         return false;
1201     } catch (RTI::InvalidLookahead& e) {
1202         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not enable time regulation: " << e._name << " " << e._reason);
1203         return false;
1204     } catch (RTI::ConcurrentAccessAttempted& e) {
1205         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not enable time regulation: " << e._name << " " << e._reason);
1206         return false;
1207     } catch (RTI::FederateNotExecutionMember& e) {
1208         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not enable time regulation: " << e._name << " " << e._reason);
1209         return false;
1210     } catch (RTI::SaveInProgress& e) {
1211         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not enable time regulation: " << e._name << " " << e._reason);
1212         return false;
1213     } catch (RTI::RestoreInProgress& e) {
1214         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not enable time regulation: " << e._name << " " << e._reason);
1215         return false;
1216     } catch (RTI::RTIinternalError& e) {
1217         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not enable time regulation: " << e._name << " " << e._reason);
1218         return false;
1219     }
1220
1221     return true;
1222 }
1223
1224 bool
1225 RTI13Federate::disableTimeRegulation()
1226 {
1227     if (!_ambassador.valid()) {
1228         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not disable time regulation at unconnected federate.");
1229         return false;
1230     }
1231
1232     if (!_federateAmbassador->_timeRegulationEnabled) {
1233         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Time regulation is not enabled.");
1234         return false;
1235     }
1236
1237     try {
1238         _ambassador->disableTimeRegulation();
1239         _federateAmbassador->_timeRegulationEnabled = false;
1240     } catch (RTI::TimeRegulationWasNotEnabled& e) {
1241         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not disable time regulation: " << e._name << " " << e._reason);
1242         return false;
1243     } catch (RTI::ConcurrentAccessAttempted& e) {
1244         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not disable time regulation: " << e._name << " " << e._reason);
1245         return false;
1246     } catch (RTI::FederateNotExecutionMember& e) {
1247         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not disable time regulation: " << e._name << " " << e._reason);
1248         return false;
1249     } catch (RTI::SaveInProgress& e) {
1250         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not disable time regulation: " << e._name << " " << e._reason);
1251         return false;
1252     } catch (RTI::RestoreInProgress& e) {
1253         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not disable time regulation: " << e._name << " " << e._reason);
1254         return false;
1255     } catch (RTI::RTIinternalError& e) {
1256         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not disable time regulation: " << e._name << " " << e._reason);
1257         return false;
1258     }
1259
1260     return true;
1261 }
1262
1263 bool
1264 RTI13Federate::modifyLookahead(const SGTimeStamp& timeStamp)
1265 {
1266     if (!_ambassador.valid()) {
1267         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not modify lookahead.");
1268         return false;
1269     }
1270     try {
1271         _ambassador->modifyLookahead(timeStamp);
1272     } catch (RTI::InvalidLookahead& e) {
1273         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not modify lookahead: " << e._name << " " << e._reason);
1274         return false;
1275     } catch (RTI::FederateNotExecutionMember& e) {
1276         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not modify lookahead: " << e._name << " " << e._reason);
1277         return false;
1278     } catch (RTI::ConcurrentAccessAttempted& e) {
1279         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not modify lookahead: " << e._name << " " << e._reason);
1280         return false;
1281     } catch (RTI::SaveInProgress& e) {
1282         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not modify lookahead: " << e._name << " " << e._reason);
1283         return false;
1284     } catch (RTI::RestoreInProgress& e) {
1285         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not modify lookahead: " << e._name << " " << e._reason);
1286         return false;
1287     } catch (RTI::RTIinternalError& e) {
1288         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not modify lookahead: " << e._name << " " << e._reason);
1289         return false;
1290     }
1291     return true;
1292 }
1293
1294 bool
1295 RTI13Federate::getTimeRegulationEnabled()
1296 {
1297     return _federateAmbassador->_timeRegulationEnabled;
1298 }
1299
1300 bool
1301 RTI13Federate::timeAdvanceRequest(const SGTimeStamp& timeStamp)
1302 {
1303     if (!_ambassador.valid()) {
1304         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not advance time at unconnected federate.");
1305         return false;
1306     }
1307
1308     try {
1309         _ambassador->timeAdvanceRequest(timeStamp);
1310         _federateAmbassador->_timeAdvancePending = true;
1311     } catch (RTI::InvalidFederationTime& e) {
1312         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not advance time: " << e._name << " " << e._reason);
1313         return false;
1314     } catch (RTI::FederationTimeAlreadyPassed& e) {
1315         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not advance time: " << e._name << " " << e._reason);
1316         return false;
1317     } catch (RTI::TimeAdvanceAlreadyInProgress& e) {
1318         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not advance time: " << e._name << " " << e._reason);
1319         return false;
1320     } catch (RTI::EnableTimeRegulationPending& e) {
1321         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not advance time: " << e._name << " " << e._reason);
1322         return false;
1323     } catch (RTI::EnableTimeConstrainedPending& e) {
1324         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not advance time: " << e._name << " " << e._reason);
1325         return false;
1326     } catch (RTI::FederateNotExecutionMember& e) {
1327         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not advance time: " << e._name << " " << e._reason);
1328         return false;
1329     } catch (RTI::ConcurrentAccessAttempted& e) {
1330         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not advance time: " << e._name << " " << e._reason);
1331         return false;
1332     } catch (RTI::SaveInProgress& e) {
1333         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not advance time: " << e._name << " " << e._reason);
1334         return false;
1335     } catch (RTI::RestoreInProgress& e) {
1336         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not advance time: " << e._name << " " << e._reason);
1337         return false;
1338     } catch (RTI::RTIinternalError& e) {
1339         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not advance time: " << e._name << " " << e._reason);
1340         return false;
1341     }
1342
1343     return true;
1344 }
1345
1346 bool
1347 RTI13Federate::timeAdvanceRequestAvailable(const SGTimeStamp& timeStamp)
1348 {
1349     if (!_ambassador.valid()) {
1350         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not advance time at unconnected federate.");
1351         return false;
1352     }
1353
1354     try {
1355         _ambassador->timeAdvanceRequestAvailable(timeStamp);
1356         _federateAmbassador->_timeAdvancePending = true;
1357     } catch (RTI::InvalidFederationTime& e) {
1358         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not advance time: " << e._name << " " << e._reason);
1359         return false;
1360     } catch (RTI::FederationTimeAlreadyPassed& e) {
1361         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not advance time: " << e._name << " " << e._reason);
1362         return false;
1363     } catch (RTI::TimeAdvanceAlreadyInProgress& e) {
1364         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not advance time: " << e._name << " " << e._reason);
1365         return false;
1366     } catch (RTI::EnableTimeRegulationPending& e) {
1367         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not advance time: " << e._name << " " << e._reason);
1368         return false;
1369     } catch (RTI::EnableTimeConstrainedPending& e) {
1370         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not advance time: " << e._name << " " << e._reason);
1371         return false;
1372     } catch (RTI::FederateNotExecutionMember& e) {
1373         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not advance time: " << e._name << " " << e._reason);
1374         return false;
1375     } catch (RTI::ConcurrentAccessAttempted& e) {
1376         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not advance time: " << e._name << " " << e._reason);
1377         return false;
1378     } catch (RTI::SaveInProgress& e) {
1379         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not advance time: " << e._name << " " << e._reason);
1380         return false;
1381     } catch (RTI::RestoreInProgress& e) {
1382         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not advance time: " << e._name << " " << e._reason);
1383         return false;
1384     } catch (RTI::RTIinternalError& e) {
1385         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not advance time: " << e._name << " " << e._reason);
1386         return false;
1387     }
1388
1389     return true;
1390 }
1391
1392 bool
1393 RTI13Federate::flushQueueRequest(const SGTimeStamp& timeStamp)
1394 {
1395     if (!_ambassador.valid()) {
1396         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not flush queue at unconnected federate.");
1397         return false;
1398     }
1399
1400     try {
1401         _ambassador->flushQueueRequest(timeStamp);
1402         _federateAmbassador->_timeAdvancePending = true;
1403     } catch (RTI::InvalidFederationTime& e) {
1404         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not flush queue: " << e._name << " " << e._reason);
1405         return false;
1406     } catch (RTI::FederationTimeAlreadyPassed& e) {
1407         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not flush queue: " << e._name << " " << e._reason);
1408         return false;
1409     } catch (RTI::TimeAdvanceAlreadyInProgress& e) {
1410         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not flush queue: " << e._name << " " << e._reason);
1411         return false;
1412     } catch (RTI::EnableTimeRegulationPending& e) {
1413         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not flush queue: " << e._name << " " << e._reason);
1414         return false;
1415     } catch (RTI::EnableTimeConstrainedPending& e) {
1416         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not flush queue: " << e._name << " " << e._reason);
1417         return false;
1418     } catch (RTI::FederateNotExecutionMember& e) {
1419         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not flush queue: " << e._name << " " << e._reason);
1420         return false;
1421     } catch (RTI::ConcurrentAccessAttempted& e) {
1422         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not flush queue: " << e._name << " " << e._reason);
1423         return false;
1424     } catch (RTI::SaveInProgress& e) {
1425         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not flush queue: " << e._name << " " << e._reason);
1426         return false;
1427     } catch (RTI::RestoreInProgress& e) {
1428         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not flush queue: " << e._name << " " << e._reason);
1429         return false;
1430     } catch (RTI::RTIinternalError& e) {
1431         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not flush queue: " << e._name << " " << e._reason);
1432         return false;
1433     }
1434
1435     return true;
1436 }
1437
1438 bool
1439 RTI13Federate::getTimeAdvancePending()
1440 {
1441     return _federateAmbassador->_timeAdvancePending;
1442 }
1443
1444 bool
1445 RTI13Federate::queryFederateTime(SGTimeStamp& timeStamp)
1446 {
1447     if (!_ambassador.valid()) {
1448         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not query federate time.");
1449         return false;
1450     }
1451
1452     try {
1453         _ambassador->queryFederateTime(timeStamp);
1454     } catch (RTI::FederateNotExecutionMember& e) {
1455         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not query federate time: " << e._name << " " << e._reason);
1456         return false;
1457     } catch (RTI::ConcurrentAccessAttempted& e) {
1458         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not query federate time: " << e._name << " " << e._reason);
1459         return false;
1460     } catch (RTI::SaveInProgress& e) {
1461         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not query federate time: " << e._name << " " << e._reason);
1462         return false;
1463     } catch (RTI::RestoreInProgress& e) {
1464         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not query federate time: " << e._name << " " << e._reason);
1465         return false;
1466     } catch (RTI::RTIinternalError& e) {
1467         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not query federate time: " << e._name << " " << e._reason);
1468         return false;
1469     }
1470     return true;
1471 }
1472
1473 bool
1474 RTI13Federate::queryLookahead(SGTimeStamp& timeStamp)
1475 {
1476     if (!_ambassador.valid()) {
1477         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not query lookahead.");
1478         return false;
1479     }
1480
1481     try {
1482         _ambassador->queryLookahead(timeStamp);
1483     } catch (RTI::FederateNotExecutionMember& e) {
1484         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not query lookahead: " << e._name << " " << e._reason);
1485         return false;
1486     } catch (RTI::ConcurrentAccessAttempted& e) {
1487         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not query lookahead: " << e._name << " " << e._reason);
1488         return false;
1489     } catch (RTI::SaveInProgress& e) {
1490         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not query lookahead: " << e._name << " " << e._reason);
1491         return false;
1492     } catch (RTI::RestoreInProgress& e) {
1493         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not query lookahead: " << e._name << " " << e._reason);
1494         return false;
1495     } catch (RTI::RTIinternalError& e) {
1496         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not query lookahead: " << e._name << " " << e._reason);
1497         return false;
1498     }
1499     return true;
1500 }
1501
1502 bool
1503 RTI13Federate::queryGALT(SGTimeStamp& timeStamp)
1504 {
1505     if (!_ambassador.valid()) {
1506         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not query GALT.");
1507         return false;
1508     }
1509
1510     try {
1511         return _ambassador->queryGALT(timeStamp);
1512     } catch (RTI::FederateNotExecutionMember& e) {
1513         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not query GALT: " << e._name << " " << e._reason);
1514         return false;
1515     } catch (RTI::ConcurrentAccessAttempted& e) {
1516         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not query GALT: " << e._name << " " << e._reason);
1517         return false;
1518     } catch (RTI::SaveInProgress& e) {
1519         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not query GALT: " << e._name << " " << e._reason);
1520         return false;
1521     } catch (RTI::RestoreInProgress& e) {
1522         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not query GALT: " << e._name << " " << e._reason);
1523         return false;
1524     } catch (RTI::RTIinternalError& e) {
1525         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not query GALT: " << e._name << " " << e._reason);
1526         return false;
1527     }
1528     return true;
1529 }
1530
1531 bool
1532 RTI13Federate::queryLITS(SGTimeStamp& timeStamp)
1533 {
1534     if (!_ambassador.valid()) {
1535         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not query LITS.");
1536         return false;
1537     }
1538
1539     try {
1540         return _ambassador->queryLITS(timeStamp);
1541     } catch (RTI::FederateNotExecutionMember& e) {
1542         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not query LITS: " << e._name << " " << e._reason);
1543         return false;
1544     } catch (RTI::ConcurrentAccessAttempted& e) {
1545         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not query LITS: " << e._name << " " << e._reason);
1546         return false;
1547     } catch (RTI::SaveInProgress& e) {
1548         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not query LITS: " << e._name << " " << e._reason);
1549         return false;
1550     } catch (RTI::RestoreInProgress& e) {
1551         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not query LITS: " << e._name << " " << e._reason);
1552         return false;
1553     } catch (RTI::RTIinternalError& e) {
1554         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not query LITS: " << e._name << " " << e._reason);
1555         return false;
1556     }
1557     return true;
1558 }
1559
1560 bool
1561 RTI13Federate::processMessage()
1562 {
1563     bool result = _ambassador->tick();
1564     _federateAmbassador->processQueues();
1565     return result;
1566 }
1567
1568 bool
1569 RTI13Federate::processMessages(const double& minimum, const double& maximum)
1570 {
1571     bool result = _ambassador->tick(minimum, 0);
1572     _federateAmbassador->processQueues();
1573     if (!result)
1574         return false;
1575     SGTimeStamp timeStamp = SGTimeStamp::now() + SGTimeStamp::fromSec(maximum);
1576     do {
1577         result = _ambassador->tick(0, 0);
1578         _federateAmbassador->processQueues();
1579     } while (result && SGTimeStamp::now() <= timeStamp);
1580     return result;
1581 }
1582
1583 RTI13ObjectClass*
1584 RTI13Federate::createObjectClass(const std::string& objectClassName, HLAObjectClass* hlaObjectClass)
1585 {
1586     try {
1587         RTI::ObjectClassHandle objectClassHandle;
1588         objectClassHandle = _ambassador->getObjectClassHandle(objectClassName);
1589         if (_federateAmbassador->_objectClassMap.find(objectClassHandle) != _federateAmbassador->_objectClassMap.end()) {
1590             SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not create object class, object class already exists!");
1591             return 0;
1592         }
1593         RTI13ObjectClass* rtiObjectClass;
1594         rtiObjectClass = new RTI13ObjectClass(hlaObjectClass, objectClassHandle, _ambassador.get());
1595         _federateAmbassador->_objectClassMap[objectClassHandle] = rtiObjectClass;
1596         return rtiObjectClass;
1597     } catch (RTI::NameNotFound& e) {
1598         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not get object class: " << e._name << " " << e._reason);
1599         return 0;
1600     } catch (RTI::FederateNotExecutionMember& e) {
1601         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not get object class: " << e._name << " " << e._reason);
1602         return 0;
1603     } catch (RTI::ConcurrentAccessAttempted& e) {
1604         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not get object class: " << e._name << " " << e._reason);
1605         return 0;
1606     } catch (RTI::RTIinternalError& e) {
1607         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not get object class: " << e._name << " " << e._reason);
1608         return 0;
1609     }
1610 }
1611
1612 RTI13InteractionClass*
1613 RTI13Federate::createInteractionClass(const std::string& interactionClassName, HLAInteractionClass* interactionClass)
1614 {
1615     try {
1616         RTI::InteractionClassHandle interactionClassHandle;
1617         interactionClassHandle = _ambassador->getInteractionClassHandle(interactionClassName);
1618         if (_federateAmbassador->_interactionClassMap.find(interactionClassHandle) != _federateAmbassador->_interactionClassMap.end()) {
1619             SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not create interaction class, interaction class already exists!");
1620             return 0;
1621         }
1622         RTI13InteractionClass* rtiInteractionClass;
1623         rtiInteractionClass = new RTI13InteractionClass(interactionClass, interactionClassHandle, _ambassador.get());
1624         _federateAmbassador->_interactionClassMap[interactionClassHandle] = rtiInteractionClass;
1625         return rtiInteractionClass;
1626     } catch (RTI::NameNotFound& e) {
1627         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not get interaction class: " << e._name << " " << e._reason);
1628         return 0;
1629     } catch (RTI::FederateNotExecutionMember& e) {
1630         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not get interaction class: " << e._name << " " << e._reason);
1631         return 0;
1632     } catch (RTI::ConcurrentAccessAttempted& e) {
1633         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not get interaction class: " << e._name << " " << e._reason);
1634         return 0;
1635     } catch (RTI::RTIinternalError& e) {
1636         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not get interaction class: " << e._name << " " << e._reason);
1637         return 0;
1638     }
1639 }
1640
1641 RTI13ObjectInstance*
1642 RTI13Federate::getObjectInstance(const std::string& objectInstanceName)
1643 {
1644     try {
1645         RTI::ObjectHandle objectHandle;
1646         objectHandle = _ambassador->getObjectInstanceHandle(objectInstanceName);
1647         FederateAmbassador::ObjectInstanceMap::iterator i = _federateAmbassador->_objectInstanceMap.find(objectHandle);
1648         if (i == _federateAmbassador->_objectInstanceMap.end()) {
1649             SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not get object instance: ObjectInstance not found.");
1650             return 0;
1651         }
1652         return i->second;
1653     } catch (RTI::ObjectNotKnown& e) {
1654         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not get object instance: " << e._name << " " << e._reason);
1655         return 0;
1656     } catch (RTI::FederateNotExecutionMember& e) {
1657         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not get object instance: " << e._name << " " << e._reason);
1658         return 0;
1659     } catch (RTI::ConcurrentAccessAttempted& e) {
1660         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not get object instance: " << e._name << " " << e._reason);
1661         return 0;
1662     } catch (RTI::RTIinternalError& e) {
1663         SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not get object instance: " << e._name << " " << e._reason);
1664         return 0;
1665     }
1666 }
1667
1668 void
1669 RTI13Federate::insertObjectInstance(RTI13ObjectInstance* objectInstance)
1670 {
1671     _federateAmbassador->_objectInstanceMap[objectInstance->getHandle()] = objectInstance;
1672 }
1673
1674 }