VR-Forces 5.0.1 Developer's Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Interface Content (interfaceContentSim)

Table of Contents

The Interface Content example demonstrates the following:

Creating a New Type of Interface Message

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.

How to Run the Example

Usage

In the Launcher, click the Plug-ins button to bring up the Plug-ins Selection dialog. Enable the plugin.

To view the new behavior:

  1. Start VR-Forces GUI and SIM.
  2. There is no need to load an existing or create a new scenario.
  3. A new menu item - 'Send Interface Content Message...' will be created under the Simulation menu.
  4. Type in a message in the displayed Interface Content dialog, and press OK button to send the message.
  5. The SIM will receive the message and send an acknowledgement to the GUI.
  6. Upon receipt, both SIM and GUI will print a message to their console windows.

Classes

MyInterfaceContentThe Interface Content Message.

Plugin Entry Points

/*******************************************************************************
** Copyright (c) 2021 MAK Technologies, Inc.
** All rights reserved.
*******************************************************************************/
//Example includes
//VR-Forces includes
//VR-Forces includes
#include "vrfcgf/cgf.h"
//VR-Link includes
#include <vlutil/vlPrint.h>
#include <vl/exerciseConn.h>
static DtSimulationAddress theSimulationAddress;
static DtSimulationServices* theSimManager = nullptr;
static int theOutgoingMessageNumber = 0;
extern "C" {
//Callback function to print out incoming messages
static void messageCallback(DtSimMessage* msg, void* usr)
{
MyInterfaceContent* myContent =
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
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)
{
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();
{
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 = "10 Fawcett Street, Suite 204, Cambridge, MA 02138 USA";
info.pluginContactPhone = "(617) 876 8085";
}
DT_VRF_DLL_PLUGIN bool DtInitializeVrfPlugin(DtCgf* cgf)
{
//Register the creator for MyInterfaceContentType with the
//DtInterfaceContentFactory
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
MyInterfaceContentType, messageCallback, NULL);
theSimulationAddress = cgf->simulationServices()->messageAddress();
theSimManager = cgf->simulationServices();
thePingCommand);
return true;
}
}

Document ID: Generated on Mon Jun 20 00:38:30 EDT 2022 from SVN revision 244029
Copyright © 2005-2021 MAK Technologies. All Rights Reserved (www.mak.com)