VR-Vantage 2.3 API Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
exampleCigiExtension

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);
// Register the CIGI extender instance with the sim connection
// This passes memory management responsibility to the 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&)
{
// Cast the packet here.
}

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/exampleCigiExtension_stealth.bat (on Windows) or ./bin/exampleCigiExtension_stealth.sh (on Linux). For more information about running examples, please see Running Applications and Examples.

Example Source Files


exampleCigiExtensionPlugin.cxx

/*********************************************************************
** Copyright (c) 2010 MaK Technologies, Inc.
** All rights reserved.
*********************************************************************/
/*********************************************************************
** $RCSfile: exampleCigiExtensionPlugin.cxx,v $ $Revision: 1.1 $ $State: Exp $
*********************************************************************/
#include <vrvCore/DtDe.h>
#include <boost/bind.hpp>
using namespace makVrv;
{
// We're done with the signal, so disconnect from it
&loadAccessory, de));
// 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.
&loadAccessory, &de));
}
}
{
// Setup the plugin. Normally, the init function and functionality
// should be in its own library.
{
init(*de);
return true;
}
return false;
}

DtCigiAccessory.h

/*********************************************************************
** Copyright (c) 2010 MaK Technologies, Inc.
** All rights reserved.
*********************************************************************/
/*********************************************************************
** $RCSfile: DtCigiAccessory.h,v $ $Revision: 1.1 $ $State: Exp $
*********************************************************************/
#pragma once
namespace makVrv
{
class DtConnection;
class DtCigiConnection;
class DtCigiAccessory : public DtBaseAccessory
{
public:
virtual ~DtCigiAccessory();
virtual void install(DtDriver* driver);
virtual void uninstall(DtDriver* baseConn);
virtual bool isCompatible(DtDriver* driver);
protected:
virtual void slot_onSimCreated(DtCigiConnection* connection);
virtual void slot_onSimConnected(DtCigiConnection* connection);
virtual void slot_onSimAboutToBeDisconnected(DtCigiConnection* connection);
};
}

DtCigiExtender.h

/*********************************************************************
** Copyright (c) 2010 MaK Technologies, Inc.
** All rights reserved.
*********************************************************************/
/*********************************************************************
** $RCSfile: DtCigiExtender.h,v $ $Revision: 1.1 $ $State: Exp $
*********************************************************************/
#pragma once
class CigiCompCtrlV3_3;
class CigiWaveCtrlV3;
class CigiBasePacket;
namespace makVrv
{
class DtCigiExtender : public DtVirtualBaseClass
{
public:
DtCigiExtender(DtCigiConnection& connection);
virtual void slot_componentControlReceived(const CigiCompCtrlV3_3&);
virtual void slot_waveControlReceived(const CigiWaveCtrlV3&);
virtual void slot_customPacketReceived(const CigiBasePacket&);
protected:
DtCigiConnection& myConnection;
};
}

DtCigiAccessory.cxx

/*********************************************************************
** Copyright (c) 2010 MaK Technologies, Inc.
** All rights reserved.
*********************************************************************/
/*********************************************************************
** $RCSfile: DtCigiAccessory.cxx,v $ $Revision: 1.1 $ $State: Exp $
*********************************************************************/
#include "DtCigiAccessory.h"
#include "DtCigiExtender.h"
#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)
{
//std::cout << "Accessory unInstall" << std::endl;
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);
// Register the CIGI extender instance with the sim connection
// This passes memory management responsibility to the connection
connection->registerInstance("DtCigiExtender", vis);
}
}
void DtCigiAccessory::slot_onSimAboutToBeDisconnected(DtCigiConnection* sim)
{
if(sim)
{
// Remove the print visualizer instance from the sim connection
sim->registerInstance("DtCigiExtender", 0);
}
}
}

DtCigiExtender.cxx

/*********************************************************************
** Copyright (c) 2010 MaK Technologies, Inc.
** All rights reserved.
*********************************************************************/
/*********************************************************************
** $RCSfile: DtCigiExtender.cxx,v $ $Revision: 1.1 $ $State: Exp $
*********************************************************************/
#include "DtCigiExtender.h"
#include <boost/bind.hpp>
#include <iostream>
#include <CigiCompCtrlV3_3.h>
#include <CigiWaveCtrlV3.h>
namespace makVrv
{
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));
}
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&)
{
// Cast the packet here.
}
}


Copyright © 2005-2018 VT MAK. All Rights Reserved (www.mak.com)