VR-Exchange 2.8 API Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Example

The timeMgmtHlaBroker example:


/****************************************************************************
* Copyright (c) 2016 VT MAK
* All rights reserved.
****************************************************************************/
#include "timeMgmtTrans.h"
#include <vlutil/vlExceptions.h>
#include <vlutil/vlMiniDumper.h>
#include <iostream>
using namespace MAKVrExchange;
using namespace MAKVrExchange::DtRprBroker;
int main( int argc, char* argv[] )
{
DtINIT_MINIDUMPER( "Time Mgmt Broker" );
try
{
DtInfo << "Starting HLA Broker with Time Management Support" << std::endl;
// Load the configuration options
hlaInit->parseCmdLine(); //Automatically loads the file specified by the CmdLine
DtBrokerApp::setBrokerDialogCreator( DtHlaBrokerDialog::create );
DtBrokerApp* brokerApp = new DtBrokerApp( hlaInit );
if ( ! ((DtVrlBroker<DtExerciseConn>*)brokerApp->broker())->connection()
&& ! hlaInit->showConnectionInfoDialog() )
{
DtWarn << "Broker initialization failed, exiting." << std::endl;
return 1;
}
// Install the time management translator by creating a default factory.
// This needs to be done before the call to DtBrokerApp::run() where all
// the translator instances are created. The translator name is used by
// the factory, so if you want to replace a translator it needs to have
// the same name, but if you want to add a translator it should have a
// different name.
// Run the broker.
brokerApp->run( hlaInit->showConnectionInfoDialog() );
DtDELETE( brokerApp );
}
DtCATCH_AND_WARN( std::cout )
return 0;
}

