VR-Link API Documentation for DIS
 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-2026 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 
25 class DT_DLL_VL DtObjClassDesc;
27 class DT_DLL_VL DtStateMsg;
29 
30 
34 class DT_DLL_VL DtHlaStateDecoder
35 {
36 public:
37 
39  DtHlaStateDecoder(
40  DtExerciseConn* exConn,
41  DtObjClassDesc* classDesc);
42 
44  virtual ~DtHlaStateDecoder();
45 
47  DtHlaStateDecoder(const DtHlaStateDecoder& orig);
48 
50  DtHlaStateDecoder& operator=(const DtHlaStateDecoder& orig);
51 
53  typedef void (*DtAttributeDecoder) (
54  DtStateRepository* stateRep,
55  const RTI::AttributeHandleValuePairSet& avlist,
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 
122  static bool theUseGetValuePointer;
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,
140  const RTI::AttributeHandleValuePairSet& attrs,
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 
151  DtExerciseConn* myExConn;
152  DtObjClassDesc* myClassDesc;
153  RTI::ObjectClassHandle myHandle;
154 
155 
158  AttributeHandleDecoderMap myDecoderList;
159 
160 private:
161 
165  mutable AttributeHandleBoolMap myMutableReportedWarning;
166 
167 };
168 
169 inline RTI::ObjectClassHandle DtHlaStateDecoder::objectClassHandle() const
170 {
171  return myHandle;
172 }
173 
174 inline DtHlaStateDecoder::DtAttributeDecoder
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 
190 inline char* DtHlaStateDecoder::attributeData(
191  const RTI::AttributeHandleValuePairSet& attrs, int index, RTI::ULong& length)
192 {
193  char* dataPtr = 0;
194  if (theUseGetValuePointer)
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 
210 inline char* DtHlaStateDecoder::attributeData(
211  const RTI::AttributeHandleValuePairSet& attrs, int index, RTI::ULong& length,
212  unsigned int expectedDataSize, char* attrName)
213 {
214  char* outDataPtr = 0;
215  if (theUseGetValuePointer)
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 
250 inline DtNetEventId* DtHlaStateDecoder::eventIdAttributeData(
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  char attrNameCstr[] = #attrName; \
300  netType* netValPtr = (netType*)attributeData(attrs, index, length, sizeof(netType), attrNameCstr); \
301  if (netValPtr) \
302  { \
303  stateRep->mutator(castExpr *netValPtr); \
304  } \
305 }
306 
314 #define DtDEFINE_SIMPLE_ATTR_DECODER_WITH_CAST_SET( \
315  decClass, stateRepClass, attrName, netType, castExpr) \
316  DtDEFINE_SIMPLE_ATTR_DECODER_WITH_CAST( \
317  decClass, stateRepClass, attrName, netType, set##attrName, castExpr)
318 
325 #define DtDEFINE_SIMPLE_ATTR_DECODER_MUTATOR( \
326  decClass, stateRepClass, attrName, netType, mutator) \
327 void decClass::decode##attrName( \
328  stateRepClass* stateRep, \
329  const RTI::AttributeHandleValuePairSet& attrs, \
330  int index) \
331 { \
332  RTI::ULong length = 0; \
333  netType* netValPtr = (netType*)attributeData(attrs, index, length, sizeof(netType), #attrName); \
334  if (netValPtr) \
335  { \
336  stateRep->mutator(*netValPtr); \
337  } \
338 }
339 
346 #define DtDEFINE_SIMPLE_ATTR_DECODER_SET( \
347  decClass, stateRepClass, attrName, netType) \
348  DtDEFINE_SIMPLE_ATTR_DECODER_MUTATOR( \
349  decClass, stateRepClass, attrName, netType, set##attrName)
350 
359 #define DtDEFINE_SIMPLE_ATTR_DECODER_WITH_CAST_AND_PARAM( \
360  decClass, stateRepClass, attrName, netType, mutator, param, castExpr) \
361 void decClass::decode##attrName( \
362  stateRepClass* stateRep, \
363  const RTI::AttributeHandleValuePairSet& attrs, \
364  int index) \
365 { \
366  RTI::ULong length = 0; \
367  netType* netValPtr = (netType*)attributeData(attrs, index, length, sizeof(netType), #attrName); \
368  if (netValPtr) \
369  { \
370  stateRep->mutator(param, castExpr *netValPtr); \
371  } \
372 }
373 
374 #define DtDEFINE_SIMPLE_GLOBAL_OBJECT_DESIGNATOR_ATTR_DECODER( \
375  decClass, stateRepClass, attrName, mutator) \
376 void decClass::decode##attrName( \
377  stateRepClass* stateRep, \
378  const RTI::AttributeHandleValuePairSet& attrs, \
379  int pairSetIndex) \
380 { \
381  RTI::ULong length = 0; \
382  DtGlobalObjectDesignator objName = (char*) attrs.getValuePointer(pairSetIndex, length); \
383  stateRep->mutator(objName); \
384 }
385 
390 #define DtDEFINE_SIMPLE_ATTR_DECODER_BUFF(decClass, stateRepClass, \
391  attrName, mutator) \
392 void decClass::decode##attrName( \
393  stateRepClass* stateRep, \
394  const RTI::AttributeHandleValuePairSet& attrs, \
395  int index) \
396 { \
397  RTI::ULong length = 0; \
398  char* buff = attributeData(attrs, index, length); \
399  if (length > 0) \
400  { \
401  stateRep->mutator(buff, length); \
402  } \
403 }
404 
406 #define DtDEFINE_SIMPLE_ATTR_DECODER( \
407  decClass, stateRepClass, attrName, netType, mutator) \
408  DtDEFINE_SIMPLE_ATTR_DECODER_MUTATOR(decClass, stateRepClass, \
409  attrName, netType, mutator)
410 
411 #endif
412 #endif
413 
Declares a function for managing decoding buffers.
Instances of DtExerciseConn are used to provide an application&#39;s interface or connection to the netwo...
Definition: exerciseConnDIS.h:63
#define DT_DLL_VL
Definition: vlMachineTypes.h:120
Definition: vlPrint.h:46
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.
int DtNotifyLevel
DtNotifyLevel is used to control the level of diagnostics output by VR-Link.
DtOutputStream DtVerbose
These DtOutputStream instances are used for all print messaging in VR-Link.
DtStateRepository is an abstract base class for maintaining state for an object.
Definition: stateRepository.h:50
DtOutputStream DtWarn
These DtOutputStream instances are used for all print messaging in VR-Link.
Definition: eventId.h:131
static const xmlChar * attrName
Definition: xmlFedTags.h:117
Instances of DtStateMsg are used to represent state data communicated via the network in a DIS (as op...
Definition: stateMsgDIS.h:21
Contains the DtVrlUuid class declaration/definition.
This file contains typedefs for machine dependant types.

Document ID: Generated on Mon Sep 28 00:09:32 EDT 2026 from SVN revision 295353
Copyright © 1992-2025 MAK Technologies. All Rights Reserved (www.mak.com)