VR-Exchange 2.9 API Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 MAK Technologies, Inc.
* 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) 2016 MAK Technologies, Inc.
* All rights reserved.
****************************************************************************/
#include <dllExport.h>
// Set plugin export macro and declare and export the plugin methods.
#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.
// 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<DtIffTranslator>();
// Replace the entity translator with our customized version.
objTransFactory->removeCreator<DtEntityTranslator>();
objTransFactory->addCreator<ModEntityTranslator>();
// Replace the data interaction translator with our customized version.
interTransFactory->removeCreator<DtDataTranslator>();
interTransFactory->addCreator<ModDataInterTranslator>();
return true;
}
// If you need to modify the broker's reload behavior (reload is performed
// when broker settings are changed instead of completely relaunching the broker),
// the brokerPluginReload method is called on reload, and can be implemented in
// your plugin to perform additional actions.
// As with brokerPluginInit( DtBroker* ), this method is exported by defining
// the export macro and including broker/exportBrokerPlugin.h.
{
DtInfo << "Perform additional reload actions here." << std::endl;
}
// Some logic changes require that the exercise connection be fully instantiated.
// Since the exercise connection isn't instantiated until after the primary plugin
// initialization method, that logic cannot be performed there. The post-initialization
// method is called after the exercise connection is created so plugins can perform such logic.
{
DtInfo << "Perform post-initialization actions here." << std::endl;
}

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

/*****************************************************************************
* Copyright (c) 2014 MAK Technologies, Inc.
* All rights reserved.
****************************************************************************/
#include <modEntityTrans.h>
#include <vl/entityStateRepository.h>
#include <vlpi/disEnums.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 DIS entities are translated to Portal entities.
const DtEntityStateRepository& src, const DtReflectedEntity& refObj )
{
// 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.
DtEntityTranslator::translate( dest, src, refObj );
// 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;
}
// 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, const DtPortalReflectedEntity& refObj )
{
// 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.
DtEntityTranslator::translate( dest, src, refObj );
// 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) 2016 MAK Technologies, Inc.
* 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) 2016 MAK Technologies, Inc.
* All rights reserved.
****************************************************************************/
#include <vl/exerciseConn.h>
#include <vlutil/vlTime.h>
using namespace MAKVrExchange;
// Default pass-through constructor.
: DtDataTranslator( disBroker )
{
}
// 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.
DtDataTranslator::translate( destination, source );
// Set the message's received time to be the translation time (absolute).
destination->setTimeReceived( disBroker()->connection()->clock()->absRealTime() );
// Return the translated interaction.
return destination;
}

Document ID: Generated on Tue Jun 25 16:45:35 EDT 2024 from SVN revision 267383
Copyright © 2005-2024 MAK Technologies. All Rights Reserved (www.mak.com)