#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 <cstdlib>
#include <cstring>
#include <map>
#include <string>
#include <iostream>
#include <sstream>
using namespace std;
std::string const& fedName,
std::string const& fedFile)
{
cout << "createFederationExecution "
<< fedName.c_str() << " "
<< fedFile.c_str() << endl;
try
{
}
catch(RTI::FederationExecutionAlreadyExists& ex)
{
cout << "Could not create Federation Execution: "
<< "FederationExecutionAlreadyExists: "
<< ex._name << " "
<< ex._reason << endl;
}
{
cout << "Could not create Federation Execution: " << endl
<< "RTI Exception: "
exit(0);
}
cout << "Federation Created" << endl;
}
{
bool joined=false;
const int maxTry = 10;
int numTries = 0;
cout << "joinFederationExecution "
<< federateType.c_str() << " "
<< federationName.c_str() << endl;
while (!joined && numTries++ < maxTry)
{
try
{
federationName.c_str(), fedAmb);
joined = true;
}
catch(RTI::FederationExecutionDoesNotExist)
{
cout << "FederationExecutionDoesNotExist, try "
<< numTries << "out of "
<< maxTry << endl;
continue;
}
{
cout << "RTI Exception: "
return;
}
}
if (joined)
cout << "Joined Federation." << endl;
else
{
cout << "Giving up." << endl;
exit(0);
}
}
std::string const& federationName)
{
cout << "Resign and Destroy Federation" << endl;
}
{
bool saveOk = true;
int count = 0;
cout << "Request federation save with label " << label.c_str() << endl;
while (count++ < 100
{
}
{
saveOk = false;
{
cout << "Timed out waiting for initiate federate save\n";
}
}
return saveOk;
}
{
bool saveOk = true;
int count = 0;
while ( count++ < 100
{
}
{
saveOk = false;
{
cout << "Timed out waiting for federation saved\n";
}
}
return saveOk;
}
{
bool saveOk = true;
int count = 0;
try
{
if ( performRequest )
{
}
{
cout << "Federate save begun\n";
cout << "Federate save complete\n";
}
}
{
cout << "RTI Exception: "
cout << "Could not save federation " << label.c_str() << endl;
saveOk = false;
}
catch(exception& stdEx)
{
cout << "Standard exception: " << stdEx.what() << endl;
cout << "Could not save federation " << label.c_str() << endl;
saveOk = false;
}
catch(...)
{
cout << "Unknown exception\n";
cout << "Could not save federation " << label.c_str() << endl;
saveOk = false;
}
return saveOk;
}
{
int count = 0;
bool restoreOk = true;
cout << "Request federation restore with label " << label.c_str() << endl;
while (count++ < 100
{
}
{
restoreOk = false;
{
cout << "Timed out waiting for request federation restore succeeded.\n";
}
}
return restoreOk;
}
{
bool restoreOk = true;
cout << "Wait for restore begun\n";
int count = 0;
while (count++ < 100
{
}
{
restoreOk = false;
{
cout << "Timed out waiting for federation restore begun.\n";
}
}
return restoreOk;
}
{
bool restoreOk = true;
cout << "Wait for initiate restore\n";
int count = 0;
while (count++ < 100
{
}
{
restoreOk = false;
}
{
restoreOk = false;
cout << "Timed out waiting for initiate federate restore.\n";
}
{
cout << "Unable to complete restore\n";
restoreOk = false;
count = 0;
while ( count++ < 100
{
}
{
cout << "Timed out waiting for federation not restored.\n";
}
}
return restoreOk;
}
{
bool restoreOk = true;
cout << "Wait for federation restored\n";
int count = 0;
while ( count++ < 100
{
}
{
restoreOk = false;
{
cout << "Timed out waiting for federation restored.\n";
}
}
return restoreOk;
}
{
bool restoreOk = true;
int count = 0;
try
{
if ( performRequest )
{
{
}
}
{
{
wcout << L"Federate restore complete\n";
}
}
}
{
cout << "RTI Exception: "
cout << "Could not save federation " << label.c_str() << endl;
restoreOk = false;
}
catch(exception& stdEx)
{
cout << "Standard exception: " << stdEx.what() << endl;
cout << "Could not save federation " << label.c_str() << endl;
restoreOk = false;
}
catch(...)
{
cout << "Unknown exception\n";
cout << "Could not save federation " << label.c_str() << endl;
restoreOk = false;
}
return restoreOk;
}
{
try
{
}
{
cout << "RTI Exception: "
<< "Could not get object class handle: "
return false;
}
std::string attrName;
try
{
attrName = "AccelerationVector";
attrName = "VelocityVector";
attrName = "Orientation";
attrName = "DeadReckoningAlgorithm";
attrName = "WorldLocation";
}
{
cout << "RTI Exception: "
<< "Could not get attribute handle "
<< attrName.c_str() << endl;
return false;
}
iter++)
{
}
int cnt=0;
try
{
cnt=1;
}
{
cout << "RTI Exception: "
<< "Could not "
<< (cnt ? "publish" : "subscribe") << endl;
delete hSet;
return false;
}
std::string objectName("Talk");
try
{
unsigned int objId = abs(getpid());
std::stringstream pid;
pid << objId;
objectName += pid.str();
objectName.c_str());
}
{
cout << "RTI Exception: "
<< "Could not Register Object "
<< objectName.c_str()
<< " with class "
delete hSet;
return false;
}
cout << "Registered object "
<< objectName.c_str()
<< " with class name "
delete hSet;
return true;
}
{
try
{
}
{
cout << "RTI Exception: "
<< "Could not get interaction class handle: "
return false;
}
std::string paramName;
try
{
paramName = "EventIdentifier";
paramName = "FireControlSolutionRange";
paramName = "FireMissionIndex";
paramName = "FiringLocation";
paramName = "FiringObjectIdentifier";
paramName = "FuseType";
paramName = "InitialVelocityVector";
paramName = "MunitionObjectIdentifier";
paramName = "MunitionType";
paramName = "QuantityFired";
paramName = "RateOfFire";
paramName = "TargetObjectIdentifier";
paramName = "WarheadType";
}
{
cout << "RTI Exception: "
<< "Could not get parameter handle "
<< paramName.c_str() << endl;
return false;
}
int cnt=0;
try
{
cnt=1;
}
{
cout << "RTI Exception: "
<< "Could not "
<< (cnt ? "publish" : "subscribe")
<< " to interaction." << endl;
return false;
}
cout << "Subscribed to interaction class: "
<< " with handle: "
return true;
}
int main(
int argc,
char** argv)
{
std::cout << "MAK rtiSimple version 1.3" << std::endl;
try
{
std::string federationFile("MAKsimple.fed");
std::string federateType("rtisimple13");
if (argc > 1)
{
if (strcmp(argv[1], "-h") == 0)
{
cout << "Usage: rtisimple13 [federationName] [federationFile] [federateType]" << endl;
cout << "default values: "
<< "\"" << federationName.c_str() << "\" "
<< "\"" << federationFile.c_str() << "\" "
<< "\"" << federateType.c_str() << "\" " << endl;
return 0;
}
federationName = argv[1];
}
if (argc > 2)
{
federationFile = argv[2];
}
if (argc > 3)
{
federateType = argv[3];
}
#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;
joinFedEx(rtiAmb, &fedAmb, federateType, federationName);
{
return 0;
}
{
return 0;
}
iter++)
{
attrValues->
add(iter->second,
iter->first.c_str(), iter->first.length()+1);
}
iter2++)
{
paramValues->
add(iter2->second,
iter2->first.c_str(), iter2->first.length()+1);
}
connected = true;
}
else if (connected)
{
std::stringstream ss;
ss << "1.3-" << count++;
std::string tag(ss.str());
*attrValues,
tag.c_str());
if ( count % 5 == 0 )
{
cout << "Sending interaction..." << endl;
*paramValues,
tag.c_str());
}
{
}
{
}
}
if (key < 0)
{
break;
}
else if ('c' == key || 'C' == key )
{
doConnect = !connected;
}
else if ('d' == key || 'D' == key )
{
if (connected)
{
try
{
if (attrValues)
{
delete attrValues;
attrValues = 0;
}
if (paramValues)
{
delete paramValues;
paramValues = 0;
}
connected = false;
}
{
cout << "RTI Exception: "
}
}
}
else if ('s' == key || 'S' == key )
{
if (connected)
{
const std::string saveLabel("rtiSimpleSave");
{
break;
}
}
}
else if ('r' == key || 'R' == key )
{
if (connected)
{
const std::string savedLabel("rtiSimpleSave");
{
break;
}
}
}
#ifdef WIN32
Sleep(2000);
#else
sleep(2);
#endif
}
}
{
cout << "RTI Exception (main loop): "
}
#ifdef WIN32
WSACleanup();
#endif
return 0;
}
#pragma warning(disable: 4786)
#pragma warning(disable: 4290)
#include <stdio.h>
#include <iostream>
using namespace std;
{
for (
unsigned int iloop = 0; iloop < attributes.
size(); iloop++)
{
}
}
{
for (
unsigned int iloop = 0; iloop < params.
size(); iloop++)
{
}
}
{
std::string timeStr(buff);
delete [] buff;
return timeStr;
}
NullFederateAmbassador(), myData(data)
{
}
throw (
RTI::FederateInternalError)
{
int x = 1;
}
throw (
RTI::UnableToPerformSave,
RTI::FederateInternalError)
{
cout << "initiateFederateSave: "
<< label << endl;
myData.myReceivedInitiateFederateSave = true;
myData.mySaveLabel = label;
}
throw (
RTI::FederateInternalError)
{
cout << "federationSaved " << endl;
}
throw (
RTI::FederateInternalError)
{
cout << "federationNotSaved: ";
}
throw (RTI::FederateInternalError)
{
cout << "requestFederationRestoreSucceeded "
<< label << endl;
myData.myReceivedRequestFederationRestoreSucceeded = true;
myData.myRestoreLabel = label;
}
const char* reason)
throw (RTI::FederateInternalError)
{
cout << "requestFederationRestoreFailed "
<< label << " " << reason << endl;
myData.myReceivedRequestFederationRestoreFailed = true;
myData.myRestoreLabel = label;
myData.myRestoreFailureReason = reason;
}
throw (
RTI::FederateInternalError)
{
cout << "federationRestoreBegun" << endl;
}
const char* label,
throw (
RTI::SpecifiedSaveLabelDoesNotExist,
RTI::CouldNotRestore,
RTI::FederateInternalError)
{
cout << "initiateFederateRestore "
<< label << " " << handle << endl;
myData.myReceivedInitiateFederateRestore = true;
myData.myRestoreLabel = label;
myData.myRestoreFederateHandle = handle;
}
throw (
RTI::FederateInternalError)
{
cout << "federationRestored" << endl;
}
throw (
RTI::FederateInternalError)
{
cout << "federationNotRestored" << endl;
}
const char* theObjectName)
throw (
RTI::CouldNotDiscover,
RTI::ObjectClassNotKnown,
RTI::FederateInternalError)
{
cout << "discoverObjectInstance: "
<< theObjectName << "("
<< theObject << ") of class "
<< myData.objectClassMap[theObjectClass].c_str() << "( "
<< theObjectClass << ")" << endl;\
myData.objectInstanceMap[theObject] = theObjectName;
}
const char *theTag,
throw (
RTI::ObjectNotKnown,
RTI::AttributeNotKnown,
RTI::FederateOwnsAttributes,
RTI::InvalidFederationTime,
RTI::FederateInternalError)
{
cout << "reflectAttributeValues: "
<< myData.objectInstanceMap[theObject].c_str() << "("
<< theObject << ") "
<< (theTag ? theTag : "") << " "
<< "#attributes: " << theAttributes.size() << endl;
}
const char *theTag)
throw (
RTI::ObjectNotKnown,
RTI::AttributeNotKnown,
RTI::FederateOwnsAttributes,
RTI::FederateInternalError)
{
cout << "reflectAttributeValues: "
<< myData.objectInstanceMap[theObject].c_str() << "("
<< theObject << ") "
<< (theTag ? theTag : "") << " "
<< "#attributes: " << theAttributes.size() << endl;
}
const char *theTag,
throw (
RTI::InteractionClassNotKnown,
RTI::InteractionParameterNotKnown,
RTI::InvalidFederationTime,
RTI::FederateInternalError)
{
cout << "receiveInteraction: "
<< myData.interactionClassMap[theInteraction].c_str() << "( "
<< theInteraction << ") "
<< (theTag ? theTag : "") << " "
<< "#parameters: " << theParameters.size() << endl;
}
const char *theTag)
throw (
RTI::InteractionClassNotKnown,
RTI::InteractionParameterNotKnown,
RTI::FederateInternalError)
{
cout << "receiveInteraction: "
<< myData.interactionClassMap[theInteraction].c_str() << "( "
<< theInteraction << ") "
<< (theTag ? theTag : "") << " "
<< "#parameters: " << theParameters.size() << endl;
}
const char *theTag,
throw (
RTI::ObjectNotKnown,
RTI::InvalidFederationTime,
RTI::FederateInternalError)
{
cout << "removeObjectInstance: "
<< myData.objectInstanceMap[theObject].c_str() << "("
<< theObject << ") "
<< (theTag ? theTag : "") << endl;
}
const char *theTag)
throw (
RTI::ObjectNotKnown,
RTI::FederateInternalError)
{
cout << "removeObjectInstance: "
<< myData.objectInstanceMap[theObject].c_str() << "("
<< theObject << ") "
<< (theTag ? theTag : "") << endl;
}