Overview
A driver accessory is an interface for executing code when a driver starts. An accessory is registered with the display engine and can support any driver class that it knows how to interface with. This example is an empty template accessory to use as a starting point.
Expected Result
N/A
Example details
When the exampleAccessoryPlugin gets loaded, it's passed a DtDe (display engine). At that point we connect the post initialize signal (which will get emitted after the display engine has been initialized) to the function we want to call, loadAccessory.
When loadAccessory gets called after the display engine is initialized we add our accessory. In this case, it prints out something when entities are discovered.
{
DtAccessoryManager::instance(*de).addAccessory(new MyAccessory());
}
An accessory has three pure virtual methods that need to be implemented. When it's time to install accessories, the display engine goes through its list of accessors and tries to install each one on every driver. The accessory has a method, isCompatible() that determines if the accessory can be installed on the driver. If so, then it's installed. Later, the accessories are uninstalled from the driver.
bool MyAccessory::isCompatible(DtDriver* driver)
{
DtVrlinkDriver* dd = dynamic_cast<DtVrlinkDriver*>(driver);
if(dd)
{
return true;
}
return false;
Once deemed compatible, the display engine gives the driver to the accessory, which installs itself. From there the accessory can do what it wants.
Building the Example
VR-Vantage includes pre-built versions of the example plug-in. To build it yourself, follow the instructions at Building VR-Vantage Examples, Applications, and Plug-ins.
Running the Example
N/A
Example Source Files
exampleAccessoryTemplatePlugin.h
#pragma once
#define DT_DE_PLUGIN_EXPORT_MACRO DT_DLL_EXAMPLEACCESSORYTEMPLATE
namespace makVrv
{
class DtDe;
}
exampleAccessoryTemplatePlugin.cxx
#include <boost/bind.hpp>
#define DL_DLL_IGCONVRLINK DT_DLL_EXAMPLEACCESSORYTEMPLATE
#define DT_PROTOCOL_NAMESPACE vrvHla13
using namespace makVrv;
#undef DT_PROTOCOL_NAMESPACE
{
}
{
{
}
}
{
return true;
}
MyAccessory.h
#pragma once
namespace makVrv
{
class DtConnection;
{
class MyAccessory : public DtBaseAccessory
{
public:
virtual void install(DtDriver* driver);
protected:
};
}
}
MyAccessory.inl
#include <boost/bind.hpp>
#include <iostream>
#include <RTI.hh>
#include <vl/exerciseConn.h>
#include <vl/fom.h>
namespace makVrv
{
{
#ifdef DtDIS
#else
#ifdef DtHLA_1516
#ifdef DtHLA_1516_EVOLVED
#else
#endif
#else
#endif
#endif
{
}
MyAccessory::~MyAccessory()
{
}
bool MyAccessory::isCompatible(DtDriver* driver)
{
DtVrlinkDriver* dd = dynamic_cast<DtVrlinkDriver*>(driver);
if(dd)
{
return true;
}
return false;
}
void MyAccessory::install(DtDriver* driver)
{
DtVrlinkDriver* vld = dynamic_cast<DtVrlinkDriver*>(driver);
if(vld)
{
vld->signal_simulationCreated.connect(
boost::bind(&MyAccessory::slot_onSimCreated,
this, _1));
}
}
void MyAccessory::uninstall(DtDriver* baseConn)
{
DtVrlinkDriver* vld = dynamic_cast<DtVrlinkDriver*>(baseConn);
if(vld)
{
vld->signal_simulationCreated.disconnect(
boost::bind(&MyAccessory::slot_onSimCreated,
this, _1));
}
}
void MyAccessory::slot_onSimCreated(DtConnection* connection)
{
connection->signal_connected.connect(
boost::bind(&MyAccessory::slot_onSimConnected,
this, connection));
connection->signal_toBeDisconnected.connect(
boost::bind(&MyAccessory::slot_onSimAboutToBeDisconnected,
this, connection));
}
void MyAccessory::slot_onSimConnected(DtConnection* connection)
{
DtVrlinkConnection* vrlCon = dynamic_cast<DtVrlinkConnection*>(connection);
if(vrlCon)
{
DtExerciseConn& exConn = *(vrlCon->exerciseConn());
DtObjClassDesc* classDesc = exConn.fom()->
objClassByName("BaseEntity.PhysicalEntity");
if (NULL != classDesc)
{
classDesc->unsubscribe();
}
classDesc = exConn.fom()->
objClassByName("BaseEntity.PhysicalEntity.Lifeform");
if (NULL != classDesc)
{
classDesc->unsubscribe();
}
classDesc = exConn.fom()->
objClassByName("BaseEntity.PhysicalEntity.Lifeform.Human");
if (NULL != classDesc)
{
classDesc->unsubscribe();
}
classDesc = exConn.fom()->
objClassByName("BaseEntity.PhysicalEntity.Lifeform.NonHuman");
if (NULL != classDesc)
{
classDesc->unsubscribe();
}
}
}
void MyAccessory::slot_onSimAboutToBeDisconnected(DtConnection* sim)
{
DtVrlinkConnection* vrlsim=dynamic_cast<DtVrlinkConnection*>(sim);
if(vrlsim)
{
}
}
}
}
[<< Examples] [Home] [Top of Page]