VR-Forces 4.0.4 Class Documentation

networkCallbackManagerAccessory.h

/******************************************************************************
** Copyright (c) 2010 MAK Technologies, Inc.
** All rights reserved.
******************************************************************************/
/******************************************************************************
** $RCSfile: DtAddAttrGuiAccessory.h,v $ $Revision: 1.1 $ $State: Exp $
******************************************************************************/

//\file DtAddAttrGuiAccessory.h
//\brief Contains DtAddAttrGuiAccessory class.  Used to install extensions to the FOM
//for mass

#include <vrfVrlSharedSource/vrfProtocol.h>
#include <vrvCore/DtBaseAccessory.h>
#include <vrfVrlSharedSource/DtVrfDriver.h>

namespace makVrv
{
   class DtConnection;
   class DtVrlinkDriver;
}

namespace makVrf
{
   class DtNetworkMessageInterface;
};

//\brief This class defines an accessory that will install itself
//into DtVrlinkDriver objects and print out the esr of entities
//as they are discovered.
class DtNetworkCallbackManagerAccessory : public makVrv::DtBaseAccessory
{
public:
   //\Default constructor
   DtNetworkCallbackManagerAccessory();

   //\Default destructor
   virtual ~DtNetworkCallbackManagerAccessory();

   //\brief Called when this accessory is installed into a connector.
   virtual void install(makVrv::DtDriver* driver);

   //\brief Called when this accessory is uninstalled
   virtual void uninstall(makVrv::DtDriver* baseConn);

   //\brief Called to find out if this accessory is compatible with a
   //particular connector. In this case, it is compatible with any
   //DtVrlinkDriver of the correct protocol
   virtual bool isCompatible(makVrv::DtDriver* driver);

   //\brief Called when an interaction or pdu is received.  Will send notification through
   //the VRF driver
   virtual void received(makVrf::DtNetworkMessageInterface*);

protected:

   //\brief Called when the driver creates a new connection
   virtual void slot_onSimCreated(makVrv::DtConnection* connection);

   //\brief Called when a sim connection is connected
   virtual void slot_onSimConnected(makVrv::DtConnection* connection);

   //\brief Called when a sim connection is disconnected
   virtual void slot_onSimAboutToBeDisconnected(makVrv::DtConnection* connection);

   //Sends out a PDU or interaction with hard coded values given a particular protoco;
   virtual void slot_onSendPdu(makVrv::DtConnection* connection);
protected:
   makVrf::VRF_PROTOCOL_NAMESPACE::DtVrfDriver* myDriver;
};

networkCallbackManagerAccessory.cxx

/******************************************************************************
** Copyright (c) 2012 MAK Technologies, Inc.
** All rights reserved.
******************************************************************************/

//\file DtNetworkCallbackManagerAccessory.inl
//\brief Contains implementation of the accessory that will be used to send
//and receive the DtTestPdu and DtTestInteraction objects.  It will show
//how to use the DtNetworkCallbackManager and how to use threaded event
//signalers in order to communicate from the front-end (network independent
//thread) to the network dependent thread
//to

#include "networkCallbackManagerAccessory.h"

//Use comment interaction as test interaction, however, any pdu/interaction could
//be used
#include <vl/commentInter.h>

//Class that will be used to communicate network information to the GUI thread
#include "DtTestInteractionInterface.h"

//Class that is used to signal events from the GUI thread to the network driver accessory
#include "DtExampleEventSignaler.h"

#include <vrvVrl/DtVrlinkConnection.h>
#include <vrvVrl/DtVrlinkDriver.h>

#include <boost/bind.hpp>
static void DtTestInteractionCb(DtCommentInteraction* pdu, void* usr)
{
   DtTestInteractionInterface iface;
   DtString message(pdu->comment());
   iface.setMessage(message.c_str());

   static_cast<DtNetworkCallbackManagerAccessory*>(usr)->received(&iface);
}

using namespace makVrf;

DtNetworkCallbackManagerAccessory::DtNetworkCallbackManagerAccessory()
: makVrv::DtBaseAccessory()
, myDriver(0)
{
#ifdef DtHLA
#ifdef DtHLA_1516
#ifdef DtHLA_1516_EVOLVED
   myName="DtNetworkCallbackManagerHLA1516eAccessory";
#else
   myName="DtNetworkCallbackManagerHLA1516Accessory";
#endif
#else
   myName="DtNetworkCallbackManagerHLA13Accessory";
#endif
#elif DtDIS
myName="DtNetworkCallbackManagerDISAccessory";
#endif
}

DtNetworkCallbackManagerAccessory::~DtNetworkCallbackManagerAccessory()
{
   if (myDriver)
   {
      slot_onSimAboutToBeDisconnected(myDriver->connection());
      uninstall(myDriver);
   }
}

