VR-Vantage
Loading...
Searching...
No Matches
exampleAccessory

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.

// The accessory must be created after the DE's initialization is
// finished, to make sure all the objects it uses exist.
postInitializeConnection = de.signal_postInitialize.connect(boost::bind(
&loadAccessory, &de));
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.

void loadAccessory(DtDe* de)
{
// We're done with the signal, so disconnect from it
postInitializeConnection.disconnect();
// Add the print accessory to the accessory manager. It will get the option
// to install itself into any DtDriver objects that are created.
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)
{
// This accessory is compatible with any DtVrlinkDriver
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)
{
//std::cout << "Accessory install" << std::endl;
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

/******************************************************************************
** Copyright (c) 2024 MAK Technologies, Inc.
** All rights reserved.
******************************************************************************/
#include <vrvCore/DtDe.h>
#include <boost/bind/bind.hpp>
// Define export macro for vrvVrl includes
#define DL_DLL_IGCONVRLINK DT_DLL_EXAMPLEACCESSORY
// Define the protocol specific macros to compile for DIS
#define DT_PROTOCOL_NAMESPACE vrvDis
#define DtDIS 1
using namespace makVrv;
#undef DT_PROTOCOL_NAMESPACE
#undef DtDIS
static vrvSignalsLib::connection postInitializeConnection;
{
// We're done with the signal, so disconnect from it
postInitializeConnection.disconnect();
// Add the print accessory to the accessory manager. It will get the option
// to install itself into any DtDriver objects that are created.
}
void init(DtDe& de)
{
// Ensure that init only gets called once
// (not strictly necessary here, but this is good practice in general)
// We only want to create the accessory if we're running in master mode:
if (de.isInMasterMode())
{
// The accessory must be created after the DE's initialization is
// finished, to make sure all the objects it uses exist.
postInitializeConnection = de.signal_postInitialize.connect(boost::bind(
&loadAccessory, &de));
}
}
{
// Setup the plug-in. Normally, the init function and functionality
// should be in its own library.
init(*de);
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.
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

/******************************************************************************
** Copyright (c) 2009 MAK Technologies, Inc.
** All rights reserved.
******************************************************************************/
#ifndef DtPrintAccessory_H_
#define DtPrintAccessory_H_
namespace makVrv
{
class DtVrlinkBaseConnection;
{
class DtPrintAccessory : public DtBaseAccessory
{
public:
virtual ~DtPrintAccessory();
virtual bool isCompatible(DtDriver* driver);
virtual void install(DtDriver* driver);
virtual void uninstall(DtDriver* baseConn);
protected:
virtual void slot_onSimCreated(DtVrlinkBaseConnection* connection);
virtual void slot_onSimConnected(DtVrlinkBaseConnection* connection);
virtual void slot_onSimAboutToBeDisconnected(DtVrlinkBaseConnection* connection);
};
}
}
#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

/******************************************************************************
** Copyright (c) 2009 MAK Technologies, Inc.
** All rights reserved.
******************************************************************************/
#ifndef DtPrintVisualizer_h_
#define DtPrintVisualizer_h_
{
public:
protected:
virtual void slot_entityDiscovered(
};
#endif
Contains implementation for DtPrintVisualizer. This class is inline so that its protocol can be defin...
Contains makVrv::DtVirtualBaseClass 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
Virtual base class. Allows for RTTI and proper virtual destruction. Used by Creators,...
Definition DtVirtualBaseClass.h:20