This example creates an accessory that installs itself into DtCigiDriver objects and hooks into signals that are triggered when particular CIGI messages are received.
The CIGI driver emits signals when a CIGI message is received. An accessory can be installed, that listens to particular CIGI messages and does some type of processing when they are received. Much of this example is like exampleAccessory, except the accessory listens to the session created signal from the DtCigiDriver.
void DtCigiAccessory::install(DtDriver* driver)
{
DtCigiDriver* cd = dynamic_cast<DtCigiDriver*>(driver);
if(cd)
{
cd->signal_sessionCreated.connect(
boost::bind(&DtCigiAccessory::slot_onSimCreated,
this, _1));
}
When the session is created, the accessory waits for the CIGI driver to be connected.
void DtCigiAccessory::slot_onSimCreated(DtCigiConnection* connection)
{
connection->signal_connected.connect(
boost::bind(&DtCigiAccessory::slot_onSimConnected,
this, connection));
connection->signal_toBeDisconnected.connect(
boost::bind(&DtCigiAccessory::slot_onSimAboutToBeDisconnected,
this, connection));
}
On connection, a DtCigiExtender object is created (much like the DtPrintVisualizer of exampleAccessory).
void DtCigiAccessory::slot_onSimConnected(DtCigiConnection* connection)
{
if(connection)
{
DtCigiExtender* vis = new DtCigiExtender(*connection);
connection->registerInstance("DtCigiExtender", vis);
}
The DtCigiExtender class listens for component control, wave control, and custom CIGI messages, and prints out the contents of known messages. The constructor connects to the appropriate signals.
DtCigiExtender::DtCigiExtender(DtCigiConnection& connection)
: DtVirtualBaseClass()
, myConnection(connection)
{
DtCigiSignalProcessor::instance(connection).signal_componentControlReceived.connect(
boost::bind(&DtCigiExtender::slot_componentControlReceived,
this, _1));
DtCigiSignalProcessor::instance(connection).signal_waveControlReceived.connect(
boost::bind(&DtCigiExtender::slot_waveControlReceived,
this, _1));
DtCigiSignalProcessor::instance(connection).signal_unrecognizedPacketReceived.connect(
boost::bind(&DtCigiExtender::slot_customPacketReceived,
this, _1));
}
The methods are called when the particular type of CIGI message is received.
void DtCigiExtender::slot_componentControlReceived(const CigiCompCtrlV3_3& msg)
{
std::cout << "Received a CIGI Component Control Message" << std::endl;
std::cout <<
" -- Instance ID: " << (
int)msg.GetInstanceID() << std::endl;
}
void DtCigiExtender::slot_waveControlReceived(const CigiWaveCtrlV3& msg)
{
std::cout << "Received a CIGI Wave Control Message" << std::endl;
std::cout <<
" -- Wave ID: " << (
int) msg.GetWaveID() << std::endl;
std::cout << " -- Wave Height: " << msg.GetWaveHt() << std::endl;
}
In the case of custom messages, the CigiBasePacket will need to be casted to a user-defined type so that the data can be extracted.
void DtCigiExtender::slot_customPacketReceived(const CigiBasePacket&)
{
}
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/exampleCigiExtension_stealth.bat (on Windows) or ./bin64/exampleCigiExtension_stealth.sh (on Linux). For more information about running examples, please see Running Applications and Examples.
Example Source Files
exampleCigiExtensionPlugin.cxx
#include <boost/bind.hpp>
using namespace makVrv;
{
}
{
{
}
}
{
{
return true;
}
return false;
}
DtCigiAccessory.h
#pragma once
namespace makVrv
{
class DtConnection;
class DtCigiConnection;
class DtCigiAccessory : public DtBaseAccessory
{
public:
virtual void install(DtDriver* driver);
protected:
};
}
DtCigiExtender.h
#pragma once
class CigiCompCtrlV3_3;
class CigiWaveCtrlV3;
class CigiBasePacket;
namespace makVrv
{
class DtCigiExtender : public DtVirtualBaseClass
{
public:
protected:
};
}
DtCigiAccessory.cxx
#include <boost/bind.hpp>
#include <iostream>
namespace makVrv
{
:DtBaseAccessory()
{
}
DtCigiAccessory::~DtCigiAccessory()
{
}
void DtCigiAccessory::install(DtDriver* driver)
{
DtCigiDriver* cd = dynamic_cast<DtCigiDriver*>(driver);
if(cd)
{
cd->signal_sessionCreated.connect(
boost::bind(&DtCigiAccessory::slot_onSimCreated,
this, _1));
}
}
void DtCigiAccessory::uninstall(DtDriver* baseConn)
{
DtCigiDriver* vld = dynamic_cast<DtCigiDriver*>(baseConn);
if(vld)
{
vld->signal_sessionCreated.disconnect(
boost::bind(&DtCigiAccessory::slot_onSimCreated,
this, _1));
}
}
bool DtCigiAccessory::isCompatible(DtDriver* driver)
{
DtCigiDriver* dd = dynamic_cast<DtCigiDriver*>(driver);
if(dd)
{
return true;
}
return false;
}
void DtCigiAccessory::slot_onSimCreated(DtCigiConnection* connection)
{
connection->signal_connected.connect(
boost::bind(&DtCigiAccessory::slot_onSimConnected,
this, connection));
connection->signal_toBeDisconnected.connect(
boost::bind(&DtCigiAccessory::slot_onSimAboutToBeDisconnected,
this, connection));
}
void DtCigiAccessory::slot_onSimConnected(DtCigiConnection* connection)
{
if(connection)
{
DtCigiExtender* vis = new DtCigiExtender(*connection);
connection->registerInstance("DtCigiExtender", vis);
}
}
void DtCigiAccessory::slot_onSimAboutToBeDisconnected(DtCigiConnection* sim)
{
if(sim)
{
sim->registerInstance("DtCigiExtender", 0);
}
}
}
DtCigiExtender.cxx
#include <boost/bind.hpp>
#include <iostream>
#include <CigiCompCtrlV3_3.h>
#include <CigiWaveCtrlV3.h>
namespace makVrv
{
: DtVirtualBaseClass()
, myConnection(connection)
{
DtCigiSignalProcessor::instance(connection).signal_componentControlReceived.connect(
boost::bind(&DtCigiExtender::slot_componentControlReceived,
this, _1));
DtCigiSignalProcessor::instance(connection).signal_waveControlReceived.connect(
boost::bind(&DtCigiExtender::slot_waveControlReceived,
this, _1));
DtCigiSignalProcessor::instance(connection).signal_unrecognizedPacketReceived.connect(
boost::bind(&DtCigiExtender::slot_customPacketReceived,
this, _1));
}
DtCigiExtender::~DtCigiExtender()
{
DtCigiSignalProcessor::instance(myConnection).signal_componentControlReceived.disconnect(
boost::bind(&DtCigiExtender::slot_componentControlReceived,
this, _1));
DtCigiSignalProcessor::instance(myConnection).signal_waveControlReceived.disconnect(
boost::bind(&DtCigiExtender::slot_waveControlReceived,
this, _1));
DtCigiSignalProcessor::instance(myConnection).signal_unrecognizedPacketReceived.disconnect(
boost::bind(&DtCigiExtender::slot_customPacketReceived,
this, _1));
}
void DtCigiExtender::slot_componentControlReceived(const CigiCompCtrlV3_3& msg)
{
std::cout << "Received a CIGI Component Control Message" << std::endl;
std::cout <<
" -- Instance ID: " << (
int)msg.GetInstanceID() << std::endl;
}
void DtCigiExtender::slot_waveControlReceived(const CigiWaveCtrlV3& msg)
{
std::cout << "Received a CIGI Wave Control Message" << std::endl;
std::cout <<
" -- Wave ID: " << (
int) msg.GetWaveID() << std::endl;
std::cout << " -- Wave Height: " << msg.GetWaveHt() << std::endl;
}
void DtCigiExtender::slot_customPacketReceived(const CigiBasePacket&)
{
}
}