void DtNetworkCallbackManagerAccessory::install(makVrv::DtDriver* driver)
{         
   makVrf::VRF_PROTOCOL_NAMESPACE::DtVrfDriver* vld = dynamic_cast<makVrf::VRF_PROTOCOL_NAMESPACE::DtVrfDriver*>(driver);
   if(vld)
   {
      //connect accessory to connection signals.
      vld->signal_simulationCreated.connect(
         boost::bind(&DtNetworkCallbackManagerAccessory::slot_onSimCreated, this, _1));

      myDriver = vld;
   }
}

void DtNetworkCallbackManagerAccessory::uninstall(makVrv::DtDriver* baseConn)
{         
   makVrv::DtVrlinkDriver* vld = dynamic_cast<makVrv::DtVrlinkDriver*>(baseConn);
   if(vld)
   {
      //disconnect accessory from connection signals.
      vld->signal_simulationCreated.disconnect(
         boost::bind(&DtNetworkCallbackManagerAccessory::slot_onSimCreated, this, _1));
   }

   myDriver = 0;
}

bool DtNetworkCallbackManagerAccessory::isCompatible(makVrv::DtDriver* driver)
{
   makVrf::VRF_PROTOCOL_NAMESPACE::DtVrfDriver* dd = dynamic_cast<makVrf::VRF_PROTOCOL_NAMESPACE::DtVrfDriver*>(driver);

   if(dd)
   {
      return true;
   }

   return false;
}

void DtNetworkCallbackManagerAccessory::received(DtNetworkMessageInterface* iface)
{
   myDriver->receivedNetworkMessage(iface);
}

void DtNetworkCallbackManagerAccessory::slot_onSimCreated(makVrv::DtConnection* connection)
{
   connection->signal_connected.connect(
      boost::bind(&DtNetworkCallbackManagerAccessory::slot_onSimConnected, this, connection));

   connection->signal_toBeDisconnected.connect(
      boost::bind(&DtNetworkCallbackManagerAccessory::slot_onSimAboutToBeDisconnected, this, connection));
}

void DtNetworkCallbackManagerAccessory::slot_onSimConnected(makVrv::DtConnection* connection)
{
   makVrv::DT_PROTOCOL_NAMESPACE::DtVrlinkConnection* vrlCon = dynamic_cast<makVrv::DT_PROTOCOL_NAMESPACE::DtVrlinkConnection*>
      (connection);

   if(vrlCon)
   {
      DtCommentInteraction::addCallback(vrlCon->exerciseConn(), DtTestInteractionCb, this);
      //Add connection for event signal to send off the pdu or interaction depending on protocol
      DtExampleEventSignaler::instance(connection->settingsManager()).signal_sendPdu.connect(
         boost::bind(&DtNetworkCallbackManagerAccessory::slot_onSendPdu, this, connection));
   }
}

//Called in response to queued signal, will send interaction or pdu onto the network
void DtNetworkCallbackManagerAccessory::slot_onSendPdu(makVrv::DtConnection* connection)
{
   makVrv::DT_PROTOCOL_NAMESPACE::DtVrlinkConnection* vrlCon = dynamic_cast<makVrv::DT_PROTOCOL_NAMESPACE::DtVrlinkConnection*>
      (connection);

   if(vrlCon)
   {
      DtCommentInteraction testPdu;

      std::string message = "Sent from " + myName;

      testPdu.setComment(message.c_str(), message.length());
#if DtHLA
      //Needed in HLA to receive interactions sent by us
      vrlCon->exerciseConn()->setReflecting();
#endif
      vrlCon->exerciseConn()->sendStamped(testPdu);
   }
}

void DtNetworkCallbackManagerAccessory::slot_onSimAboutToBeDisconnected(makVrv::DtConnection* connection)
{
   connection->signal_connected.disconnect(
      boost::bind(&DtNetworkCallbackManagerAccessory::slot_onSimConnected, this, connection));

   connection->signal_toBeDisconnected.disconnect(
      boost::bind(&DtNetworkCallbackManagerAccessory::slot_onSimAboutToBeDisconnected, this, connection));
   makVrv::DT_PROTOCOL_NAMESPACE::DtVrlinkConnection* vrlCon = dynamic_cast<makVrv::DT_PROTOCOL_NAMESPACE::DtVrlinkConnection*>
      (connection);

   if(vrlCon)
   {
      DtCommentInteraction::removeCallback(vrlCon->exerciseConn(), DtTestInteractionCb, this);
      DtExampleEventSignaler::instance(connection->settingsManager()).signal_sendPdu.disconnect(
         boost::bind(&DtNetworkCallbackManagerAccessory::slot_onSendPdu, this, connection));
   }
}

Document ID: Generated on Fri Jun 29 16:33:32 EDT 2012 from SVN revision 116588
Copyright © 2005-2012 VT MÄK Inc. All Rights Reserved (www.mak.com)