This is a simple program that prints all received HLA Interactions and all HLA Object updates.
#if DtHLA
#include "stealthControlRegister.h"
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <string>
void reflectCb(
const DtStateMsg& msg, DtHlaObject* obj,
void* usr );
void removeObjectCb( DtHlaObject* obj, void* usr );
void discoverObjectCb( DtHlaObject* obj, void* usr );
int keybrdTick( void );
std::string clearScreen("");
const std::string theSeperator("************************************************************\n");
#if !DtHLA_1516
std::map<RTI::ObjectHandle, DtDdmFederateAmbassador::DtRegionInfo> myRegionInfo;
#else
std::map<RTI::ObjectInstanceHandle, DtDdmFederateAmbassador::DtRegionInfo> myRegionInfo;
#endif
RTI::DimensionHandle myXHandle;
RTI::DimensionHandle myYHandle;
#if VXWORKS
#define main realMain
#endif
void DtRtiShutdownHandler(const char * label, void* finished)
{
int* finishedInt = (int*)finished;
if (*finishedInt)
{
DtWarn <<
"Shutting down: " << label << std::endl;
}
*finishedInt = 0;
}
{
std::vector<DtString> result;
std::vector<DtString> fomModuleNames;
fomModuleNames.insert(fomModuleNames.end(), cmdLineFomModuleNames.
getValue().begin(), cmdLineFomModuleNames.
getValue().end());
if (suppressDefaultModules == false)
{
bool foundVRFExt = false;
bool foundDIGuy = false;
bool foundLgrControl = false;
bool foundVRFAggregate = false;
bool foundDynamicTerrain = false;
std::vector<DtString>::iterator modName = fomModuleNames.begin();
std::vector<DtString>::iterator end = fomModuleNames.end();
while ( modName != end )
{
if ( modName->findString("MAK-") != -1 && modName->findString("_evolved") != -1 )
{
if ( modName->findString("-VRFExt-") != -1 )
{
DtInfo <<
"Override MAK-VRFExt-4_evolved.xml with " << *modName << std::endl;
foundVRFExt = true;
}
else if ( modName->findString("-DIGuy-") != -1 )
{
DtInfo <<
"Override MAK-DIGuy-4_evolved.xml with " << *modName << std::endl;
foundDIGuy = true;
}
else if ( modName->findString("-LgrControl-") != -1 )
{
DtInfo <<
"Override MAK-LgrControl-2_evolved.xml with " << *modName << std::endl;
foundLgrControl = true;
}
else if ( modName->findString("-VRFAggregate-") != -1 )
{
DtInfo <<
"Override MAK-VRFAggregate-3_evolved.xml with " << *modName << std::endl;
foundVRFAggregate = true;
}
else if ( modName->findString("-DynamicTerrain-") != -1 )
{
DtInfo <<
"Override MAK-DynamicTerrain-2_evolved.xml with " << *modName << std::endl;
foundDynamicTerrain = true;
}
}
++modName;
}
if ( ! foundVRFExt )
{
result.push_back( "MAK-VRFExt-4_evolved.xml" );
}
if ( ! foundDIGuy )
{
result.push_back( "MAK-DIGuy-6_evolved.xml" );
}
if ( ! foundLgrControl )
{
result.push_back( "MAK-LgrControl-2_evolved.xml" );
}
if ( ! foundVRFAggregate )
{
result.push_back( "MAK-VRFAggregate-3_evolved.xml" );
}
if ( ! foundDynamicTerrain )
{
result.push_back( "MAK-DynamicTerrain-2_evolved.xml" );
}
}
result.insert( result.end(), fomModuleNames.begin(), fomModuleNames.end() );
std::vector<DtString>::iterator res = fomModuleNames.begin();
std::vector<DtString>::iterator resEnd = fomModuleNames.end();
while ( res != resEnd )
{
DtInfo <<
"Loading FOM module " << *res << std::endl;
++res;
}
return result;
}
int main( int argc, char* argv[] )
{
DtCmdLine::ValueArg<int> rprFomRevision(
"",
"rprFomRevision",
"Internal revision of the implementation of the RPR FOM version",
false, 1,
"int", cmd );
#if DtHLA_1516_EVOLVED
DtCmdLine::SwitchArg suppressDefaultModules(
"s",
"suppressDefaultModules",
"Do not load Default FOM Modules automatically",
false, cmd );
#endif
cmd.add( raw );
cmd.add( clearScreenSwitch );
cmd.add( fullReport );
cmd.add( ddmDump );
cmd.add( showRegionData );
cmd.add( subWithDdm );
cmd.parse( argc, argv );
if (clearScreenSwitch)
{
clearScreen = "\033[H\033[2J";
}
if (ddmDump || showRegionData)
{
DtExerciseConn::setFedAmbCreator(DtDdmFederateAmbassador::create);
}
if ( !fomMapperLib.getValue().isEmpty() )
{
if ( fomMapperInitData.getValue().isEmpty() )
{
#if DtHLA_1516_EVOLVED
std::vector<DtString> fomModules = selectFomModules(fomModuleNames, suppressDefaultModules.getValue());
fedFileName.getValue().c_str(),
fomMapperLib.getValue().c_str(), (void*)0,
"", fomModules, &status);
#else
fedType.
c_str(), fomMapperLib.getValue().c_str(),
fedFileName.getValue().c_str(), (void*)0, &status );
#endif
}
else
{
#if DtHLA_1516_EVOLVED
std::vector<DtString> fomModules = selectFomModules(fomModuleNames, suppressDefaultModules.getValue());
fedFileName.getValue().c_str(),
fomMapperLib.getValue().c_str(),
(void*)fomMapperInitData.getValue().c_str(),
"", fomModules, &status );
#else
fedType.
c_str(), fomMapperLib.getValue().c_str(),
fedFileName.getValue().c_str(),
(void*)fomMapperInitData.getValue().c_str(), &status );
#endif
}
{
return 1;
}
}
else
{
DtFomMapper* mapper = new DtRprFomMapper( rprFomVersion, rprFomRevision );
#if DtHLA_1516_EVOLVED
std::vector<DtString> fomModules = selectFomModules(fomModuleNames, suppressDefaultModules.getValue());
"", fedType.
c_str(), fedFileName.getValue(),
mapper, "", fomModules,
&status );
#else
fedType.
c_str(), mapper, fedFileName.getValue().c_str(), &status );
#endif
{
return 1;
}
if (exConn->fom()->interClassByName("ViewControl"))
{
DtStealthControlRegister(exConn);
}
}
int forever = 1;
#ifdef DtHLA
exConn->addRtiErrorCb(&DtRtiShutdownHandler, &forever);
#endif
if(passiveSubs)
{
exConn->setPassiveMode();
}
DtDDMRegionSP region = DtDDMRegionSP();
DtDDMRegionSet* regionSet = 0;
if (subWithDdm)
{
try
{
DtGeodeticRegionSP geodRegion(new DtGeodeticRegion(exConn));
geodOrigin.getGeocentric(geocentricPoint);
geodRegion->setRegionBounds(geocentricPoint, regionSize.getValue(),
regionSize.getValue());
region = geodRegion;
regionSet = new DtDDMRegionSet();
regionSet->insert(region);
}
catch (RTI::Exception& except)
{
std::cout << "Caught exception creating region: " << except << std::endl;
std::cout << "Exiting..." << std::endl;
return -1;
}
{
std::cout << "Caught exception creating region: " << except << std::endl;
std::cout << "Exiting..." << std::endl;
return -1;
}
}
if (ddmDump || showRegionData)
{
DtDdmFederateAmbassador* fedAmb = dynamic_cast<DtDdmFederateAmbassador*>(
exConn->fedAmb());
if (fedAmb)
{
try
{
#if !DtHLA_1516
RTI::SpaceHandle spaceHandle = exConn->rtiAmb()->getRoutingSpaceHandle(
"BenchmarkGeographicSpace");
myXHandle = exConn->rtiAmb()->getDimensionHandle(
"X", spaceHandle);
myYHandle = exConn->rtiAmb()->getDimensionHandle(
"Y", spaceHandle);
#else
myXHandle = exConn->rtiAmb()->getDimensionHandle(
myYHandle = exConn->rtiAmb()->getDimensionHandle(
#endif
fedAmb->setXHandle(myXHandle);
fedAmb->setYHandle(myYHandle);
}
catch (RTI::Exception& )
{
}
catch (...)
{
}
}
}
DtFom* fom = exConn->fom();
DtObjClassDesc *momObjectClass = 0;
DtObjClassDesc *rootObjectClass = 0;
DtInterClassDesc *momInterClass = 0;
DtInterClassDesc *rootInterClass = 0;
{
rootObjectClass = fom->objClassByName("ObjectRoot");
rootInterClass = fom->interClassByName("InteractionRoot");
momObjectClass = fom->objClassByName( "Manager" );
momInterClass = fom->interClassByName("Manager");
}
else
{
rootObjectClass = fom->objClassByName("HLAobjectRoot");
rootInterClass = fom->interClassByName("HLAinteractionRoot");
momObjectClass = fom->objClassByName( "HLAmanager" );
momInterClass = fom->interClassByName("HLAmanager");
}
DtObjClassDesc* objClassDesc = 0;
#if DtHLA_1516
for (std::list<DtObjClassDesc*>::const_iterator item = fom->objClassList().begin();
item != fom->objClassList().end();
++item)
{
objClassDesc = const_cast<DtObjClassDesc*>(*item);
#else
for( objClassDesc = fom->firstObjClass();
objClassDesc;
objClassDesc = fom->nextObjClass( objClassDesc ) )
{
#endif
if ( includeMom || !momObjectClass
|| (momObjectClass && !objClassDesc->isOfClass(momObjectClass->handle())))
{
if (rootObjectClass && (objClassDesc->handle() != rootObjectClass->handle()))
{
objClassDesc->subscribe();
}
}
}
DtInterClassDesc* intClassDesc = 0;
#if DtHLA_1516
for (std::list<DtInterClassDesc*>::const_iterator item = fom->interClassList().begin();
item != fom->interClassList().end();
++item)
{
intClassDesc = const_cast<DtInterClassDesc*>(*item);;
#else
for( intClassDesc = fom->firstInterClass();
intClassDesc;
intClassDesc = fom->nextInterClass( intClassDesc ) )
{
#endif
if ( includeMom || !momInterClass
|| (momInterClass && !intClassDesc->isOfClass( momInterClass->handle() )) )
{
if (rootInterClass && (intClassDesc->handle() != rootInterClass->handle()))
{
intClassDesc->subscribe();
}
}
}
if ( !raw )
{
}
if ( !raw )
{
}
if ( !raw )
{
}
DtReflectedDIGuyObjectList* rdgl = 0;
if ( ! raw && exConn->fom()->objClassByName("DIGuyObject") )
{
rdgl = new DtReflectedDIGuyObjectList( exConn, regionSet );
}
if ( !raw )
{
}
if ( !raw )
{
}
if ( !raw )
{
}
if ( !raw )
{
}
if ( !raw )
{
}
if ( !raw )
{
}
if ( !raw )
{
}
if ( !raw )
{
}
if ( !raw )
{
}
if ( !raw )
{
}
#if DtHLA_1516
exConn->addDiscoverObjectCallback( RTI::ObjectClassHandle(), discoverObjectCb, 0 );
exConn->addInteractionCallback( RTI::InteractionClassHandle(), receiveInterCb, 0,
region );
#else
exConn->addDiscoverObjectCallback( 0, discoverObjectCb, 0 );
exConn->addInteractionCallback( 0, receiveInterCb, 0, region );
#endif
while( forever )
{
if ( keybrdTick() == -1 )
{
break;
}
}
if (forever)
{
#if DtHLA_1516
for (std::list<DtObjClassDesc*>::const_iterator item = fom->objClassList().begin();
item != fom->objClassList().end();
++item)
{
objClassDesc = const_cast<DtObjClassDesc*>(*item);
#else
for( objClassDesc = fom->firstObjClass();
objClassDesc;
objClassDesc = fom->nextObjClass( objClassDesc ) )
{
#endif
if (includeMom || !momObjectClass
|| (momObjectClass && !objClassDesc->isOfClass(momObjectClass->handle())))
{
objClassDesc->unsubscribe();
}
}
#if DtHLA_1516
for (std::list<DtInterClassDesc*>::const_iterator item = fom->interClassList().begin();
item != fom->interClassList().end();
++item)
{
intClassDesc = const_cast<DtInterClassDesc*>(*item);
#else
for( intClassDesc = fom->firstInterClass();
intClassDesc;
intClassDesc = fom->nextInterClass( intClassDesc ) )
{
#endif
if (includeMom || !momInterClass
|| (momInterClass && !intClassDesc->isOfClass(momInterClass->handle())))
{
intClassDesc->subscribe();
}
}
}
if (subWithDdm)
{
delete regionSet;
region.reset();
}
return 0;
}
void reflectCb(
const DtStateMsg& msg, DtHlaObject* obj,
void* usr )
{
DtClock* clock = obj->exerciseConn()->clock();
DtString lastProducingFederateName =
"Unknown";
#if DtHLA_1516_EVOLVED
lastProducingFederateName = obj->lastProducingFederate();
#endif
if (ddmDump)
{
DtDdmFederateAmbassador* ddmFedAmb = dynamic_cast<DtDdmFederateAmbassador*>(
obj->exerciseConn()->fedAmb());
const DtDdmFederateAmbassador::DtRegionInfo& regionInfo =
ddmFedAmb->regionInfoForObject(obj->objectId());
bool printProducingFederate = false;
if (regionInfo.infoSet)
{
std::map<RTI::ObjectHandle, DtDdmFederateAmbassador::DtRegionInfo>::iterator iter =
myRegionInfo.find(obj->objectId());
if (iter == myRegionInfo.end())
{
myRegionInfo[obj->objectId()] = regionInfo;
std::cout
<< clearScreen
<< theSeperator
<< "*************** Update at "
<< "Object: " << obj->objectId() << "\n"
<< "Name: " << obj->name() << "\n";
#if DtHLA_1516_EVOLVED
if (!lastProducingFederateName.
isEmpty())
{
std::cout
<< "Updated by Federate: "
<< lastProducingFederateName
<< "\n";
}
#endif
std::cout
<< "DDM Info: " << "\n"
<< " -- Lower X Bound: " << regionInfo.lowerXBound << "\n"
<< " -- Upper X Bound: " << regionInfo.upperXBound << "\n"
<< " -- Lower Y Bound: " << regionInfo.lowerYBound << "\n"
<< " -- Upper Y Bound: " << regionInfo.upperYBound << "\n";
}
else
{
const DtDdmFederateAmbassador::DtRegionInfo& lastRegion = iter->second;
if (regionInfo.lowerXBound != lastRegion.lowerXBound ||
regionInfo.upperXBound != lastRegion.upperXBound ||
regionInfo.lowerYBound != lastRegion.lowerYBound ||
regionInfo.upperYBound != lastRegion.upperYBound)
{
myRegionInfo[obj->objectId()] = regionInfo;
std::cout
<< clearScreen
<< theSeperator
<< "*************** Update at "
<< "Object: " << obj->objectId() << "\n"
<< "Name: " << obj->name() << "\n";
#if DtHLA_1516_EVOLVED
if (!lastProducingFederateName.
isEmpty())
{
std::cout
<< "Updated by Federate: "
<< lastProducingFederateName << "\n";
}
#endif
std::cout
<< "DDM Info: " << "\n"
<< " -- Lower X Bound: " << regionInfo.lowerXBound << "\n"
<< " -- Upper X Bound: " << regionInfo.upperXBound << "\n"
<< " -- Lower Y Bound: " << regionInfo.lowerYBound << "\n"
<< " -- Upper Y Bound: " << regionInfo.upperYBound << "\n";
}
}
}
else
{
std::cout
<< clearScreen
<< theSeperator
<< "*************** Update at "
<< theSeperator
<< "Object: " << obj->objectId() << "\n"
<< "Name: " << obj->name() << "\n";
#if DtHLA_1516_EVOLVED
if (!lastProducingFederateName.
isEmpty())
{
std::cout
<< "Updated by Federate: "
<< lastProducingFederateName
<< "\n";
}
#endif
std::cout
<< "DDM Info: " << "\n"
<< " -- No DDM Region information set." << "\n";
}
}
else
{
std::cout
<< clearScreen
<< theSeperator
<< "*************** Update at "
<< theSeperator;
#if DtHLA_1516_EVOLVED
if (!lastProducingFederateName.
isEmpty())
{
std::cout
<< "Updated by Federate: "
<< lastProducingFederateName;
std::cout
<< "\n";
}
#endif
if ( raw )
{
msg.
print( obj->exerciseConn(), obj->objectClassHandle() );
}
else
{
msg.
print( obj, fullReport );
}
if (showRegionData)
{
DtDdmFederateAmbassador* ddmFedAmb = dynamic_cast<DtDdmFederateAmbassador*>(
obj->exerciseConn()->fedAmb());
const DtDdmFederateAmbassador::DtRegionInfo& regionInfo =
ddmFedAmb->regionInfoForObject(obj->objectId());
std::cout << "DDM Region Data: ";
if (regionInfo.infoSet)
{
std::cout
<< "\n"
<< " -- Lower X Bound: " << regionInfo.lowerXBound << "\n"
<< " -- Upper X Bound: " << regionInfo.upperXBound << "\n"
<< " -- Lower Y Bound: " << regionInfo.lowerYBound << "\n"
<< " -- Upper Y Bound: " << regionInfo.upperYBound << "\n";
}
else
{
std::cout << "None" << "\n";
}
}
std::cout << std::endl;
}
}
void removeObjectCb( DtHlaObject* obj, void* usr )
{
obj->removeRemoveObjectCb( removeObjectCb, 0 );
obj->removePostReflectCb( reflectCb, 0 );
}
void discoverObjectCb( DtHlaObject* obj, void* usr )
{
obj->addPostReflectCb( reflectCb, 0 );
obj->addRemoveObjectCb( removeObjectCb, 0 );
}
{
DtClock* clock = inter->exerciseConn()->clock();
std::cout << clearScreen << theSeperator << "*************** Interaction at "
if (!ddmDump)
{
if ( raw )
{
inter->printParams( true );
}
else
{
}
if (showRegionData)
{
DtDdmFederateAmbassador* ddmFedAmb = dynamic_cast<DtDdmFederateAmbassador*>(
inter->exerciseConn()->fedAmb());
DtDdmFederateAmbassador::DtRegionInfo regionInfo = ddmFedAmb->lastInteractionRegion();
ddmFedAmb->clearLastInteractionRegion();
std::cout << "DDM Region Data: ";
if (regionInfo.infoSet)
{
std::cout << std::endl;
std::cout << " -- Lower X Bound: " << regionInfo.lowerXBound << std::endl;
std::cout << " -- Upper X Bound: " << regionInfo.upperXBound << std::endl;
std::cout << " -- Lower Y Bound: " << regionInfo.lowerYBound << std::endl;
std::cout << " -- Upper Y Bound: " << regionInfo.upperYBound << std::endl;
}
else
{
std::cout << "None" << std::endl;
}
}
std::cout << std::endl;
}
else
{
std::cout << "Interaction Class: " << inter->interactionClassName() << std::endl;
DtDdmFederateAmbassador* ddmFedAmb = dynamic_cast<DtDdmFederateAmbassador*>(
inter->exerciseConn()->fedAmb());
DtDdmFederateAmbassador::DtRegionInfo regionInfo = ddmFedAmb->lastInteractionRegion();
ddmFedAmb->clearLastInteractionRegion();
if (regionInfo.infoSet)
{
std::cout << " -- Lower X Bound: " << regionInfo.lowerXBound << std::endl;
std::cout << " -- Upper X Bound: " << regionInfo.upperXBound << std::endl;
std::cout << " -- Lower Y Bound: " << regionInfo.lowerYBound << std::endl;
std::cout << " -- Upper Y Bound: " << regionInfo.upperYBound << std::endl;
}
else
{
std::cout << "-- No Interaction Region" << std::endl;
}
}
}
int keybrdTick()
{
if ( !keyPtr )
{
return 0;
}
switch( *keyPtr )
{
case 'q':
case 'Q':
{
return -1;
}
default:
{
std::cout << "Unrecognized command key <"<< *keyPtr <<">" << std::endl;
break;
}
}
return 0;
}
#endif // DtHLA