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