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 accessory installs itself into DtVrlinkDriver objects and prints out the entity state repositories of entities as they are discovered.
Expected Result
Console Result
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 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_connectionCreated.connect(
boost::bind(&DtPrintAccessory::slot_onSimCreated, this, boost::placeholders::_1));
}
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 ./bin64/exampleAccessory_stealth.bat (on Windows from cmd.exe) or ./bin64/exampleAccessory_stealth.sh (on Linux). From Vantage menu Settings->Connection connect DIS (localhost) then start MAK Logger DIS (make sure you are connected with the local DIS connection), load HawaiiTour-2019-DIS.lgr. Click on the play button and you should see the printout appear in the console. For more information about running examples, please see Running Applications and Examples.
Example Source Files
exampleAccessoryPlugin.cxx
#include <boost/bind/bind.hpp>
#define DL_DLL_IGCONVRLINK DT_DLL_EXAMPLEACCESSORY
#define DT_PROTOCOL_NAMESPACE vrvDis
#define DtDIS 1
#undef DT_PROTOCOL_NAMESPACE
#undef DtDIS
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 DtPrintAccessory class.
Contains makVrv::DtVrlinkEntityStateListener class.
This class defines an accessory that will install itself into DtVrlinkDriver objects and print out th...
Definition DtPrintAccessory.h:25
static DtAccessoryManager & instance(DtDe &de)
Lazily create singleton.
The DtDe is the core component of any VR-Vantage application. It owns a DtRenderer,...
Definition DtDe.h:77
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_DLL_EXAMPLEACCESSORY void init(makVrv::DtDe &de)
DT_DE_PLUGIN_EXPORT_MACRO bool initDeModule(makVrv::DtDe *de)
Definition DtAudioInit.h:25
Contains DtCreateSensorFieldOfViewCommand and DtCreateSensorFieldOfViewCommandCreator class declarati...
Definition DtGridLinesSettingsRecord.h:16
DtPrintAccessory.h
#ifndef DtPrintAccessory_H_
#define DtPrintAccessory_H_
{
class DtVrlinkBaseConnection;
{
class DtPrintAccessory : public DtBaseAccessory
{
public:
virtual void install(DtDriver* driver);
protected:
};
}
}
#endif
Contains makVrv::DtBaseAccessory class.
Contains implementation for DtPrintAccessory. This class is inline so that its protocol can be define...
virtual ~DtPrintAccessory()
\Default destructor
Definition DtPrintAccessory.inl:46
virtual void uninstall(DtDriver *baseConn)
Called when this accessory is uninstalled.
Definition DtPrintAccessory.inl:74
virtual bool isCompatible(DtDriver *driver)
Called to find out if this accessory is compatible with a particular connector. In this case,...
Definition DtPrintAccessory.inl:50
virtual void install(DtDriver *driver)
Called when this accessory is installed into a connector.
Definition DtPrintAccessory.inl:62
virtual void slot_onSimConnected(DtVrlinkBaseConnection *connection)
Called when a sim connection is connected.
Definition DtPrintAccessory.inl:95
virtual void slot_onSimCreated(DtVrlinkBaseConnection *connection)
Called when the driver creates a new connection.
Definition DtPrintAccessory.inl:86
DtPrintAccessory()
\Default constructor
Definition DtPrintAccessory.inl:41
virtual void slot_onSimAboutToBeDisconnected(DtVrlinkBaseConnection *connection)
Called when a sim connection is disconnected.
Definition DtPrintAccessory.inl:108
Contains DLL export macros.
#define DT_PROTOCOL_NAMESPACE
Definition vrvAudioShared/dllExport.h:43
DtPrintVisualizer.h
#ifndef DtPrintVisualizer_h_
#define DtPrintVisualizer_h_
{
public:
protected:
};
#endif
Contains implementation for DtPrintVisualizer. This class is inline so that its protocol can be defin...
Contains makVrv::DtVirtualBaseClass class.
Contains makVrv::DtVrlinkSimulation class.
Handles visualizing entities by printing out their esr on discovery. Inherits DtVirtualBaseClass to a...
Definition DtPrintVisualizer.h:20
virtual void slot_entityDiscovered(makVrv::DT_PROTOCOL_NAMESPACE::DtVrlinkEntityStateListener &listener)
Called when a DIS entity is discovered.
Definition DtPrintVisualizer.inl:48
~DtPrintVisualizer()
DTOR.
Definition DtPrintVisualizer.inl:35
DtPrintVisualizer(makVrv::DT_PROTOCOL_NAMESPACE::DtVrlinkConnection &connection)
CTOR.
Definition DtPrintVisualizer.inl:15
makVrv::DT_PROTOCOL_NAMESPACE::DtVrlinkConnection & myConnection
VR-Link connection the instance is visualizing.
Definition DtPrintVisualizer.h:34
A class which represents the simulation the driver manages.
Definition DtVrlinkConnection.h:44
Definition DtVrlinkEntityStateListener.h:61
Virtual base class. Allows for RTTI and proper virtual destruction. Used by Creators,...
Definition DtVirtualBaseClass.h:20