MAK RTIspy API Documentation for HLA 4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
rtisimple Example Code for HLA Evolved

rtiSimple1516e.cxx and rtiSimpleFedAmb1516e.cxx (rtiSimpleFedAmb1516e.h) have the RTI calls and federate ambassador calls for the HLA Evolved version of rtisimple.

This page has the code for the following files:


rtiSimple1516e.cxx

/*******************************************************************************
** Copyright (c) 2010 MaK Technologies, Inc.
** All rights reserved.
*******************************************************************************/
// A simple federate that updates an object with attributes whose values
// are the name of the attribute. Objects from other simple federates
// are discovered and reflected. The string values are byte encoded to allow
// compatibility between 1.3 and 1516
#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>
#include <RTI/RTI1516.h>
using namespace rti1516e;
using namespace std;
// Map between strings and attribute handles
typedef std::map<std::wstring, AttributeHandle> DtAttrNameHandleMap;
// Map between strings and parameter handles
typedef std::map<std::wstring, ParameterHandle> DtParamNameHandleMap;
// Handles keyboard input without blocking
keyboard theInput;
// Data shared between federate and federate ambassador
DtSimpleData theAmbData;
// The federate handle
FederateHandle theFederateHandle;
// The object class name
std::wstring theClassName = L"BaseEntity";
// The interaction class name
std::wstring theInterClassName = L"WeaponFire";
// The object class handle (to be retrieved from RTI).
ObjectClassHandle theClassHandle;
// The interaction class handle (to be retrieved from RTI).
InteractionClassHandle theInterClassHandle;
// The object instance handle (to be retrieved from the RTI).
ObjectInstanceHandle theObjectHandle;
// Map between strings and attribute handles
DtAttrNameHandleMap theAttrNameHandleMap;
// Map between strings and parameter handles
DtParamNameHandleMap theParamNameHandleMap;
// Connect
bool connect(RTIambassador& rtiAmb, MyFederateAmbassador& fedAmb, const std::wstring& localDesignator)
{
wcout << L"Connect to RTI" << endl;
try
{
rtiAmb.connect(fedAmb, HLA_EVOKED, localDesignator);
}
catch (Exception& ex)
{
wcout << L"RTI Exception: " << ex.what() << endl;
return false;
}
rtiAmb.evokeMultipleCallbacks(0.1, 0.2);
wcout << L"Connected." << endl;
return true;
}
// List the federation executions
void listFederations(RTIambassador& rtiAmb)
{
try
{
int count = 0;
theAmbData.listFederationsReturned = false;
rtiAmb.listFederationExecutions();
wcout << L"Waiting for reportFederationExecutions\n";
while (count < 100 && !theAmbData.listFederationsReturned)
{
rtiAmb.evokeMultipleCallbacks(0.1, 0.5);
count++;
}
if (!theAmbData.listFederationsReturned)
{
wcout << L"\nFailed to get reportFederationExecutions callback\n";
}
}
catch (RTIinternalError& ex)
{
// This fails in lightweight mode due to no rtiexec and is expected.
}
catch (Exception& ex)
{
wcout << L"RTI Exception: " << ex.what() << endl
<< L"\tCould not list federation executions!" << endl;
}
}
// Create the federation execution
void createFedEx(RTIambassador& rtiAmb, std::wstring const& fedName, std::wstring const& fedFile)
{
wcout << L"createFederationExecution " << fedName << L" " << fedFile << endl;
try
{
rtiAmb.createFederationExecution(fedName, fedFile);
}
catch (FederationExecutionAlreadyExists& ex)
{
wcout << L"FederationExecutionAlreadyExists: " << ex.what() << endl
<< L"\tCould not create federation execution!" << endl;
}
catch (Exception& ex)
{
wcout << L"RTI Exception: " << ex.what() << endl
<< L"\tCould not create federation execution!" << endl;
exit(0);
}
rtiAmb.evokeMultipleCallbacks(0.1, 0.2);
wcout << L"Federation Created." << endl;
}
// Join the federation execution
void joinFedEx(RTIambassador& rtiAmb, std::wstring const& federateType, std::wstring const& federationName)
{
bool joined = false;
const int maxTry = 10;
int numTries = 0;
wcout << L"joinFederationExecution " << federateType << L" " << federationName << endl;
while (!joined && numTries++ < maxTry)
{
try
{
theFederateHandle = rtiAmb.joinFederationExecution(federateType, federationName);
joined = true;
}
catch (FederationExecutionDoesNotExist)
{
wcout << L"FederationExecutionDoesNotExist, try " << numTries << L" out of " << maxTry << endl;
continue;
}
catch (Exception& ex)
{
wcout << L"RTI Exception: " << ex.what() << endl;
return;
}
rtiAmb.evokeMultipleCallbacks(0.1, 0.2);
}
if (joined)
{
wcout << L"Joined Federation." << endl;
}
else
{
wcout << L"Giving up." << endl;
rtiAmb.destroyFederationExecution(federationName);
exit(0);
}
}
// Resign and destroy the federation execution
void resignAndDestroy(RTIambassador& rtiAmb, std::wstring const& federationName)
{
wcout << L"Resign and Destroy Federation" << endl;
rtiAmb.resignFederationExecution(DELETE_OBJECTS);
rtiAmb.destroyFederationExecution(federationName);
rtiAmb.disconnect();
}
// Publish and subscribe the object class attributes.
// Register an object instance of the class.
bool publishSubscribeAndRegisterObject(RTIambassador& rtiAmb)
{
// Get the object class handle
try
{
theClassHandle = rtiAmb.getObjectClassHandle(theClassName);
theAmbData.objectClassMap[theClassHandle] = theClassName;
}
catch (Exception& ex)
{
wcout << L"RTI Exception: " << ex.what() << endl
<< L"\tCould not get object class handle: " << theClassName << endl;
return false;
}
// Get the attribute handles and construct the name-handle map and attribute set
std::wstring attrName;
try
{
attrName = L"AccelerationVector";
theAttrNameHandleMap[attrName] = rtiAmb.getAttributeHandle(theClassHandle, attrName);
hSet.insert(theAttrNameHandleMap[attrName]);
attrName = L"VelocityVector";
theAttrNameHandleMap[attrName] = rtiAmb.getAttributeHandle(theClassHandle, attrName);
hSet.insert(theAttrNameHandleMap[attrName]);
attrName = L"Orientation";
theAttrNameHandleMap[attrName] = rtiAmb.getAttributeHandle(theClassHandle, attrName);
hSet.insert(theAttrNameHandleMap[attrName]);
attrName = L"DeadReckoningAlgorithm";
theAttrNameHandleMap[attrName] = rtiAmb.getAttributeHandle(theClassHandle, attrName);
hSet.insert(theAttrNameHandleMap[attrName]);
attrName = L"WorldLocation";
theAttrNameHandleMap[attrName] = rtiAmb.getAttributeHandle(theClassHandle, attrName);
hSet.insert(theAttrNameHandleMap[attrName]);
}
catch (Exception& ex)
{
wcout << L"RTI Exception: " << ex.what() << endl
<< L"\tCould not get attribute handle " << attrName << endl;
return false;
}
// Publish and subscribe
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 (Exception& ex)
{
wcout << L"RTI Exception: " << ex.what() << endl
<< L"\tCould not " << (cnt ? L"subscribe" : L"publish") << endl;
return false;
}
std::wstring objectName(L"Talk");
// Reserve object name and register the object instance
try
{
unsigned int objId = abs(getpid());
std::wstringstream pid;
pid << objId;
objectName += pid.str();
theAmbData.nameReservationReturned =
theAmbData.nameReservationSucceeded = false;
try
{
rtiAmb.reserveObjectInstanceName(objectName);
}
catch (RTIinternalError& ex)
{
// This fails in lightweight mode due to no rtiexec and is expected.
theAmbData.nameReservationReturned =
theAmbData.nameReservationSucceeded = true;
}
wcout << L"Waiting for objectInstanceNameReservationSucceeded\n";
int count = 0;
while (count++ < 100 && !theAmbData.nameReservationReturned)
{
rtiAmb.evokeMultipleCallbacks(0.1, 0.2);
}
if (theAmbData.nameReservationSucceeded)
{
theObjectHandle = rtiAmb.registerObjectInstance(theClassHandle, objectName);
// Add name-handle to map
theAmbData.objectInstanceMap[theObjectHandle] = rtiAmb.getObjectInstanceName(theObjectHandle);
}
else if (theAmbData.nameReservationReturned)
{
wcout << L"Object name reservation failed for " << objectName << endl;
return false;
}
else
{
wcout << L"Failed waiting for reserve object name " << objectName << endl;
return false;
}
rtiAmb.evokeMultipleCallbacks(0.1, 0.2);
}
catch (Exception& ex)
{
wcout << L"RTI Exception: " << ex.what() << endl
<< L"\tCould not Register Object " << objectName << L" with class " << theClassName << endl;
return false;
}
wcout << L"Registered object " << objectName << L" with class name " << theClassName << endl;
return true;
}
// Publish and Subscribe to an interaction class
bool publishAndSubscribeInteraction(RTIambassador& rtiAmb)
{
// Get the interaction class handle
try
{
theInterClassHandle = rtiAmb.getInteractionClassHandle(theInterClassName);
}
catch (Exception& ex)
{
wcout << L"RTI Exception: " << ex.what() << endl
<< L"\tCould not get interaction class handle: " << theInterClassName << endl;
return false;
}
// Get the parameter handles and construct the name-handle map
std::wstring paramName;
try
{
paramName = L"EventIdentifier";
theParamNameHandleMap[paramName] = rtiAmb.getParameterHandle(theInterClassHandle, paramName);
paramName = L"FireControlSolutionRange";
theParamNameHandleMap[paramName] = rtiAmb.getParameterHandle(theInterClassHandle, paramName);
paramName = L"FireMissionIndex";
theParamNameHandleMap[paramName] = rtiAmb.getParameterHandle(theInterClassHandle, paramName);
paramName = L"FiringLocation";
theParamNameHandleMap[paramName] = rtiAmb.getParameterHandle(theInterClassHandle, paramName);
paramName = L"FiringObjectIdentifier";
theParamNameHandleMap[paramName] = rtiAmb.getParameterHandle(theInterClassHandle, paramName);
paramName = L"FuseType";
theParamNameHandleMap[paramName] = rtiAmb.getParameterHandle(theInterClassHandle, paramName);
paramName = L"InitialVelocityVector";
theParamNameHandleMap[paramName] = rtiAmb.getParameterHandle(theInterClassHandle, paramName);
paramName = L"MunitionObjectIdentifier";
theParamNameHandleMap[paramName] = rtiAmb.getParameterHandle(theInterClassHandle, paramName);
paramName = L"MunitionType";
theParamNameHandleMap[paramName] = rtiAmb.getParameterHandle(theInterClassHandle, paramName);
paramName = L"QuantityFired";
theParamNameHandleMap[paramName] = rtiAmb.getParameterHandle(theInterClassHandle, paramName);
paramName = L"RateOfFire";
theParamNameHandleMap[paramName] = rtiAmb.getParameterHandle(theInterClassHandle, paramName);
paramName = L"TargetObjectIdentifier";
theParamNameHandleMap[paramName] = rtiAmb.getParameterHandle(theInterClassHandle, paramName);
paramName = L"WarheadType";
theParamNameHandleMap[paramName] = rtiAmb.getParameterHandle(theInterClassHandle, paramName);
}
catch (Exception& ex)
{
wcout << L"RTI Exception: " << ex.what() << endl
<< L"\tCould not get parameter handle " << paramName << endl;
return false;
}
// Publish and subscribe
int cnt = 0;
try
{
rtiAmb.publishInteractionClass(theInterClassHandle);
rtiAmb.evokeMultipleCallbacks(0.1, 0.2);
cnt = 1;
rtiAmb.subscribeInteractionClass(theInterClassHandle);
rtiAmb.evokeMultipleCallbacks(0.1, 0.2);
}
catch (Exception& ex)
{
wcout << L"RTI Exception: " << ex.what() << endl
<< L"\tCould not " << (cnt ? L"publish" : L"subscribe") << L" to interaction class." << endl;
return false;
}
wcout << L"Subscribed to interaction class: " << theInterClassName << L" with handle: "
<< theInterClassHandle.toString() << endl;
return true;
}
int main(int argc, char** argv)
{
std::cout << "MAK rtiSimple version 1516e" << std::endl;
RTIambassador* rtiAmb = 0;
try
{
// Federate and Federation info
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 << L"\" "
<< L"\"" << federationFile << L"\" "
<< L"\"" << federateType << L"\" " << endl;
return 0;
}
federationName = DtToWString(argv[1]);
}
if (argc > 2)
{
federationFile = DtToWString(argv[2]);
}
if (argc > 3)
{
federateType = DtToWString(argv[3]);
}
if (argc > 4)
{
for (int argIndex = 4; argIndex < argc; ++argIndex)
{
localSettingsDesignator += L" ";
localSettingsDesignator += DtToWString(argv[argIndex]);
}
}
wcout << L"Using " << rtiName() << L" " << rtiVersion() << L"\n";
theAmbData.clear();
// RTI and Federate Ambassadors
RTIambassadorFactory* rtiAmbFactory = new RTIambassadorFactory();
std::auto_ptr<RTIambassador> rtiAmbAP = rtiAmbFactory->createRTIambassador();
rtiAmb = rtiAmbAP.release();
MyFederateAmbassador fedAmb(theAmbData);
#ifdef WIN32
WSADATA data;
WSAStartup(MAKEWORD(1, 1), &data);
#endif
rtiAmb->evokeCallback(0.0);
long count = 0;
bool doConnect = true;
bool connected = false;
while (1)
{
if (doConnect)
{
doConnect = false;
// Connect
if (!connect(*rtiAmb, fedAmb, localSettingsDesignator))
{
wcout << L"Connect to RTI failed!" << endl;
continue;
}
// List the federations
listFederations(*rtiAmb);
// Create the federation
createFedEx(*rtiAmb, federationName, federationFile);
// Join the federation
joinFedEx(*rtiAmb, federateType, federationName);
// Publish, subscribe and register and object
if (!publishSubscribeAndRegisterObject(*rtiAmb))
{
resignAndDestroy(*rtiAmb, federationName);
if (rtiAmb != 0)
{
delete rtiAmb;
rtiAmb = 0;
}
return 0;
}
// Publish and subscribe to the required interaction
if (!publishAndSubscribeInteraction(*rtiAmb))
{
resignAndDestroy(*rtiAmb, federationName);
if (rtiAmb != 0)
{
delete rtiAmb;
rtiAmb = 0;
}
return 0;
}
// Construct an attribute handle value pair set with the values containing the attribute names
attrValues.clear();
DtAttrNameHandleMap::iterator attrIter = theAttrNameHandleMap.begin();
DtAttrNameHandleMap::iterator attrEnd = theAttrNameHandleMap.end();
for (; attrIter != attrEnd; attrIter++)
{
// Attribute values will be just the name of the attribute.
// Format is narrow string representation of attribute name to remain compatible with 1.3 simple federate
std::string temp = DtToString(attrIter->first);
attrValues[attrIter->second].setData(temp.c_str(), temp.length() + 1);
}
// Construct a parameter handle value pair set with the values containing the parameter names
paramValues.clear();
DtParamNameHandleMap::iterator paramIter = theParamNameHandleMap.begin();
DtParamNameHandleMap::iterator paramEnd = theParamNameHandleMap.end();
for ( ; paramIter != paramEnd; paramIter++)
{
// Parameter values will be just the name of the attribute.
// Format is narrow string representation of parameter name to remain compatible with 1.3 simple federate
std::string temp = DtToString(paramIter->first);
paramValues[paramIter->second].setData(temp.c_str(), temp.length() + 1);
}
connected = true;
}
else if (connected)
{
// Tag format is narrow string representation compatible with 1.3 simple federate
std::stringstream ss;
ss << "1516-" << count++;
std::string tag(ss.str());
// Update the object
rtiAmb->updateAttributeValues(theObjectHandle, attrValues, VariableLengthData(tag.c_str(), tag.size() + 1));
// Send an interaction every few passes
if (count % 5 == 0)
{
wcout << L"Sending interaction..." << endl;
rtiAmb->sendInteraction(theInterClassHandle, paramValues, VariableLengthData(tag.c_str(), tag.size() + 1));
}
rtiAmb->evokeMultipleCallbacks(0.1, 0.5);
}
int key = theInput.keybrdTick();
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 (Exception& ex)
{
wcout << L"RTI Exception: " << ex.what() << endl;
}
}
}
#ifdef WIN32
Sleep(2000);
#else
sleep(2);
#endif
}
if (connected)
{
// Resign and destroy federation
resignAndDestroy(*rtiAmb, federationName);
}
}
catch (Exception& ex)
{
wcout << L"RTI Exception (main loop): " << ex.what() << endl;
}
if (rtiAmb != 0)
{
delete rtiAmb;
rtiAmb = 0;
}
#ifdef WIN32
WSACleanup();
#endif
return 0;
}

