#ifdef WIN32
#pragma warning(disable: 4251)
#pragma warning(disable: 4786)
#pragma warning(disable: 4290)
#include <winsock2.h>
#include <process.h>
#else
#include <unistd.h>
#include <stdlib.h>
#include <sched.h>
#include <netdb.h>
#endif
#include <iostream>
#include <wchar.h>
#include <sstream>
#include <string>
#include <sstream>
#include <iterator>
#include <RTI/logicalTimeFactoryImpl.h>
#include <RTI/logicalTimeImpl.h>
#include <RTI/logicalTimeIntervalImpl.h>
using namespace std;
using namespace rti1516;
inline bool parseCmdLine( int argc, char* argv[] );
LogicalTimeFactoryImpl theTimeFactory;
std::wstring theClassName = L"BaseEntity";
string fireInteractionName = "WeaponFire";
string detonateInteractionName = "MunitionDetonation";
ObjectClassHandle theClassHandle;
InteractionClassHandle fireInteractionHandle;
InteractionClassHandle detonateInteractionHandle;
ObjectInstanceHandle theObjectHandle;
bool Master(false);
int numFederates(0);
bool dedicatedMachine(false);
bool unManagedFederate(false);
int sleepTime(850);
wstring fedFileName(L"MAKsimpletime.xml");
wstring federationName(L"MAKsimpletime");
wstring initSyncPointLabel(L"begin");
void createFedEx(RTIambassador* rtiAmb,
std::wstring const& fedName,
std::wstring const& fedFile)
{
std::cout << "createFederationExecution "
try
{
rtiAmb->createFederationExecution(fedName, fedFile);
rtiAmb->evokeMultipleCallbacks(0.1, 0.2);
}
catch(FederationExecutionAlreadyExists& ex)
{
std::cout << "Could not create Federation Execution: "
<< "FederationExecutionAlreadyExists: "
}
catch(rti1516::Exception& ex)
{
std::cout << "RTI Exception: "
<< "Could not create Federation Execution: " << endl;
exit(0);
}
std::cout << "Federation Created." << endl;
}
void joinFedEx(
std::wstring const& federateType, std::wstring const& federationName)
{
bool joined=false;
const int maxTry = 10;
int numTries = 0;
std::cout << "joinFederationExecution "
while (!joined && numTries++ < maxTry)
{
try
{
rtiAmb->joinFederationExecution(federateType, federationName, fedAmb);
joined = true;
}
catch(FederationExecutionDoesNotExist)
{
std::cout << "FederationExecutionDoesNotExist, try "
<< numTries << " out of "
<< maxTry << endl;
continue;
}
catch(rti1516::Exception& ex)
{
std::cout << "RTI Exception: "
return;
}
rtiAmb->evokeMultipleCallbacks(0.1, 0.2);
}
if (joined)
{
std::cout << "Joined Federation." << endl;
}
else
{
std::cout << "Giving up." << endl;
rtiAmb->destroyFederationExecution(federationName);
exit(0);
}
}
void resignAndDestroy( RTIambassador * rtiAmb)
{
try
{
rtiAmb->destroyFederationExecution(federationName);
}
catch (rti1516::Exception& ex)
{
std::cout << "RTI Exception: "
std::cout << "During resign and destroy." << endl;
}
}
bool publishSubscribeAndRegisterObject(RTIambassador* rtiAmb)
{
theAmbData.ourAttrs.insert(string("AccelerationVector"));
theAmbData.ourAttrs.insert(string("DeadReckoningAlgorithm"));
theAmbData.ourAttrs.insert(string("Orientation"));
theAmbData.ourAttrs.insert(string("WorldLocation"));
theAmbData.ourAttrs.insert(string("VelocityVector"));
theAmbData.ourAttrs.insert(string("DamageState"));
try
{
theClassHandle = rtiAmb->getObjectClassHandle(theClassName);
theAmbData.objectClassMap[theClassHandle] = theClassName;
}
catch (rti1516::Exception& ex)
{
std::cout << "RTI Exception: "
std::cout << "Could not get object class handle: "
return false;
}
std::wstring attrName;
set<string>::iterator attributeSetIterator = theAmbData.ourAttrs.begin();
set<string>::iterator attributeSetEnd = theAmbData.ourAttrs.end();
string currentAttribute("");
AttributeHandle retrievedHandle;
for( ; attributeSetIterator != attributeSetEnd; ++attributeSetIterator)
{
currentAttribute = *attributeSetIterator;
try{
retrievedHandle =
rtiAmb->getAttributeHandle(theClassHandle,
DtToWString(currentAttribute.c_str()));
}
catch (rti1516::Exception& ex)
{
std::cout << "RTI Exception: "
std::cout << "Could not get attribute handle "
return false;
}
hSet.insert(retrievedHandle);
theAmbData.attrValues->insert(
std::make_pair(
retrievedHandle,
VariableLengthData(
currentAttribute.c_str(),
currentAttribute.length() + 1)));
theAmbData.theAttrNameHandleMap.insert(
std::make_pair(
DtToWString(currentAttribute.c_str()), retrievedHandle));
}
int cnt=0;
try
{
rtiAmb->publishObjectClassAttributes(theClassHandle, hSet);
rtiAmb->evokeMultipleCallbacks(0.1, 0.2);
cnt=1;
rtiAmb->subscribeObjectClassAttributes(theClassHandle, hSet);
rtiAmb->evokeMultipleCallbacks(0.1, 0.2);
}
catch (rti1516::Exception& ex)
{
std::cout << "RTI Exception: "
std::cout << "Could not "
<< (cnt ? "publish" : "subscribe") << endl;
return false;
}
std::string objectName("Talk");
try
{
unsigned int objId = abs(getpid());
std::stringstream pid;
pid << objId;
objectName += pid.str();
theAmbData.myNameReservationReturned =
theAmbData.myNameReservationSucceeded = false;
rtiAmb->reserveObjectInstanceName(
DtToWString(objectName.c_str()));
int count = 0;
while (count++ < 100 && !theAmbData.myNameReservationReturned)
{
rtiAmb->evokeMultipleCallbacks(0.1, 0.2);
}
if (count < 100)
{
theObjectHandle = rtiAmb->registerObjectInstance(theClassHandle,
theAmbData.objectInstanceMap[theObjectHandle] =
DtToWString(objectName.c_str());
}
else
{
std::cout << "Failed waiting for reserve object name "
<< objectName << endl;
return false;
}
rtiAmb->evokeMultipleCallbacks(0.1, 0.2);
}
catch (rti1516::Exception& ex)
{
std::cout << "RTI Exception: "
std::cout << "Could not Register Object "
<< objectName
<< " with class "
return false;
}
std::cout << "Registered object "
<< objectName
<< " with class name "
return true;
}
bool publishAndSubscribeInteraction(RTIambassador* rtiAmb)
{
theAmbData.ourParms.insert("EventIdentifier");
theAmbData.ourParms.insert("FiringLocation");
theAmbData.ourParms.insert("FiringObjectIdentifier");
theAmbData.ourParms.insert("MunitionObjectIdentifier");
theAmbData.ourParms.insert("TargetObjectIdentifier");
try
{
fireInteractionHandle = rtiAmb->getInteractionClassHandle(
theAmbData.interactionClassMap[fireInteractionHandle] =
detonateInteractionHandle = rtiAmb->getInteractionClassHandle(
theAmbData.interactionClassMap[detonateInteractionHandle] =
}
catch (rti1516::Exception& ex)
{
std::cout << "RTI Exception: "
std::cout << "Could not get interaction class handle: "
return false;
}
string paramName;
set<string>::const_iterator parameterIter = theAmbData.ourParms.begin();
set<string>::const_iterator parameterEnd = theAmbData.ourParms.end();
ParameterHandle retrievedHandle;
for( ; parameterIter != parameterEnd; ++parameterIter )
{
paramName = *parameterIter;
try
{
retrievedHandle =
rtiAmb->getParameterHandle(fireInteractionHandle,
}
catch (rti1516::Exception& ex)
{
std::cout << "RTI Exception: "
std::cout << "Could not get parameter handle "
<< paramName << endl;
return false;
}
theAmbData.paramValues->insert(std::make_pair(
retrievedHandle,
VariableLengthData(
paramName.c_str(),
paramName.length() + 1 )));
theAmbData.theParamNameHandleMap.insert(
std::make_pair(
DtToWString(paramName.c_str()), retrievedHandle));
}
int cnt=0;
try
{
rtiAmb->publishInteractionClass(fireInteractionHandle);
rtiAmb->evokeMultipleCallbacks(0.1, 0.2);
rtiAmb->publishInteractionClass(detonateInteractionHandle);
rtiAmb->evokeMultipleCallbacks(0.1, 0.2);
cnt=1;
rtiAmb->subscribeInteractionClass(fireInteractionHandle);
rtiAmb->evokeMultipleCallbacks(0.1, 0.2);
rtiAmb->subscribeInteractionClass(detonateInteractionHandle);
rtiAmb->evokeMultipleCallbacks(0.1, 0.2);
}
catch (rti1516::Exception& ex)
{
std::cout <<
"RTI Exception: " <<
DtToString(ex.what()) << endl;
std::cout << "Could not "
<< (cnt ? "publish" : "subscribe")
<< " to interaction class." << endl;
return false;
}
std::cout << "Subscribed to interaction class: "
<< fireInteractionName
<< " with handle: "
<<
DtToString(fireInteractionHandle.toString()) << endl
<< " and interaction class "
<< detonateInteractionName
<< " with handle: "
<<
DtToString(detonateInteractionHandle.toString()) << endl;
return true;
}
void cleanUpProgram(RTIambassador* rtiAmb)
{
try
{
if ( theAmbData.isRegulating )
{
rtiAmb->disableTimeRegulation();
}
resignAndDestroy(rtiAmb);
delete rtiAmb;
}
catch (rti1516::Exception& ex)
{
std::cout << "RTI Exception (during exit): "
}
#ifdef WIN32
WSACleanup();
#endif
exit(0);
}
void printOutFedTime(LogicalTime* time)
{
}
void printOutFedTime(LogicalTimeInterval* time)
{
}
void sleepFunction()
{
if ( ! dedicatedMachine )
{
#ifdef WIN32
Sleep(sleepTime);
#else
usleep(sleepTime * 1000);
#endif
}
}
void minimalSleepFunction()
{
#ifdef WIN32
Sleep(10);
#else
usleep(10 * 1000);
#endif
}
void yieldFunction()
{
if ( ! dedicatedMachine )
{
#ifdef _WIN32
Sleep( 0 );
#elif __solaris__
yield();
#else
sched_yield();
#endif
}
}
void becomeConstrainedAndRegulating(RTIambassador* rtiAmb,
LogicalTime* currentTime, LogicalTimeInterval* lookAhead )
{
try
{
rtiAmb->enableTimeRegulation((*lookAhead));
std::cout << "Waiting to become Time Regulating " << endl;
while ( ! theAmbData.isRegulating )
{
rtiAmb->evokeMultipleCallbacks(.1, 1);
std::cout << ".";
{
cleanUpProgram(rtiAmb);
}
minimalSleepFunction();
}
std::cout << endl;
rtiAmb->enableTimeConstrained();
std::cout << "Waiting to become Time Constrained \n";
rtiAmb->evokeMultipleCallbacks(.1, 1);
while ( ! theAmbData.isConstrained )
{
std::cout << ".";
{
cleanUpProgram(rtiAmb);
}
rtiAmb->evokeMultipleCallbacks(.1, 1);
if ( ! theAmbData.isConstrained )
{
yieldFunction();
}
}
cout << std::endl;
}
catch (Exception& )
{
std::cout << " unable to become regulating and constrained\n"
<< " Exiting ...\n";
cleanUpProgram(rtiAmb);
}
}
void synchronizeFederation(RTIambassador* rtiAmb)
{
if ( theAmbData.isMaster )
{
std::wstring syncPointLabel(initSyncPointLabel.c_str());
std::string synchPointTag("");
int maximumSize(256);
char* hostName = new char[maximumSize];
if ( -1 == gethostname(hostName, maximumSize) )
{
unsigned int objId = abs(getpid());
std::stringstream pid;
pid.str(std::string(""));
pid << "unknownHostName"
<< "_"
<< objId;
synchPointTag = pid.str();
}
else
{
unsigned int objId = abs(getpid());
std::stringstream pid;
pid.str(std::string(""));
pid << hostName
<< "_"
<< objId;
synchPointTag = pid.str();
}
delete hostName;
rtiAmb->evokeMultipleCallbacks(0.1, 0.2);
std::cout << " Master waiting for all federates to Join.\n";
while ( theAmbData.otherFederatesReady < (theAmbData.numFederates - 1) )
{
{
cleanUpProgram(rtiAmb);
}
yieldFunction();
rtiAmb->evokeMultipleCallbacks(0.1, 0.2);
}
std::cout << " Master federate has discovered the required number of other federates.\n\n";
VariableLengthData ourTag(synchPointTag.c_str(), synchPointTag.size());
rtiAmb->registerFederationSynchronizationPoint(syncPointLabel.c_str(),
ourTag);
rtiAmb->evokeMultipleCallbacks(0.1, 0.2);
while ( !theAmbData.registerFailed && !theAmbData.registerSucceeded )
{
{
cleanUpProgram(rtiAmb);
}
yieldFunction();
rtiAmb->evokeMultipleCallbacks(0.1, 0.2);
}
if ( theAmbData.registerFailed )
{
std::cout <<
" We failed to register synch point " <<
DtToString(syncPointLabel) << std::endl
<< " with tag " << synchPointTag << std::endl;
cleanUpProgram(rtiAmb);
}
std::cout << "Master succesfully registered\n";
}
else
{
rtiAmb->evokeMultipleCallbacks(0.1, 0.2);
std::cout << " Ordinary federate is waiting for synchPoint message\n";
while ( ! theAmbData.announceSyncReceived )
{
{
cleanUpProgram(rtiAmb);
}
yieldFunction();
rtiAmb->evokeMultipleCallbacks(0.1, 0.2);
}
std::cout << "sync Point message received\n";
}
try
{
rtiAmb->synchronizationPointAchieved(initSyncPointLabel.c_str());
}
catch (Exception& )
{
std::cout << " Synch point achieved failed\n"
<< " Exiting....\n";
cleanUpProgram(rtiAmb);
}
rtiAmb->evokeMultipleCallbacks(0.1, 0.2);
while ( !theAmbData.federationIsSynchronized )
{
{
cleanUpProgram(rtiAmb);
}
minimalSleepFunction();
rtiAmb->evokeMultipleCallbacks(0.1, 0.2);
}
}
int main(int argc, char** argv)
{
std::cout << "MAK simpleTime version 1516" << std::endl;
RTIambassador* rtiAmb = 0;
try
{
if (argc > 1)
{
if (! parseCmdLine(argc, argv) )
{
exit(0);
}
}
std::vector< std::wstring > args;
std::wstring federateType(L"simpletime1516");
std::cout << "Using "
RTIambassadorFactory* rtiAmbFactory = new RTIambassadorFactory();
std::auto_ptr < RTIambassador > rtiAmbAP =
rtiAmbFactory->createRTIambassador(args);
delete rtiAmbFactory;
rtiAmb = rtiAmbAP.release();
createFedEx(rtiAmb, federationName, fedFileName);
joinFedEx(rtiAmb, fedAmb, federateType, federationName);
#ifdef WIN32
WSADATA data;
WSAStartup(MAKEWORD(1,1), &data);
#endif
rtiAmb->evokeCallback(0.0);
long count=0;
LogicalTime* currentTime = new LogicalTimeImpl(0.0);
LogicalTimeInterval* lookAhead = new LogicalTimeIntervalImpl(1.0f);
LogicalTime* currentRTITime = new LogicalTimeImpl(0.0);
LogicalTimeInterval* oneTimeStep = new LogicalTimeIntervalImpl(5.0f);
becomeConstrainedAndRegulating(rtiAmb, currentTime, lookAhead);
(*currentTime) += (*oneTimeStep);
if (!publishSubscribeAndRegisterObject(rtiAmb))
{
resignAndDestroy(rtiAmb);
delete rtiAmb;
return 0;
}
if ( !unManagedFederate )
{
synchronizeFederation(rtiAmb);
}
if (!publishAndSubscribeInteraction(rtiAmb))
{
resignAndDestroy(rtiAmb);
delete rtiAmb;
return 0;
}
while ( !theAmbData.timeManagedObject.isDetonated() )
{
std::cout << "============================================"
"============================================"
<< endl;
std::cout << " Fedtime (";
printOutFedTime(currentRTITime);
std::cout << "), Lookahead (";
printOutFedTime(lookAhead);
std::cout << ") and wallclock time (";
printOutFedTime(currentTime);
std::cout << ") " << endl;
std::cout << endl;
std::stringstream ss;
ss << "1516-" << count++;
std::string tag(ss.str());
theAmbData.timeManagedObject.tick();
theAmbData.timeManagedObject.incPosition();
try{
rtiAmb->updateAttributeValues(
theObjectHandle,
(*theAmbData.attrValues),
VariableLengthData(tag.c_str(), tag.size()+1),
(*currentTime));
rtiAmb->evokeMultipleCallbacks(0.1, 0.5);
if ( theAmbData.timeManagedObject.shouldDetonate() )
{
string munitionString = "MunitionObjectIdentifier";
ParameterHandle retrievedHandle =
theAmbData.theParamNameHandleMap[
DtToWString(munitionString.c_str())];
ParameterHandleValueMap::iterator munitionData =
theAmbData.paramValues->find( retrievedHandle );
VariableLengthData prior =
theAmbData.paramValues->find( munitionData->first)->second;
VariableLengthData emptySet("\0", 1);
(*theAmbData.paramValues)[munitionData->first] = emptySet;
rtiAmb->sendInteraction(
fireInteractionHandle,
(*theAmbData.paramValues),
VariableLengthData(tag.c_str(), tag.size()+1),
(*currentTime));
(*theAmbData.paramValues)[munitionData->first] = prior;
}
if ( theAmbData.timeManagedObject.shouldFire() )
{
string fireString = "FiringObjectIdentifier";
ParameterHandleValueMap::iterator fireData =
theAmbData.paramValues->find(
theAmbData.theParamNameHandleMap[
DtToWString(fireString.c_str())]);
VariableLengthData prior =
theAmbData.paramValues->find(fireData->first)->second;
VariableLengthData emptySet("\0", 1);
(*theAmbData.paramValues)[fireData->first] = emptySet;
rtiAmb->sendInteraction(
fireInteractionHandle,
(*theAmbData.paramValues),
VariableLengthData(tag.c_str(), tag.size()+1),
(*currentTime));
(*theAmbData.paramValues)[fireData->first] = prior;
}
}
catch( InvalidLogicalTime& ex)
{
std::cout << "RTI Invalid Logical Time" << endl;
<< "Could not update object or send interaction"
<< endl;
cleanUpProgram(rtiAmb);
}
catch( Exception& ex)
{
std::cout << "RTI Exception "
<< endl
<< " Could not update object or send interaction"
<< endl;
}
int kb(0);
try
{
if ( theAmbData.isRegulating )
{
(*currentRTITime) += (*oneTimeStep);
(*currentTime) += (*oneTimeStep);
rtiAmb->timeAdvanceRequest(*currentRTITime);
theAmbData.timeAdvanced = false;
rtiAmb->evokeMultipleCallbacks(0.1, 0.5);
while ( ! theAmbData.timeAdvanced )
{
if (kb < 0)
{
break;
}
else if ( kb == 1 )
{
theAmbData.timeManagedObject.firePressed();
cout << "**********Firing at time " ;
printOutFedTime(currentRTITime);
cout << "*************\n";
}
else if ( !theAmbData.timeAdvanced )
{
rtiAmb->evokeMultipleCallbacks(0.1, 0.5);
yieldFunction();
}
}
}
}
catch( Exception& ex )
{
std::cout << "RTI Exception" << endl
<< "Could not advance time" << endl;
}
rtiAmb->evokeMultipleCallbacks(0.1, 0.5);
if ( kb == 0 )
{
}
if (kb < 0)
{
break;
}
else if ( kb == 1 )
{
theAmbData.timeManagedObject.firePressed();
cout << "**********Firing at time " ;
printOutFedTime(currentRTITime);
cout << "*************\n";
}
std::cout << "============================================"
"============================================"
<< endl << endl;
sleepFunction();
}
delete currentTime;
delete currentRTITime;
delete lookAhead;
delete oneTimeStep;
delete theAmbData.paramValues;
delete theAmbData.attrValues;
if ( theAmbData.isRegulating )
{
rtiAmb->disableTimeRegulation();
}
resignAndDestroy(rtiAmb);
if( rtiAmb )
{
delete rtiAmb;
rtiAmb = 0;
}
}
catch (rti1516::Exception& ex)
{
std::cout << "RTI Exception (main loop): "
if( rtiAmb )
{
delete rtiAmb;
}
}
#ifdef WIN32
WSACleanup();
#endif
return 0;
}
bool parseCmdLine( int argc, char* argv[] )
{
vector < std::string > cmdArgs;
copy( argv + 1, argv + argc, back_inserter(cmdArgs));
vector<std::string>::const_iterator cur = cmdArgs.begin();
vector<std::string>::const_iterator last = cmdArgs.end();
while ( cur != last )
{
vector<std::string>::const_iterator next = cur + 1;
if ( *cur == "-h" )
{
return false;
}
else if ( *cur == "-fedFile" )
{
++cur;
}
else if (*cur == "-m" )
{
if ( !convert<int> (*cur, *next, theAmbData.numFederates))
{
return false;
}
theAmbData.isMaster = true;
++cur;
}
else if ( *cur == "-phaseLine" )
{
int phaseLine(0);
if ( !convert<int>(*cur, *next, phaseLine))
{
return false;
}
theAmbData.timeManagedObject.setPhaseLine(phaseLine);
++cur;
}
else if ( *cur == "-sleepTime" )
{
if ( !convert<int> (*cur, *next, sleepTime ))
{
return false;
}
++cur;
}
else if ( *cur == "-dedicated" )
{
dedicatedMachine = true;
}
else if ( *cur == "-unManaged" )
{
unManagedFederate = true;
}
else
{
return false;
}
++cur;
}
return true;
}
#ifdef WIN32
#pragma warning(disable: 4251)
#pragma warning(disable: 4786)
#pragma warning(disable: 4290)
#endif
#include <iostream>
using namespace std;
isConstrained(false),
isRegulating(false),
timeAdvanced(false),
otherFederatesReady(false)
{
}
{
}
throw () {}
void
std::wstring const & theObjectInstanceName)
throw (
UnknownName,
FederateInternalError)
{
myData.myNameReservationReturned =
myData.myNameReservationSucceeded = true;
}
std::wstring const & theObjectInstanceName)
throw (
UnknownName,
FederateInternalError)
{
myData.myNameReservationReturned = true;
myData.myNameReservationSucceeded = false;
}
ObjectInstanceHandle theObject,
ObjectClassHandle theObjectClass,
std::wstring const & theObjectInstanceName)
throw (
CouldNotDiscover,
ObjectClassNotKnown,
FederateInternalError)
{
++myData.otherFederatesReady;
if ( myData.isMaster )
{
std::cout << " Master federate is aware of "
<< myData.otherFederatesReady + 1
<< " federates, including itself\n";
}
for ( DtAttrNameHandleMap::iterator iter = myData.theAttrNameHandleMap.begin();
iter != myData.theAttrNameHandleMap.end();
++iter )
{
hSet->insert( iter->second );
}
myData.objectInstanceMap[theObject] = theObjectInstanceName;
myData.updateRequestMap.insert( std::make_pair(theObject, hSet) );
delete hSet;
}
ObjectInstanceHandle theObject,
VariableLengthData const & theUserSuppliedTag,
throw (
ObjectInstanceNotKnown,
AttributeNotRecognized,
AttributeNotSubscribed,
FederateInternalError)
{
VariableLengthData const theUserSuppliedTag2;
myData.timeManagedObject.addAttrUpdateEvent(tmp);
}
ObjectInstanceHandle theObject,
VariableLengthData const & theUserSuppliedTag,
throw (
ObjectInstanceNotKnown,
AttributeNotRecognized,
AttributeNotSubscribed,
FederateInternalError)
{
theAttributeValues,
theUserSuppliedTag,
sentOrder,
theType);
}
ObjectInstanceHandle theObject,
VariableLengthData const & theUserSuppliedTag,
LogicalTime const & theTime,
throw (
ObjectInstanceNotKnown,
AttributeNotRecognized,
AttributeNotSubscribed,
FederateInternalError)
{
theAttributeValues,
theUserSuppliedTag,
sentOrder,
theType,
theTime ));
}
ObjectInstanceHandle theObject,
VariableLengthData const & theUserSuppliedTag,
LogicalTime const & theTime,
throw (
ObjectInstanceNotKnown,
AttributeNotRecognized,
AttributeNotSubscribed,
FederateInternalError)
{
theAttributeValues,
theUserSuppliedTag,
sentOrder,
theType,
theTime,
receivedOrder);
}
ObjectInstanceHandle theObject,
VariableLengthData const & theUserSuppliedTag,
LogicalTime const & theTime,
MessageRetractionHandle theHandle)
throw (
ObjectInstanceNotKnown,
AttributeNotRecognized,
AttributeNotSubscribed,
InvalidLogicalTime,
FederateInternalError)
{
theAttributeValues,
theUserSuppliedTag,
sentOrder,
theType,
theTime,
receivedOrder);
}
ObjectInstanceHandle theObject,
VariableLengthData const & theUserSuppliedTag,
LogicalTime const & theTime,
MessageRetractionHandle theHandle,
throw (
ObjectInstanceNotKnown,
AttributeNotRecognized,
AttributeNotSubscribed,
InvalidLogicalTime,
FederateInternalError)
{
theAttributeValues,
theUserSuppliedTag,
sentOrder,
theType,
theTime,
receivedOrder);
}
InteractionClassHandle theInteraction,
VariableLengthData const & theUserSuppliedTag,
throw (InteractionClassNotRecognized,
InteractionParameterNotRecognized,
InteractionClassNotSubscribed,
FederateInternalError)
{
theParameterValues,
theUserSuppliedTag,
sentOrder,
theType );
myData.timeManagedObject.addInteractionEvent(receivedInteraction);
}
InteractionClassHandle theInteraction,
VariableLengthData const & theUserSuppliedTag,
throw (InteractionClassNotRecognized,
InteractionParameterNotRecognized,
InteractionClassNotSubscribed,
FederateInternalError)
{
theParameterValues,
theUserSuppliedTag,
sentOrder,
theType);
}
InteractionClassHandle theInteraction,
VariableLengthData const & theUserSuppliedTag,
LogicalTime const & theTime,
throw (InteractionClassNotRecognized,
InteractionParameterNotRecognized,
InteractionClassNotSubscribed,
FederateInternalError)
{
string munitionString("MunitionObjectIdentifier");
string fireString("FiringObjectIdentifier");
if ( myData.theParamNameHandleMap.find(
DtToWString(munitionString.c_str()))
!= myData.theParamNameHandleMap.end() )
{
ParameterHandle munitionHandle =
myData.theParamNameHandleMap.find(
DtToWString(munitionString.c_str()))->second;
ParameterHandleValueMap::const_iterator munitionEntry = theParameterValues.find(munitionHandle);
if ( munitionEntry != theParameterValues.end() )
{
VariableLengthData munitionData = munitionEntry->second;
if ( munitionData.size() == 1 )
{
}
}
}
if ( myData.theParamNameHandleMap.find(
DtToWString(fireString.c_str()))
!= myData.theParamNameHandleMap.end())
{
ParameterHandle fireHandle = myData.theParamNameHandleMap.find(
DtToWString(fireString.c_str()))->second
;
ParameterHandleValueMap::const_iterator fireEntry = theParameterValues.find(fireHandle);
if ( fireEntry != theParameterValues.end() )
{
VariableLengthData fireData = fireEntry->second;
if ( fireData.size() == 1 )
{
}
}
}
theInteraction,
theParameterValues,
theUserSuppliedTag,
sentOrder,
theType,
theTime,
receivedOrder,
interactionType
));
}
InteractionClassHandle theInteraction,
VariableLengthData const & theUserSuppliedTag,
LogicalTime const & theTime,
throw (InteractionClassNotRecognized,
InteractionParameterNotRecognized,
InteractionClassNotSubscribed,
FederateInternalError)
{
theParameterValues,
theUserSuppliedTag,
sentOrder,
theType,
theTime,
receivedOrder);
}
InteractionClassHandle theInteraction,
VariableLengthData const & theUserSuppliedTag,
LogicalTime const & theTime,
MessageRetractionHandle theHandle)
throw (InteractionClassNotRecognized,
InteractionParameterNotRecognized,
InteractionClassNotSubscribed,
InvalidLogicalTime,
FederateInternalError)
{
theParameterValues,
theUserSuppliedTag,
sentOrder,
theType,
theTime,
receivedOrder);
}
InteractionClassHandle theInteraction,
VariableLengthData const & theUserSuppliedTag,
LogicalTime const & theTime,
MessageRetractionHandle theHandle,
throw (InteractionClassNotRecognized,
InteractionParameterNotRecognized,
InteractionClassNotSubscribed,
InvalidLogicalTime,
FederateInternalError)
{
theParameterValues,
theUserSuppliedTag,
sentOrder,
theType,
theTime,
receivedOrder);
}
ObjectInstanceHandle theObject,
VariableLengthData const & theUserSuppliedTag,
throw (
ObjectInstanceNotKnown,
FederateInternalError)
{
if ( myData.objectInstanceMap.find(theObject) != myData.objectInstanceMap.end() )
myData.objectInstanceMap.erase(theObject);
myData.timeManagedObject.reset();
}
ObjectInstanceHandle theObject,
VariableLengthData const & theUserSuppliedTag,
LogicalTime const & theTime,
throw (
ObjectInstanceNotKnown,
FederateInternalError)
{
if ( myData.objectInstanceMap.find(theObject) != myData.objectInstanceMap.end() )
myData.objectInstanceMap.erase(theObject);
}
ObjectInstanceHandle theObject,
VariableLengthData const & theUserSuppliedTag,
LogicalTime const & theTime,
MessageRetractionHandle theHandle)
throw (
ObjectInstanceNotKnown,
InvalidLogicalTime,
FederateInternalError)
{
if ( myData.objectInstanceMap.find(theObject) != myData.objectInstanceMap.end() )
myData.objectInstanceMap.erase(theObject);
}
ObjectInstanceHandle theObject,
VariableLengthData const & theUserSuppliedTag)
throw (ObjectInstanceNotKnown,
AttributeNotRecognized,
AttributeNotOwned,
FederateInternalError)
{
for ( DtAttrNameHandleMap::iterator iter = myData.theAttrNameHandleMap.begin();
iter != myData.theAttrNameHandleMap.end();
++iter )
{
hSet->insert( iter->second );
}
myData.updateRequestMap.insert( std::make_pair(theObject, hSet) );
}
throw (InvalidLogicalTime,
NoRequestToEnableTimeRegulationWasPending,
FederateInternalError)
{
std::cout << " This federate is now able to Regulate time\n";
myData.isRegulating = true;
}
throw (InvalidLogicalTime,
NoRequestToEnableTimeConstrainedWasPending,
FederateInternalError)
{
std::cout << " This federate is now time Constrained\n";
myData.isConstrained = true;
}
throw (InvalidLogicalTime,
JoinedFederateIsNotInTimeAdvancingState,
FederateInternalError)
{
std::cout << " Federate Time has been advanced to "
<< std::endl;
myData.timeAdvanced = true;
}
throw (FederateInternalError)
{
}
std::wstring const & label)
throw (FederateInternalError)
{
myData.registerSucceeded = true;
}
std::wstring const & label,
SynchronizationFailureReason reason)
throw (FederateInternalError)
{
myData.registerFailed = true;
}
std::wstring const & label,
VariableLengthData const & theUserSuppliedTag)
throw (FederateInternalError)
{
myData.announceSyncReceived = true;
std::cout << "Announce Sync Received for label "
<< reinterpret_cast<const char*>(theUserSuppliedTag.data()) << endl;
}
throw (FederateInternalError)
{
myData.federationIsSynchronized = true;
std::cout << " My Federation has been synchronized.\n";
}
#ifndef MyFederateAmbassador_H_
#define MyFederateAmbassador_H_
#ifdef WIN32
#pragma warning(disable: 4251)
#pragma warning(disable: 4786)
#pragma warning(disable: 4290)
#endif
#include <string>
#include <map>
using namespace rti1516;
{
public:
public:
bool myNameReservationReturned;
bool myNameReservationSucceeded;
std::map<ObjectClassHandle, std::wstring> objectClassMap;
std::map<ObjectInstanceHandle, std::wstring> objectInstanceMap;
std::map<InteractionClassHandle,std::wstring> interactionClassMap;
std::map<ObjectInstanceHandle, AttributeHandleSet*> updateRequestMap;
DtAttrNameHandleMap theAttrNameHandleMap;
DtParamNameHandleMap theParamNameHandleMap;
std::set<std::string> ourAttrs;
std::set<std::string> ourParms;
bool isMaster;
int numFederates;
bool isConstrained;
bool isRegulating;
bool timeAdvanced;
int otherFederatesReady;
bool registerFailed;
bool registerSucceeded;
bool announceSyncReceived;
bool federationIsSynchronized;
};
{
public:
throw ();
virtual
void
objectInstanceNameReservationSucceeded(std::wstring const &
theObjectInstanceName)
throw (UnknownName,
FederateInternalError);
virtual
void
objectInstanceNameReservationFailed(std::wstring const &
theObjectInstanceName)
throw (UnknownName,
FederateInternalError);
ObjectInstanceHandle theObject,
ObjectClassHandle theObjectClass,
std::wstring const & theObjectInstanceName)
throw (
CouldNotDiscover,
ObjectClassNotKnown,
FederateInternalError);
virtual
void
(ObjectInstanceHandle theObject,
VariableLengthData const & theUserSuppliedTag,
throw (ObjectInstanceNotKnown,
AttributeNotRecognized,
AttributeNotSubscribed,
FederateInternalError);
virtual
void
(ObjectInstanceHandle theObject,
VariableLengthData const & theUserSuppliedTag,
throw (ObjectInstanceNotKnown,
AttributeNotRecognized,
AttributeNotSubscribed,
FederateInternalError);
virtual
void
(ObjectInstanceHandle theObject,
VariableLengthData const & theUserSuppliedTag,
LogicalTime const & theTime,
throw (ObjectInstanceNotKnown,
AttributeNotRecognized,
AttributeNotSubscribed,
FederateInternalError);
virtual
void
(ObjectInstanceHandle theObject,
VariableLengthData const & theUserSuppliedTag,
LogicalTime const & theTime,
throw (ObjectInstanceNotKnown,
AttributeNotRecognized,
AttributeNotSubscribed,
FederateInternalError);
virtual
void
(ObjectInstanceHandle theObject,
VariableLengthData const & theUserSuppliedTag,
LogicalTime const & theTime,
MessageRetractionHandle theHandle)
throw (ObjectInstanceNotKnown,
AttributeNotRecognized,
AttributeNotSubscribed,
InvalidLogicalTime,
FederateInternalError);
virtual
void
(ObjectInstanceHandle theObject,
VariableLengthData const & theUserSuppliedTag,
LogicalTime const & theTime,
MessageRetractionHandle theHandle,
throw (ObjectInstanceNotKnown,
AttributeNotRecognized,
AttributeNotSubscribed,
InvalidLogicalTime,
FederateInternalError);
virtual
void
(InteractionClassHandle theInteraction,
VariableLengthData const & theUserSuppliedTag,
throw (InteractionClassNotRecognized,
InteractionParameterNotRecognized,
InteractionClassNotSubscribed,
FederateInternalError);
virtual
void
(InteractionClassHandle theInteraction,
VariableLengthData const & theUserSuppliedTag,
throw (InteractionClassNotRecognized,
InteractionParameterNotRecognized,
InteractionClassNotSubscribed,
FederateInternalError);
virtual
void
(InteractionClassHandle theInteraction,
VariableLengthData const & theUserSuppliedTag,
LogicalTime const & theTime,
throw (InteractionClassNotRecognized,
InteractionParameterNotRecognized,
InteractionClassNotSubscribed,
FederateInternalError);
virtual
void
(InteractionClassHandle theInteraction,
VariableLengthData const & theUserSuppliedTag,
LogicalTime const & theTime,
throw (InteractionClassNotRecognized,
InteractionParameterNotRecognized,
InteractionClassNotSubscribed,
FederateInternalError);
virtual
void
(InteractionClassHandle theInteraction,
VariableLengthData const & theUserSuppliedTag,
LogicalTime const & theTime,
MessageRetractionHandle theHandle)
throw (InteractionClassNotRecognized,
InteractionParameterNotRecognized,
InteractionClassNotSubscribed,
InvalidLogicalTime,
FederateInternalError);
virtual
void
(InteractionClassHandle theInteraction,
VariableLengthData const & theUserSuppliedTag,
LogicalTime const & theTime,
MessageRetractionHandle theHandle,
throw (InteractionClassNotRecognized,
InteractionParameterNotRecognized,
InteractionClassNotSubscribed,
InvalidLogicalTime,
FederateInternalError);
virtual
void
VariableLengthData const & theUserSuppliedTag,
throw (ObjectInstanceNotKnown,
FederateInternalError);
virtual
void
VariableLengthData const & theUserSuppliedTag,
LogicalTime const & theTime,
throw (ObjectInstanceNotKnown,
FederateInternalError);
virtual
void
VariableLengthData const & theUserSuppliedTag,
LogicalTime const & theTime,
MessageRetractionHandle theHandle)
throw (ObjectInstanceNotKnown,
InvalidLogicalTime,
FederateInternalError);
virtual
void
VariableLengthData const & theUserSuppliedTag)
throw (ObjectInstanceNotKnown,
AttributeNotRecognized,
AttributeNotOwned,
FederateInternalError);
virtual
void
throw (InvalidLogicalTime,
NoRequestToEnableTimeRegulationWasPending,
FederateInternalError);
virtual
void
throw (InvalidLogicalTime,
NoRequestToEnableTimeConstrainedWasPending,
FederateInternalError);
virtual
void
throw (InvalidLogicalTime,
JoinedFederateIsNotInTimeAdvancingState,
FederateInternalError);
virtual
void
throw (FederateInternalError);
virtual
void
throw (FederateInternalError);
virtual
void
SynchronizationFailureReason reason)
throw (FederateInternalError);
virtual
void
VariableLengthData const & theUserSuppliedTag)
throw (FederateInternalError);
virtual
void
throw (FederateInternalError);
public:
};
#endif