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.
postInitializeConnection = de.signal_postInitialize.connect(boost::bind(
void loadAccessory(makVrv::DtDe *de)
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.
{
postInitializeConnection.disconnect();
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
{
class DtDe;
}
The DtDe is the core component of any VR-Vantage application. It owns a DtRenderer,...
Definition DtDe.h:77
DT_DLL_EXAMPLEACCESSORY void init(makVrv::DtDe &de)
Contains DLL export macros.
#define DT_DLL_EXAMPLEACCESSORYTEMPLATE
Definition exampleAccessoryTemplate.h:19
Contains DtCreateSensorFieldOfViewCommand and DtCreateSensorFieldOfViewCommandCreator class declarati...
Definition DtGridLinesSettingsRecord.h:16
exampleAccessoryTemplatePlugin.cxx
#include <boost/bind/bind.hpp>
#define DL_DLL_IGCONVRLINK DT_DLL_EXAMPLEACCESSORYTEMPLATE
#define DT_PROTOCOL_NAMESPACE vrvHla13
#undef DT_PROTOCOL_NAMESPACE
static vrvSignalsLib::connection postInitializeConnection;
{
postInitializeConnection.disconnect();
}
{
{
}
}
{
return true;
}
Contains makVrv::DtAccessoryManager class.
Contains makVrv::DtDe class.
#define DT_DE_INIT_ONCE(de)
This macro is called by modules in their init() function. This macro ensures that the module is only ...
Definition DtDe.h:30
Contains MyAccessory class.
This class defines an accessory that will install itself into DtVrlinkDriver objects.
Definition MyAccessory.h:23
static DtAccessoryManager & instance(DtDe &de)
Lazily create singleton.
virtual bool isInMasterMode() const
Returns true if the DtDe is in master mode.
boost::signalslib::signal< void()> signal_postInitialize
Definition DtDe.h:535
Contains declarations for plugin initialization functions.
DT_DE_PLUGIN_EXPORT_MACRO bool initDeModule(makVrv::DtDe *de)
Definition DtAudioInit.h:25
MyAccessory.h
#pragma once
{
class DtVrlinkBaseConnection;
{
class MyAccessory : public DtBaseAccessory
{
public:
virtual void install(DtDriver* driver);
protected:
};
}
}
Contains makVrv::DtBaseAccessory class.
Contains implementation for MyAccessory. This class is inline so that its protocol can be defined by ...
virtual ~MyAccessory()
\Default destructor
Definition MyAccessory.inl:48
virtual void install(DtDriver *driver)
Called when this accessory is installed into a connector.
Definition MyAccessory.inl:64
MyAccessory()
\Default constructor
Definition MyAccessory.inl:43
virtual void slot_onSimConnected(DtVrlinkBaseConnection *connection)
Called when a sim connection is connected.
Definition MyAccessory.inl:97
virtual void uninstall(DtDriver *baseConn)
Called when this accessory is uninstalled.
Definition MyAccessory.inl:76
virtual bool isCompatible(DtDriver *driver)
Called to find out if this accessory is compatible with a particular connector. In this case,...
Definition MyAccessory.inl:52
virtual void slot_onSimCreated(DtVrlinkBaseConnection *connection)
Called when the driver creates a new connection.
Definition MyAccessory.inl:88
virtual void slot_onSimAboutToBeDisconnected(DtVrlinkBaseConnection *connection)
Called when a sim connection is disconnected.
Definition MyAccessory.inl:132
#define DT_PROTOCOL_NAMESPACE
Definition vrvAudioShared/dllExport.h:43
MyAccessory.inl
#include <boost/bind/bind.hpp>
#include <iostream>
#include <RTI.hh>
#include <vl/exerciseConn.h>
#include <vl/fom.h>
{
{
#ifdef DtDIS
#else
#ifdef DtHLA_1516
#ifdef DtHLA_4
#elif 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_connectionCreated.connect(
boost::bind(&MyAccessory::slot_onSimCreated, this, boost::placeholders::_1));
}
}
void MyAccessory::uninstall(DtDriver* baseConn)
{
DtVrlinkDriver* vld = dynamic_cast<DtVrlinkDriver*>(baseConn);
if(vld)
{
vld->signal_connectionCreated.disconnect(
boost::bind(&MyAccessory::slot_onSimCreated, this, boost::placeholders::_1));
}
}
void MyAccessory::slot_onSimCreated(DtVrlinkBaseConnection* 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(DtVrlinkBaseConnection* 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(DtVrlinkBaseConnection* sim)
{
DtVrlinkConnection* vrlsim=dynamic_cast<DtVrlinkConnection*>(sim);
if(vrlsim)
{
}
}
}
}
Contains makVrv::DtVrlinkSimulation class.
Contains makVrv::DtVrlinkDriver class.
static std::string accessoryName
Definition DtGlStudioAccessory.inl:40