VR-Link API Documentation for HLA 1516
 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 MAK Technologies, Inc
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 
26 
31 class DT_DLL_VL DtInteractionRep;
32 
33 
38 {
39 public:
40 
42  typedef void (*DtParameterDecoder)(DtInteractionRep* inter,
44  int i);
45 
46 public:
47 
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
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 
123 
126  static void decodeGenericParameter(DtInteractionWithEncDec* inter,
127  const RTI::ParameterHandleValuePairSet& pvlist, int i);
128 
129 
130 protected:
131 
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 
146 
147  RTI::InteractionClassHandle myClassHandle;
148 
150  std::map<RTI::ParameterHandle, DtParameterDecoder> myList;
151 
152 };
153 
154 inline RTI::InteractionClassHandle
156 {
157  return myClassHandle;
158 }
159 
160 inline char* DtInteractionDecoder::decodingBuffer(int length)
161 {
162  return DtDecodingBuffer(length);
163 }
164 
166  const RTI::ParameterHandleValuePairSet& pvList, int index, RTI::ULong& length)
167 {
168  char* dataPtr = 0;
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 
186  const RTI::ParameterHandleValuePairSet& pvList, int index, RTI::ULong& length,
187  unsigned int expectedDataSize, char* paramName)
188 {
189  char* outDataPtr = 0;
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 
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 
static char * decodingBuffer(int length)
Returns a pointer to a buffer that can be used to copy data obtained from a phvps.
Definition: interactionDecoder.h:160
Declares a function for managing decoding buffers.
DtExerciseConn * myExConn
Definition: interactionDecoder.h:144
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
virtual RTI::InteractionClassHandle interactionClassHandle()
Get the interaction&#39;s class handle.
Definition: interactionDecoder.h:155
#define DT_DLL_VL
Definition: vlMachineTypes.h:108
Instances of DtInterClassDesc are used to represent HLA Object and Interaction classes.
Definition: interClassDesc.h:33
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.
static DtNetEventId * eventIdParameterData(const RTI::ParameterHandleValuePairSet &params, int index)
Get the parameter data as a DtNetEventId (adds defensive null terminator) Returns a pointer to the pa...
Definition: interactionDecoder.h:225
static bool theUseGetValuePointer
Definition: interactionDecoder.h:122
void getValue(unsigned long i, char *buffer, unsigned long &valueLength) const
static char * parameterData(const RTI::ParameterHandleValuePairSet &pvList, int index, RTI::ULong &length)
Returns a pointer to a buffer containing the parameter data.
Definition: interactionDecoder.h:165
std::map< RTI::ParameterHandle, DtParameterDecoder > myList
myList is an array of classDesc-&gt;maxParamHandle() items.
Definition: interactionDecoder.h:150
RTI::InteractionClassHandle myClassHandle
Definition: interactionDecoder.h:147
int DtNotifyLevel
DtNotifyLevel is used to control the level of diagnostics output by VR-Link.
DtInterClassDesc * myClassDesc
Definition: interactionDecoder.h:145
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:23
char * getValuePointer(unsigned long i, unsigned long &valueLength) const
This file provides a declaration of the class DtInteractionWithEncDec.
Instances of DtInteractionDecoder are used to decode interactions from the network.
Definition: interactionDecoder.h:37
Used to provide backwards compatibility for VR-Link Encoders and Decoders who use either AttributeHan...
Definition: rtiCompatibility.h:154
class DtInteractionWithEncDec:
Definition: interactionWithEncDec.h:44
unsigned long ULong
These typedefs are provided for source compatibility.
Definition: rtiCompatibility.h:191
This file contains typedefs for machine dependant types.

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)