VR-Link API Documentation for HLA 1.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
patch.h
Go to the documentation of this file.
1 //********************************************************************
2 // Copyright (c) 2006 MaK Technologies, Inc.
3 // All rights reserved.
4 //********************************************************************
5 #if DtHLA
6 
7 #include <stdio.h>
9 #include <vlutil/vlString.h>
10 #include <vl/platformEncoder.h>
11 #include <vl/platformDecoder.h>
12 #include <vl/fomMapper.h>
13 #include <vl/stateEncoderFactory.h>
14 #include <vl/stateDecoderFactory.h>
15 #include <vl/fom.h>
16 #include <vlpi/entityTypes.h>
17 
23 {
24 public:
27  myAttrib("")
28 
29  { printf("\n===================\n"
30  "Constructing DtF18EntityStateRep\n"
31  "=====================\n"); }
32 
34  virtual ~DtF18EntityStateRep() {}
35 
36 private:
37 
40 
43 
44 public:
45 
47  virtual void setF18Attribute(const DtString & val) { myAttrib = val;}
49  virtual DtString f18Attribute() const { return myAttrib;}
50 
53  static DtF18EntityStateRep* create() { return new DtF18EntityStateRep; };
54 
55 
56 protected:
57 
59 
60 };
61 
66 {
67 public:
70  DtObjClassDesc* classDesc):
72  DtPlatformDecoder(exConn, classDesc)
73  {
75  addDecoder("SpecialF18Attribute",
77  }
78 
80  virtual ~DtF18EntityDecoder(){}
81 
82 protected:
83 
88  const RTI::AttributeHandleValuePairSet& attrs,
89  int pairSetIndex)
90  {
91  RTI::ULong length = attrs.getValueLength(pairSetIndex);
92  // if there is nothing in there, we can exit safely
93  if (length == 0) return;
94 
95  char* buffer = DtDecodingBuffer(length+1);
96  attrs.getValue(pairSetIndex, buffer, length);
97  buffer[length] = '\0';
98 
99  stateRep->setF18Attribute(buffer);
100  }
101 
102 };
103 
108 {
109 public:
112  DtObjClassDesc* classDesc):
113  // By calling the base class ctor all the needed encoders and checkers are registered
114  DtPlatformEncoder(exConn, classDesc)
115  {
116  // Register our encoder functions for all the attributes we need.
117  addEncoder("SpecialF18Attribute",
119  addChecker("SpecialF18Attribute",
121  }
122  virtual ~DtF18EntityEncoder() {}
123 
124 protected:
125 
126  static bool needSpecialF18Attribute( const DtF18EntityStateRep& stateRep,
127  const DtF18EntityStateRep& asSeenByRemote)
128  {
129  return(stateRep.f18Attribute() != asSeenByRemote.f18Attribute());
130  }
131 
132  static void encodeSpecialF18Attribute( const DtF18EntityStateRep& stateRep,
133  RTI::AttributeHandleValuePairSet* avList,
134  RTI::AttributeHandle attrHandle)
135  {
136  // This is easy, they are not all this easy. The point of this example
137  // is not to show how to encode/decode complex data types.
138  avList->add(attrHandle,
139  stateRep.f18Attribute().c_str(),
140  stateRep.f18Attribute().size());
141  }
142 
143 };
144 
145 // Some useful macros for adding the encoders/decoders
147 #define DtADD_ENCODER(className, derivedEnc) \
148 { \
149  DtObjClassDesc* classDesc = exConn.fom()->objClassByName(#className); \
150  if (classDesc) \
151  { \
152  exConn.fomMapper()->stateEncoderFactory()->addEncoder( \
153  classDesc->handle(), new derivedEnc(&exConn, classDesc)); \
154  } \
155  else \
156  { \
157  DtWarn("Can't add encoder for object class %s: Not in FOM.\n", #className); \
158  } \
159 }
160 
162 #define DtADD_DECODER(className, derivedDec) \
163 { \
164  DtObjClassDesc* classDesc = exConn.fom()->objClassByName(#className); \
165  if (classDesc) \
166  { \
167  exConn.fomMapper()->stateDecoderFactory()->addDecoder( \
168  classDesc->handle(), new derivedDec(&exConn, classDesc)); \
169  } \
170  else \
171  { \
172  DtWarn("Can't add decoder for object class %s: Not in FOM.\n", #className); \
173  } \
174 }
175 
177 char* DtF18EntityChooser( const char* vrlinkClassName,
178  DtExerciseConn* exConn,
179  void *usr)
180 {
181  printf("=========\n");
182  printf(" In Class Chooser, deciding which entity Type to publish\n");
183  printf("=========\n");
184 
185  // For Entities, the usr data is always of DtEntityType. This is just
186  // the way it is.
187 
188  DtEntityType& type = *((DtEntityType*) usr);
189 
190  if (type.subCategory() == DtF18)
191  {
192  printf("Choosing F18 Type, we will use the new class!\n");
193  // Return the FOM OBJECT CLASS name
194  return "BaseEntity.PhysicalEntity.Platform.Aircraft.F18";
195  }
196 
197  // If this is not the right type, let the default chooser decide
198  return(DtRprFomMapper::dfltEntityClassChooser(vrlinkClassName,
199  exConn, usr));
200 }
201 
202 
203 #endif

Document ID: Generated on Mon Feb 6 18:36:34 EST 2017 from SVN revision 173107
Copyright © 2005-2016 VT MÄK. All Rights Reserved (www.mak.com)