VR-Exchange 2.2 API Documentation
Example

The timeMgmtHlaBroker example:


/*********************************************************************
** Copyright (c) 1992-2012 VT MAK
** All rights reserved.
*********************************************************************/
#include "timeMgmtTrans.h"
#include <vlutil/vlExceptions.h>
#include <iostream>
using namespace MAKVrExchange;
using namespace MAKVrExchange::DtRprBroker;
int main( int argc, char* argv[] )
{
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
DtRprBrokerApp brokerApp( hlaInit );
if ( ! hlaInit->showConnectionInfoDialog() )
{
// 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.
brokerApp.rprBroker()->objectTranslatorFactory()->
addCreator<DtTimeManagementTranslator>();
brokerApp.run();
}
else
{
brokerApp.showInfoDialog();
}
}
DtCATCH_AND_WARN( std::cout )
return 0;
}

/****************************************************************************
* Copyright (c) 2012 VT MAK
* All rights reserved.
****************************************************************************/
#include "timeMgmtTrans.h"
#include <vl/collideInter.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
: DtObjectTranslator( broker, translatorName(), DtPortalTimeMgmtObject::theKind )
, myRprBroker( 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
broker->connection()->fedAmb()->addTimeConstrainedEnabledCb(processTimeConstrained, this);
broker->connection()->fedAmb()->addTimeRegulationEnabledCb(processTimeRegulating, this);
broker->connection()->fedAmb()->addTimeAdvanceGrantCb(processTimeGrant, this);
// Enable asynchronous delivery. We want to receive RO messages regardless
// of whether or not we are time advancing.
broker->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 )
}
const MAKVrExchange::DtPortalReflectedObject* object, void* userData )
{
bool canBeDiscovered = false;
if (userData && object)
{
canBeDiscovered = true;
}
return canBeDiscovered;
}
#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);
}
}
void DtTimeManagementTranslator::createPortalPublisher( DtBrokerObject* brokerObject )
{
}
void DtTimeManagementTranslator::createHlaPublisher(DtBrokerObject* brokerObject)
{
}
void DtTimeManagementTranslator::deletePortalPublisher(DtBrokerObject* brokerObject)
{
}
void DtTimeManagementTranslator::deleteHlaPublisher(DtBrokerObject* brokerObject)
{
}
bool DtTimeManagementTranslator::isPortalPublishable(const DtBrokerObject* brokerObject) const
{
return true;
}
bool DtTimeManagementTranslator::isHlaPublishable(const DtBrokerObject* brokerObject) const
{
return false;
}

/******************************************************************************
** Copyright (c) 1992-2012 VT MAK
******************************************************************************/
#include "pTimeMgmtObj.h"
#include <vlutil/vlPrintUtil.h> //DtPrintAttribute()
: MAKVrExchange::DtPortalBaseObject()
, myLbts(0)
{
}
{
}
: DtPortalBaseObject( original )
, myLbts( original.lbts() )
{
}
{
if (this != &original)
{
setLbts( original.lbts() );
}
return *this;
}
{
int rc = ( (DtPortalBaseObject::operator==( rightOperand )) &&
(myLbts == rightOperand.lbts()) );
return rc;
}
{
return ! (*this == rightOperand);
}
unsigned int DtPortalTimeMgmtObject::netSize() const
{
size += getSize( myLbts );
return size;
}
{
char *ptr = (char *)buffer + DtPortalBaseObject::netSize();
ptr = encode( myLbts, ptr );
}
{
const char *ptr = (const char *)buffer + DtPortalBaseObject::netSize();
ptr = decode( myLbts, ptr );
}
std::ostream &DtPortalTimeMgmtObject::printDataToStream( std::ostream &stream ) const
{
DtPrintAttribute( stream, "LBTS", myLbts );
return stream;
}

Document ID: Generated on Mon Apr 15 17:15:50 EDT 2013 from SVN revision 126154
Copyright © 2005-2012 VT MÄK. All Rights Reserved (www.mak.com)