VR-Forces 4.6.1 Class Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Air Vehicle Set Controller

This subclass of the DtAirVehicleSetController registers for the new DtSetSpeedAndHeadingRequest and sets the appropriate values into the VRF state repository.


Header file:

/*******************************************************************************
** Copyright (c) 2006 MAK Technologies, Inc.
** All rights reserved.
*******************************************************************************/
/*******************************************************************************
** $RCSfile: myAirVehSetCtlr.h,v $ $Revision: 1.2 $ $State: Exp $
*******************************************************************************/

//\file myAirVehSetCtlr.h
//\brief MyAirVehicleSetController; handles new DtSetSpeedAndHeadingRequest


#ifndef MyAirVehicleSetController_H_
#define MyAirVehicleSetController_H_


#include "vrfmodel/airVehicleSetController.h"
#include "vrfobjcore/simRadio.h"

namespace vrfAddSetExample
{

   //\brief MyAirVehicleSetController is a controller that handles new
   //DtSetSpeedAndHeadingRequest.  It replaces the existing DtAirVehicleSetController
   //
   //Uses Descriptor Type: DtComponentDescriptor

   class MyAirVehicleSetController : public DtAirVehicleSetController
   {

   public:

      //\copydoc DtSimComponent(const DtString&,DtVrfObject*,DtSimManager*,
      //DtComponentDescriptor*,DtReaderWriterRegistry* parentRegistry)
   MyAirVehicleSetController(const DtString& name, 
      DtVrfObject* owner,
      DtSimManager* simManager, 
      DtComponentDescriptor* desc = 0,
      DtReaderWriterRegistry* parentRegistry = 0);

      //destructor
   virtual ~MyAirVehicleSetController();

   virtual void processSetSpeedAndHeading(DtSimMessage * msg);

   static void setSpeedAndHeadingCallback(DtSimMessage * msg, void * usrData);

      //\copydoc DtSimComponent(const DtString&,DtVrfObject*,DtSimManager*,
      //DtComponentDescriptor*,DtReaderWriterRegistry* parentRegistry)
      //\return New instance of this class.
   static DtSimComponent * creator(const DtString& name, 
      DtVrfObject* owner,
      DtSimManager* simManager, 
      DtComponentDescriptor* desc = 0,
      DtReaderWriterRegistry* parentRegistry = 0);

   private:
      //Default constructor; should not be called.  Here because the compiler
      //will generate an unprotected one otherwise.
   MyAirVehicleSetController();

      //copy constructor
   MyAirVehicleSetController(const MyAirVehicleSetController& orig);

      //assignment operator
   const MyAirVehicleSetController & operator=(const 
      MyAirVehicleSetController& orig);


   protected:
      //Overrides this so it can register its interest in the set commands.
   virtual void setRadio(DtSimRadio * radio);
   };
}
#endif


Implementation:

/*******************************************************************************
** Copyright (c) 2006 MAK Technologies, Inc.
** All rights reserved.
*******************************************************************************/
/*******************************************************************************
** $RCSfile: myAirVehSetCtlr.cxx,v $ $Revision: 1.1 $ $State: Exp $
*******************************************************************************/

//
//File:        myAirVehSetCtlr.cxx
//
//Class:       MyIndividualLifeFormSetController
//

#include "myAirVehSetCtlr.h"
#include "vrfcore/simManager.h"
#include "vrfobjcore/vrfObjectManager.h"

#include "vrfobjcore/simComponentTypes.h"
#include "vrfobjcore/simRadio.h"
#include "vrftasks/setDataTypes.h"
#include "vrfobjcore/setDataManager.h"
#include "vrfobjcore/vrfMovingObjectStateRepository.h"

#include "vrfmsgs/setDataRequestMessage.h"
#include "setSpeedAndHeading.h"

namespace vrfAddSetExample
{
   //constructor
   MyAirVehicleSetController::MyAirVehicleSetController(
   const DtString& name, 
   DtVrfObject* owner,
   DtSimManager* simManager, 
   DtComponentDescriptor* desc, 
   DtReaderWriterRegistry* parentRegistry) :
   DtAirVehicleSetController(name, owner, simManager, desc, parentRegistry)
   {
   }

   //destructor
   MyAirVehicleSetController::~MyAirVehicleSetController()
   {
   entity()->setDataManager()->removeSetDataCallback(DtSetSpeedAndHeadingType, 
      setSpeedAndHeadingCallback, (void *) this);
   }

   void MyAirVehicleSetController::processSetSpeedAndHeading(DtSimMessage* msg)
   {
   DtSetDataRequestMessage* drMsg = (DtSetDataRequestMessage *) msg;
   DtSetSpeedAndHeadingRequest* req = (DtSetSpeedAndHeadingRequest *)drMsg->setDataRequest();
   DtVrfMovingObjectStateRepository* movingSR = 
      DtVrfMovingObjectStateRepository::isVrfMovingObjectStateRepository(
      localStateRepository());

   if (movingSR)
   {
      movingSR->setOrderedSpeed(req->speed());
   }

   myLocalEntity->place(req->heading());
   objectConsoleInfo() << "Setting heading: " << req->heading() << " and speed: " << req->speed() << std::endl;
   }

   void MyAirVehicleSetController::setSpeedAndHeadingCallback(DtSimMessage* msg, 
   void* usrData)
   {
   ((MyAirVehicleSetController *)usrData)->processSetSpeedAndHeading(msg);
   }

   //overrides this so it can register it's interest in the set commands
   void MyAirVehicleSetController::setRadio(DtSimRadio* radio)
   {
   DtAirVehicleSetController::setRadio(radio);

   entity()->setDataManager()->addSetDataProcessorCallback(DtSetSpeedAndHeadingType, 
      setSpeedAndHeadingCallback, (void *) this);
   }

   DtSimComponent* MyAirVehicleSetController::creator(
   const DtString& name, 
   DtVrfObject* owner,
   DtSimManager* simManager, 
   DtComponentDescriptor* desc, 
   DtReaderWriterRegistry* parentRegistry)
   {
   return new MyAirVehicleSetController(name, owner, simManager, desc,
      parentRegistry);
   }
}

Document ID: Generated on Wed Jul 25 16:57:45 EDT 2018 from SVN revision 190790
Copyright © 2005-2018 VT MÄK. All Rights Reserved (www.mak.com)