VR-Link API Documentation for HLA 1516
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
patch.h
Go to the documentation of this file.
1 //********************************************************************
2 // Copyright (c) 2006 MaK Technologies, Inc.
3 // All rights reserved.
4 //********************************************************************
5 #if DtHLA
6 
7 #include <stdio.h>
9 #include <vlutil/vlString.h>
10 #include <vl/platformEncoder.h>
11 #include <vl/platformDecoder.h>
12 #include <vl/fomMapper.h>
13 #include <vl/stateEncoderFactory.h>
14 #include <vl/stateDecoderFactory.h>
15 #include <vl/fom.h>
16 #include <vlpi/entityTypes.h>
17 
23 {
24 public:
27  myAttrib("")
28 
29  { printf("\n===================\n"
30  "Constructing DtF18EntityStateRep\n"
31  "=====================\n"); }
32 
34  virtual ~DtF18EntityStateRep() {}
35 
36 private:
37 
40 
43 
44 public:
45 
47  virtual void setF18Attribute(const DtString & val) { myAttrib = val;}
49  virtual DtString f18Attribute() const { return myAttrib;}
50 
53  static DtF18EntityStateRep* create() { return new DtF18EntityStateRep; };
54 
55 
56 protected:
57 
59 
60 };
61 
66 {
67 public:
70  DtObjClassDesc* classDesc):
72  DtPlatformDecoder(exConn, classDesc)
73  {
75  addDecoder("SpecialF18Attribute",
77  }
78 
80  virtual ~DtF18EntityDecoder(){}
81 
82 protected:
83 
89  int pairSetIndex)
90  {
91  RTI::ULong length = attrs.getValueLength(pairSetIndex);
92  // if there is nothing in there, we can exit safely
93  if (length == 0) return;
94 
95  char* buffer = DtDecodingBuffer(length+1);
96  attrs.getValue(pairSetIndex, buffer, length);
97  buffer[length] = '\0';
98 
99  stateRep->setF18Attribute(buffer);
100  }
101 
102 };
103 
108 {
109 public:
112  DtObjClassDesc* classDesc):
113  // By calling the base class ctor all the needed encoders and checkers are registered
114  DtPlatformEncoder(exConn, classDesc)
115  {
116  // Register our encoder functions for all the attributes we need.
117  addEncoder("SpecialF18Attribute",
119  addChecker("SpecialF18Attribute",
121  }
122  virtual ~DtF18EntityEncoder() {}
123 
124 protected:
125 
126  static bool needSpecialF18Attribute( const DtF18EntityStateRep& stateRep,
127  const DtF18EntityStateRep& asSeenByRemote)
128  {
129  return(stateRep.f18Attribute() != asSeenByRemote.f18Attribute());
130  }
131 
132  static void encodeSpecialF18Attribute( const DtF18EntityStateRep& stateRep,
134  RTI::AttributeHandle attrHandle)
135  {
136  // This is easy, they are not all this easy. The point of this example
137  // is not to show how to encode/decode complex data types.
138  avList->add(attrHandle,
139  stateRep.f18Attribute().c_str(),
140  stateRep.f18Attribute().size());
141  }
142 
143 };
144 
145 // Some useful macros for adding the encoders/decoders
147 #define DtADD_ENCODER(className, derivedEnc) \
148 { \
149  DtObjClassDesc* classDesc = exConn.fom()->objClassByName(#className); \
150  if (classDesc) \
151  { \
152  exConn.fomMapper()->stateEncoderFactory()->addEncoder( \
153  classDesc->handle(), new derivedEnc(&exConn, classDesc)); \
154  } \
155  else \
156  { \
157  DtWarn("Can't add encoder for object class %s: Not in FOM.\n", #className); \
158  } \
159 }
160 
162 #define DtADD_DECODER(className, derivedDec) \
163 { \
164  DtObjClassDesc* classDesc = exConn.fom()->objClassByName(#className); \
165  if (classDesc) \
166  { \
167  exConn.fomMapper()->stateDecoderFactory()->addDecoder( \
168  classDesc->handle(), new derivedDec(&exConn, classDesc)); \
169  } \
170  else \
171  { \
172  DtWarn("Can't add decoder for object class %s: Not in FOM.\n", #className); \
173  } \
174 }
175 
177 char* DtF18EntityChooser( const char* vrlinkClassName,
178  DtExerciseConn* exConn,
179  void *usr)
180 {
181  printf("=========\n");
182  printf(" In Class Chooser, deciding which entity Type to publish\n");
183  printf("=========\n");
184 
185  // For Entities, the usr data is always of DtEntityType. This is just
186  // the way it is.
187 
188  DtEntityType& type = *((DtEntityType*) usr);
189 
190  if (type.subCategory() == DtF18)
191  {
192  printf("Choosing F18 Type, we will use the new class!\n");
193  // Return the FOM OBJECT CLASS name
194  return "BaseEntity.PhysicalEntity.Platform.Aircraft.F18";
195  }
196 
197  // If this is not the right type, let the default chooser decide
198  return(DtRprFomMapper::dfltEntityClassChooser(vrlinkClassName,
199  exConn, usr));
200 }
201 
202 
203 #endif
virtual ~DtF18EntityStateRep()
Destructor.
Definition: patch.h:34
unsigned long getValueLength(unsigned long i) const
DtString myAttrib
Definition: patch.h:53
Instances of DtExerciseConn are used to provide an application&#39;s interface or connection to the netwo...
Definition: exerciseConnHLA.h:61
DtAttributeEncoder addEncoder(RTI::AttributeHandle hand, DtAttributeEncoder func)
Add/Remove an encoding function for the attribute specified by handle.
An example subclass of DtPlatformEncoder for use with DtF18EntityStateRep.
Definition: patch.h:107
Contains the DtString class declaration.
void add(HandleType h, const char *buffer, unsigned long valueLength)
void(* DtAttributeDecoder)(DtStateRepository *stateRep, const RTI::AttributeHandleValuePairSet &avlist, unsigned long pairSetIndex)
Attribute decoding function declaration.
Definition: hlaStateDecoder.h:53
char * DtF18EntityChooser(const char *vrlinkClassName, DtExerciseConn *exConn, void *usr)
Definition: patch.h:177
class DtPlatformEncoder:
Definition: platformEncoder.h:25
This file declares enumerations for use with DtEntityType.
void(* DtAttributeEncoder)(const DtStateRepository &stateRep, RTI::AttributeHandleValuePairSet *avList, RTI::AttributeHandle handle)
Attribute encoding function declaration.
Definition: hlaStateEncoder.h:50
DT_DLL_VLPROTIND char * DtDecodingBuffer(unsigned int requestedLength)
DtDecodingBuffer returns a pointer to a chunk of memory requestedLength long which can be used for de...
This file declares DtFomMapper.
static void encodeSpecialF18Attribute(const DtF18EntityStateRep &stateRep, RTI::AttributeHandleValuePairSet *avList, RTI::AttributeHandle attrHandle)
Definition: patch.h:132
int subCategory() const
Definition: entityType.h:88
DtF18EntityStateRep & operator=(const DtF18EntityStateRep &orig)
assignment operator – Not Implemented
DtF18EntityEncoder(DtExerciseConn *exConn, DtObjClassDesc *classDesc)
Constructor that registers the new attributes.
Definition: patch.h:111
void getValue(unsigned long i, char *buffer, unsigned long &valueLength) const
An instance of DtObjClassDesc is a &quot;class descriptor&quot; for an HLA Object class.
Definition: objClassDesc1516.h:41
class DtPlatformDecoder:
Definition: platformDecoder.h:26
static bool needSpecialF18Attribute(const DtF18EntityStateRep &stateRep, const DtF18EntityStateRep &asSeenByRemote)
Definition: patch.h:126
This file declares DtFom.
DtF18EntityDecoder(DtExerciseConn *exConn, DtObjClassDesc *classDesc)
Ctor.
Definition: patch.h:69
Instances of DtEntityStateRepository are used to maintain attributes and state of entity objects in a...
Definition: entityStateRepository.h:41
DtAttributeChecker addChecker(RTI::AttributeHandle hand, DtAttributeChecker func)
Add/Remove a checker function for the attribute specified by handle.
Definition: entityTypes.h:219
Contains the DtEntityStateRepository class declaration.
This file provides a declaration of the class DtPlatformDecoder.
virtual DtString f18Attribute() const
The new attribute string.
Definition: patch.h:49
virtual ~DtF18EntityDecoder()
destructor
Definition: patch.h:80
virtual const char * c_str() const
Returns a char* representation of the DtString;.
static DtF18EntityStateRep * create()
Need this so that reflected Lists will know how to create an instance of the DtF18EntityStateRep.
Definition: patch.h:53
virtual void setF18Attribute(const DtString &val)
Set the new attribute string.
Definition: patch.h:47
static char * dfltEntityClassChooser(const char *vrlinkClassName, DtExerciseConn *exConn, void *usr)
The default entity class chooser function.
Used to provide backwards compatibility for VR-Link Encoders and Decoders who use either AttributeHan...
Definition: rtiCompatibility.h:154
An example subclass of the DtEntityStateRepository.
Definition: patch.h:22
DtF18EntityStateRep()
Constructor.
Definition: patch.h:26
static void decodeSpecialF18Attribute(DtF18EntityStateRep *stateRep, const RTI::AttributeHandleValuePairSet &attrs, int pairSetIndex)
all Encoder/Decoder classes need to be static.
Definition: patch.h:87
An example subclass of DtPlatformDecoder for use with DtF18EntityStateRep.
Definition: patch.h:65
DtAttributeDecoder addDecoder(RTI::AttributeHandle h, DtAttributeDecoder func)
Add/Remove a decoding function for the attribute specified by handle.
Instances of DtString are used to represent strings.
Definition: vlString.h:29
virtual int size() const
size() - returns the length of the string not including the terminating &#39;\0&#39;
unsigned long ULong
These typedefs are provided for source compatibility.
Definition: rtiCompatibility.h:191
This file provides a declaration of the class DtPlatformEncoder.
bool(* DtAttributeChecker)(const DtStateRepository &stateRep, const DtStateRepository &asSeenByRemote)
Attribute checking function declaration.
Definition: hlaStateEncoder.h:56
DtEntityType is used to represent the type an entity object.
Definition: entityType.h:26
This file contains the declaration of DtStateDecoderFactory.
virtual ~DtF18EntityEncoder()
Definition: patch.h:122

Document ID: Generated on Wed Mar 27 02:04:30 EDT 2024 from SVN revision 264570
Copyright © 2005-2024 MAK Technologies. All Rights Reserved (www.mak.com)