/****************************************************************************
* Copyright (c) 2016 VT MAK
* All rights reserved.
****************************************************************************/
#include "timeMgmtTrans.h"
#include <vl/collisionInteraction.h>
#include <vl/exerciseConn.h>
#ifdef DtHLA_1516_EVOLVED
#include <RTI/RTI1516.h>
#include <RTI/RTIambassadorFactory.h>
#include <RTI/time/HLAfloat64TimeFactory.h>
#include <RTI/time/HLAfloat64Time.h>
#include <RTI/time/HLAfloat64Interval.h>
#elif defined DtHLA_1516
#include <RTI/RTI1516.h>
#include <RTI/RTIambassadorFactory.h>
#include <RTI/logicalTimeFactoryImpl.h>
#include <RTI/logicalTimeImpl.h>
#include <RTI/logicalTimeIntervalImpl.h>
#else // HLA 1.3
#include <fedtime.hh>
#endif
using namespace MAKVrExchange;
broker, translatorName(), DtPortalTimeMgmtObject::theKind )
, myRprBroker( (MAKVrExchange::DtRprBroker::DtRprBroker*)broker )
, myPortalReflectedList( 0 )
, myPortalPublisher( 0 )
, myLookahead( 1.0 )
, myCurrentLbts( 0 )
, myCurrentTime( 0 )
, myIsTimeRegulating( false )
, myIsTimeConstrained( false )
, myRequestTime( false )
{
try
{
if ( initializer )
{
myLookahead = initializer->lookahead();
}
myPortalReflectedList = new DtPortalReflectedTimeMgmtObjectManager( broker->portalConnection() );
myPortalReflectedList->addRemovalCallback( portalRemovalCallback, this );
myPortalReflectedList->setDiscoveryCondition( portalDiscoveryCriteria, this );
myPortalPublisher = new DtPortalTimeMgmtObjectPublisher(broker->portalConnection());
DtString tmObjId("TmObj");
tmObjId += DtString(broker->brokerId());
myPortalPublisher->sr()->setIdentifier( tmObjId );
// Register for any callbacks that inform us of our logical time
myRprBroker->connection()->fedAmb()->addTimeConstrainedEnabledCb( processTimeConstrained, this );
myRprBroker->connection()->fedAmb()->addTimeRegulationEnabledCb( processTimeRegulating, this );
myRprBroker->connection()->fedAmb()->addTimeAdvanceGrantCb( processTimeGrant, this );
// Enable asynchronous delivery. We want to receive RO messages regardless
// of whether or not we are time advancing.
myRprBroker->connection()->rtiAmb()->enableAsynchronousDelivery();
}
DtCATCH_AND_PROPAGATE( DtException );
}
{
DtDELETE( myPortalReflectedList );
}
{
if ( enabled )
{
// Become time regulating and constrained
{
#ifdef DtHLA_1516_EVOLVED
rti1516e::HLAfloat64Interval lookAhead(myLookahead);
myRprBroker->connection()->rtiAmb()->enableTimeRegulation(lookAhead);
#elif defined DtHLA_1516
LogicalTimeIntervalImpl lookAhead(myLookahead);
myRprBroker->connection()->rtiAmb()->enableTimeRegulation(lookAhead);
#else // HLA 1.3
RTIfedTime currentTime(0.0);
RTIfedTime lookAhead(myLookahead);
myRprBroker->connection()->rtiAmb()->enableTimeRegulation(currentTime, lookAhead);
#endif
}
{
myRprBroker->connection()->rtiAmb()->enableTimeConstrained();
}
}
else
{
// Stop being time regulating and constrained
{
myRprBroker->connection()->rtiAmb()->disableTimeRegulation();
}
{
myRprBroker->connection()->rtiAmb()->disableTimeConstrained();
}
}
}
{
try
{
{
}
}
DtCATCH_AND_PROPAGATE( DtException )
}
const DtPortalReflectedTimeMgmtObject& object, void* userData )
{
DtTimeManagementTranslator *translator = static_cast<DtTimeManagementTranslator*>( userData );
translator->discoverPortalObject( object );
}
const DtPortalReflectedTimeMgmtObject& object, void* userData )
{
DtTimeManagementTranslator *translator = static_cast<DtTimeManagementTranslator*>( userData );
translator->receivePortalUpdate( object );
}
const DtPortalReflectedTimeMgmtObject& object, void *userData )
{
DtTimeManagementTranslator *translator = static_cast<DtTimeManagementTranslator*>( userData );
translator->removePortalObject( object );
}
{
try
{
object.addUpdateCallback( portalUpdateCallback, this );
}
DtCATCH_AND_PROPAGATE( DtException )
}
{
try
{
const DtPortalTimeMgmtObject& portalTMState = *(object.sr());
myLbtsValues[portalTMState.identifier()] = portalTMState.lbts();
}
DtCATCH_AND_PROPAGATE( DtException )
}
{
try
{
const DtPortalTimeMgmtObject& portalTMState = *(object.sr());
myLbtsValues.erase(portalTMState.identifier());
}
DtCATCH_AND_PROPAGATE( DtException )
}
const DtPortalReflectedObject* object, void* userData )
{
if ( userData && object )
{
return true;
}
return false;
}
#if DtHLA_1516
const RTI::LogicalTime &fedTime,
#else
const RTI::FedTime &fedTime,
#endif
void *usr)
{
reinterpret_cast<DtTimeManagementTranslator*>(usr)->processTimeGrant(fedTime);
}
#if DtHLA_1516
const RTI::LogicalTime &fedTime)
#else
const RTI::FedTime &fedTime)
#endif
{
#ifdef DtHLA_1516_EVOLVED
myCurrentTime = static_cast<rti1516e::HLAfloat64Time>(fedTime).getTime();
#elif defined DtHLA_1516
myCurrentTime = static_cast<LogicalTimeImpl>(fedTime).getTime();
#else // HLA 1.3
myCurrentTime = static_cast<RTIfedTime>(fedTime).getTime();
#endif
myRequestTime = true;
}
#if DtHLA_1516
const RTI::LogicalTime &fedTime,
#else
const RTI::FedTime &fedTime,
#endif
void *usr)
{
reinterpret_cast<DtTimeManagementTranslator*>(usr)->processTimeRegulating(fedTime);
}
#if DtHLA_1516
const RTI::LogicalTime &fedTime)
#else
const RTI::FedTime &fedTime)
#endif
{
myIsTimeRegulating = true;
#ifdef DtHLA_1516_EVOLVED
myCurrentTime = static_cast<rti1516e::HLAfloat64Time>(fedTime).getTime();
#elif defined DtHLA_1516
myCurrentTime = static_cast<LogicalTimeImpl>(fedTime).getTime();
#else // HLA 1.3
myCurrentTime = static_cast<RTIfedTime>(fedTime).getTime();
#endif
if(myIsTimeRegulating && myIsTimeConstrained)
{
myRequestTime = true;
}
}
#if DtHLA_1516
const RTI::LogicalTime &fedTime,
#else
const RTI::FedTime &fedTime,
#endif
void *usr)
{
reinterpret_cast<DtTimeManagementTranslator*>(usr)->processTimeConstrained(fedTime);
}
#if DtHLA_1516
const RTI::LogicalTime& fedTime )
#else
const RTI::FedTime& fedTime )
#endif
{
myIsTimeConstrained = true;
#ifdef DtHLA_1516_EVOLVED
myCurrentTime = static_cast<rti1516e::HLAfloat64Time>(fedTime).getTime();
#elif defined DtHLA_1516
myCurrentTime = static_cast<LogicalTimeImpl>(fedTime).getTime();
#else // HLA 1.3
myCurrentTime = static_cast<RTIfedTime>(fedTime).getTime();
#endif
if ( myIsTimeRegulating && myIsTimeConstrained )
{
myRequestTime = true;
}
}
{
// Get current LBTS/GALT
#ifdef DtHLA_1516_EVOLVED
rti1516e::HLAfloat64Time galt;
myRprBroker->connection()->rtiAmb()->queryGALT( galt );
if ( galt.isFinal() )
{
// No other regulating federates yet. Just stick to our current time.
}
else
{
myCurrentLbts = galt.getTime();
}
#elif defined DtHLA_1516
LogicalTimeImpl galt;
myRprBroker->connection()->rtiAmb()->queryGALT( galt );
if ( galt.isFinal() )
{
// No other regulating federates yet. Just stick to our current time.
}
else
{
myCurrentLbts = galt.getTime();
}
#else // HLA 1.3
RTIfedTime lbts;
myRprBroker->connection()->rtiAmb()->queryLBTS( lbts );
if ( lbts.isPositiveInfinity() )
{
// No other regulating federates yet. Just stick to our current time.
}
else
{
myCurrentLbts = lbts.getTime();
}
#endif
// Inform other brokers of current LBTS/GALT
{
}
// Determine the lowest of all the LBTS values
double lowestLbts = myCurrentLbts;
std::map<DtString, double>::const_iterator lbtsIter = myLbtsValues.begin();
std::map<DtString, double>::const_iterator iterEnd = myLbtsValues.end();
for ( ; lbtsIter != iterEnd; ++lbtsIter )
{
if ( lbtsIter->second < lowestLbts )
{
lowestLbts = lbtsIter->second;
}
}
// Perform time advance request to lowest LBTS/GALT value.
// TAR is only done if our current time is less than the request value.
// If not, then we are ahead of other federations, and we need to chill.
if ( myCurrentTime < lowestLbts )
{
myRequestTime = false;
#ifdef DtHLA_1516_EVOLVED
rti1516e::HLAfloat64Time req( lowestLbts );
#elif defined DtHLA_1516
LogicalTimeImpl req( lowestLbts );
#else // HLA 1.3
RTIfedTime req( lowestLbts );
#endif
myRprBroker->connection()->rtiAmb()->timeAdvanceRequest( req );
}
}
{
}
{
}
{
}
{
}
{
return true;
}
const DtPortalReflectedTimeMgmtObject* refObj ) const
{
return false;
}