rtiSimpleFedAmb1516e.cxx

/*******************************************************************************
** Copyright (c) 2010 MaK Technologies, Inc.
** All rights reserved.
*******************************************************************************/
#pragma warning(disable: 4251)
#pragma warning(disable: 4786)
#pragma warning(disable: 4290)
#include <iostream>
using namespace std;
using namespace rti1516e;
void printAttrValues(AttributeHandleValueMap const& attrVals)
{
AttributeHandleValueMap::const_iterator iter;
for (iter = attrVals.begin(); iter != attrVals.end(); iter++)
{
wcout << L"\t" << iter->first.toString() << L" " << DtToWString((char*)iter->second.data()) << endl;
}
}
void printParamValues(ParameterHandleValueMap const& paramVals)
{
ParameterHandleValueMap::const_iterator iter;
for (iter = paramVals.begin(); iter != paramVals.end(); iter++)
{
wcout << L"\t" << iter->first.toString() << L" " << DtToWString((char*)iter->second.data()) << endl;
}
}
: NullFederateAmbassador(), myData(data)
{
}
throw ()
{
}
std::wstring const& faultDescription)
throw (FederateInternalError)
{
wcout << L"\nconnectionLost: " << faultDescription << std::endl;
myData.connectionLost = true;
}
FederationExecutionInformationVector const& theFederationExecutionInformationList)
throw (FederateInternalError)
{
myData.listFederationsReturned = true;
wcout << L"\nreportFederationExecutions \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;
}
}
std::wstring const& theObjectInstanceName)
throw (FederateInternalError)
{
wcout << L"\nobjectInstanceNameReservationSucceeded: " << theObjectInstanceName << endl;
myData.nameReservationReturned =
myData.nameReservationSucceeded = true;
}
std::wstring const& theObjectInstanceName)
throw (FederateInternalError)
{
wcout << L"\nobjectInstanceNameReservationFailed: " << theObjectInstanceName << endl;
myData.nameReservationReturned = true;
myData.nameReservationSucceeded = false;
}
ObjectInstanceHandle theObject,
ObjectClassHandle theObjectClass,
std::wstring const& theObjectInstanceName)
throw (FederateInternalError)
{
wcout << L"\ndiscoverObjectInstance: "
<< theObjectInstanceName << L"("
<< theObject.toString() << L") of class "
<< myData.objectClassMap[theObjectClass] << L"( "
<< theObjectClass.toString() << L")" << endl;
myData.objectInstanceMap[theObject] = theObjectInstanceName;
}
ObjectInstanceHandle theObject,
ObjectClassHandle theObjectClass,
std::wstring const& theObjectInstanceName,
FederateHandle producingFederate)
throw (FederateInternalError)
{
wcout << L"\ndiscoverObjectInstance: "
<< theObjectInstanceName << L"("
<< theObject.toString() << L") of class "
<< myData.objectClassMap[theObjectClass] << L"( "
<< theObjectClass.toString() << L")"
<< L" produced by " << producingFederate.toString()
<< endl;
myData.objectInstanceMap[theObject] = theObjectInstanceName;
}
ObjectInstanceHandle theObject,
AttributeHandleValueMap const& theAttributeValues,
VariableLengthData const& theUserSuppliedTag,
OrderType sentOrder,
SupplementalReflectInfo theReflectInfo)
throw (FederateInternalError)
{
const char* tag = theUserSuppliedTag.size() ? (const char*)theUserSuppliedTag.data() : "";
wcout << L"\nreflectAttributeValues: "
<< myData.objectInstanceMap[theObject] << L"("
<< theObject.toString() << L") "
<< DtToWString(tag) << 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,
AttributeHandleValueMap const& theAttributeValues,
VariableLengthData const& theUserSuppliedTag,
OrderType sentOrder,
LogicalTime const& theTime,
OrderType receivedOrder,
SupplementalReflectInfo theReflectInfo)
throw (FederateInternalError)
{
const char* tag = theUserSuppliedTag.size() ? (const char*)theUserSuppliedTag.data() : "";
wcout << L"\nreflectAttributeValues: "
<< myData.objectInstanceMap[theObject] << L"("
<< theObject.toString() << L") "
<< DtToWString(tag) << L" "
<< (sentOrder == RECEIVE ? L"RECEIVE " : L"TIMESTAMP ")
<< (theType == RELIABLE ? L"RELIABLE " : L"BEST_EFFORT ")
<< theTime.toString() << 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,
AttributeHandleValueMap const& theAttributeValues,
VariableLengthData const& theUserSuppliedTag,
OrderType sentOrder,
LogicalTime const& theTime,
OrderType receivedOrder,
MessageRetractionHandle theHandle,
SupplementalReflectInfo theReflectInfo)
throw (FederateInternalError)
{
const char* tag = theUserSuppliedTag.size() ? (const char*)theUserSuppliedTag.data() : "";
wcout << L"\nreflectAttributeValues: "
<< myData.objectInstanceMap[theObject] << L"("
<< theObject.toString() << L") "
<< DtToWString(tag) << 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() << 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);
}
// 6.9
InteractionClassHandle theInteraction,
ParameterHandleValueMap const& theParameterValues,
VariableLengthData const& theUserSuppliedTag,
OrderType sentOrder,
SupplementalReceiveInfo theReceiveInfo)
throw (FederateInternalError)
{
const char* tag = theUserSuppliedTag.size() ? (const char*)theUserSuppliedTag.data() : "";
wcout << L"\nreceiveInteraction: "
<< theInteraction.toString() << L" "
<< DtToWString(tag) << 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,
ParameterHandleValueMap const& theParameterValues,
VariableLengthData const& theUserSuppliedTag,
OrderType sentOrder,
LogicalTime const& theTime,
OrderType receivedOrder,
SupplementalReceiveInfo theReceiveInfo)
throw (FederateInternalError)
{
const char* tag = theUserSuppliedTag.size() ? (const char*)theUserSuppliedTag.data() : "";
wcout << L"\nreceiveInteraction: "
<< theInteraction.toString() << L" "
<< DtToWString(tag) << 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,
ParameterHandleValueMap const& theParameterValues,
VariableLengthData const& theUserSuppliedTag,
OrderType sentOrder,
LogicalTime const& theTime,
OrderType receivedOrder,
MessageRetractionHandle theHandle,
SupplementalReceiveInfo theReceiveInfo)
throw (FederateInternalError)
{
const char* tag = theUserSuppliedTag.size() ? (const char*)theUserSuppliedTag.data() : "";
wcout << L"\nreceiveInteraction: "
<< theInteraction.toString() << L" "
<< DtToWString(tag) << 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() << 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,
VariableLengthData const& theUserSuppliedTag,
OrderType sentOrder,
SupplementalRemoveInfo theRemoveInfo)
throw (FederateInternalError)
{
const char* tag = theUserSuppliedTag.size() ? (const char*)theUserSuppliedTag.data() : "";
wcout << L"\nremoveObjectInstance: "
<< myData.objectInstanceMap[theObject] << L"("
<< theObject.toString() << L") "
<< DtToWString(tag) << L" "
<< (sentOrder == RECEIVE ? L"RECEIVE " : L"TIMESTAMP ")
<< (theRemoveInfo.hasProducingFederate ? L"produced by " : L" ")
<< (theRemoveInfo.hasProducingFederate ? theRemoveInfo.producingFederate.toString() : L"")
<< endl;
}
ObjectInstanceHandle theObject,
VariableLengthData const& theUserSuppliedTag,
OrderType sentOrder,
LogicalTime const& theTime,
OrderType receivedOrder,
SupplementalRemoveInfo theRemoveInfo)
throw (FederateInternalError)
{
const char* tag = theUserSuppliedTag.size() ? (const char*)theUserSuppliedTag.data() : "";
wcout << L"\nremoveObjectInstance: "
<< myData.objectInstanceMap[theObject] << L"("
<< theObject.toString() << L") "
<< DtToWString(tag) << L" "
<< (sentOrder == RECEIVE ? L"RECEIVE " : L"TIMESTAMP ")
<< theTime.toString() << L" "
<< (receivedOrder == RECEIVE ? L"RECEIVE " : L"TIMESTAMP ")
<< (theRemoveInfo.hasProducingFederate ? L"produced by " : L" ")
<< (theRemoveInfo.hasProducingFederate ? theRemoveInfo.producingFederate.toString() : L"")
<< endl;
}
ObjectInstanceHandle theObject,
VariableLengthData const& theUserSuppliedTag,
OrderType sentOrder,
LogicalTime const& theTime,
OrderType receivedOrder,
MessageRetractionHandle theHandle,
SupplementalRemoveInfo theRemoveInfo)
throw (FederateInternalError)
{
const char* tag = theUserSuppliedTag.size() ? (const char*)theUserSuppliedTag.data() : "";
wcout << L"\nremoveObjectInstance: "
<< myData.objectInstanceMap[theObject] << L"("
<< theObject.toString() << L") "
<< DtToWString(tag) << L" "
<< (sentOrder == RECEIVE ? L"RECEIVE " : L"TIMESTAMP ")
<< theTime.toString() << L" " << (receivedOrder == RECEIVE ? L"RECEIVE " : L"TIMESTAMP ")
<< theHandle.toString()
<< (theRemoveInfo.hasProducingFederate ? L"produced by " : L" ")
<< (theRemoveInfo.hasProducingFederate ? theRemoveInfo.producingFederate.toString() : L"")
<< endl;
}

