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 accessory installs itself into DtVrlinkDriver objects and prints out the entity state repositories of entities as they are discovered.
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.
de.signal_postInitialize.connect(boost::bind(
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.
{
de->signal_postInitialize.disconnect(boost::bind(
DtAccessoryManager::instance(*de).addAccessory(new DtPrintAccessory());
}
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 DtPrintAccessory::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. Here, we connect to a signal on the VR-Link driver which causes a DtPrintVisualizer to get created.
void DtPrintAccessory::install(
DtDriver* driver)
{
DtVrlinkDriver* vld = dynamic_cast<DtVrlinkDriver*>(driver);
if(vld)
{
vld->signal_simulationCreated.connect(
boost::bind(&DtPrintAccessory::slot_onSimCreated, this, _1));
}
void DtPrintAccessory::slot_onSimConnected(DtConnection* connection)
{
DtVrlinkConnection* vrlCon = dynamic_cast<DtVrlinkConnection*>(connection);
if(vrlCon)
{
vrlCon->registerInstance("DtPrintVisualizer", vis);
}
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
This example is a plug-in. You can run it by running ./bin/exampleAccessory_stealth.bat (on Windows) or ./bin/exampleAccessory_stealth.sh (on Linux). For more information about running examples, please see Running Applications and Examples.
Example Source Files
exampleAccessoryPlugin.cxx
#include <vrvCore/DtDe.h>
#include <vrvCore/DtAccessoryManager.h>
#include <boost/bind.hpp>
#define DL_DLL_IGCONVRLINK DT_DLL_EXAMPLEACCESSORY
#define DT_PROTOCOL_NAMESPACE vrvDis
#define DtDIS 1
#include <vrvVrl/DtVrlinkEntityStateListener.h>
#include <vrvVrl/DtVrlinkEntityStateListener.inl>
using namespace makVrv;
#undef DT_PROTOCOL_NAMESPACE
#undef DtDIS
{
de->signal_postInitialize.disconnect(boost::bind(
}
{
DT_DE_INIT_ONCE(de);
if (de.isInMasterMode())
{
de.signal_postInitialize.connect(boost::bind(
}
}
{
return true;
}
DtPrintAccessory.h
#ifndef DtPrintAccessory_H_
#define DtPrintAccessory_H_
#include <vrvCore/DtBaseAccessory.h>
namespace makVrv
{
class DtConnection;
{
{
public:
protected:
};
}
}
#include "DtPrintAccessory.inl"
#endif
DtPrintVisualizer.h
#ifndef DtPrintVisualizer_h_
#define DtPrintVisualizer_h_
#include <vrvUtil/DtVirtualBaseClass.h>
#include <vrvVrl/DtVrlinkConnection.h>
#include <vrvVrl/DtVrlinkEntityStateListener.h>
{
public:
protected:
makVrv::DT_PROTOCOL_NAMESPACE::DtVrlinkEntityStateListener& listener);
makVrv::DT_PROTOCOL_NAMESPACE::DtVrlinkConnection&
myConnection;
};
#include "DtPrintVisualizer.inl"
#endif