VR-Link API Documentation for DIS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
interactionDecoder.h
Go to the documentation of this file.
1 /*********************************************************************
2 ** Copyright (c) 1992-2010 VT MAK
3 ** All rights reserved.
4 *********************************************************************/
5 
8 
9 #ifndef DtInteractionDecoder_H_
10 #define DtInteractionDecoder_H_
11 
12 #if DtHLA
13 
15 #include <vlutil/vlMachineTypes.h>
16 #include <vlutil/vlPrint.h>
17 #include <vlpi/bufferMgr.h>
18 
19 #include "rtiNamespace.h"
20 #include "rtiCompatibility.h"
21 #include <map>
22 
24 class DT_DLL_VL DtInterClassDesc;
26 
31 class DT_DLL_VL DtInteractionRep;
32 
33 
37 class DT_DLL_VL DtInteractionDecoder
38 {
39 public:
40 
42  typedef void (*DtParameterDecoder)(DtInteractionRep* inter,
43  const RTI::ParameterHandleValuePairSet& pvlist,
44  int i);
45 
46 public:
47 
49  DtInteractionDecoder(DtExerciseConn* exConn,
50  DtInterClassDesc* classDesc);
51 
53  virtual ~DtInteractionDecoder();
54 
60  DtParameterDecoder addDecoder(RTI::ParameterHandle handle,
61  DtParameterDecoder proc);
62 
68  DtParameterDecoder addDecoder(char* name,
69  DtParameterDecoder proc);
70 
72  virtual DtParameterDecoder decoder(RTI::ParameterHandle handle) const;
73 
75  virtual void decode(
76  DtInteractionRep* interaction,
77 #if DtHLA_1516
78  const RTI::ParameterHandleValueMap& pvMap
79 #else
80  const RTI::ParameterHandleValuePairSet& pvList
81 #endif
82  );
83 
85  virtual RTI::InteractionClassHandle interactionClassHandle();
86 
88  virtual DtInteractionDecoder* clone() const;
89 
94  virtual DtInteractionDecoder* clone(DtInterClassDesc* interDesc) const;
95 
96 public:
97 
102  static char* decodingBuffer(int length);
103 
105  static char* parameterData(const RTI::ParameterHandleValuePairSet& pvList,
106  int index, RTI::ULong& length);
107 
113  static char* parameterData(
114  const RTI::ParameterHandleValuePairSet& pvList, int index, RTI::ULong& length,
115  unsigned int expectedDataSize, char* paramName);
116 
119  static DtNetEventId* eventIdParameterData(
120  const RTI::ParameterHandleValuePairSet& params, int index);
121 
122  static bool theUseGetValuePointer;
123 
126  static void decodeGenericParameter(DtInteractionWithEncDec* inter,
127  const RTI::ParameterHandleValuePairSet& pvlist, int i);
128 
129 
130 protected:
131 
133  DtInteractionDecoder(const DtInteractionDecoder& orig);
134 
136  DtInteractionDecoder& operator=(const DtInteractionDecoder& orig);
137 
139  virtual void decodeParameter(DtInteractionRep* inter,
140  const RTI::ParameterHandleValuePairSet& pvList, int index);
141 
142 protected:
143 
144  DtExerciseConn* myExConn;
145  DtInterClassDesc* myClassDesc;
146 
147  RTI::InteractionClassHandle myClassHandle;
148 
150  std::map<RTI::ParameterHandle, DtParameterDecoder> myList;
151 
152 };
153 
154 inline RTI::InteractionClassHandle
155  DtInteractionDecoder::interactionClassHandle()
156 {
157  return myClassHandle;
158 }
159 
160 inline char* DtInteractionDecoder::decodingBuffer(int length)
161 {
162  return DtDecodingBuffer(length);
163 }
164 
165 inline char* DtInteractionDecoder::parameterData(
166  const RTI::ParameterHandleValuePairSet& pvList, int index, RTI::ULong& length)
167 {
168  char* dataPtr = 0;
169  if (theUseGetValuePointer)
170  {
171  dataPtr = pvList.getValuePointer(index, length);
172  }
173  else
174  {
175  length = pvList.getValueLength(index);
176  if (length > 0)
177  {
178  dataPtr = decodingBuffer(length);
179  pvList.getValue(index, dataPtr, length);
180  }
181  }
182  return dataPtr;
183 }
184 
185 inline char* DtInteractionDecoder::parameterData(
186  const RTI::ParameterHandleValuePairSet& pvList, int index, RTI::ULong& length,
187  unsigned int expectedDataSize, char* paramName)
188 {
189  char* outDataPtr = 0;
190  if (theUseGetValuePointer)
191  {
192  outDataPtr = pvList.getValuePointer(index, length);
193  }
194  else
195  {
196  length = pvList.getValueLength(index);
197  if (length > 0 && length >= expectedDataSize)
198  {
199  outDataPtr = decodingBuffer(length);
200  pvList.getValue(index, outDataPtr, length);
201  }
202  }
203 
204  if (length != expectedDataSize)
205  {
206  if (length < expectedDataSize)
207  {
208  DtWarn("Cannot decode parameter %s.\n"
209  "Size of data (%d) is smaller than expected (%d).\n",
210  paramName, length, expectedDataSize);
211  length = 0;
212  outDataPtr = 0;
213  }
214  else if (length > expectedDataSize && DtNotifyLevel >= DtNlVerbose)
215  {
216  DtVerbose("When decoding parameter %s,\n"
217  "found size of data (%d) is larger than expected (%d).\n",
218  paramName, length, expectedDataSize);
219  }
220  }
221 
222  return outDataPtr;
223 }
224 
225 inline DtNetEventId* DtInteractionDecoder::eventIdParameterData(
226  const RTI::ParameterHandleValuePairSet& params, int index)
227 {
228  RTI::ULong length = 0;
229  char* dataPtr = 0;
230  length = params.getValueLength(index);
231  if (length > 0)
232  {
233  dataPtr = decodingBuffer(length+1);
234  params.getValue(index, dataPtr, length);
235  dataPtr[length] = 0;
236  }
237 
238  return (DtNetEventId*)dataPtr;
239 }
240 
243 #define DtADD_PARAM_DECODER(paramName) \
244  addDecoder((char *)#paramName, (DtParameterDecoder) decode##paramName)
245 
248 #define DtDECLARE_PARAM_DECODER(RepT, paramName) \
249  static void decode##paramName(RepT* inter, \
250  const RTI::ParameterHandleValuePairSet& params, int pairSetIndex)
251 
259 #define DtDEFINE_SIMPLE_PARAM_DECODER_WITH_CAST(decClass, interClass, \
260  paramName, netType, mutator, castExpr) \
261 void decClass::decode##paramName(interClass* inter, \
262  const RTI::ParameterHandleValuePairSet& params, \
263  int index) \
264 { \
265  RTI::ULong length = 0; \
266  netType* netValPtr = (netType*)parameterData(params, index, length, sizeof(netType), #paramName); \
267  if (netValPtr) \
268  { \
269  inter->mutator(castExpr *netValPtr); \
270  } \
271 }
272 
280 #define DtDEFINE_SIMPLE_PARAM_DECODER_WITH_CAST_SET(decClass, interClass, \
281  paramName, netType, castExpr) \
282  DtDEFINE_SIMPLE_PARAM_DECODER_WITH_CAST(decClass, interClass, \
283  paramName, netType, set##paramName, castExpr)
284 
291 #define DtDEFINE_SIMPLE_PARAM_DECODER_MUTATOR(decClass, interClass, \
292  paramName, netType, mutator) \
293  void decClass::decode##paramName(interClass* inter, \
294  const RTI::ParameterHandleValuePairSet& params, \
295  int index) \
296 { \
297  RTI::ULong length = 0; \
298  netType* netValPtr = (netType*)parameterData(params, index, length, sizeof(netType), #paramName); \
299  if (netValPtr) \
300  { \
301  inter->mutator(*netValPtr); \
302  } \
303 }
304 
311 #define DtDEFINE_SIMPLE_PARAM_DECODER_MUTATOR_SET(decClass, interClass, \
312  paramName, netType) \
313  DtDEFINE_SIMPLE_PARAM_DECODER_MUTATOR(decClass, interClass, \
314  paramName, netType, set##paramName)
315 
316 #define DtDEFINE_SIMPLE_GLOBAL_OBJECT_DESIGNATOR_PARAM_DECODER( \
317  decClass, interClass, paramName, mutator) \
318 void decClass::decode##paramName(interClass* inter, \
319  const RTI::ParameterHandleValuePairSet& params, \
320  int index) \
321 { \
322  RTI::ULong length = 0; \
323  DtGlobalObjectDesignator objName = (char*) params.getValuePointer(index, length); \
324  inter->mutator(objName); \
325 }
326 
331 #define DtDEFINE_SIMPLE_PARAM_DECODER_BUFF(decClass, interClass, \
332  paramName, mutator) \
333 void decClass::decode##paramName(interClass* inter, \
334  const RTI::ParameterHandleValuePairSet& params, \
335  int index) \
336 { \
337  RTI::ULong length = 0; \
338  char* buff = parameterData(params, index, length); \
339  if (length > 0) \
340  { \
341  inter->mutator(buff, length); \
342  } \
343 }
344 
345 #define DtDEFINE_SIMPLE_PARAM_DECODER(decClass, interClass, \
346  paramName, netType, mutator) \
347  DtDEFINE_SIMPLE_PARAM_DECODER_MUTATOR(decClass, interClass, \
348  paramName, netType, mutator)
349 
350 #endif
351 #endif
352 
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:61
#define DT_DLL_VL
Definition: vlMachineTypes.h:108
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.
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.
DtOutputStream DtWarn
These DtOutputStream instances are used for all print messaging in VR-Link.
Definition: eventId.h:131
This file contains typedefs for machine dependant types.

Document ID: Generated on Mon Apr 25 03:39:01 EDT 2022 from SVN revision 242502
Copyright © 2005-2021 MAK Technologies. All Rights Reserved (www.mak.com)