VR-Link API Documentation for HLA 1.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Test Interaction

The files testInter.h and testInter.cxx contain definitions for a new class called TestInteraction, and its member functions.

Like all interaction classes in VR-Link, it is derived from DtInteractionWithEncDec, rather than directly from DtInteraction. DtInteraction is rather general, and allows for a wide variety of subclass implementations, including those that do not involve our concept of encoders and decoders. DtInteractionWithEncDec is set up to deal with encoders and decoders, and we will be taking advantage of this.

TestInteraction includes inspector and mutator functions to access the values of the Number and Parameter attributes. We represent them in the same way as in the FOM, but this is not strictly necessary. We could perform a non-trivial conversion in FOM mapping code instead.

The TestInteraction class hard-codes its own FOM mapping information, rather than relying on the default behavior, which is to obtain it from the FOM Mapper. We do this here, because it make things simpler, by saving us the step of configuring the FOM Mapper with mappings for our new class. But this choice means that it would be more difficult to change the way this kind of interaction is represented in the FOM.

This choice manifests itself in the fact that we override the virtual functions interactionClassToUse(), createEncoder() and createDecoder(). The base class implementation of interactionClassToUse() asks the FOM Mapper for the name of a FOM class to use. But TestInteraction's implementation just returns the class name Test. The base versions of createEncoder() and createDecoder() ask the FOM Mapper for instances of the kind of encoder and decoder that have been registered with it for use with the Test interaction class. But TestInteraction's implementations of these functions just return a new'ed TestEncoder and TestDecoder instance respectively.

In addition, within TestInteraction::addCallback(), we inform the DtExerciseConn's interaction factory that it should create an instance of the TestInteraction class to represent incoming interactions of FOM class Test. This is achieved using DtInteractionFactory's addCreator() member function.

Notice that the TestInteraction has decided that it will use instances of the classes TestEncoder and TestDecoder to map between its representation of its parameters, and the FOM representation.


/*********************************************************************
** Copyright (c) 1992-2010 VT MAK
** All rights reserved.
*********************************************************************/
#ifndef TestInteraction_H_
#define TestInteraction_H_
#if DtHLA
typedef void (*TestInteractionCb)(TestInteraction* inter, void* usr);
{
public:
virtual ~TestInteraction();
virtual const char* name() const;
virtual void printData() const;
// **************************************************************
// Inspector and mutator functions for the interaction class' data.
// These will look different for each DtInteraction subclass.
// None are required by VR-Link, but the class will not be
// particularly useful without a way to get data in and out in a
// typesafe manner.
// **************************************************************
virtual void setNumber(int num);
virtual int number() const;
virtual void setVector(const DtVector& vec);
virtual const DtVector& vector() const;
public:
static DtInteraction* create();
static void addCallback(DtExerciseConn* conn,
TestInteractionCb cb, void* usr);
static void removeCallback(DtExerciseConn* conn,
TestInteractionCb cb, void* usr);
protected:
virtual const char* interactionClassToUse(DtExerciseConn* exConn) const;
protected:
int myNum;
};
#endif
#endif

/*********************************************************************
** Copyright (c) 1992-2010 VT MAK
** All rights reserved.
*********************************************************************/
#if DtHLA
#include "testInter.h"
// Header files for encoder and decoder.
#include "testEnc.h"
#include "testDec.h"
#include <iostream>
// Constructor - just initialize the base class, and local data holders.
myNum(0),
myVec()
{
}
// Destructor - nothing to do.
{
}
// Copy constructor
{
myNum = orig.number();
myVec = orig.vector();
}
// Assignment operator
{
// Guard against assignment to yourself.
if (this == &orig)
{
return *this;
}
myNum = orig.number();
myVec = orig.vector();
return *this;
}
const char* TestInteraction::name() const
{
// Return the name of this C++ class.
return "TestInteraction";
}
{
std::cout << "Number: " << number() << '\n';
// DtVector has a string() member function to get a printable string.
// Since it returns a DtString, we need to force it to const char* with a
// cast.
std::cout << "Vector: " << vector().string() << std::endl;
}
// Accessor functions are typically pretty straightforward.
{
myNum = num;
}
{
return myNum;
}
{
myVec = vec;
}
{
return myVec;
}
{
return new TestInteraction();
}
TestInteractionCb cb, void* usr)
{
// Cast the TestInteractionCb to the more general DtReceiveInteractionCb
// and pass it along with the FOM class name to the DtExerciseConn who
// actually maintains the callback lists for all interaction classes.
"Test", (DtReceiveInteractionCb) cb, usr);
// In addition, we choose to register the TestInteraction class with
// VR-Link here, by associating TestInteraction's create function with the
// right FOM class. By doing this here, we avoid making the user perform
// this registration step.
conn->interactionFactory()->addCreator("Test",
}
TestInteractionCb cb, void* usr)
{
// Cast the TestInteractionCb to the more general DtReceiveInteractionCb
// and pass it along with the FOM class name to the DtExerciseConn who
// actually maintains the callback lists for all interaction classes.
"Test", (DtReceiveInteractionCb) cb, usr);
}
{
return "Test";
}
DtExerciseConn* exConn) const
{
return new TestDecoder(exConn, classDesc());
}
DtExerciseConn* exConn) const
{
return new TestEncoder(exConn, classDesc());
}
#endif

Document ID: Generated on Mon Apr 8 04:49:21 EDT 2019 from SVN revision 197403
Copyright © 2005-2016 VT MÄK. All Rights Reserved (www.mak.com)