/****************************************************************************
* Copyright (c) 2016 VT MAK
* All rights reserved.
****************************************************************************/
#include "pTimeMgmtObj.h"
#include <vlutil/vlPrintUtil.h>
: MAKVrExchange::DtPortalObject(
DtPortalTimeMgmtObject::theKind, "Time Management" )
, myLbts( 0 )
{
}
const DtPortalTimeMgmtObject& original )
: DtPortalObject( original )
, myLbts( original.lbts() )
{
}
{
}
const DtPortalTimeMgmtObject& original )
{
// Avoid assignment to self.
if ( this == &original )
{
return *this;
}
DtPortalObject::operator = ( original );
setLbts( original.lbts() );
return *this;
}
const DtPortalTimeMgmtObject& rightOperand ) const
{
return ( DtPortalObject::operator == (rightOperand)
&& myLbts == rightOperand.lbts() );
}
const DtPortalTimeMgmtObject& rightOperand ) const
{
return !( *this == rightOperand );
}
unsigned int DtPortalTimeMgmtObject::netSize() const
{
int size = DtPortalObject::netSize();
size += getSize( myLbts );
return size;
}
void DtPortalTimeMgmtObject::writeSelfToBuffer( void* buffer, int bufferSize ) const
{
DtPortalObject::writeSelfToBuffer( buffer, bufferSize );
int baseSize = DtPortalObject::netSize();
char* ptr = (char*) buffer + baseSize;
bufferSize -= baseSize;
ptr = encode( myLbts, ptr, bufferSize );
}
void DtPortalTimeMgmtObject::readSelfFromBuffer( const void* buffer, int bufferSize )
{
DtPortalObject::readSelfFromBuffer( buffer, bufferSize );
int baseSize = DtPortalObject::netSize();
const char* ptr = (const char*) buffer + baseSize;
bufferSize -= baseSize;
ptr = decode( myLbts, ptr, bufferSize );
}
std::ostream& DtPortalTimeMgmtObject::printDataToStream( std::ostream& stream ) const
{
DtPortalObject::printDataToStream( stream );
DtPrintAttribute( stream, "LBTS", myLbts );
return stream;
}

Document ID: Generated on Tue Aug 16 16:15:26 EDT 2022 from SVN revision 245901
Copyright © 2005-2022 MAK Technologies. All Rights Reserved (www.mak.com)