VR-Exchange 2.2 API Documentation
Example Plugin for the DIS Broker

An example DIS Broker plugin that overrides some of the existing DIS object and interaction translators.

Plugins are loaded from their respective brokers' plugin directories. Default plugin directories for each broker are a subfolder in the 'plugins' directory that shares the name of the broker (For example, the DIS Broker's plugin directory is 'plugins/disBroker'. The plugin directory is a broker setting, and can be configured on a broker-by-broker basis.

When a broker is run, it checks the plugin directory for shared libraries and if they are valid plugins, loads them and calls their initialization method.

The example plugin library installs and builds into your install's runtime library folder (bin on windows, lib on linux), and must be manually copied into the plugins/disBroker directory if you want to test it with the DIS Broker.


/****************************************************************************
* Copyright (c) 2013 VT MAK
* All rights reserved.
****************************************************************************/
#pragma once
// Get proper local export symbol
#ifdef _WIN32
# ifdef DT_DLL_BROKERPLUGIN
# undef DT_DLL_BROKERPLUGIN
# define DT_DLL_BROKERPLUGIN __declspec ( dllexport )
# else
# define DT_DLL_BROKERPLUGIN __declspec ( dllimport )
# endif
#else
# define DT_DLL_BROKERPLUGIN
#endif

/****************************************************************************
* Copyright (c) 2013 VT MAK
* All rights reserved.
****************************************************************************/
#include <dllExport.h>
// Set plugin export macro and declare and export the plugin init method.
#define DT_VRX_PLUGIN_EXPORT_MACRO DT_DLL_BROKERPLUGIN
#include <modEntityTrans.h>
using namespace MAKVrExchange::DtDisBroker;
{
DtDisBroker* disBroker = dynamic_cast<DtDisBroker*>( broker );
if ( ! disBroker )
{
DtWarn << "Broker is not a DtDisBroker! Aborting plugin init." << std::endl;
return false;
}
// Get pointers to the broker's object and interaction translator factories.
DtObjectTranslatorFactory* objTransFactory =
DtInteractionTranslatorFactory* interTransFactory =
// Remove some translators we're not interested in.
// New translators can also be added in this manner, by
// calling addCreator instead of removeCreator (see below).
objTransFactory->removeCreator<DtIffObjectTranslator>();
// Replace the entity translator with our customized version.
objTransFactory->removeCreator<DtEntityTranslator>();
objTransFactory->addCreator<ModEntityTranslator>();
// Replace the data interaction translator with our customized version.
interTransFactory->addCreator<ModDataInterTranslator>();
return true;
}

/*****************************************************************************
* Copyright (c) 2013 VT MAK
* All rights reserved.
****************************************************************************/
#pragma once
#include <dllExport.h>
#include <portal/pEntity.h>
namespace MAKVrExchange
{
namespace DtDisBroker
{
class DtDisBroker;
}
}
{
public:
virtual ~ModEntityTranslator();
virtual DtEntityStateRepository* translate( DtEntityStateRepository* dest,
const DtEntityStateRepository& source );
private:
// Copy Constructor not implemented -- do not copy!
// Assignment Operator not implemented -- do not copy!
};

/*****************************************************************************
* Copyright (c) 2013 VT MAK
* All rights reserved.
****************************************************************************/
#include <modEntityTrans.h>
#include <vlpi/disEnums.h>
#include <vl/entitySR.h>
using namespace MAKVrExchange;
// Default pass-through constructor.
: DtEntityTranslator( broker )
{
}
// Default destructor.
{
}
// In order to modify how the state is translated and/or set additional
// values, the translate method can be overridden. This version modifies
// how Portal entities are translated to DIS entities.
DtEntityStateRepository* ModEntityTranslator::translate(
DtEntityStateRepository* dest, const DtPortalEntity& src )
{
// Call the base class method first. This way all the translation is done
// and you can selectively go back and modify a few parameters. This is
// not required of course, but it can be useful.
// We want this translator to always use static dead reckoning.
dest->setAlgorithm( DtDrStatic );
// Override the antenna so it's always up.
dest->setAntennaRaised( true );
// Return the translated state rep.
return dest;
}
// In order to modify how the state is translated and/or set additional
// values, the translate method can be overridden. This version modifies
// how DIS entities are translated to Portal entities.
const DtEntityStateRepository& src )
{
// Call the base class method first. This way all the translation is done
// and you can selectively go back and modify a few parameters. This is
// not required of course, but it can be useful.
// Only for entities incoming from DIS, set the guise to something specific.
dest->setGuise( "DIS Force Guise" );
// We want this translator to always use static dead reckoning.
dest->setAlgorithm( DtDrStatic );
// Override the antenna so it's always up.
dest->setAntennaRaised( true );
// Return the translated state rep.
return dest;
}

/****************************************************************************
* Copyright (c) 2013 VT MAK
* All rights reserved.
****************************************************************************/
#pragma once
#include <dllExport.h>
namespace MAKVrExchange
{
namespace DtDisBroker
{
class DtDisBroker;
}
}
{
public:
const DtDataInteraction& source );
private:
// Copy Constructor not implemented -- do not copy!
// Assignment Operator not implemented -- do not copy!
};

/****************************************************************************
* Copyright (c) 2013 VT MAK
* All rights reserved.
****************************************************************************/
#include <vl/exerciseConn.h>
#include <vlutil/vlTime.h>
using namespace MAKVrExchange;
// Default pass-through constructor.
{
}
// Default destructor.
{
}
// In order to modify how the state is translated and/or set additional
// values, the translate method can be overridden. This version modifies
// how DIS data interactions are translated to Portal data interactions.
DtPortalDataInteraction* destination, const DtDataInteraction& source )
{
// Call the base class method first. This way all the translation is done
// and you can selectively go back and modify a few parameters. This is
// not required of course, but it can be useful.
// Set the message's received time to be the translation time (absolute).
destination->setTimeReceived( myDisBroker->connection()->clock()->absRealTime() );
// Return the translated interaction.
return destination;
}

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)