1 // Copyright (C) 2009 - 2010 Mathias Froehlich - Mathias.Froehlich@web.de
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Library General Public
5 // License as published by the Free Software Foundation; either
6 // version 2 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Library General Public License for more details.
13 // You should have received a copy of the GNU General Public License
14 // along with this program; if not, write to the Free Software
15 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 #include "RTI13Federate.hxx"
20 #include "RTI13Ambassador.hxx"
24 RTI13Federate::RTI13Federate() :
26 _ambassador(new RTI13Ambassador)
30 RTI13Federate::~RTI13Federate()
35 RTI13Federate::createFederationExecution(const std::string& federationName, const std::string& objectModel)
38 _ambassador->createFederationExecution(federationName, objectModel);
40 } catch (RTI::FederationExecutionAlreadyExists& e) {
42 } catch (RTI::CouldNotOpenFED& e) {
43 SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not create federation execution: " << e._name << " " << e._reason);
45 } catch (RTI::ErrorReadingFED& e) {
46 SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not create federation execution: " << e._name << " " << e._reason);
48 } catch (RTI::ConcurrentAccessAttempted& e) {
49 SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not create federation execution: " << e._name << " " << e._reason);
51 } catch (RTI::RTIinternalError& e) {
52 SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not create federation execution: " << e._name << " " << e._reason);
58 RTI13Federate::destroyFederationExecution(const std::string& federation)
61 _ambassador->destroyFederationExecution(federation);
63 } catch (RTI::FederatesCurrentlyJoined& e) {
65 } catch (RTI::FederationExecutionDoesNotExist& e) {
67 } catch (RTI::ConcurrentAccessAttempted& e) {
68 SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not destroy federation execution: " << e._name << " " << e._reason);
70 } catch (RTI::RTIinternalError& e) {
71 SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not destroy federation execution: " << e._name << " " << e._reason);
77 RTI13Federate::join(const std::string& federateType, const std::string& federationName)
80 _federateHandle = _ambassador->joinFederationExecution(federateType, federationName);
81 SG_LOG(SG_NETWORK, SG_INFO, "RTI: Joined federation \""
82 << federationName << "\" as \"" << federateType << "\"");
83 setFederateType(federateType);
84 setFederationName(federationName);
86 } catch (RTI::FederateAlreadyExecutionMember& e) {
87 SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not join federation execution: " << e._name << " " << e._reason);
89 } catch (RTI::FederationExecutionDoesNotExist& e) {
90 SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not join federation execution: " << e._name << " " << e._reason);
92 } catch (RTI::CouldNotOpenFED& e) {
93 SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not join federation execution: " << e._name << " " << e._reason);
95 } catch (RTI::ErrorReadingFED& e) {
96 SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not join federation execution: " << e._name << " " << e._reason);
98 } catch (RTI::ConcurrentAccessAttempted& e) {
99 SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not join federation execution: " << e._name << " " << e._reason);
101 } catch (RTI::SaveInProgress& e) {
102 SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not join federation execution: " << e._name << " " << e._reason);
104 } catch (RTI::RestoreInProgress& e) {
105 SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not join federation execution: " << e._name << " " << e._reason);
107 } catch (RTI::RTIinternalError& e) {
108 SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not join federation execution: " << e._name << " " << e._reason);
114 RTI13Federate::resign()
117 _ambassador->resignFederationExecution();
118 SG_LOG(SG_NETWORK, SG_INFO, "RTI: Resigned from federation.");
119 _federateHandle = -1;
121 } catch (RTI::FederateOwnsAttributes& e) {
122 SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not resign federation execution: " << e._name << " " << e._reason);
124 } catch (RTI::FederateNotExecutionMember& e) {
125 SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not resign federation execution: " << e._name << " " << e._reason);
127 } catch (RTI::InvalidResignAction& e) {
128 SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not resign federation execution: " << e._name << " " << e._reason);
130 } catch (RTI::ConcurrentAccessAttempted& e) {
131 SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not resign federation execution: " << e._name << " " << e._reason);
133 } catch (RTI::RTIinternalError& e) {
134 SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not resign federation execution: " << e._name << " " << e._reason);
140 RTI13Federate::registerFederationSynchronizationPoint(const std::string& label, const RTIData& tag)
143 _ambassador->registerFederationSynchronizationPoint(label, tag);
144 SG_LOG(SG_NETWORK, SG_INFO, "RTI: registerFederationSynchronizationPoint(" << label << ", tag )");
146 } catch (RTI::FederateNotExecutionMember& e) {
147 SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not register federation synchronization point: " << e._name << " " << e._reason);
149 } catch (RTI::ConcurrentAccessAttempted& e) {
150 SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not register federation synchronization point: " << e._name << " " << e._reason);
152 } catch (RTI::SaveInProgress& e) {
153 SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not register federation synchronization point: " << e._name << " " << e._reason);
155 } catch (RTI::RestoreInProgress& e) {
156 SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not register federation synchronization point: " << e._name << " " << e._reason);
158 } catch (RTI::RTIinternalError& e) {
159 SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not register federation synchronization point: " << e._name << " " << e._reason);
165 RTI13Federate::waitForFederationSynchronizationPointAnnounced(const std::string& label)
167 while (!_ambassador->getFederationSynchronizationPointAnnounced(label)) {
168 _ambassador->tick(_tickTimeout, 0);
169 _ambassador->processQueues();
175 RTI13Federate::synchronizationPointAchieved(const std::string& label)
178 _ambassador->synchronizationPointAchieved(label);
179 SG_LOG(SG_NETWORK, SG_INFO, "RTI: synchronizationPointAchieved(" << label << ")");
181 } catch (RTI::SynchronizationPointLabelWasNotAnnounced& e) {
182 SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not signal synchronization point: " << e._name << " " << e._reason);
184 } catch (RTI::FederateNotExecutionMember& e) {
185 SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not signal synchronization point: " << e._name << " " << e._reason);
187 } catch (RTI::ConcurrentAccessAttempted& e) {
188 SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not signal synchronization point: " << e._name << " " << e._reason);
190 } catch (RTI::SaveInProgress& e) {
191 SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not signal synchronization point: " << e._name << " " << e._reason);
193 } catch (RTI::RestoreInProgress& e) {
194 SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not signal synchronization point: " << e._name << " " << e._reason);
196 } catch (RTI::RTIinternalError& e) {
197 SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not signal synchronization point: " << e._name << " " << e._reason);
203 RTI13Federate::waitForFederationSynchronized(const std::string& label)
205 while (!_ambassador->getFederationSynchronized(label)) {
206 _ambassador->tick(_tickTimeout, 0);
207 _ambassador->processQueues();
213 RTI13Federate::enableTimeConstrained()
215 if (!_ambassador.valid()) {
216 SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not enable time constrained at unconnected federate.");
220 if (_ambassador->getTimeConstrainedEnabled()) {
221 SG_LOG(SG_NETWORK, SG_WARN, "RTI: Time constrained is already enabled.");
226 _ambassador->enableTimeConstrained();
227 } catch (RTI::TimeConstrainedAlreadyEnabled& e) {
228 SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not resign federation execution: " << e._name << " " << e._reason);
230 } catch (RTI::EnableTimeConstrainedPending& e) {
231 SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not resign federation execution: " << e._name << " " << e._reason);
233 } catch (RTI::TimeAdvanceAlreadyInProgress& e) {
234 SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not resign federation execution: " << e._name << " " << e._reason);
236 } catch (RTI::ConcurrentAccessAttempted& e) {
237 SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not resign federation execution: " << e._name << " " << e._reason);
239 } catch (RTI::FederateNotExecutionMember& e) {
240 SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not resign federation execution: " << e._name << " " << e._reason);
242 } catch (RTI::SaveInProgress& e) {
243 SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not resign federation execution: " << e._name << " " << e._reason);
245 } catch (RTI::RestoreInProgress& e) {
246 SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not resign federation execution: " << e._name << " " << e._reason);
248 } catch (RTI::RTIinternalError& e) {
249 SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not resign federation execution: " << e._name << " " << e._reason);
253 while (!_ambassador->getTimeConstrainedEnabled()) {
254 _ambassador->tick(_tickTimeout, 0);
255 _ambassador->processQueues();
262 RTI13Federate::disableTimeConstrained()
264 if (!_ambassador.valid()) {
265 SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not disable time constrained at unconnected federate.");
269 if (!_ambassador->getTimeConstrainedEnabled()) {
270 SG_LOG(SG_NETWORK, SG_WARN, "RTI: Time constrained is not enabled.");
275 _ambassador->disableTimeConstrained();
276 } catch (RTI::TimeConstrainedWasNotEnabled& e) {
277 SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not resign federation execution: " << e._name << " " << e._reason);
279 } catch (RTI::FederateNotExecutionMember& e) {
280 SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not resign federation execution: " << e._name << " " << e._reason);
282 } catch (RTI::ConcurrentAccessAttempted& e) {
283 SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not resign federation execution: " << e._name << " " << e._reason);
285 } catch (RTI::SaveInProgress& e) {
286 SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not resign federation execution: " << e._name << " " << e._reason);
288 } catch (RTI::RestoreInProgress& e) {
289 SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not resign federation execution: " << e._name << " " << e._reason);
291 } catch (RTI::RTIinternalError& e) {
292 SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not resign federation execution: " << e._name << " " << e._reason);
300 RTI13Federate::enableTimeRegulation(const SGTimeStamp& lookahead)
302 if (!_ambassador.valid()) {
303 SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not enable time regulation at unconnected federate.");
307 if (_ambassador->getTimeRegulationEnabled()) {
308 SG_LOG(SG_NETWORK, SG_WARN, "RTI: Time regulation already enabled.");
313 _ambassador->enableTimeRegulation(SGTimeStamp(), lookahead);
314 } catch (RTI::TimeRegulationAlreadyEnabled& e) {
315 SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not resign federation execution: " << e._name << " " << e._reason);
317 } catch (RTI::EnableTimeRegulationPending& e) {
318 SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not resign federation execution: " << e._name << " " << e._reason);
320 } catch (RTI::TimeAdvanceAlreadyInProgress& e) {
321 SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not resign federation execution: " << e._name << " " << e._reason);
323 } catch (RTI::InvalidFederationTime& e) {
324 SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not resign federation execution: " << e._name << " " << e._reason);
326 } catch (RTI::InvalidLookahead& e) {
327 SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not resign federation execution: " << e._name << " " << e._reason);
329 } catch (RTI::ConcurrentAccessAttempted& e) {
330 SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not resign federation execution: " << e._name << " " << e._reason);
332 } catch (RTI::FederateNotExecutionMember& e) {
333 SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not resign federation execution: " << e._name << " " << e._reason);
335 } catch (RTI::SaveInProgress& e) {
336 SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not resign federation execution: " << e._name << " " << e._reason);
338 } catch (RTI::RestoreInProgress& e) {
339 SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not resign federation execution: " << e._name << " " << e._reason);
341 } catch (RTI::RTIinternalError& e) {
342 SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not resign federation execution: " << e._name << " " << e._reason);
346 while (!_ambassador->getTimeRegulationEnabled()) {
347 _ambassador->tick(_tickTimeout, 0);
348 _ambassador->processQueues();
355 RTI13Federate::disableTimeRegulation()
357 if (!_ambassador.valid()) {
358 SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not disable time regulation at unconnected federate.");
362 if (!_ambassador->getTimeRegulationEnabled()) {
363 SG_LOG(SG_NETWORK, SG_WARN, "RTI: Time regulation is not enabled.");
368 _ambassador->disableTimeRegulation();
369 } catch (RTI::TimeRegulationWasNotEnabled& e) {
370 SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not resign federation execution: " << e._name << " " << e._reason);
372 } catch (RTI::ConcurrentAccessAttempted& e) {
373 SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not resign federation execution: " << e._name << " " << e._reason);
375 } catch (RTI::FederateNotExecutionMember& e) {
376 SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not resign federation execution: " << e._name << " " << e._reason);
378 } catch (RTI::SaveInProgress& e) {
379 SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not resign federation execution: " << e._name << " " << e._reason);
381 } catch (RTI::RestoreInProgress& e) {
382 SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not resign federation execution: " << e._name << " " << e._reason);
384 } catch (RTI::RTIinternalError& e) {
385 SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not resign federation execution: " << e._name << " " << e._reason);
393 RTI13Federate::timeAdvanceRequestBy(const SGTimeStamp& dt)
395 if (!_ambassador.valid()) {
396 SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not disable time regulation at unconnected federate.");
400 SGTimeStamp fedTime = _ambassador->getCurrentLogicalTime() + dt;
401 return timeAdvanceRequest(fedTime);
405 RTI13Federate::timeAdvanceRequest(const SGTimeStamp& fedTime)
407 if (!_ambassador.valid()) {
408 SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not disable time regulation at unconnected federate.");
413 _ambassador->timeAdvanceRequest(fedTime);
414 } catch (RTI::InvalidFederationTime& e) {
415 SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not resign federation execution: " << e._name << " " << e._reason);
417 } catch (RTI::FederationTimeAlreadyPassed& e) {
418 SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not resign federation execution: " << e._name << " " << e._reason);
420 } catch (RTI::TimeAdvanceAlreadyInProgress& e) {
421 SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not resign federation execution: " << e._name << " " << e._reason);
423 } catch (RTI::EnableTimeRegulationPending& e) {
424 SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not resign federation execution: " << e._name << " " << e._reason);
426 } catch (RTI::EnableTimeConstrainedPending& e) {
427 SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not resign federation execution: " << e._name << " " << e._reason);
429 } catch (RTI::FederateNotExecutionMember& e) {
430 SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not resign federation execution: " << e._name << " " << e._reason);
432 } catch (RTI::ConcurrentAccessAttempted& e) {
433 SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not resign federation execution: " << e._name << " " << e._reason);
435 } catch (RTI::SaveInProgress& e) {
436 SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not resign federation execution: " << e._name << " " << e._reason);
438 } catch (RTI::RestoreInProgress& e) {
439 SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not resign federation execution: " << e._name << " " << e._reason);
441 } catch (RTI::RTIinternalError& e) {
442 SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not resign federation execution: " << e._name << " " << e._reason);
446 while (_ambassador->getTimeAdvancePending()) {
447 _ambassador->tick(_tickTimeout, 0);
448 _ambassador->processQueues();
455 RTI13Federate::tick()
457 bool result = _ambassador->tick();
458 _ambassador->processQueues();
463 RTI13Federate::tick(const double& minimum, const double& maximum)
465 bool result = _ambassador->tick(minimum, maximum);
466 _ambassador->processQueues();
471 RTI13Federate::createObjectClass(const std::string& objectClassName, HLAObjectClass* hlaObjectClass)
474 return _ambassador->createObjectClass(objectClassName, hlaObjectClass);
475 } catch (RTI::NameNotFound& e) {
476 SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not get object class: " << e._name << " " << e._reason);
478 } catch (RTI::FederateNotExecutionMember& e) {
479 SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not get object class: " << e._name << " " << e._reason);
481 } catch (RTI::ConcurrentAccessAttempted& e) {
482 SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not get object class: " << e._name << " " << e._reason);
484 } catch (RTI::RTIinternalError& e) {
485 SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not get object class: " << e._name << " " << e._reason);
491 RTI13Federate::getObjectInstance(const std::string& objectInstanceName)
494 return _ambassador->getObjectInstance(objectInstanceName);
495 } catch (RTI::ObjectNotKnown& e) {
496 SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not get object class: " << e._name << " " << e._reason);
498 } catch (RTI::FederateNotExecutionMember& e) {
499 SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not get object class: " << e._name << " " << e._reason);
501 } catch (RTI::ConcurrentAccessAttempted& e) {
502 SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not get object class: " << e._name << " " << e._reason);
504 } catch (RTI::RTIinternalError& e) {
505 SG_LOG(SG_NETWORK, SG_WARN, "RTI: Could not get object class: " << e._name << " " << e._reason);