rtiSimpleKeyboard.cxx

/*******************************************************************************
* Adapted from "Beginning Linux Programming", from Wrox Press -- www.wrox.com
*******************************************************************************/
#ifdef WIN32
#include <conio.h>
#else
#include <unistd.h>
#endif
{
#ifndef WIN32
tcgetattr(0,&initial_settings);
new_settings = initial_settings;
new_settings.c_lflag &= ~ICANON;
new_settings.c_lflag &= ~ECHO;
new_settings.c_lflag &= ~ISIG;
new_settings.c_cc[VMIN] = 1;
new_settings.c_cc[VTIME] = 0;
tcsetattr(0, TCSANOW, &new_settings);
#endif
}
{
#ifndef WIN32
tcsetattr(0, TCSANOW, &initial_settings);
#endif
}
{
#ifdef WIN32
return _kbhit();
#else
unsigned char ch;
int nread;
if (peek_character != -1) return 1;
new_settings.c_cc[VMIN]=0;
tcsetattr(0, TCSANOW, &new_settings);
nread = read(0,&ch,1);
new_settings.c_cc[VMIN]=1;
tcsetattr(0, TCSANOW, &new_settings);
if (nread == 1)
{
return 1;
}
return 0;
#endif
}
{
char ch;
#ifdef WIN32
ch = _getch();
#else
if (peek_character != -1)
{
}
else
read(0,&ch,1);
#endif
return ch;
}
{
char key = ' ';
if (!kbhit())
return 0;
key = getkey();
while (key != 'q' && key != 'Q' && kbhit())
key = getkey();
return (key == 'q' || key == 'Q') ? -1 : key;
}

