VR-Forces 4.0.4 Class Documentation
Interface Content Example

The Interface Content example demonstrates the following:

The Interface Content example creates a new type of VRF interface message class MyInterfaceContent which demonstrates how to send and receive interface content messages.

Since this example is loaded as a plugin, it can be used in conjunction with the released VR-Forces application

Classes

MyInterfaceContentThe interface content message.

Plugin Entry Points

/*******************************************************************************
** Copyright (c) 2003 MAK Technologies, Inc.
** All rights reserved.
*******************************************************************************/
/*******************************************************************************
** $RCSfile: plugin.cxx,v $ $Revision: 1.3 $ $State: Exp $
*******************************************************************************/

//Example includes
#include "myInterfaceContent.h"

//VR-Forces includes
#include "vrfcgf/vrfPluginExtension.h"

//VR-Forces includes
#include "vrfcgf/cgf.h"
#include "vrfcgf/factoryMgr.h"
#include "vrfcore/simMgr.h"
#include "vrfMsgTransport/vrfMsgIf.h"
#include "vrfmsgs/ifaceMsg.h"
#include "vrfutil/consoleCommandManager.h"

//VR-Link includes
#include <vlutil/vlPrint.h>
#include <vl/exerciseConn.h>

static DtSimulationAddress theSimulationAddress;
static DtSimManager* theSimManager = 0;
static int theOutgoingMessageNumber = 0;

extern "C" {
   //Callback function to print out incoming messages
   static void messageCallback(DtSimMessage* msg, void* usr)
   {
      DtSimInterfaceMessage* ifMsg = (DtSimInterfaceMessage*)msg;
      MyInterfaceContent* myContent =
         (MyInterfaceContent*)ifMsg->interfaceContent();

      if (myContent->ack())
      {
         //Don't send out a response as this could cause an infinite loop.
      }
      else if (ifMsg->sender() == theSimulationAddress)
      {
         //Don't send out a response to a message you sent.
      }
      else if (theSimManager)
      {
         DtString output;
         myContent->printDataToString(output);
         DtInfo("messageCallback received MyInterfaceContent:\n");
         DtInfo("--------------------------------------------\n");
         DtInfo("%s\n", output.string());

         //Now, send out ack with receipt string
     
         //Send a test message 
         MyInterfaceContent msg;
         DtString response;

         response = "Server Response (";
         response += theSimulationAddress.string();
         response += "): Received: ";
         response += myContent->message();

         msg.setMessage(response);
         msg.setNumber(myContent->number());
         msg.setAck(true);

         theSimManager->createAndDeliverMessage(DtSimSendToAll, msg);
      }
   }

   class DtPingCommand : public DtConsoleCommand
   {
      ~DtPingCommand() { };
      //Execute the command.
      //\return True on success of the command.
      virtual bool execute(const DtString& parameters)
      {
         MyInterfaceContent msg;
         DtString messageToSend;

         messageToSend = "Test message from (";
         messageToSend += theSimulationAddress.string();
         messageToSend += "): Sending Text: ";
         messageToSend += parameters;

         msg.setMessage(messageToSend);
         msg.setNumber(theOutgoingMessageNumber++);
         msg.setAck(false);

         theSimManager->createAndDeliverMessage(DtSimSendToAll, msg);
         return true;
      }
      //\return Some help text for the command.
      virtual DtString help(const DtString& parameters)
      {
         return "Send a message with the given text.";
      };
      //\return True if this command should show up in the help list.
      //If false, than this command will not be presented to the user.
      virtual bool showInHelp() const { return true; };
   };

   static DtPingCommand* thePingCommand = new DtPingCommand();

   DT_VRF_DLL_PLUGIN void DtPluginInformation(DtVrfPluginInformation& info)
   {
      info.pluginName = "interfaceContentSim";
      info.pluginDescription = "This is an example of how to add a new interface message in the VRF back-end.";
      info.pluginVersion = "1.00";
      info.pluginCreator = "MAK Technologies";
      info.pluginCreatorEmail = "sales@mak.com";
      info.pluginContactWebPage = "www.mak.com";
      info.pluginContactMailingAddress = "68 Moulton Street - Cambridge, MA 02138";
      info.pluginContactPhone = "(617) 876 8085";
   }

   DT_VRF_DLL_PLUGIN bool DtInitializeVrfPlugin(DtCgf* cgf)
   {          
      //Register the creator for MyInterfaceContentType with the
      //DtInterfaceContentFactory
      cgf->factoryManager()->interfaceContentFactory()->addCreatorFcn(
         MyInterfaceContentType, MyInterfaceContent::creator);  

      return true;
   }

   //Now that everything is initialized, send out a test message
   DT_VRF_DLL_PLUGIN bool DtPostInitializeVrfPlugin(DtCgf* cgf)
   {
      //Register for callbacks on MyInterfaceContent with the
      //DtVrfMessageInterface
      cgf->simManager()->messageInterface()->addMessageCallback(
         MyInterfaceContentType, messageCallback, NULL);

      theSimulationAddress = cgf->exerciseConn()->applicationId();
      theSimManager = cgf->simManager();

      DtConsoleCommandManager::globalConsoleCommandManager()->addCommand("ping",
         thePingCommand);

      return true;
   }
}


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)