VR-Link API Documentation for HLA 1516
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
hlaStateDecoder.h
Go to the documentation of this file.
1 /*********************************************************************
2 ** Copyright (c) 1992-2025 MAK Technologies, Inc
3 ** All rights reserved.
4 *********************************************************************/
5 
8 
9 #ifndef DtHlaStateDecoder_H_
10 #define DtHlaStateDecoder_H_
11 
12 #if DtHLA
13 
14 
15 #include <vlutil/vlMachineTypes.h>
16 #include <vlutil/vlPrint.h>
17 #include <vlutil/vlUuid.h>
18 #include <vlpi/bufferMgr.h>
19 #include "rtiNamespace.h"
20 #include "rtiCompatibility.h"
21 #include <map>
22 #include <vector>
23 
27 class DT_DLL_VL DtStateMsg;
29 
30 
35 {
36 public:
37 
40  DtExerciseConn* exConn,
41  DtObjClassDesc* classDesc);
42 
44  virtual ~DtHlaStateDecoder();
45 
48 
50  DtHlaStateDecoder& operator=(const DtHlaStateDecoder& orig);
51 
53  typedef void (*DtAttributeDecoder) (
54  DtStateRepository* stateRep,
56  unsigned long pairSetIndex);
57 
63  DtAttributeDecoder addDecoder(RTI::AttributeHandle h,
64  DtAttributeDecoder func);
65  DtAttributeDecoder removeDecoder(RTI::AttributeHandle h);
66 
73  DtAttributeDecoder addDecoder(char* attrName,
74  DtAttributeDecoder func, bool complain = true);
75  DtAttributeDecoder removeDecoder(char* attrName, bool complain = true);
76 
78  virtual DtAttributeDecoder decoder(const RTI::AttributeHandle &handle) const;
79 
81  virtual void decode(const DtStateMsg& msg,
82  DtStateRepository* stateRep) const ;
83 
85  virtual RTI::ObjectClassHandle objectClassHandle() const;
86 
88  virtual DtHlaStateDecoder* clone() const;
89 
94  virtual DtHlaStateDecoder* clone(DtObjClassDesc* classDesc) const;
95 
96 public:
97 
102  static inline char* decodingBuffer(int length);
103 
105  static char* attributeData(const RTI::AttributeHandleValuePairSet& attrs,
106  int index, RTI::ULong& length);
107 
113  static char* attributeData(
114  const RTI::AttributeHandleValuePairSet& attrs, int index, RTI::ULong& length,
115  unsigned int expectedDataSize, char* attrName);
116 
119  static DtNetEventId* eventIdAttributeData(const RTI::AttributeHandleValuePairSet& attrs,
120  int index);
121 
123 
127  static std::wstring wideStringFromHlaUnicodeString(char* buffer, int size, bool* error = nullptr);
128 
132  static bool getVectorFromArrayOfUuid(char* buffer, int size, std::vector< DtVrlUuid >& uuids);
133 
134 protected:
135 
138  virtual void decodeAttribute(
139  DtStateRepository* stateRep,
141  unsigned long pairSetIndex) const;
142 
143  virtual void copyDecFuncs( const DtHlaStateDecoder& orig);
144 protected:
145 
146  typedef std::map<RTI::AttributeHandle, DtAttributeDecoder> AttributeHandleDecoderMap;
147  typedef std::map<RTI::AttributeHandle, bool> AttributeHandleBoolMap;
148 
149 protected:
150 
153  RTI::ObjectClassHandle myHandle;
154 
155 
159 
160 private:
161 
166 
167 };
168 
169 inline RTI::ObjectClassHandle DtHlaStateDecoder::objectClassHandle() const
170 {
171  return myHandle;
172 }
173 
175 DtHlaStateDecoder::decoder(const RTI::AttributeHandle &handle) const
176 {
177  AttributeHandleDecoderMap::const_iterator pos = myDecoderList.find(handle);
178  if (pos != myDecoderList.end())
179  {
180  return pos->second;
181  }
182  return 0;
183 };
184 
185 inline char* DtHlaStateDecoder::decodingBuffer(int length)
186 {
187  return DtDecodingBuffer(length);
188 }
189 
191  const RTI::AttributeHandleValuePairSet& attrs, int index, RTI::ULong& length)
192 {
193  char* dataPtr = 0;
195  {
196  dataPtr = attrs.getValuePointer(index, length);
197  }
198  else
199  {
200  length = attrs.getValueLength(index);
201  if (length > 0)
202  {
203  dataPtr = decodingBuffer(length);
204  attrs.getValue(index, dataPtr, length);
205  }
206  }
207  return dataPtr;
208 }
209 
211  const RTI::AttributeHandleValuePairSet& attrs, int index, RTI::ULong& length,
212  unsigned int expectedDataSize, char* attrName)
213 {
214  char* outDataPtr = 0;
216  {
217  outDataPtr = attrs.getValuePointer(index, length);
218  }
219  else
220  {
221  length = attrs.getValueLength(index);
222  if (length > 0 && length >= expectedDataSize)
223  {
224  outDataPtr = decodingBuffer(length);
225  attrs.getValue(index, outDataPtr, length);
226  }
227  }
228 
229  if (length != expectedDataSize)
230  {
231  if (length < expectedDataSize)
232  {
233  DtWarn("Cannot decode attribute %s.\n"
234  "Size of data (%d) is smaller than expected (%d).\n",
235  attrName, length, expectedDataSize);
236  length = 0;
237  outDataPtr = 0;
238  }
239  else if (length > expectedDataSize && DtNotifyLevel >= DtNlVerbose)
240  {
241  DtVerbose("When decoding attribute %s,\n"
242  "found size of data (%d) is larger than expected (%d).\n",
243  attrName, length, expectedDataSize);
244  }
245  }
246 
247  return outDataPtr;
248 }
249 
251  const RTI::AttributeHandleValuePairSet& attrs, int index)
252 {
253  RTI::ULong length = 0;
254  char* dataPtr = 0;
255  length = attrs.getValueLength(index);
256  if (length > 0)
257  {
258  dataPtr = decodingBuffer(length+1);
259  attrs.getValue(index, dataPtr, length);
260  dataPtr[length] = 0;
261  }
262 
263  return (DtNetEventId*)dataPtr;
264 }
265 
268 #define DtADD_ATTR_DECODER(attrName) \
269  addDecoder((char *)#attrName, (DtAttributeDecoder) decode##attrName);
270 
272 #define DtADD_ATTR_DECODER_QUIET(attrName) \
273  addDecoder((char *)#attrName, (DtAttributeDecoder) decode##attrName, false);
274 
278 
279 #define DtDECLARE_ATTR_DECODER(stateRepClass, attrName) \
280  static void decode##attrName(stateRepClass* stateRep, \
281  const RTI::AttributeHandleValuePairSet& attrs, int pairSetIndex)
282 
283 
291 #define DtDEFINE_SIMPLE_ATTR_DECODER_WITH_CAST( \
292  decClass, stateRepClass, attrName, netType, mutator, castExpr) \
293 void decClass::decode##attrName( \
294  stateRepClass* stateRep, \
295  const RTI::AttributeHandleValuePairSet& attrs, \
296  int index) \
297 { \
298  RTI::ULong length = 0; \
299  netType* netValPtr = (netType*)attributeData(attrs, index, length, sizeof(netType), #attrName); \
300  if (netValPtr) \
301  { \
302  stateRep->mutator(castExpr *netValPtr); \
303  } \
304 }
305 
313 #define DtDEFINE_SIMPLE_ATTR_DECODER_WITH_CAST_SET( \
314  decClass, stateRepClass, attrName, netType, castExpr) \
315  DtDEFINE_SIMPLE_ATTR_DECODER_WITH_CAST( \
316  decClass, stateRepClass, attrName, netType, set##attrName, castExpr)
317 
324 #define DtDEFINE_SIMPLE_ATTR_DECODER_MUTATOR( \
325  decClass, stateRepClass, attrName, netType, mutator) \
326 void decClass::decode##attrName( \
327  stateRepClass* stateRep, \
328  const RTI::AttributeHandleValuePairSet& attrs, \
329  int index) \
330 { \
331  RTI::ULong length = 0; \
332  netType* netValPtr = (netType*)attributeData(attrs, index, length, sizeof(netType), #attrName); \
333  if (netValPtr) \
334  { \
335  stateRep->mutator(*netValPtr); \
336  } \
337 }
338 
345 #define DtDEFINE_SIMPLE_ATTR_DECODER_SET( \
346  decClass, stateRepClass, attrName, netType) \
347  DtDEFINE_SIMPLE_ATTR_DECODER_MUTATOR( \
348  decClass, stateRepClass, attrName, netType, set##attrName)
349 
358 #define DtDEFINE_SIMPLE_ATTR_DECODER_WITH_CAST_AND_PARAM( \
359  decClass, stateRepClass, attrName, netType, mutator, param, castExpr) \
360 void decClass::decode##attrName( \
361  stateRepClass* stateRep, \
362  const RTI::AttributeHandleValuePairSet& attrs, \
363  int index) \
364 { \
365  RTI::ULong length = 0; \
366  netType* netValPtr = (netType*)attributeData(attrs, index, length, sizeof(netType), #attrName); \
367  if (netValPtr) \
368  { \
369  stateRep->mutator(param, castExpr *netValPtr); \
370  } \
371 }
372 
373 #define DtDEFINE_SIMPLE_GLOBAL_OBJECT_DESIGNATOR_ATTR_DECODER( \
374  decClass, stateRepClass, attrName, mutator) \
375 void decClass::decode##attrName( \
376  stateRepClass* stateRep, \
377  const RTI::AttributeHandleValuePairSet& attrs, \
378  int pairSetIndex) \
379 { \
380  RTI::ULong length = 0; \
381  DtGlobalObjectDesignator objName = (char*) attrs.getValuePointer(pairSetIndex, length); \
382  stateRep->mutator(objName); \
383 }
384 
389 #define DtDEFINE_SIMPLE_ATTR_DECODER_BUFF(decClass, stateRepClass, \
390  attrName, mutator) \
391 void decClass::decode##attrName( \
392  stateRepClass* stateRep, \
393  const RTI::AttributeHandleValuePairSet& attrs, \
394  int index) \
395 { \
396  RTI::ULong length = 0; \
397  char* buff = attributeData(attrs, index, length); \
398  if (length > 0) \
399  { \
400  stateRep->mutator(buff, length); \
401  } \
402 }
403 
405 #define DtDEFINE_SIMPLE_ATTR_DECODER( \
406  decClass, stateRepClass, attrName, netType, mutator) \
407  DtDEFINE_SIMPLE_ATTR_DECODER_MUTATOR(decClass, stateRepClass, \
408  attrName, netType, mutator)
409 
410 #endif
411 #endif
412 
Declares a function for managing decoding buffers.
std::map< RTI::AttributeHandle, DtAttributeDecoder > AttributeHandleDecoderMap
Definition: hlaStateDecoder.h:146
unsigned long getValueLength(unsigned long i) const
Instances of DtExerciseConn are used to provide an application&#39;s interface or connection to the netwo...
Definition: exerciseConnHLA.h:61
#define DT_DLL_VL
Definition: vlMachineTypes.h:108
void(* DtAttributeDecoder)(DtStateRepository *stateRep, const RTI::AttributeHandleValuePairSet &avlist, unsigned long pairSetIndex)
Attribute decoding function declaration.
Definition: hlaStateDecoder.h:53
Definition: vlPrint.h:44
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...
Functions in vlPrint.h provide an error and print facility for vrlink.
virtual RTI::ObjectClassHandle objectClassHandle() const
Get the object&#39;s class handle.
Definition: hlaStateDecoder.h:169
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
AttributeHandleDecoderMap myDecoderList
myDecoderList is a map of decoders for each attribute registered to this state.
Definition: hlaStateDecoder.h:158
static DtNetEventId * eventIdAttributeData(const RTI::AttributeHandleValuePairSet &attrs, int index)
Get the attribute data as a DtNetEventId (adds defensive null terminator) Returns a pointer to the at...
Definition: hlaStateDecoder.h:250
int DtNotifyLevel
DtNotifyLevel is used to control the level of diagnostics output by VR-Link.
DtHlaStateDecoder is used to provide decoding of a state message into a state repository in an HLA (a...
Definition: hlaStateDecoder.h:34
static char * decodingBuffer(int length)
Returns a pointer to a buffer that can be used to copy data obtained from a phvps.
Definition: hlaStateDecoder.h:185
DtOutputStream DtVerbose
These DtOutputStream instances are used for all print messaging in VR-Link.
DtExerciseConn * myExConn
Definition: hlaStateDecoder.h:151
DtStateRepository is an abstract base class for maintaining state for an object.
Definition: stateRepository.h:50
std::map< RTI::AttributeHandle, bool > AttributeHandleBoolMap
Definition: hlaStateDecoder.h:147
DtOutputStream DtWarn
These DtOutputStream instances are used for all print messaging in VR-Link.
Definition: eventId.h:23
char * getValuePointer(unsigned long i, unsigned long &valueLength) const
static char * attributeData(const RTI::AttributeHandleValuePairSet &attrs, int index, RTI::ULong &length)
Returns a pointer to the attribute data.
Definition: hlaStateDecoder.h:190
AttributeHandleBoolMap myMutableReportedWarning
myReportedWarnings is an array for keeping track of which warnings have been already issued...
Definition: hlaStateDecoder.h:165
static const xmlChar * attrName
Definition: xmlFedTags.h:116
RTI::ObjectClassHandle myHandle
Definition: hlaStateDecoder.h:153
static bool theUseGetValuePointer
Definition: hlaStateDecoder.h:122
Used to provide backwards compatibility for VR-Link Encoders and Decoders who use either AttributeHan...
Definition: rtiCompatibility.h:237
virtual DtAttributeDecoder decoder(const RTI::AttributeHandle &handle) const
Get the attribute decoder for the specified handle.
Definition: hlaStateDecoder.h:175
DtObjClassDesc * myClassDesc
Definition: hlaStateDecoder.h:152
unsigned long ULong
These typedefs are provided for source compatibility.
Definition: rtiCompatibility.h:274
class DtStateMsg:
Definition: stateMsgHLA.h:32
Contains the DtVrlUuid class declaration/definition.
This file contains typedefs for machine dependant types.

Document ID: Generated on Thu Oct 16 00:12:25 EDT 2025 from SVN revision 280738
Copyright © 1992-2025 MAK Technologies. All Rights Reserved (www.mak.com)