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

rtiSimple1516.cxx and rtiSimpleFedAmb1516.cxx (rtiSimpleFedAmb1516.h) have the RTI calls and federate ambassador calls for the HLA 1516 version of rtisimple.

This page has the code for the following files:


rtiSimple1516.cxx

/*******************************************************************************
** Copyright (c) 2004 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 rti1516;
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;
// 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, MyFederateAmbassador& fedAmb, 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, fedAmb);
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
<< "\tCould not join federation execution!" << endl;
exit(0);
}
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.destroyFederationExecution(federationName);
}
// 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 1516" << std::endl;
RTIambassador* rtiAmb = 0;
try
{
// Federate and Federation info
std::wstring federationName(L"MAKsimple");
std::wstring federationFile(L"MAKsimple.xml");
std::wstring federateType(L"rtisimple1516");
std::vector<std::wstring> args;
if (argc > 1)
{
if (strcmp(argv[1], "-h") == 0)
{
wcout << L"Usage: rtisimple1516 [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]);
}
wcout << L"Using " << RTIname() << L" " << RTIversion() << L"\n";
theAmbData.clear();
#ifdef WIN32
WSADATA data;
WSAStartup(MAKEWORD(1, 1), &data);
#endif
// RTI and Federate Ambassadors
std::auto_ptr< RTIambassador > rtiAmbAP = rtiAmbFactory->createRTIambassador(args);
rtiAmb = rtiAmbAP.release();
MyFederateAmbassador fedAmb(theAmbData);
rtiAmb->evokeCallback(0.0);
long count=0;
bool doConnect = true;
bool connected = false;
while (1)
{
if (doConnect)
{
doConnect = false;
// Create the federation
createFedEx(*rtiAmb, federationName, federationFile);
// Join the federation
joinFedEx(*rtiAmb, fedAmb, 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;
}

rtiSimpleFedAmb1516.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 rti1516;
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& theObjectInstanceName)
throw (UnknownName, FederateInternalError)
{
wcout << L"objectInstanceNameReservationSucceeded: " << theObjectInstanceName << endl;
myData.nameReservationReturned =
myData.nameReservationSucceeded = true;
}
std::wstring const& theObjectInstanceName)
throw (UnknownName, FederateInternalError)
{
wcout << L"objectInstanceNameReservationFailed: " << theObjectInstanceName << endl;
myData.nameReservationReturned = true;
myData.nameReservationSucceeded = false;
}
ObjectInstanceHandle theObject,
ObjectClassHandle theObjectClass,
std::wstring const& theObjectInstanceName)
throw (CouldNotDiscover, ObjectClassNotKnown, FederateInternalError)
{
wcout << L"discoverObjectInstance: "
<< theObjectInstanceName << L"("
<< theObject.toString() << L") of class "
<< myData.objectClassMap[theObjectClass] << L"( "
<< theObjectClass.toString() << L")" << endl;
myData.objectInstanceMap[theObject] = theObjectInstanceName;
}
ObjectInstanceHandle theObject,
AttributeHandleValueMap const& theAttributeValues,
VariableLengthData const& theUserSuppliedTag,
OrderType sentOrder,
throw (ObjectInstanceNotKnown, AttributeNotRecognized, AttributeNotSubscribed, FederateInternalError)
{
const char* tag = theUserSuppliedTag.size() ? (const char*)theUserSuppliedTag.data() : "";
wcout << L"reflectAttributeValues h v u o p: "
<< myData.objectInstanceMap[theObject] << L"("
<< theObject.toString() << L") "
<< DtToWString(tag) << L" "
<< (sentOrder == RECEIVE ? L"RECEIVE " : L"TIMESTAMP ")
<< (theType == RELIABLE ? L"RELIABLE " : L"BEST_EFFORT ")
<< L"#attributes: " << theAttributeValues.size() << endl;
printAttrValues(theAttributeValues);
}
ObjectInstanceHandle theObject,
AttributeHandleValueMap const& theAttributeValues,
VariableLengthData const& theUserSuppliedTag,
OrderType sentOrder,
RegionHandleSet const& theSentRegionHandleSet)
throw (ObjectInstanceNotKnown, AttributeNotRecognized, AttributeNotSubscribed, FederateInternalError)
{
const char* tag = theUserSuppliedTag.size() ? (const char*)theUserSuppliedTag.data() : "";
wcout << L"reflectAttributeValues h v u o p r: "
<< myData.objectInstanceMap[theObject] << L"("
<< theObject.toString() << L") "
<< DtToWString(tag) << L" "
<< (sentOrder == RECEIVE ? L"RECEIVE " : L"TIMESTAMP ")
<< (theType == RELIABLE ? L"RELIABLE " : L"BEST_EFFORT ")
<< L"#regions: " << theSentRegionHandleSet.size() << L" "
<< L"#attributes: " << theAttributeValues.size() << endl;
printAttrValues(theAttributeValues);
}
ObjectInstanceHandle theObject,
AttributeHandleValueMap const& theAttributeValues,
VariableLengthData const& theUserSuppliedTag,
OrderType sentOrder,
LogicalTime const& theTime,
OrderType receivedOrder)
throw (ObjectInstanceNotKnown, AttributeNotRecognized, AttributeNotSubscribed, FederateInternalError)
{
const char* tag = theUserSuppliedTag.size() ? (const char*)theUserSuppliedTag.data() : "";
wcout << L"reflectAttributeValues h v u o p t o: "
<< 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 ")
<< L"#attributes: " << theAttributeValues.size() << endl;
printAttrValues(theAttributeValues);
}
ObjectInstanceHandle theObject,
AttributeHandleValueMap const& theAttributeValues,
VariableLengthData const& theUserSuppliedTag,
OrderType sentOrder,
LogicalTime const& theTime,
OrderType receivedOrder,
RegionHandleSet const& theSentRegionHandleSet)
throw (ObjectInstanceNotKnown, AttributeNotRecognized, AttributeNotSubscribed, FederateInternalError)
{
const char* tag = theUserSuppliedTag.size() ? (const char*)theUserSuppliedTag.data() : "";
wcout << L"reflectAttributeValues h v u o p t o r: "
<< 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 ")
<< L"#regions: " << theSentRegionHandleSet.size() << L" "
<< L"#attributes: " << theAttributeValues.size() << endl;
printAttrValues(theAttributeValues);
}
ObjectInstanceHandle theObject,
AttributeHandleValueMap const& theAttributeValues,
VariableLengthData const& theUserSuppliedTag,
OrderType sentOrder,
LogicalTime const& theTime,
OrderType receivedOrder,
MessageRetractionHandle theHandle)
throw (ObjectInstanceNotKnown, AttributeNotRecognized, AttributeNotSubscribed, InvalidLogicalTime, FederateInternalError)
{
const char* tag = theUserSuppliedTag.size() ? (const char*)theUserSuppliedTag.data() : "";
wcout << L"reflectAttributeValues h v u o p t o m: "
<< 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" "
<< L"#attributes: " << theAttributeValues.size() << endl;
printAttrValues(theAttributeValues);
}
ObjectInstanceHandle theObject,
AttributeHandleValueMap const& theAttributeValues,
VariableLengthData const& theUserSuppliedTag,
OrderType sentOrder,
LogicalTime const& theTime,
OrderType receivedOrder,
MessageRetractionHandle theHandle,
RegionHandleSet const& theSentRegionHandleSet)
throw (ObjectInstanceNotKnown, AttributeNotRecognized, AttributeNotSubscribed, InvalidLogicalTime, FederateInternalError)
{
const char* tag = theUserSuppliedTag.size() ? (const char*)theUserSuppliedTag.data() : "";
wcout << L"reflectAttributeValues h v u o p t o m r: "
<< 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" "
<< theHandle.toString() << L" "
<< L"#regions: " << theSentRegionHandleSet.size() << L" "
<< L"#attributes: " << theAttributeValues.size() << endl;
printAttrValues(theAttributeValues);
}
// 6.9
InteractionClassHandle theInteraction,
ParameterHandleValueMap const& theParameterValues,
VariableLengthData const& theUserSuppliedTag,
OrderType sentOrder,
throw (InteractionClassNotRecognized, InteractionParameterNotRecognized, InteractionClassNotSubscribed, FederateInternalError)
{
const char* tag = theUserSuppliedTag.size() ? (const char*)theUserSuppliedTag.data() : "";
wcout << L"receiveInteraction: "
<< theInteraction.toString() << L" "
<< DtToWString(tag) << L" "
<< (sentOrder == RECEIVE ? L"RECEIVE " : L"TIMESTAMP ")
<< (theType == RELIABLE ? L"RELIABLE " : L"BEST_EFFORT ")
<< L"#parameters: " << theParameterValues.size() << endl;
printParamValues(theParameterValues);
}
InteractionClassHandle theInteraction,
ParameterHandleValueMap const& theParameterValues,
VariableLengthData const& theUserSuppliedTag,
OrderType sentOrder,
RegionHandleSet const& theSentRegionHandleSet)
throw (InteractionClassNotRecognized, InteractionParameterNotRecognized, InteractionClassNotSubscribed,
FederateInternalError)
{
const char* tag = theUserSuppliedTag.size() ? (const char*)theUserSuppliedTag.data() : "";
wcout << L"receiveInteraction: "
<< theInteraction.toString() << L" "
<< DtToWString(tag) << L" "
<< (sentOrder == RECEIVE ? L"RECEIVE " : L"TIMESTAMP ")
<< (theType == RELIABLE ? L"RELIABLE " : L"BEST_EFFORT ")
<< L"#regions: " << theSentRegionHandleSet.size() << L" "
<< L"#parameters: " << theParameterValues.size() << endl;
printParamValues(theParameterValues);
}
InteractionClassHandle theInteraction,
ParameterHandleValueMap const& theParameterValues,
VariableLengthData const& theUserSuppliedTag,
OrderType sentOrder,
LogicalTime const& theTime,
OrderType receivedOrder)
throw (InteractionClassNotRecognized, InteractionParameterNotRecognized, InteractionClassNotSubscribed, FederateInternalError)
{
const char* tag = theUserSuppliedTag.size() ? (const char*)theUserSuppliedTag.data() : "";
wcout << L"receiveInteraction: "
<< 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 ")
<< L"#parameters: " << theParameterValues.size() << endl;
printParamValues(theParameterValues);
}
InteractionClassHandle theInteraction,
ParameterHandleValueMap const& theParameterValues,
VariableLengthData const& theUserSuppliedTag,
OrderType sentOrder,
LogicalTime const& theTime,
OrderType receivedOrder,
RegionHandleSet const& theSentRegionHandleSet)
throw (InteractionClassNotRecognized, InteractionParameterNotRecognized, InteractionClassNotSubscribed,
FederateInternalError)
{
const char* tag = theUserSuppliedTag.size() ? (const char*)theUserSuppliedTag.data() : "";
wcout << L"receiveInteraction: "
<< 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 ")
<< L"#regions: " << theSentRegionHandleSet.size() << L" "
<< L"#parameters: " << theParameterValues.size() << endl;
printParamValues(theParameterValues);
}
InteractionClassHandle theInteraction,
ParameterHandleValueMap const& theParameterValues,
VariableLengthData const& theUserSuppliedTag,
OrderType sentOrder,
LogicalTime const& theTime,
OrderType receivedOrder,
MessageRetractionHandle theHandle)
throw (InteractionClassNotRecognized, InteractionParameterNotRecognized, InteractionClassNotSubscribed,
InvalidLogicalTime, FederateInternalError)
{
const char* tag = theUserSuppliedTag.size() ? (const char*)theUserSuppliedTag.data() : "";
wcout << L"receiveInteraction: "
<< 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" "
<< L"#parameters: " << theParameterValues.size() << endl;
printParamValues(theParameterValues);
}
InteractionClassHandle theInteraction,
ParameterHandleValueMap const& theParameterValues,
VariableLengthData const& theUserSuppliedTag,
OrderType sentOrder,
LogicalTime const& theTime,
OrderType receivedOrder,
MessageRetractionHandle theHandle,
RegionHandleSet const& theSentRegionHandleSet)
throw (InteractionClassNotRecognized, InteractionParameterNotRecognized, InteractionClassNotSubscribed,
InvalidLogicalTime, FederateInternalError)
{
}
ObjectInstanceHandle theObject,
VariableLengthData const& theUserSuppliedTag,
OrderType sentOrder)
throw (ObjectInstanceNotKnown, FederateInternalError)
{
const char* tag = theUserSuppliedTag.size() ? (const char*)theUserSuppliedTag.data() : "";
wcout << L"removeObjectInstance: "
<< myData.objectInstanceMap[theObject] << L"("
<< theObject.toString() << L") "
<< DtToWString(tag) << L" "
<< (sentOrder == RECEIVE ? L"RECEIVE " : L"TIMESTAMP ") << endl;
}
ObjectInstanceHandle theObject,
VariableLengthData const& theUserSuppliedTag,
OrderType sentOrder,
LogicalTime const& theTime,
OrderType receivedOrder)
throw (ObjectInstanceNotKnown, FederateInternalError)
{
const char* tag = theUserSuppliedTag.size() ? (const char*)theUserSuppliedTag.data() : "";
wcout << L"removeObjectInstance: "
<< 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 ") << endl;
}
ObjectInstanceHandle theObject,
VariableLengthData const& theUserSuppliedTag,
OrderType sentOrder,
LogicalTime const& theTime,
OrderType receivedOrder,
MessageRetractionHandle theHandle)
throw (ObjectInstanceNotKnown, InvalidLogicalTime, FederateInternalError)
{
const char* tag = theUserSuppliedTag.size() ? (const char*)theUserSuppliedTag.data() : "";
wcout << L"removeObjectInstance: "
<< 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() << 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;
}

rtiSimpleFedAmb1516.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<rti1516::ObjectClassHandle, std::wstring> objectClassMap;
std::map<rti1516::ObjectInstanceHandle, std::wstring> objectInstanceMap;
{
clear();
}
void clear()
{
objectClassMap.clear();
}
};
{
public:
throw ();
// 6.3
std::wstring const & theObjectInstanceName)
throw (rti1516::UnknownName, rti1516::FederateInternalError);
std::wstring const & theObjectInstanceName)
throw (rti1516::UnknownName, rti1516::FederateInternalError);
// 6.5
virtual void discoverObjectInstance(
rti1516::ObjectInstanceHandle theObject,
rti1516::ObjectClassHandle theObjectClass,
std::wstring const & theObjectInstanceName)
throw (rti1516::CouldNotDiscover, rti1516::ObjectClassNotKnown, rti1516::FederateInternalError);
// 6.7
virtual void reflectAttributeValues(
rti1516::ObjectInstanceHandle theObject,
rti1516::AttributeHandleValueMap const & theAttributeValues,
rti1516::VariableLengthData const & theUserSuppliedTag,
rti1516::OrderType sentOrder,
rti1516::TransportationType theType)
throw (rti1516::ObjectInstanceNotKnown, rti1516::AttributeNotRecognized, rti1516::AttributeNotSubscribed,
rti1516::FederateInternalError);
virtual void reflectAttributeValues(
rti1516::ObjectInstanceHandle theObject,
rti1516::AttributeHandleValueMap const & theAttributeValues,
rti1516::VariableLengthData const & theUserSuppliedTag,
rti1516::OrderType sentOrder,
rti1516::TransportationType theType,rti1516::RegionHandleSet const & theSentRegionHandleSet)
throw (rti1516::ObjectInstanceNotKnown,rti1516::AttributeNotRecognized, rti1516::AttributeNotSubscribed,
rti1516::FederateInternalError);
virtual void reflectAttributeValues(
rti1516::ObjectInstanceHandle theObject,
rti1516::AttributeHandleValueMap const & theAttributeValues,
rti1516::VariableLengthData const & theUserSuppliedTag,
rti1516::OrderType sentOrder,
rti1516::TransportationType theType,
rti1516::LogicalTime const & theTime,
rti1516::OrderType receivedOrder)
throw (rti1516::ObjectInstanceNotKnown, rti1516::AttributeNotRecognized, rti1516::AttributeNotSubscribed,
rti1516::FederateInternalError);
virtual void reflectAttributeValues(
rti1516::ObjectInstanceHandle theObject,
rti1516::AttributeHandleValueMap const & theAttributeValues,
rti1516::VariableLengthData const & theUserSuppliedTag,
rti1516::OrderType sentOrder,
rti1516::TransportationType theType,
rti1516::LogicalTime const & theTime,
rti1516::OrderType receivedOrder,
rti1516::RegionHandleSet const & theSentRegionHandleSet)
throw (rti1516::ObjectInstanceNotKnown, rti1516::AttributeNotRecognized, rti1516::AttributeNotSubscribed,
rti1516::FederateInternalError);
virtual void reflectAttributeValues(
rti1516::ObjectInstanceHandle theObject,
rti1516::AttributeHandleValueMap const & theAttributeValues,
rti1516::VariableLengthData const & theUserSuppliedTag,
rti1516::OrderType sentOrder,
rti1516::TransportationType theType,
rti1516::LogicalTime const & theTime,
rti1516::OrderType receivedOrder,
rti1516::MessageRetractionHandle theHandle)
throw (rti1516::ObjectInstanceNotKnown, rti1516::AttributeNotRecognized, rti1516::AttributeNotSubscribed,
rti1516::InvalidLogicalTime, rti1516::FederateInternalError);
virtual void reflectAttributeValues(
rti1516::ObjectInstanceHandle theObject,
rti1516::AttributeHandleValueMap const & theAttributeValues,
rti1516::VariableLengthData const & theUserSuppliedTag,
rti1516::OrderType sentOrder,
rti1516::TransportationType theType,
rti1516::LogicalTime const & theTime,
rti1516::OrderType receivedOrder,
rti1516::MessageRetractionHandle theHandle,
rti1516::RegionHandleSet const & theSentRegionHandleSet)
throw (rti1516::ObjectInstanceNotKnown, rti1516::AttributeNotRecognized, rti1516::AttributeNotSubscribed,
rti1516::InvalidLogicalTime, rti1516::FederateInternalError);
// 6.9
virtual void receiveInteraction(
rti1516::InteractionClassHandle theInteraction,
rti1516::ParameterHandleValueMap const & theParameterValues,
rti1516::VariableLengthData const & theUserSuppliedTag,
rti1516::OrderType sentOrder,
rti1516::TransportationType theType)
throw (rti1516::InteractionClassNotRecognized, rti1516::InteractionParameterNotRecognized,
rti1516::InteractionClassNotSubscribed, rti1516::FederateInternalError);
virtual void receiveInteraction(
rti1516::InteractionClassHandle theInteraction,
rti1516::ParameterHandleValueMap const & theParameterValues,
rti1516::VariableLengthData const & theUserSuppliedTag,
rti1516::OrderType sentOrder,
rti1516::TransportationType theType,
rti1516::RegionHandleSet const & theSentRegionHandleSet)
throw (rti1516::InteractionClassNotRecognized, rti1516::InteractionParameterNotRecognized,
rti1516::InteractionClassNotSubscribed, rti1516::FederateInternalError);
virtual void receiveInteraction(
rti1516::InteractionClassHandle theInteraction,
rti1516::ParameterHandleValueMap const & theParameterValues,
rti1516::VariableLengthData const & theUserSuppliedTag,
rti1516::OrderType sentOrder,
rti1516::TransportationType theType,
rti1516::LogicalTime const & theTime,
rti1516::OrderType receivedOrder)
throw (rti1516::InteractionClassNotRecognized, rti1516::InteractionParameterNotRecognized,
rti1516::InteractionClassNotSubscribed, rti1516::FederateInternalError);
virtual void receiveInteraction(
rti1516::InteractionClassHandle theInteraction,
rti1516::ParameterHandleValueMap const & theParameterValues,
rti1516::VariableLengthData const & theUserSuppliedTag,
rti1516::OrderType sentOrder,
rti1516::TransportationType theType,
rti1516::LogicalTime const & theTime,
rti1516::OrderType receivedOrder,
rti1516::RegionHandleSet const & theSentRegionHandleSet)
throw (rti1516::InteractionClassNotRecognized, rti1516::InteractionParameterNotRecognized,
rti1516::InteractionClassNotSubscribed, rti1516::FederateInternalError);
virtual void receiveInteraction(
rti1516::InteractionClassHandle theInteraction,
rti1516::ParameterHandleValueMap const & theParameterValues,
rti1516::VariableLengthData const & theUserSuppliedTag,
rti1516::OrderType sentOrder,
rti1516::TransportationType theType,
rti1516::LogicalTime const & theTime,
rti1516::OrderType receivedOrder,
rti1516::MessageRetractionHandle theHandle)
throw (rti1516::InteractionClassNotRecognized, rti1516::InteractionParameterNotRecognized,
rti1516::InteractionClassNotSubscribed, rti1516::InvalidLogicalTime, rti1516::FederateInternalError);
virtual void receiveInteraction(
rti1516::InteractionClassHandle theInteraction,
rti1516::ParameterHandleValueMap const & theParameterValues,
rti1516::VariableLengthData const & theUserSuppliedTag,
rti1516::OrderType sentOrder,
rti1516::TransportationType theType,
rti1516::LogicalTime const & theTime,
rti1516::OrderType receivedOrder,
rti1516::MessageRetractionHandle theHandle,
rti1516::RegionHandleSet const & theSentRegionHandleSet)
throw (rti1516::InteractionClassNotRecognized, rti1516::InteractionParameterNotRecognized,
rti1516::InteractionClassNotSubscribed, rti1516::InvalidLogicalTime, rti1516::FederateInternalError);
// 6.11
virtual void removeObjectInstance(
rti1516::ObjectInstanceHandle theObject,
rti1516::VariableLengthData const & theUserSuppliedTag,
rti1516::OrderType sentOrder)
throw (rti1516::ObjectInstanceNotKnown, rti1516::FederateInternalError);
virtual void removeObjectInstance(
rti1516::ObjectInstanceHandle theObject,
rti1516::VariableLengthData const & theUserSuppliedTag,
rti1516::OrderType sentOrder,
rti1516::LogicalTime const & theTime,
rti1516::OrderType receivedOrder)
throw (rti1516::ObjectInstanceNotKnown, rti1516::FederateInternalError);
virtual void removeObjectInstance(
rti1516::ObjectInstanceHandle theObject,
rti1516::VariableLengthData const & theUserSuppliedTag,
rti1516::OrderType sentOrder,
rti1516::LogicalTime const & theTime,
rti1516::OrderType receivedOrder,
rti1516::MessageRetractionHandle theHandle)
throw (rti1516::ObjectInstanceNotKnown, rti1516::InvalidLogicalTime, rti1516::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 Wed Jul 8 16:20:32 EDT 2026 from SVN revision 291616
Copyright © 2005-2025 MAK Technologies Inc. All Rights Reserved (www.mak.com)