rtiSimpleFedAmb1516e.h

/*******************************************************************************
** Copyright (c) 2010 MaK Technologies, Inc.
** All rights reserved.
*******************************************************************************/
#pragma once
#pragma warning(disable: 4251)
#pragma warning(disable: 4786)
#pragma warning(disable: 4290)
#include <RTI/RTI1516.h>
#include <string>
#include <map>
{
public:
std::map<rti1516e::ObjectClassHandle, std::wstring> objectClassMap;
std::map<rti1516e::ObjectInstanceHandle, std::wstring> objectInstanceMap;
{
clear();
}
void clear()
{
objectClassMap.clear();
}
};
class MyFederateAmbassador : public rti1516e::NullFederateAmbassador
{
public:
throw ();
// 4.4
virtual void connectionLost(
std::wstring const& faultDescription)
throw (rti1516e::FederateInternalError);
// 4.8
rti1516e::FederationExecutionInformationVector const& theFederationExecutionInformationList)
throw (rti1516e::FederateInternalError);
// 6.3
std::wstring const& theObjectInstanceName)
throw (rti1516e::FederateInternalError);
std::wstring const& theObjectInstanceName)
throw (rti1516e::FederateInternalError);
// 6.9
virtual void discoverObjectInstance(
rti1516e::ObjectInstanceHandle theObject,
rti1516e::ObjectClassHandle theObjectClass,
std::wstring const& theObjectInstanceName)
throw (rti1516e::FederateInternalError);
virtual void discoverObjectInstance(
rti1516e::ObjectInstanceHandle theObject,
rti1516e::ObjectClassHandle theObjectClass,
std::wstring const& theObjectInstanceName,
rti1516e::FederateHandle producingFederate)
throw (rti1516e::FederateInternalError);
// 6.11
virtual void reflectAttributeValues(
rti1516e::ObjectInstanceHandle theObject,
rti1516e::AttributeHandleValueMap const& theAttributeValues,
rti1516e::VariableLengthData const& theUserSuppliedTag,
rti1516e::OrderType sentOrder,
rti1516e::TransportationType theType,
rti1516e::SupplementalReflectInfo theReflectInfo)
throw (rti1516e::FederateInternalError);
virtual void reflectAttributeValues(
rti1516e::ObjectInstanceHandle theObject,
rti1516e::AttributeHandleValueMap const& theAttributeValues,
rti1516e::VariableLengthData const& theUserSuppliedTag,
rti1516e::OrderType sentOrder,
rti1516e::TransportationType theType,
rti1516e::LogicalTime const& theTime,
rti1516e::OrderType receivedOrder,
rti1516e::SupplementalReflectInfo theReflectInfo)
throw (rti1516e::FederateInternalError);
virtual void reflectAttributeValues(
rti1516e::ObjectInstanceHandle theObject,
rti1516e::AttributeHandleValueMap const& theAttributeValues,
rti1516e::VariableLengthData const& theUserSuppliedTag,
rti1516e::OrderType sentOrder,
rti1516e::TransportationType theType,
rti1516e::LogicalTime const& theTime,
rti1516e::OrderType receivedOrder,
rti1516e::MessageRetractionHandle theHandle,
rti1516e::SupplementalReflectInfo theReflectInfo)
throw (rti1516e::FederateInternalError);
// 6.13
virtual void receiveInteraction(
rti1516e::InteractionClassHandle theInteraction,
rti1516e::ParameterHandleValueMap const& theParameterValues,
rti1516e::VariableLengthData const& theUserSuppliedTag,
rti1516e::OrderType sentOrder,
rti1516e::TransportationType theType,
rti1516e::SupplementalReceiveInfo theReceiveInfo)
throw (rti1516e::FederateInternalError);
virtual void receiveInteraction(
rti1516e::InteractionClassHandle theInteraction,
rti1516e::ParameterHandleValueMap const& theParameterValues,
rti1516e::VariableLengthData const& theUserSuppliedTag,
rti1516e::OrderType sentOrder,
rti1516e::TransportationType theType,
rti1516e::LogicalTime const& theTime,
rti1516e::OrderType receivedOrder,
rti1516e::SupplementalReceiveInfo theReceiveInfo)
throw (rti1516e::FederateInternalError);
virtual void receiveInteraction(
rti1516e::InteractionClassHandle theInteraction,
rti1516e::ParameterHandleValueMap const& theParameterValues,
rti1516e::VariableLengthData const& theUserSuppliedTag,
rti1516e::OrderType sentOrder,
rti1516e::TransportationType theType,
rti1516e::LogicalTime const& theTime,
rti1516e::OrderType receivedOrder,
rti1516e::MessageRetractionHandle theHandle,
rti1516e::SupplementalReceiveInfo theReceiveInfo)
throw (rti1516e::FederateInternalError);
// 6.15
virtual void removeObjectInstance(
rti1516e::ObjectInstanceHandle theObject,
rti1516e::VariableLengthData const& theUserSuppliedTag,
rti1516e::OrderType sentOrder,
rti1516e::SupplementalRemoveInfo theRemoveInfo)
throw (rti1516e::FederateInternalError);
virtual void removeObjectInstance(
rti1516e::ObjectInstanceHandle theObject,
rti1516e::VariableLengthData const& theUserSuppliedTag,
rti1516e::OrderType sentOrder,
rti1516e::LogicalTime const& theTime,
rti1516e::OrderType receivedOrder,
rti1516e::SupplementalRemoveInfo theRemoveInfo)
throw (rti1516e::FederateInternalError);
virtual void removeObjectInstance(
rti1516e::ObjectInstanceHandle theObject,
rti1516e::VariableLengthData const& theUserSuppliedTag,
rti1516e::OrderType sentOrder,
rti1516e::LogicalTime const& theTime,
rti1516e::OrderType receivedOrder,
rti1516e::MessageRetractionHandle theHandle,
rti1516e::SupplementalRemoveInfo theRemoveInfo)
throw (rti1516e::FederateInternalError);
public:
DtSimpleData& myData;
};

