#pragma warning(disable: 4251)
#pragma warning(disable: 4786)
#pragma warning(disable: 4290)
#ifdef WIN32
#include <winsock2.h>
#include <process.h>
#else
#include <unistd.h>
#endif
#include <stdio.h>
#include <wchar.h>
#include <sstream>
#include <string>
#include <iostream>
#include <sstream>
#include <cstring>
#include <cstdlib>
using namespace rti1516e;
using namespace std;
bool myRequestAttributeOwnershipAssumption;
bool myAttributeOwnershipAcquisitionNotification;
FederateHandle theFederateHandle;
std::wstring theClassName = L"BaseEntity";
std::wstring theInterClassName = L"WeaponFire";
ObjectClassHandle theClassHandle;
InteractionClassHandle theInterClassHandle;
ObjectInstanceHandle theObjectHandle;
{
wcout << L"Connect to RTI" << endl;
try
{
rtiAmb.connect(fedAmb, HLA_EVOKED, localDesignator);
}
catch(rti1516e::Exception& ex)
{
wcout << L"RTI Exception: "
<< ex.what().c_str() << endl;
return false;
}
wcout << L"Connected." << endl;
return true;
}
{
try
{
int count = 0;
theAmbData.myListFederationsReturned = false;
rtiAmb.listFederationExecutions();
while (count < 100 && !theAmbData.myListFederationsReturned)
{
count++;
}
if (!theAmbData.myListFederationsReturned)
{
wcout << L"Failed to get reportFederationExecutions callback\n";
}
}
catch(rti1516e::RTIinternalError& ex)
{
}
catch(rti1516e::Exception& ex)
{
wcout << L"RTI Exception: "
<< ex.what().c_str() << endl
<< L"Could not create Federation Execution: " << endl;
exit(0);
}
}
std::wstring const& fedName,
std::wstring const& fedFile)
{
wcout << L"createFederationExecution "
<< fedName.c_str() << L" "
<< fedFile.c_str() << endl;
try
{
}
catch(FederationExecutionAlreadyExists& ex)
{
wcout << L"Could not create Federation Execution: "
<< L"FederationExecutionAlreadyExists: "
<< ex.what().c_str() << endl;
}
catch(rti1516e::Exception& ex)
{
wcout << L"RTI Exception: "
<< ex.what().c_str() << endl
<< L"Could not create Federation Execution: " << endl;
exit(0);
}
wcout << L"Federation Created." << endl;
}
void joinFedEx(
std::wstring const& federationName)
{
bool joined=false;
const int maxTry = 10;
int numTries = 0;
wcout << L"joinFederationExecution "
<< federateType.c_str() << L" "
<< federationName.c_str() << endl;
while (!joined && numTries++ < maxTry)
{
try
{
joined = true;
}
catch(FederationExecutionDoesNotExist)
{
wcout << L"FederationExecutionDoesNotExist, try "
<< numTries << L" out of "
<< maxTry << endl;
continue;
}
catch(rti1516e::Exception& ex)
{
wcout << L"RTI Exception: "
<< ex.what().c_str() << endl;
return;
}
}
if (joined)
{
wcout << L"Joined Federation." << endl;
}
else
{
wcout << L"Giving up." << endl;
exit(0);
}
}
std::wstring const& federationName)
{
wcout << L"Resign and Destroy Federation" << endl;
rtiAmb.disconnect();
}
{
wcout << L"Query save status\n";
int count = 0;
while ( count++ < 100
&& !theAmbData.myReceivedFederationSaveStatusResponse )
{
}
if ( !theAmbData.myReceivedFederationSaveStatusResponse )
{
wcout << L"Timed out waiting for status response\n";
}
else
{
FederateHandleSaveStatusPairVector::const_iterator statusIter = theAmbData.myFederateHandleSaveStatus.begin();
FederateHandleSaveStatusPairVector::const_iterator statusEnd = theAmbData.myFederateHandleSaveStatus.end();
for ( ; statusIter != statusEnd; ++statusIter )
{
wcout << L"Status federate " << statusIter->first.toString().c_str() << L" is ";
switch (statusIter->second)
{
wcout << L"NO_SAVE_IN_PROGRESS\n";
break;
wcout << L"FEDERATE_INSTRUCTED_TO_SAVE\n";
break;
wcout << L"FEDERATE_SAVING\n";
break;
wcout << L"FEDERATE_WAITING_FOR_FEDERATION_TO_SAVE\n";
break;
default:
wcout << L"UNKNOWN\n";
break;
}
}
}
}
bool requestFederationSave(
RTIambassador & rtiAmb, std::wstring
const& label)
{
bool saveOk = true;
int count = 0;
theAmbData.myReceivedInitiateFederateSave =
theAmbData.myReceivedFederationSaved =
theAmbData.myReceivedFederationNotSaved =
theAmbData.myReceivedFederationSaveStatusResponse = false;
wcout << L"Request federation save with label " << label.c_str() << endl;
while (count++ < 100
&& !theAmbData.myReceivedInitiateFederateSave
&& !theAmbData.myReceivedFederationNotSaved)
{
}
if ( !theAmbData.myReceivedInitiateFederateSave )
{
saveOk = false;
if ( !theAmbData.myReceivedFederationNotSaved )
{
wcout << L"Timed out waiting for initiate federate save\n";
queryFederationSaveStatus(rtiAmb);
}
}
return saveOk;
}
{
bool saveOk = true;
int count = 0;
while ( count++ < 100
&& !theAmbData.myReceivedFederationNotSaved
&& !theAmbData.myReceivedFederationSaved )
{
}
if ( !theAmbData.myReceivedFederationSaved )
{
saveOk = false;
if ( !theAmbData.myReceivedFederationNotSaved )
{
wcout << L"Timed out waiting for federation saved\n";
queryFederationSaveStatus(rtiAmb);
}
}
return saveOk;
}
bool saveFederation(
RTIambassador & rtiAmb, std::wstring
const& label,
bool performRequest)
{
bool saveOk = true;
int count = 0;
try
{
if ( performRequest )
{
saveOk = requestFederationSave(rtiAmb, label);
}
if ( theAmbData.myReceivedInitiateFederateSave )
{
wcout << L"Federate save begun\n";
wcout << L"Federate save complete\n";
saveOk = waitForFederationSaved(rtiAmb);
}
}
catch (rti1516e::Exception& ex)
{
wcout << L"RTI Exception: " << ex.what().c_str() << endl;
wcout << L"Could not save federation " << label.c_str() << endl;
saveOk = false;
}
catch(exception& stdEx)
{
wcout << L"Standard exception: " << stdEx.what() << endl;
wcout << L"Could not save federation " << label.c_str() << endl;
saveOk = false;
}
catch(...)
{
wcout << L"Unknown exception\n";
wcout << L"Could not save federation " << label.c_str() << endl;
saveOk = false;
}
theAmbData.myReceivedInitiateFederateSave =
theAmbData.myReceivedFederationSaved =
theAmbData.myReceivedFederationNotSaved =
theAmbData.myReceivedFederationSaveStatusResponse = false;
return saveOk;
}
{
int count = 0;
while ( count++ < 100
&& !theAmbData.myReceivedFederationRestoreStatusResponse )
{
}
if ( !theAmbData.myReceivedFederationRestoreStatusResponse )
{
wcout << L"Timed out waiting for restore status\n";
}
else
{
FederateRestoreStatusVector::const_iterator statusIter = theAmbData.myFederateHandleRestoreStatus.begin();
FederateRestoreStatusVector::const_iterator statusEnd = theAmbData.myFederateHandleRestoreStatus.end();
for ( ; statusIter != statusEnd; ++statusIter )
{
wcout << L"Status federate " << statusIter->postRestoreHandle.toString() << L" is ";
switch (statusIter->status)
{
wcout << L"NO_RESTORE_IN_PROGRESS\n";
break;
wcout << L"FEDERATE_RESTORE_REQUEST_PENDING\n";
break;
wcout << L"FEDERATE_WAITING_FOR_RESTORE_TO_BEGIN\n";
break;
wcout << L"FEDERATE_PREPARED_TO_RESTORE\n";
break;
wcout << L"FEDERATE_RESTORING\n";
break;
wcout << L"FEDERATE_WAITING_FOR_FEDERATION_TO_RESTORE\n";
break;
default:
wcout << L"UNKNOWN\n";
break;
}
}
}
}
bool requestFederationRestore(
RTIambassador & rtiAmb, std::wstring
const& label)
{
int count = 0;
bool restoreOk = true;
wcout << L"Request federation restore with label " << label.c_str() << endl;
theAmbData.myReceivedRequestFederationRestoreSucceeded =
theAmbData.myReceivedRequestFederationRestoreFailed =
theAmbData.myReceivedFederationRestoreBegun =
theAmbData.myReceivedInitiateFederateRestore =
theAmbData.myReceivedFederationRestored =
theAmbData.myReceivedFederationNotRestored =
theAmbData.myReceivedFederationRestoreStatusResponse = false;
theAmbData.myFederateHandleRestoreStatus.clear();
while (count++ < 100
&& !theAmbData.myReceivedRequestFederationRestoreSucceeded
&& !theAmbData.myReceivedRequestFederationRestoreFailed)
{
}
if ( !theAmbData.myReceivedRequestFederationRestoreSucceeded )
{
restoreOk = false;
if ( !theAmbData.myReceivedRequestFederationRestoreFailed )
{
wcout << L"Timed out waiting for request federation restore succeeded.\n";
queryRestoreStatus(rtiAmb);
}
}
return restoreOk;
}
{
bool restoreOk = true;
wcout << L"Wait for restore begun\n";
int count = 0;
while (count++ < 100
&& !theAmbData.myReceivedFederationRestoreBegun
&& !theAmbData.myReceivedFederationNotRestored)
{
}
if ( !theAmbData.myReceivedFederationRestoreBegun )
{
restoreOk = false;
if (!theAmbData.myReceivedFederationNotRestored)
{
wcout << L"Timed out waiting for federation restore begun.\n";
queryRestoreStatus(rtiAmb);
}
}
return restoreOk;
}
{
bool restoreOk = true;
wcout << L"Wait for initiate restore\n";
int count = 0;
while (count++ < 100
&& !theAmbData.myReceivedInitiateFederateRestore
&& !theAmbData.myReceivedFederationNotRestored)
{
}
if ( theAmbData.myReceivedFederationNotRestored )
{
restoreOk = false;
}
else if ( !theAmbData.myReceivedInitiateFederateRestore )
{
restoreOk = false;
wcout << L"Timed out waiting for initiate federate restore.\n";
queryRestoreStatus(rtiAmb);
}
else if ( theAmbData.myRestoreFederateHandle != theFederateHandle )
{
wcout << L"Restore initiated with handle " << theAmbData.myRestoreFederateHandle.toString().c_str()
<< L" does not match current handle " << theFederateHandle.toString().c_str() << endl;
wcout << L"Unable to complete restore\n";
restoreOk = false;
count = 0;
while ( count++ < 100
&& !theAmbData.myReceivedFederationNotRestored )
{
}
if ( !theAmbData.myReceivedFederationNotRestored )
{
wcout << L"Timed out waiting for federation not restored.\n";
queryRestoreStatus(rtiAmb);
}
}
return restoreOk;
}
{
bool restoreOk = true;
wcout << L"Wait for federation restored\n";
int count = 0;
while ( count++ < 100
&& !theAmbData.myReceivedFederationRestored
&& !theAmbData.myReceivedFederationNotRestored )
{
}
if ( !theAmbData.myReceivedFederationRestored )
{
restoreOk = false;
if ( !theAmbData.myReceivedFederationNotRestored )
{
wcout << L"Timed out waiting for federation restored.\n";
queryRestoreStatus(rtiAmb);
}
}
return restoreOk;
}
bool restoreFederation(
RTIambassador & rtiAmb, std::wstring
const& label,
bool performRequest)
{
bool restoreOk = true;
int count = 0;
theAmbData.myReceivedFederationNotRestored = false;
try
{
if ( performRequest )
{
if ( requestFederationRestore(rtiAmb, label) )
{
restoreOk = waitForRestoreBegun(rtiAmb);
}
}
if ( theAmbData.myReceivedFederationRestoreBegun )
{
if ( restoreOk = waitForInitiateRestore(rtiAmb) )
{
wcout << L"Federate restore complete\n";
restoreOk = waitForFederationRestored(rtiAmb);
}
}
}
catch (rti1516e::FederateInternalError& ex)
{
wcout << L"RTI Exception: " << ex.what().c_str() << endl;
wcout << L"Could not restore federation " << label.c_str() << endl;
restoreOk = false;
}
catch (rti1516e::Exception& ex)
{
wcout << L"RTI Exception: " << ex.what().c_str() << endl;
wcout << L"Could not restore federation " << label.c_str() << endl;
restoreOk = false;
}
catch(exception& stdEx)
{
wcout << L"Standard exception: " << stdEx.what() << endl;
wcout << L"Could not restore federation " << label.c_str() << endl;
restoreOk = false;
}
catch(...)
{
wcout << L"Unknown exception\n";
wcout << L"Could not restore federation " << label.c_str() << endl;
restoreOk = false;
}
theAmbData.myReceivedRequestFederationRestoreSucceeded =
theAmbData.myReceivedRequestFederationRestoreFailed =
theAmbData.myReceivedFederationRestoreBegun =
theAmbData.myReceivedInitiateFederateRestore =
theAmbData.myReceivedFederationRestored =
theAmbData.myReceivedFederationNotRestored =
theAmbData.myReceivedFederationRestoreStatusResponse = false;
theAmbData.myFederateHandleRestoreStatus.clear();
return restoreOk;
}
{
try
{
theAmbData.objectClassMap[theClassHandle] = theClassName;
}
catch (rti1516e::Exception& ex)
{
wcout << L"RTI Exception: "
<< ex.what().c_str() << endl;
wcout << L"Could not get object class handle: "
<< theClassName.c_str() << endl;
return false;
}
std::wstring attrName;
try
{
attrName = L"AccelerationVector";
theAttrNameHandleMap[attrName] =
hSet.insert(theAttrNameHandleMap[attrName]);
attrName = L"VelocityVector";
theAttrNameHandleMap[attrName] =
hSet.insert(theAttrNameHandleMap[attrName]);
attrName = L"Orientation";
theAttrNameHandleMap[attrName] =
hSet.insert(theAttrNameHandleMap[attrName]);
attrName = L"DeadReckoningAlgorithm";
theAttrNameHandleMap[attrName] =
hSet.insert(theAttrNameHandleMap[attrName]);
attrName = L"WorldLocation";
theAttrNameHandleMap[attrName] =
hSet.insert(theAttrNameHandleMap[attrName]);
}
catch (rti1516e::Exception& ex)
{
wcout << L"RTI Exception: "
<< ex.what().c_str() << endl;
wcout << L"Could not get attribute handle "
<< attrName.c_str() << endl;
return false;
}
int cnt=0;
try
{
cnt=1;
}
catch (rti1516e::Exception& ex)
{
wcout << L"RTI Exception: "
<< ex.what().c_str() << endl;
wcout << L"Could not "
<< (cnt ? L"subscribe" : L"publish") << endl;
return false;
}
std::wstring objectName(L"Talk");
try
{
unsigned int objId = abs(getpid());
std::wstringstream pid;
pid << objId;
objectName += pid.str();
theAmbData.myNameReservationReturned =
theAmbData.myNameReservationSucceeded = false;
try
{
}
catch (rti1516e::RTIinternalError& ex)
{
}
int count = 0;
while (count++ < 100 && !theAmbData.myNameReservationReturned)
{
}
if (count < 100)
{
objectName);
theAmbData.objectInstanceMap[theObjectHandle] =
}
else
{
wcout << L"Failed waiting for reserve object name "
<< objectName.c_str() << endl;
return false;
}
}
catch (rti1516e::Exception& ex)
{
wcout << L"RTI Exception: "
<< ex.what().c_str() << endl;
wcout << L"Could not Register Object "
<< objectName.c_str()
<< L" with class "
<< theClassName.c_str() << endl;
return false;
}
wcout << L"Registered object "
<< objectName.c_str()
<< L" with class name "
<< theClassName.c_str() << endl;
return true;
}
{
try
{
theAmbData.interactionClassMap[theInterClassHandle] = theInterClassName;
}
catch (rti1516e::Exception& ex)
{
wcout << L"RTI Exception: "
<< ex.what().c_str() << endl;
wcout << L"Could not get interaction class handle: "
<< theInterClassName.c_str() << endl;
return false;
}
std::wstring paramName;
try
{
paramName = L"EventIdentifier";
theParamNameHandleMap[paramName] =
paramName = L"FireControlSolutionRange";
theParamNameHandleMap[paramName] =
paramName = L"FireMissionIndex";
theParamNameHandleMap[paramName] =
paramName = L"FiringLocation";
theParamNameHandleMap[paramName] =
paramName = L"FiringObjectIdentifier";
theParamNameHandleMap[paramName] =
paramName = L"FuseType";
theParamNameHandleMap[paramName] =
paramName = L"InitialVelocityVector";
theParamNameHandleMap[paramName] =
paramName = L"MunitionObjectIdentifier";
theParamNameHandleMap[paramName] =
paramName = L"MunitionType";
theParamNameHandleMap[paramName] =
paramName = L"QuantityFired";
theParamNameHandleMap[paramName] =
paramName = L"RateOfFire";
theParamNameHandleMap[paramName] =
paramName = L"TargetObjectIdentifier";
theParamNameHandleMap[paramName] =
paramName = L"WarheadType";
theParamNameHandleMap[paramName] =
}
catch (rti1516e::Exception& ex)
{
wcout << L"RTI Exception: "
<< ex.what().c_str() << endl;
wcout << L"Could not get parameter handle "
<< paramName.c_str() << endl;
return false;
}
int cnt=0;
try
{
cnt=1;
}
catch (rti1516e::Exception& ex)
{
wcout << L"RTI Exception: "
<< ex.what().c_str() << endl;
wcout << L"Could not "
<< (cnt ? L"publish" : L"subscribe")
<< L" to interaction class." << endl;
return false;
}
wcout << L"Subscribed to interaction class: "
<< theInterClassName.c_str()
<< L" with handle: "
<< theInterClassHandle.toString() << endl;
return true;
}
int main(int argc, char** argv)
{
std::cout << "MAK rtiSimple version 1516e" << std::endl;
try
{
std::wstring federationName(L"MAKsimple");
std::wstring federationFile(L"MAKsimple1516e.xml");
std::wstring federateType(L"rtisimple1516e");
std::wstring localSettingsDesignator;
if (argc > 1)
{
if (strcmp(argv[1], "-h") == 0)
{
wcout << L"Usage: rtisimple1516e [federationName] [federationFile] [federateType]" << endl;
wcout << L"default values: "
<< L"\"" << federationName.c_str() << L"\" "
<< L"\"" << federationFile.c_str() << L"\" "
<< L"\"" << federateType.c_str() << L"\" " << endl;
return 0;
}
}
if (argc > 2)
{
}
if (argc > 3)
{
}
if (argc > 4)
{
for (int argIndex = 4; argIndex < argc; ++argIndex)
{
localSettingsDesignator += L" ";
localSettingsDesignator +=
DtToWString(argv[argIndex]);
}
}
wcout << L"Using " << rtiName().c_str() << L" " << rtiVersion().c_str() << L"\n";
theAmbData.myNameReservationReturned =
theAmbData.myNameReservationSucceeded =
theAmbData.myReceivedInitiateFederateSave =
theAmbData.myReceivedFederationSaved =
theAmbData.myReceivedFederationNotSaved =
theAmbData.myReceivedFederationSaveStatusResponse =
theAmbData.myReceivedRequestFederationRestoreSucceeded =
theAmbData.myReceivedRequestFederationRestoreFailed =
theAmbData.myReceivedFederationRestoreBegun =
theAmbData.myReceivedInitiateFederateRestore =
theAmbData.myReceivedFederationRestored =
theAmbData.myReceivedFederationNotRestored =
theAmbData.myReceivedFederationRestoreStatusResponse = false;
std::auto_ptr < RTIambassador > rtiAmbAP =
rtiAmb = rtiAmbAP.release();
#ifdef WIN32
WSADATA data;
WSAStartup(MAKEWORD(1,1), &data);
#endif
long count=0;
bool doConnect = true;
bool connected = false;
while (1)
{
if (doConnect)
{
doConnect = false;
if (!connect(*rtiAmb, fedAmb, localSettingsDesignator))
{
wcout << L"Connect to RTI failed!" << endl;
continue;
}
listFederations(*rtiAmb);
createFedEx(*rtiAmb, federationName, federationFile);
joinFedEx(*rtiAmb, federateType, federationName);
if (!publishSubscribeAndRegisterObject(*rtiAmb))
{
resignAndDestroy(*rtiAmb, federationName);
if (rtiAmb != 0)
{
delete rtiAmb;
rtiAmb = 0;
}
return 0;
}
if (!publishAndSubscribeInteraction(*rtiAmb))
{
resignAndDestroy(*rtiAmb, federationName);
if (rtiAmb != 0)
{
delete rtiAmb;
rtiAmb = 0;
}
return 0;
}
attrValues.clear();
for (DtAttrNameHandleMap::iterator iter = theAttrNameHandleMap.begin();
iter != theAttrNameHandleMap.end();
iter++)
{
attrValues[iter->second].setData(temp.c_str(), temp.length()+1);
}
paramValues.clear();
for (DtParamNameHandleMap::iterator iter2 = theParamNameHandleMap.begin();
iter2 != theParamNameHandleMap.end();
iter2++)
{
paramValues[iter2->second].setData(temp.c_str(), temp.length()+1);
}
connected = true;
}
else if (connected)
{
std::stringstream ss;
ss << "1516-" << count++;
std::string tag(ss.str());
theObjectHandle,
attrValues,
if ( count % 5 == 0 )
{
wcout << L"Sending interaction..." << endl;
theInterClassHandle,
paramValues,
}
if ( theAmbData.myReceivedInitiateFederateSave )
{
if ( !saveFederation(*rtiAmb, theAmbData.mySaveLabel, false) )
{
break;
}
}
if ( theAmbData.myReceivedFederationRestoreBegun )
{
if ( !restoreFederation(*rtiAmb, theAmbData.myRestoreLabel, false) )
{
break;
}
}
}
if (key < 0)
{
break;
}
else if ('c' == key || 'C' == key )
{
doConnect = !connected;
}
else if ('d' == key || 'D' == key )
{
if (connected)
{
try
{
resignAndDestroy(*rtiAmb, federationName);
connected = false;
}
catch(rti1516e::Exception& ex)
{
wcout << L"RTI Exception: "
<< ex.what().c_str() << endl;
}
}
}
else if ('s' == key || 'S' == key )
{
if (connected)
{
const wstring saveLabel(L"rtiSimpleSave");
if ( !saveFederation(*rtiAmb, saveLabel, true) )
{
break;
}
}
}
else if ('r' == key || 'R' == key )
{
if (connected)
{
const wstring savedLabel(L"rtiSimpleSave");
if ( !restoreFederation(*rtiAmb, savedLabel, true) )
{
break;
}
}
}
#ifdef WIN32
Sleep(2000);
#else
sleep(2);
#endif
}
if (connected)
{
resignAndDestroy(*rtiAmb, federationName);
}
}
catch (rti1516e::Exception& ex)
{
wcout << L"RTI Exception (main loop): "
<< ex.what().c_str() << endl;
}
if (rtiAmb != 0)
{
delete rtiAmb;
rtiAmb = 0;
}
#ifdef WIN32
WSACleanup();
#endif
return 0;
}
#pragma warning(disable: 4251)
#pragma warning(disable: 4786)
#pragma warning(disable: 4290)
#include <iostream>
using namespace std;
{
AttributeHandleValueMap::const_iterator iter;
for (iter = attrVals.begin(); iter != attrVals.end(); iter++)
{
wcout << iter->first.toString().c_str() << L" "
<<
DtToWString((
char*)iter->second.data()).c_str() << endl;
}
}
{
ParameterHandleValueMap::const_iterator iter;
for (iter = paramVals.begin(); iter != paramVals.end(); iter++)
{
wcout << iter->first.toString().c_str() << L" "
<<
DtToWString((
char*)iter->second.data()).c_str() << endl;
}
}
throw () {}
FederationExecutionInformationVector const &
theFederationExecutionInformationList)
throw (
FederateInternalError)
{
myData.myListFederationsReturned = true;
wcout << L"reportFederationExecutions \n";
FederationExecutionInformationVector::const_iterator fedIter = theFederationExecutionInformationList.begin();
FederationExecutionInformationVector::const_iterator fedEnd = theFederationExecutionInformationList.end();
for ( ; fedIter != fedEnd; ++fedIter)
{
wcout << fedIter->federationExecutionName << L" " << fedIter->logicalTimeImplementationName
<< std::endl;
}
}
throw (FederateInternalError)
{
wcout << L"initiateFederateSave: " << label.c_str() << endl;
myData.myReceivedInitiateFederateSave = true;
myData.mySaveLabel = label;
}
{
wcout << L"federationSaved " << endl;
myData.myReceivedFederationSaved = true;
}
throw (FederateInternalError)
{
wcout << L"federationNotSaved: ";
switch (theSaveFailureReason)
{
wcout << L"RTI_UNABLE_TO_SAVE\n";
break;
wcout << L"FEDERATE_REPORTED_FAILURE_DURING_SAVE\n";
break;
wcout << L"FEDERATE_RESIGNED_DURING_SAVE\n";
break;
wcout << L"RTI_DETECTED_FAILURE_DURING_SAVE\n";
break;
wcout << L"SAVE_TIME_CANNOT_BE_HONORED\n";
break;
case SAVE_ABORTED:
wcout << L"SAVE_ABORTED\n";
break;
default:
wcout << L"UNKNOWN\n";
break;
}
myData.mySaveFailureReason = theSaveFailureReason;
myData.myReceivedFederationNotSaved = true;
}
throw (FederateInternalError)
{
wcout << L"federationSaveStatusResponse" << endl;
myData.myReceivedFederationSaveStatusResponse = true;
myData.myFederateHandleSaveStatus = theFederateStatusVector;
}
throw (FederateInternalError)
{
wcout << L"requestFederationRestoreSucceeded " << label.c_str() << endl;
myData.myReceivedRequestFederationRestoreSucceeded = true;
myData.myRestoreLabel = label;
}
throw (FederateInternalError)
{
wcout << L"requestFederationRestoreFailed " << label.c_str() << endl;
myData.myReceivedRequestFederationRestoreFailed = true;
myData.myRestoreLabel = label;
}
throw (FederateInternalError)
{
wcout << L"federationRestoreBegun" << endl;
myData.myReceivedFederationRestoreBegun = true;
}
std::wstring const & label,
std::wstring const & federateName,
FederateHandle handle)
throw (FederateInternalError)
{
wcout << L"initiateFederateRestore " << label.c_str()
<< L" " << federateName << L" " << handle.toString().c_str() << endl;
myData.myReceivedInitiateFederateRestore = true;
myData.myRestoreLabel = label;
myData.myRestoreFederateHandle = handle;
}
throw (FederateInternalError)
{
wcout << L"federationRestored" << endl;
myData.myReceivedFederationRestored = true;
}
throw (FederateInternalError)
{
wcout << L"federationNotRestored: ";
switch (theRestoreFailureReason)
{
wcout << L"RTI_UNABLE_TO_RESTORE\n";
break;
wcout << L"FEDERATE_REPORTED_FAILURE_DURING_RESTORE\n";
break;
wcout << L"FEDERATE_RESIGNED_DURING_RESTORE\n";
break;
wcout << L"RTI_DETECTED_FAILURE_DURING_RESTORE\n";
break;
case RESTORE_ABORTED:
wcout << L"RESTORE_ABORTED\n";
break;
default:
wcout << L"Unknown reason\n";
break;
}
myData.myReceivedFederationNotRestored = true;
myData.myRestoreFailureReason = theRestoreFailureReason;
}
FederateRestoreStatusVector const& theFederateRestoreStatusVector)
throw (FederateInternalError)
{
wcout << L"federationRestoreStatusResponse" << endl;
myData.myReceivedFederationRestoreStatusResponse = true;
myData.myFederateHandleRestoreStatus = theFederateRestoreStatusVector;
}
std::wstring const & theObjectInstanceName)
throw (FederateInternalError)
{
wcout << L"objectInstanceNameReservationSucceeded: "
<< theObjectInstanceName.c_str() << endl;
myData.myNameReservationReturned =
myData.myNameReservationSucceeded = true;
}
std::wstring const & theObjectInstanceName)
throw (FederateInternalError)
{
wcout << L"objectInstanceNameReservationFailed: "
<< theObjectInstanceName.c_str() << endl;
myData.myNameReservationReturned = true;
myData.myNameReservationSucceeded = false;
}
std::set<std::wstring> const & theObjectInstanceNames)
throw (
FederateInternalError)
{
wcout << L"multipleObjectInstanceNameReservationSucceeded: "
<< theObjectInstanceNames.size() << endl;
myData.myNameReservationReturned =
myData.myNameReservationSucceeded = true;
}
std::set<std::wstring> const & theObjectInstanceNames)
throw (
FederateInternalError)
{
wcout << L"multipleObjectInstanceNameReservationFailed: "
<< theObjectInstanceNames.size() << endl;
myData.myNameReservationReturned = true;
myData.myNameReservationSucceeded = false;
}
ObjectInstanceHandle theObject,
ObjectClassHandle theObjectClass,
std::wstring const & theObjectInstanceName)
throw (FederateInternalError)
{
wcout << L"discoverObjectInstance: "
<< theObjectInstanceName.c_str() << L"("
<< theObject.toString().c_str() << L") of class "
<< myData.objectClassMap[theObjectClass].c_str() << L"( "
<< theObjectClass.toString().c_str() << L")" << endl;
myData.objectInstanceMap[theObject] = theObjectInstanceName;
}
ObjectInstanceHandle theObject,
ObjectClassHandle theObjectClass,
std::wstring const & theObjectInstanceName,
FederateHandle producingFederate)
throw (FederateInternalError)
{
wcout << L"discoverObjectInstance: "
<< theObjectInstanceName.c_str() << L"("
<< theObject.toString().c_str() << L") of class "
<< myData.objectClassMap[theObjectClass].c_str() << L"( "
<< theObjectClass.toString().c_str() << L")"
<< L" produced by " << producingFederate.toString().c_str()
<< endl;
myData.objectInstanceMap[theObject] = theObjectInstanceName;
}
ObjectInstanceHandle theObject,
SupplementalReflectInfo theReflectInfo)
throw (FederateInternalError)
{
const char* tag = theUserSuppliedTag.size()
? (const char*)theUserSuppliedTag.data() : "";
wcout << L"reflectAttributeValues: "
<< myData.objectInstanceMap[theObject].c_str() << L"("
<< theObject.toString().c_str() << L") "
<< (sentOrder ==
RECEIVE ? L
"RECEIVE " : L
"TIMESTAMP ")
<< (theType ==
RELIABLE ? L
"RELIABLE " : L
"BEST_EFFORT ")
<< (theReflectInfo.hasProducingFederate ? L"produced by " : L" ")
<< (theReflectInfo.hasProducingFederate ? theReflectInfo.producingFederate.toString() : L"")
<< L"#regions: " << (theReflectInfo.hasSentRegions ? theReflectInfo.sentRegions.size() : 0)
<< L" #attributes: " << theAttributeValues.size() << endl;
printAttrValues(theAttributeValues);
}
ObjectInstanceHandle theObject,
LogicalTime const & theTime,
SupplementalReflectInfo theReflectInfo)
throw (FederateInternalError)
{
const char* tag = theUserSuppliedTag.size()
? (const char*)theUserSuppliedTag.data() : "";
wcout << L"reflectAttributeValues: "
<< myData.objectInstanceMap[theObject].c_str() << L"("
<< theObject.toString().c_str() << L") "
<< (sentOrder ==
RECEIVE ? L
"RECEIVE " : L
"TIMESTAMP ")
<< (theType ==
RELIABLE ? L
"RELIABLE " : L
"BEST_EFFORT ")
<< theTime.toString().c_str() << L" "
<< (receivedOrder ==
RECEIVE ? L
"RECEIVE " : L
"TIMESTAMP ")
<< (theReflectInfo.hasProducingFederate ? L"produced by " : L" ")
<< (theReflectInfo.hasProducingFederate ? theReflectInfo.producingFederate.toString() : L"")
<< L"#regions: " << (theReflectInfo.hasSentRegions ? theReflectInfo.sentRegions.size() : 0)
<< L" #attributes: " << theAttributeValues.size() << endl;
printAttrValues(theAttributeValues);
}
ObjectInstanceHandle theObject,
LogicalTime const & theTime,
MessageRetractionHandle theHandle,
SupplementalReflectInfo theReflectInfo)
throw (FederateInternalError)
{
const char* tag = theUserSuppliedTag.size()
? (const char*)theUserSuppliedTag.data() : "";
wcout << L"reflectAttributeValues: "
<< myData.objectInstanceMap[theObject].c_str() << L"("
<< theObject.toString().c_str() << L") "
<< (sentOrder ==
RECEIVE ? L
"RECEIVE " : L
"TIMESTAMP ")
<< (theType ==
RELIABLE ? L
"RELIABLE " : L
"BEST_EFFORT ")
<< theTime.toString().c_str() << L" "
<< (receivedOrder ==
RECEIVE ? L
"RECEIVE " : L
"TIMESTAMP ")
<< theHandle.toString().c_str() << L" "
<< (theReflectInfo.hasProducingFederate ? L"produced by " : L" ")
<< (theReflectInfo.hasProducingFederate ? theReflectInfo.producingFederate.toString() : L"")
<< L"#regions: " << (theReflectInfo.hasSentRegions ? theReflectInfo.sentRegions.size() : 0)
<< L" #attributes: " << theAttributeValues.size() << endl;
printAttrValues(theAttributeValues);
}
InteractionClassHandle theInteraction,
SupplementalReceiveInfo theReceiveInfo)
throw (FederateInternalError)
{
const char* tag = theUserSuppliedTag.size() ?
(const char*)theUserSuppliedTag.data() : "";
wcout << L"receiveInteraction: "
<< theInteraction.toString() << L" "
<< (sentOrder ==
RECEIVE ? L
"RECEIVE " : L
"TIMESTAMP ")
<< (theType ==
RELIABLE ? L
"RELIABLE " : L
"BEST_EFFORT ")
<< (theReceiveInfo.hasProducingFederate ? L"produced by " : L" ")
<< (theReceiveInfo.hasProducingFederate ? theReceiveInfo.producingFederate.toString() : L"")
<< L"#regions: " << (theReceiveInfo.hasSentRegions ? theReceiveInfo.sentRegions.size() : 0)
<< L" #parameters: " << theParameterValues.size() << endl;
printParamValues(theParameterValues);
}
InteractionClassHandle theInteraction,
LogicalTime const & theTime,
SupplementalReceiveInfo theReceiveInfo)
throw (FederateInternalError)
{
const char* tag = theUserSuppliedTag.size() ?
(const char*)theUserSuppliedTag.data() : "";
wcout << L"receiveInteraction: "
<< theInteraction.toString() << L" "
<< (sentOrder ==
RECEIVE ? L
"RECEIVE " : L
"TIMESTAMP ")
<< (theType ==
RELIABLE ? L
"RELIABLE " : L
"BEST_EFFORT ")
<< theTime.toString() << L" "
<< (receivedOrder ==
RECEIVE ? L
"RECEIVE " : L
"TIMESTAMP ")
<< (theReceiveInfo.hasProducingFederate ? L"produced by " : L" ")
<< (theReceiveInfo.hasProducingFederate ? theReceiveInfo.producingFederate.toString() : L"")
<< L"#regions: " << (theReceiveInfo.hasSentRegions ? theReceiveInfo.sentRegions.size() : 0)
<< L" #parameters: " << theParameterValues.size() << endl;
printParamValues(theParameterValues);
}
InteractionClassHandle theInteraction,
LogicalTime const & theTime,
MessageRetractionHandle theHandle,
SupplementalReceiveInfo theReceiveInfo)
throw (FederateInternalError)
{
const char* tag = theUserSuppliedTag.size() ?
(const char*)theUserSuppliedTag.data() : "";
wcout << L"receiveInteraction: "
<< theInteraction.toString() << L" "
<< (sentOrder ==
RECEIVE ? L
"RECEIVE " : L
"TIMESTAMP ")
<< (theType ==
RELIABLE ? L
"RELIABLE " : L
"BEST_EFFORT ")
<< theTime.toString() << L" "
<< (receivedOrder ==
RECEIVE ? L
"RECEIVE " : L
"TIMESTAMP ")
<< theHandle.toString().c_str() << L" "
<< (theReceiveInfo.hasProducingFederate ? L"produced by " : L" ")
<< (theReceiveInfo.hasProducingFederate ? theReceiveInfo.producingFederate.toString() : L"")
<< L"#regions: " << (theReceiveInfo.hasSentRegions ? theReceiveInfo.sentRegions.size() : 0)
<< L" #parameters: " << theParameterValues.size() << endl;
printParamValues(theParameterValues);
}
ObjectInstanceHandle theObject,
SupplementalRemoveInfo theRemoveInfo)
throw (FederateInternalError)
{
const char* tag = theUserSuppliedTag.size()
? (const char*)theUserSuppliedTag.data() : "";
wcout << L"removeObjectInstance: "
<< myData.objectInstanceMap[theObject].c_str() << L"("
<< theObject.toString().c_str() << L") "
<< (sentOrder ==
RECEIVE ? L
"RECEIVE " : L
"TIMESTAMP ")
<< (theRemoveInfo.hasProducingFederate ? L"produced by " : L" ")
<< (theRemoveInfo.hasProducingFederate ? theRemoveInfo.producingFederate.toString() : L"")
<< endl;
}
ObjectInstanceHandle theObject,
LogicalTime const & theTime,
SupplementalRemoveInfo theRemoveInfo)
throw (FederateInternalError)
{
const char* tag = theUserSuppliedTag.size()
? (const char*)theUserSuppliedTag.data() : "";
wcout << L"removeObjectInstance: "
<< myData.objectInstanceMap[theObject].c_str() << L"("
<< theObject.toString().c_str() << L") "
<< (sentOrder ==
RECEIVE ? L
"RECEIVE " : L
"TIMESTAMP ")
<< theTime.toString().c_str() << L" "
<< (receivedOrder ==
RECEIVE ? L
"RECEIVE " : L
"TIMESTAMP ")
<< (theRemoveInfo.hasProducingFederate ? L"produced by " : L" ")
<< (theRemoveInfo.hasProducingFederate ? theRemoveInfo.producingFederate.toString() : L"")
<< endl;
}
ObjectInstanceHandle theObject,
LogicalTime const & theTime,
MessageRetractionHandle theHandle,
SupplementalRemoveInfo theRemoveInfo)
throw (FederateInternalError)
{
const char* tag = theUserSuppliedTag.size()
? (const char*)theUserSuppliedTag.data() : "";
wcout << L"removeObjectInstance: "
<< myData.objectInstanceMap[theObject].c_str() << L"("
<< theObject.toString().c_str() << L") "
<< (sentOrder ==
RECEIVE ? L
"RECEIVE " : L
"TIMESTAMP ")
<< theTime.toString().c_str() << L
" "<< (receivedOrder ==
RECEIVE ? L
"RECEIVE " : L
"TIMESTAMP ")
<< theHandle.toString().c_str()
<< (theRemoveInfo.hasProducingFederate ? L"produced by " : L" ")
<< (theRemoveInfo.hasProducingFederate ? theRemoveInfo.producingFederate.toString() : L"")
<< endl;
}
ObjectInstanceHandle theObject,
AttributeHandle theAttribute,
throw (FederateInternalError)
{
wcout << L"reportAttributeTransportationType"
<< theObject.toString().c_str() << L"( "
<< L" ) : "
<< ( theTransportation ==
BEST_EFFORT ? L
"Best Effort" : L
"Reliable" ) << endl;
}
ObjectInstanceHandle theObject,
throw (
FederateInternalError)
{
wcout << L"confimAttributeTransportationTypeChange: "
<< theObject.toString().c_str() << endl;
wcout << ( theTransportation ==
BEST_EFFORT ?
"Best Effort" :
"Reliable" ) << endl;
}
InteractionClassHandle theInteraction,
throw (
FederateInternalError)
{
wcout << L"confirmInteractionTransportationTypeChange: "
<< ( theTransportation ==
BEST_EFFORT ? L
"Best Effort" : L
"Reliable" ) << endl;
}
FederateHandle federateHandle,
InteractionClassHandle theInteraction,
throw (
FederateInternalError)
{
wcout << L"reportInteractionTransportationType: "
<< ( theTransportation ==
BEST_EFFORT ? L
"Best Effort" : L
"Reliable" ) << endl;
}
#ifndef MyFederateAmbassador_H_
#define MyFederateAmbassador_H_
#pragma warning(disable: 4251)
#pragma warning(disable: 4786)
#pragma warning(disable: 4290)
#include <string>
#include <map>
using namespace rti1516e;
{
public:
bool myListFederationsReturned;
bool myNameReservationReturned;
bool myNameReservationSucceeded;
bool myReceivedInitiateFederateSave;
bool myReceivedFederationSaved;
bool myReceivedFederationNotSaved;
bool myReceivedFederationSaveStatusResponse;
std::wstring mySaveLabel;
bool myReceivedRequestFederationRestoreSucceeded;
bool myReceivedRequestFederationRestoreFailed;
bool myReceivedFederationRestoreBegun;
bool myReceivedInitiateFederateRestore;
bool myReceivedFederationRestored;
bool myReceivedFederationNotRestored;
bool myReceivedFederationRestoreStatusResponse;
std::wstring myRestoreLabel;
FederateHandle myRestoreFederateHandle;
FederateRestoreStatusVector myFederateHandleRestoreStatus;
std::map<ObjectClassHandle, std::wstring> objectClassMap;
std::map<ObjectInstanceHandle, std::wstring> objectInstanceMap;
std::map<InteractionClassHandle, std::wstring> interactionClassMap;
};
{
public:
throw ();
virtual void reportFederationExecutions (
FederationExecutionInformationVector const &
theFederationExecutionInformationList)
throw (
FederateInternalError);
std::wstring const & label)
throw (FederateInternalError);
throw (FederateInternalError);
throw (FederateInternalError);
virtual void federationSaveStatusResponse(
throw (FederateInternalError);
throw (FederateInternalError);
throw (FederateInternalError);
throw (FederateInternalError);
std::wstring const & label,
std::wstring const & federateName,
FederateHandle handle)
throw (FederateInternalError);
throw (FederateInternalError);
throw (FederateInternalError);
virtual void federationRestoreStatusResponse(
FederateRestoreStatusVector const &
theFederateRestoreStatusVector)
throw (FederateInternalError);
virtual void objectInstanceNameReservationSucceeded(
std::wstring const & theObjectInstanceName)
throw (FederateInternalError);
virtual void objectInstanceNameReservationFailed(
std::wstring const & theObjectInstanceName)
throw (FederateInternalError);
ObjectInstanceHandle theObject,
ObjectClassHandle theObjectClass,
std::wstring const & theObjectInstanceName)
throw (FederateInternalError);
ObjectInstanceHandle theObject,
ObjectClassHandle theObjectClass,
std::wstring const & theObjectInstanceName,
FederateHandle producingFederate)
throw (FederateInternalError);
ObjectInstanceHandle theObject,
SupplementalReflectInfo theReflectInfo)
throw (FederateInternalError);
ObjectInstanceHandle theObject,
LogicalTime const & theTime,
SupplementalReflectInfo theReflectInfo)
throw (FederateInternalError);
ObjectInstanceHandle theObject,
LogicalTime const & theTime,
MessageRetractionHandle theHandle,
SupplementalReflectInfo theReflectInfo)
throw (FederateInternalError);
InteractionClassHandle theInteraction,
SupplementalReceiveInfo theReceiveInfo)
throw (FederateInternalError);
InteractionClassHandle theInteraction,
LogicalTime const & theTime,
SupplementalReceiveInfo theReceiveInfo)
throw (FederateInternalError);
InteractionClassHandle theInteraction,
LogicalTime const & theTime,
MessageRetractionHandle theHandle,
SupplementalReceiveInfo theReceiveInfo)
throw (FederateInternalError);
ObjectInstanceHandle theObject,
SupplementalRemoveInfo theRemoveInfo)
throw (FederateInternalError);
ObjectInstanceHandle theObject,
LogicalTime const & theTime,
SupplementalRemoveInfo theRemoveInfo)
throw (FederateInternalError);
ObjectInstanceHandle theObject,
LogicalTime const & theTime,
MessageRetractionHandle theHandle,
SupplementalRemoveInfo theRemoveInfo)
throw (FederateInternalError);
virtual void reportAttributeTransportationType (
ObjectInstanceHandle theObject,
AttributeHandle theAttribute,
throw (FederateInternalError);
virtual void confirmAttributeTransportationTypeChange (
ObjectInstanceHandle theObject,
throw (
FederateInternalError);
virtual void confirmInteractionTransportationTypeChange (
InteractionClassHandle theInteraction,
throw (
FederateInternalError);
virtual void reportInteractionTransportationType (
FederateHandle federateHandle,
InteractionClassHandle theInteraction,
throw (
FederateInternalError);
virtual void multipleObjectInstanceNameReservationSucceeded (
std::set<std::wstring> const & theObjectInstanceNames)
throw (
FederateInternalError);
virtual void multipleObjectInstanceNameReservationFailed (
std::set<std::wstring> const & theObjectInstanceNames)
throw (
FederateInternalError);
public:
};
#endif