VR-Forces Development_Version Class Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
genericAttributeEncoderHLA.h
Go to the documentation of this file.
1 /*******************************************************************************
2 ** Copyright (c) 2013 MAK Technologies, Inc.
3 ** All rights reserved.
4 *******************************************************************************/
5 
8 
9 #pragma once
10 
11 #ifdef DtHLA
12 
13 #include <vlutil/vlString.h>
14 #include <vl/fom.h>
15 #include <vl/objClassDesc.h>
16 #include <vl/hlaStateEncoder.h>
18 
19 namespace makVrfVrlinkExtToolkit
20 {
21  template <typename StateRepType, typename EncoderType>
23  {
24  public:
25 
28  DtExerciseConn* exConn,
29  DtObjClassDesc* classDesc) : EncoderType(exConn, classDesc) {}
30 
33 
37  : EncoderType(orig) {}
38 
42  {
44  return *this;
45  }
46 
50  static void encodeGenericAttribute(const StateRepType& rep,
51  RTI::AttributeHandleValuePairSet* attrs,
52  RTI::AttributeHandle attrHandle)
53  {
56  unsigned srLength = 0;
57  const char* srValue = genSR->getAttributeByHandle(attrHandle, srLength);
58  attrs->add(attrHandle, (char*)srValue, srLength);
59  }
60 
61  virtual DtHlaStateEncoder* clone() const
62  {
64  }
65 
66  virtual DtHlaStateEncoder* clone(DtObjClassDesc* classDesc) const
67  {
68  if (classDesc->isOfClass(this->myClassDesc->handle()))
69  {
71  <StateRepType, EncoderType>(this->myExConn, classDesc);
72 
73  std::map<RTI::AttributeHandle,DtHlaStateEncoder::DtAttributeEncoder>::const_iterator
74  encIter = this->myEncoderList.begin();
75  std::map<RTI::AttributeHandle,DtHlaStateEncoder::DtAttributeEncoder>::const_iterator
76  encEnd = this->myEncoderList.end();
77  for(; encIter != encEnd; ++encIter)
78  {
79  enc->addEncoder(encIter->first, encIter->second);
80  }
81 
82  std::map<RTI::AttributeHandle,DtHlaStateEncoder::DtAttributeChecker>::const_iterator
83  chIter = this->myCheckerList.begin();
84  std::map<RTI::AttributeHandle,DtHlaStateEncoder::DtAttributeChecker>::const_iterator
85  chEnd = this->myCheckerList.end();
86  for(; chIter != chEnd; ++chIter)
87  {
88  enc->addChecker(chIter->first, chIter->second);
89  }
90 
91  return enc;
92  }
93  else
94  {
95  DtWarn << "DtGenericAttributeEncoder: ClassDesc is not a subclass. "
96  << "Returning a normal clone " << std::endl;
97  return clone();
98  }
99  }
100 
113  virtual void encode(const DtStateRepository& stateRep,
114  const DtStateRepository& asSeenByRemote,
115  const RTI::AttributeHandleSet& neededAttrs,
116  const RTI::AttributeHandleSet& includeThese,
117  DtStateMsg* msg)
118  {
119  if (!this->myClassDesc)
120  {
121  return;
122  }
123 
124  #if DtHLA_1516
125  //
126  // Here we construct a Dummy wrapper AHVPS around the map.
127  //
128  RTI::AttributeHandleValuePairSet* avList =
129  new RTI::AttributeHandleValuePairSet(msg->handleMap());
130  #else
131  HandleValueMap* avList = msg->handleMap();
132  #endif
133 
134  #if DtHLA_1516
135  RTI::AttributeHandleSet::const_iterator end = neededAttrs.end();
136  RTI::AttributeHandleSet::const_iterator pos = neededAttrs.begin();
137  for (; pos != end; ++pos)
138  {
139  RTI::AttributeHandle handle = *pos;
140  #else
141  for (RTI::ULong index = 0; index < neededAttrs.size(); index++)
142  {
143  RTI::AttributeHandle handle = neededAttrs.getHandle(index);
144  #endif
145 
146  DtHlaStateEncoder::DtAttributeEncoder enc = this->encoder(handle);
147  if (!enc)
148  {
149  if (handle != this->myClassDesc->privilegeHandle())
150  {
151  DtHlaStateEncoder::DtAttributeEncoder unknownEncoder = this->myClassDesc->unknownAttributeEncoder();
152  if (unknownEncoder)
153  {
154  // Before using the unknown encoder, use our generic unknown
155  // attribute checker
156  #if DtHLA_1516
157  if(includeThese.find(handle) != includeThese.end() ||
158  #else
159  if(includeThese.isMember(handle) ||
160  #endif
161  needGenericAttribute(stateRep, asSeenByRemote, handle))
162  {
163  (*unknownEncoder)(stateRep, avList, handle);
164  }
165  continue;
166  }
167  else if (!this->myReportedWarning[handle])
168  {
169  DtWarn << "DtHlaStateEncoder for class "<< this->myClassDesc->name()
170  << " has no encoder for attribute "
171  << this->myClassDesc->attributeNameByHandle(handle)
172  << std::endl;
173  }
174  }
175  }
176 
177  DtHlaStateEncoder::DtAttributeChecker check = this->checker(handle);
178  if (!check)
179  {
180  if (handle != this->myClassDesc->privilegeHandle() && !this->myReportedWarning[handle])
181  {
182  DtWarn << "DtHlaStateEncoder for class "<< this->myClassDesc->name()
183  << " has no checker for attribute "
184  << this->myClassDesc->attributeNameByHandle(handle) << std::endl;
185  }
186  }
187 
188  if (!enc || !check)
189  {
190  this->myReportedWarning[handle] = true;
191  continue;
192  }
193 
194  #if DtHLA_1516
195  if ( includeThese.find(handle) != includeThese.end() ||
196  (*check)(stateRep, asSeenByRemote))
197  #else
198  if (includeThese.isMember(handle) ||
199  (*check)(stateRep, asSeenByRemote))
200  #endif
201  {
202  (*enc)(stateRep, avList, handle);
203  }
204  }
205  #if DtHLA_1516
206  delete avList;
207  #endif
208  }
209 
210  public:
211 
214  DtExerciseConn* exConn,
215  DtObjClassDesc* classDesc)
216  {
217  return new DtGenericAttributeEncoder<StateRepType, EncoderType>(exConn, classDesc);
218  }
219 
220  protected:
221 
224  static bool needGenericAttribute(
225  const DtStateRepository& stateRep,
226  const DtStateRepository& asSeenByRemote,
227  RTI::AttributeHandle attrHandle)
228  {
230  static_cast<const DtGenericAttributeStateRepository<StateRepType>*>(&stateRep);
232  static_cast<const DtGenericAttributeStateRepository<StateRepType>*>(&asSeenByRemote);
233 
234  unsigned srLength = 0;
235  unsigned asbrLength = 0;
236  const char* srValue = genSR->getAttributeByHandle(attrHandle, srLength);
237  const char* asbrValue = genASBR->getAttributeByHandle(attrHandle, asbrLength);
238 
239  return (srLength != asbrLength ||
240  memcmp(srValue, asbrValue, srLength) != 0);
241  }
242 
243  };
244 }
245 
246 #endif

Document ID: Generated on Tue Mar 8 22:13:38 EST 2016 from SVN revision 162938
Copyright © 2005-2015 VT MÄK. All Rights Reserved (www.mak.com)