rtiSimpleKeyboard.h

/*******************************************************************************
* Adapted from "Beginning Linux Programming", from Wrox Press -- www.wrox.com
*******************************************************************************/
// Utility to allow keyboard input without blocking
#ifndef MYKBHIT_H_
#define MYKBHIT_H_
#ifndef WIN32
#include <termios.h>
#endif
class keyboard
{
public:
// Returns 1 if keyboard input is ready; otherwise, 0
int kbhit();
// Returns character from keyboard if avaialable; otherwise, 0
int keybrdTick();
protected:
// Return character from keyboard input
int getkey();
private:
#ifndef WIN32
struct termios initial_settings, new_settings;
#endif
};
#endif

rtiSimpleStringUtil.h

/*******************************************************************************
** Copyright (c) 2010 MaK Technologies, Inc.
** All rights reserved.
*******************************************************************************/
#ifndef stringUtil_H_
#define stringUtil_H_
#include <string>
#include <sstream>
// Convert narrow C string to wide string
inline std::wstring DtToWString(const char * in_val)
{
std::wstring temp;
while (*in_val != '\0')
temp += *in_val++;
return temp;
}
// Convert narrow string to wide string
inline std::string DtToString(const std::wstring &in_val)
{
std::string temp;
std::wstring::const_iterator b = in_val.begin();
const std::wstring::const_iterator e = in_val.end();
while (b != e)
{
temp += static_cast<char>(*b);
++b;
}
return temp;
}
#endif

Document ID: Generated on Sun Jul 20 16:15:30 EDT 2025 from SVN revision 277985
Copyright © 2005-2025 MAK Technologies Inc. All Rights Reserved (www.mak.com)