MAK RTIspy API Documentation for HLA Evolved
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
rtiTemplateMsgInetAddrParams.h
Go to the documentation of this file.
1 /*********************************************************************
2 ** Copyright (c) 2011 MaK Technologies, Inc.
3 ** All rights reserved.
4 *********************************************************************/
5 
14 
15 #ifndef DtRtiTemplateMsgInetAddrParams_H_
16 #define DtRtiTemplateMsgInetAddrParams_H_
17 
18 #include "rtiTemplateMsgParams.h"
20 #include <vlutil/vlInetAddr.h>
21 #include <assert.h>
22 
23 
25 template<>
26 class DtRtiMsgParam<MAKRti::DtInetAddr, MAKRti::DtNetU128> : public DtRtiBaseMsgParam
27 {
28 public:
29  DtRtiMsgParam(const char* paramName,
31  : DtRtiBaseMsgParam(paramName)
32  , myFamilyParam(familyParam) {}
34 
36  void setParamRef(const MAKRti::DtInetAddr& addr)
37  {
38  MAKRti::DtNetU128* ptr = paramPtr();
39  *ptr = addr.toU128();
40  myFamilyParam->setParam(addr.family());
41  }
42 
44  MAKRti::DtInetAddr param() const
45  {
46  const MAKRti::DtNetU128* ptr = paramPtr();
47  return MAKRti::DtInetAddr(*ptr,
48  MAKRti::DtInetUtils::DtInetAddrFamily(
49  static_cast<MAKRti::DtU32>(myFamilyParam->param())));
50  }
51 
53  void getParam(MAKRti::DtInetAddr& addr) const
54  {
55  const MAKRti::DtNetU128* ptr = paramPtr();
56  addr = MAKRti::DtInetAddr(*ptr,
57  MAKRti::DtInetUtils::DtInetAddrFamily(
58  static_cast<MAKRti::DtU32>(myFamilyParam->param())));
59  }
60 
62  void* endPtr()
63  {
64  return (reinterpret_cast<char*>(paramPtr()) + sizeof(MAKRti::DtNetU128));
65  }
66 
67  const void* endPtr() const
68  {
69  return (reinterpret_cast<const char*>(paramPtr()) + sizeof(MAKRti::DtNetU128));
70  }
71 
73  unsigned minSize() { return sizeof(MAKRti::DtNetU128); }
74 
76  unsigned elementSize() { return sizeof(MAKRti::DtNetU128); }
77 
79  void print() const
80  {
81  MAKRti::DtVerbose << name() << ": " << param().toDtString() << std::endl;
82  }
83 
86  void setOctetBoundary(unsigned prevBoundary)
87  {
88  myOctetBoundary = 0;
89 
90  // Check that our message is assembled properly
91  assert(prevBoundary == 0 || (prevBoundary % 8) == 0);
92  }
93 
94 protected:
96 
98  MAKRti::DtNetU128* paramPtr() { return reinterpret_cast<MAKRti::DtNetU128*>(beginPtr()); }
99  const MAKRti::DtNetU128* paramPtr() const { return reinterpret_cast<const MAKRti::DtNetU128*>(beginPtr()); }
100 
101 protected:
102 
105 
106 };
107 
108 
111 template<typename AllocatedMsgParamType>
112 class DtRtiArrayMsgParam<MAKRti::DtInetAddr, MAKRti::DtU128, MAKRti::DtNetU128, AllocatedMsgParamType> : public DtRtiBaseMsgParam
113 {
114 public:
115  DtRtiArrayMsgParam(const char* paramName,
116  AllocatedMsgParamType* allocatedNumParam, DtRtiMsgParam<MAKRti::DtU32,
117  MAKRti::DtNetU32>* familyParam)
118  : DtRtiBaseMsgParam(paramName)
119  , myAllocatedNumParam(allocatedNumParam)
120  , myFamilyParam(familyParam)
121  , myNumUsed(0)
124 
127  bool addParam(const MAKRti::DtInetAddr& addr)
128  {
129  bool result = false;
130  if(myNumUsed+1 <= numItems())
131  {
132  result = true;
133 
134  MAKRti::DtNetU128* ptr = paramPtr() + myNumUsed;
135  *ptr = addr.toU128();
136  ++myNumUsed;
137  }
138 
139  return result;
140  }
141 
144  bool setParams(const MAKRti::DtInetAddr* addrs, unsigned num)
145  {
146  bool result = false;
147  if(num <= numItems())
148  {
149  result = true;
150 
151  MAKRti::DtNetU128* ptr = paramPtr();
152  myNumUsed = num;
153 
154  for(unsigned i = 0; i < num; ++i)
155  {
156  if(i == 0)
157  {
158  myFamilyParam->setParam(static_cast<MAKRti::DtU32>(addrs[i].family()));
159  }
160  ptr[i] = addrs[i].toU128();
161  }
162  }
163 
164  return result;
165  }
166 
169  template <typename ParamContainerType>
170  bool setParams(const ParamContainerType& container)
171  {
172  bool result = false;
173  if(container.size() <= numItems())
174  {
175  result = true;
176 
177  MAKRti::DtNetU128* ptr = paramPtr();
178  myNumUsed = container.size();
179 
180  typename ParamContainerType::const_iterator iter = container.begin();
181  typename ParamContainerType::const_iterator iterEnd = container.end();
182  for(unsigned i = 0; iter != iterEnd; ++iter, ++i)
183  {
184  if(i == 0)
185  {
186  myFamilyParam->setParam(static_cast<MAKRti::DtU32>(iter->family()));
187  }
188  ptr[i] = iter->toU128();
189  }
190  }
191 
192  return result;
193  }
194 
197  template <typename ParamContainerType>
198  void getParams(ParamContainerType& container) const
199  {
200  unsigned count = numItems();
201  const MAKRti::DtNetU128* ptr = paramPtr();
202  DtInetUtils::DtInetAddrFamily family =
203  DtInetUtils::DtInetAddrFamily(static_cast<DtU32>(myFamilyParam->param()));
204  for(unsigned i = 0; i < count; ++i)
205  {
206  container.insert(container.end(), MAKRti::DtInetAddr(ptr[i], family));
207  }
208  }
209 
212  unsigned getParams(MAKRti::DtInetAddr* buff) const
213  {
214  unsigned count = numItems();
215  const MAKRti::DtNetU128* ptr = paramPtr();
216  DtInetUtils::DtInetAddrFamily family =
217  DtInetUtils::DtInetAddrFamily(static_cast<MAKRti::DtU32>(myFamilyParam->param()));
218  for(unsigned i = 0; i < count; ++i)
219  {
220  buff[i] = MAKRti::DtInetAddr(ptr[i], family);
221  }
222 
223  return count;
224  }
225 
228  bool getFirstParam(MAKRti::DtInetAddr& addr) const
229  {
230  bool itemExists = numItems() > 0;
231  if(itemExists)
232  {
233  const MAKRti::DtNetU128* ptr = paramPtr();
234  addr = MAKRti::DtInetAddr(ptr[0],
235  DtInetUtils::DtInetAddrFamily(static_cast<MAKRti::DtU32>(myFamilyParam->param())));
237  }
238  return itemExists;
239  }
240 
243  bool getNextParam(MAKRti::DtInetAddr& addr) const
244  {
245  bool itemExists = numItems() > myMutableNextParamIndex;
246  if(itemExists)
247  {
248  const MAKRti::DtNetU128* ptr = paramPtr();
249  addr = MAKRti::DtInetAddr(ptr[myMutableNextParamIndex++],
250  DtInetUtils::DtInetAddrFamily(static_cast<MAKRti::DtU32>(myFamilyParam->param())));
251  }
252  return itemExists;
253  }
254 
256  void* endPtr()
257  {
258  return (paramPtr() + myAllocatedNumParam->param());
259  }
260 
261  const void* endPtr() const
262  {
263  return (paramPtr() + myAllocatedNumParam->param());
264  }
265 
268  unsigned minSize() { return 0; }
269 
271  unsigned elementSize() { return sizeof(MAKRti::DtU128); }
272 
274  unsigned numItems() const { return myAllocatedNumParam->param(); }
275 
277  void setNumItems(unsigned num) { myAllocatedNumParam->setParam(num); }
278 
280  void print() const
281  {
282  MAKRti::DtVerbose << name() << ": " << std::endl;
283  MAKRti::DtInetAddr addr;
284  if(getFirstParam(addr))
285  {
286  MAKRti::DtVerbose << " " << addr.toDtString() << std::endl;
287  while(getNextParam(addr))
288  {
289  MAKRti::DtVerbose << " " << addr.toDtString() << std::endl;
290  }
291  }
292  else
293  {
294  MAKRti::DtVerbose << " Empty" << std::endl;
295  }
296  }
297 
302  void setOctetBoundary(unsigned prevBoundary)
303  {
304  myOctetBoundary = 0;
305 
306  // Check that our message is assembled properly
307  assert(prevBoundary == 0 || (prevBoundary % 8) == 0);
308  }
309 
310 protected:
311 
313  MAKRti::DtNetU128* paramPtr() { return reinterpret_cast<MAKRti::DtNetU128*>(beginPtr()); }
314  const MAKRti::DtNetU128* paramPtr() const { return reinterpret_cast<const MAKRti::DtNetU128*>(beginPtr()); }
315 
316 protected:
317 
319 
322  AllocatedMsgParamType* myAllocatedNumParam;
323 
326 
328  unsigned myNumUsed;
329 
331  mutable unsigned myMutableNextParamIndex;
332 
333 };
334 
335 
336 
337 // PARAMETER DECLARATION MACROS
338 // These macros declare parameters and their accessor methods within a message.
339 // In your class definition, simply use one of the macros below. All DtInetAddr
340 // parameters will require the definition of a separate parameter which stores
341 // 32 bit unsigned integer which represents the address family (IPv4 or IPv6).
342 // DtInetAddr array parameters also require another parameter to store the size
343 // of the array. Arrays are expected to contain address of the same family.
344 
345 // Defines a new DtInetAddr message parameter and declares its get and set
346 // methods.
347 // ParamName = the name of the parameter
348 #define DtDECLARE_INET_ADDR_PARAMETER_METHODS(ParamName) \
349  DtDECLARE_BY_REF_PARAMETER_METHODS(ParamName, MAKRti::DtInetAddr) \
350  protected: \
351  typedef DtRtiMsgParam<MAKRti::DtInetAddr, MAKRti::DtNetU128> ParamName##Type; \
352  ParamName##Type* my##ParamName;
353 
354 // Defines a message parameter which is an array of DtInetAddrs declares
355 // its get and set methods.
356 // ParamName = the name of the parameter
357 // CountBitSize = the number of bits in the parameter that holds the item count
358 #define DtDECLARE_INET_ADDR_ARRAY_PARAMETER_METHODS(ParamName, CountBitSize) \
359  DtDECLARE_ARRAY_PARAMETER_METHODS(ParamName, MAKRti::DtInetAddr) \
360  protected: \
361  typedef DtRtiArrayMsgParam<MAKRti::DtInetAddr, MAKRti::DtU128, MAKRti::DtNetU128, \
362  DtRtiMsgParam<MAKRti::DtU##CountBitSize, MAKRti::DtNetU##CountBitSize> > ParamName##Type; \
363  ParamName##Type* my##ParamName;
364 
365 
366 
367 // PARAMETER DEFINITION MACROS
368 // These macros define the accessor methods for a message parameter.
369 // In your .cxx file, simply use one of the macros below. The macro should
370 // match the type used in the DtDECLARE macro in your class definition.
371 
372 // Defines the set and get methods for DtInetAddr parameters.
373 // ClassName = the name of the message class
374 // ParamName = the name of the parameter
375 #define DtDEFINE_INET_ADDR_PARAMETER_METHODS(ClassName, ParamName) \
376  DtDEFINE_BY_REF_PARAMETER_METHODS(ClassName, ParamName, MAKRti::DtInetAddr)
377 
378 // Defines the set and get methods which take a standard container type for
379 // input and output for DtInetAddr array parameters. Should not be used
380 // directly. Use DtDEFINE_INET_ADDR_ARRAY_PARAMETER_METHODS instead.
381 // ClassName = the name of the message class
382 // ClassName = the name of the message class
383 // ParamName = the name of the parameter
384 // CtrType = the type of a container to be accepted as input/output (e.g. set)
385 #define DtDEFINE_INET_ADDR_ARRAY_PARAMETER_CONTAINER_METHODS(ClassName, ParamName, CtrType)\
386  void ClassName::set##ParamName(const CtrType& container, \
387  DtResizeArrayFlag resizeFlag) \
388  { \
389  unsigned currNum = my##ParamName->numItems(); \
390  if(resizeFlag == DtResizeIfNeeded && container.size() != currNum) \
391  { \
392  unsigned currSize = currNum * sizeof(MAKRti::DtNetU128); \
393  unsigned newSize = container.size() * sizeof(MAKRti::DtNetU128); \
394  char* begPtr = static_cast<char*>(my##ParamName->beginPtr()); \
395  if(newSize > currSize) \
396  { \
397  insertBytes(begPtr + currSize, newSize - currSize); \
398  } \
399  else if(currSize > newSize) \
400  { \
401  deleteBytes(begPtr + newSize, currSize - newSize); \
402  } \
403  my##ParamName->setNumItems(container.size()); \
404  } \
405  my##ParamName->setParams(container); \
406  } \
407  void ClassName::get##ParamName(CtrType& container) const \
408  { \
409  my##ParamName->getParams(container); \
410  }
411 
412 // Defines the set and get methods for parameters which are an array of
413 // DtInetAddrs.
414 // ClassName = the name of the message class
415 // ParamName = the name of the parameter
416 #define DtDEFINE_INET_ADDR_ARRAY_PARAMETER_METHODS(ClassName, ParamName) \
417  const char* ClassName::ParamName##Name = #ParamName; \
418  DtDEFINE_INET_ADDR_ARRAY_PARAMETER_CONTAINER_METHODS(ClassName, ParamName, std::set<MAKRti::DtInetAddr>) \
419  DtDEFINE_INET_ADDR_ARRAY_PARAMETER_CONTAINER_METHODS(ClassName, ParamName, std::vector<MAKRti::DtInetAddr>) \
420  DtDEFINE_INET_ADDR_ARRAY_PARAMETER_CONTAINER_METHODS(ClassName, ParamName, std::list<MAKRti::DtInetAddr>) \
421  DtDEFINE_INET_ADDR_ARRAY_PARAMETER_CONTAINER_METHODS(ClassName, ParamName, std::deque<MAKRti::DtInetAddr>) \
422  void ClassName::set##ParamName(const MAKRti::DtInetAddr* buff, \
423  unsigned num, DtResizeArrayFlag resizeFlag) \
424  { \
425  unsigned currNum = my##ParamName->numItems(); \
426  if(resizeFlag == DtResizeIfNeeded && num != currNum) \
427  { \
428  unsigned currSize = currNum * sizeof(MAKRti::DtNetU128); \
429  unsigned newSize = num * sizeof(MAKRti::DtNetU128); \
430  char* begPtr = static_cast<char*>(my##ParamName->beginPtr()); \
431  if(newSize > currSize) \
432  { \
433  insertBytes(begPtr + currSize, newSize - currSize); \
434  } \
435  else if(currSize > newSize) \
436  { \
437  deleteBytes(begPtr + newSize, currSize - newSize); \
438  } \
439  my##ParamName->setNumItems(num); \
440  } \
441  my##ParamName->setParams(buff, num); \
442  } \
443  unsigned ClassName::get##ParamName(MAKRti::DtInetAddr* buff) const \
444  { \
445  return my##ParamName->getParams(buff); \
446  }
447 
448 
449 
450 
451 // PARAMETER ADDITION MACROS
452 // These macros should be used within the addAllParameters() function of your
453 // new message class. The order parameters are added matters! You must order
454 // them in a way to ensure proper alignment. If you don't, the parameter
455 // classes will try to help you out by asserting in debug builds.
456 
457 // Adds an IP address parameter to the message.
458 // ParamName = the name of the parameter
459 // FamilyParamName = the name of the parameter which stores the address family
460 #define DtADD_INET_ADDR_PARAMETER(ParamName, FamilyParamName) \
461  addParameter(my##ParamName = new ParamName##Type(ParamName##Name, my##FamilyParamName));
462 
463 // Adds an IP address array parameter to the message.
464 // ParamName = the name of the parameter
465 // SizeParamName = the name of the parameter which stores the number of items
466 // FamilyParamName = the name of the parameter which stores the address family
467 #define DtADD_INET_ADDR_ARRAY_PARAMETER(ParamName, SizeParamName, FamilyParamName) \
468  addParameter(my##ParamName = new ParamName##Type(ParamName##Name, my##SizeParamName, my##FamilyParamName));
469 
470 #endif
471 
unsigned numItems() const
Returns the number of items in this array.
Definition: rtiTemplateMsgArrayParams.h:241
DtRtiMsgParam< MAKRti::DtU32, MAKRti::DtNetU32 > * myFamilyParam
The parameter which points to the IP address family.
Definition: rtiTemplateMsgInetAddrParams.h:104
unsigned elementSize()
Returns the size of single element in this parameter.
Definition: rtiTemplateMsgInetAddrParams.h:271
unsigned minSize()
Returns the minimum size of this parameter, which is 0 since it could be an empty array...
Definition: rtiTemplateMsgInetAddrParams.h:268
void * beginPtr()
Returns a pointer to the start of this parameter in the message.
Definition: rtiTemplateMsgParams.h:47
AllocatedMsgParamType * myAllocatedNumParam
The parameter which specifies how many elements can fit in the space allotted for this array...
Definition: rtiTemplateMsgArrayParams.h:287
const void * endPtr() const
Definition: rtiTemplateMsgInetAddrParams.h:261
AllocatedMsgParamType * myAllocatedNumParam
The parameter which specifies how many elements can fit in the space allotted for this array...
Definition: rtiTemplateMsgInetAddrParams.h:322
unsigned myMutableNextParamIndex
The index to the next item to be retrieved by nextParam.
Definition: rtiTemplateMsgInetAddrParams.h:331
unsigned myOctetBoundary
Octet boundary of this parameter.
Definition: rtiTemplateMsgParams.h:87
void setOctetBoundary(unsigned prevBoundary)
Sets the octet boundary of the parameter in the message.
Definition: rtiTemplateMsgInetAddrParams.h:302
NetParamType * paramPtr()
Returns a pointer to location of this parameter in the message.
Definition: rtiTemplateMsgArrayParams.h:280
void print() const
Prints the parameter.
Definition: rtiTemplateMsgInetAddrParams.h:79
unsigned myNumUsed
The number of items currently used in the array.
Definition: rtiTemplateMsgArrayParams.h:290
ParamType param() const
Gets the value of the parameter.
Definition: rtiTemplateMsgParams.h:116
const MAKRti::DtNetU128 * paramPtr() const
Definition: rtiTemplateMsgInetAddrParams.h:314
void setNumItems(unsigned num)
Sets the number of items in this array.
Definition: rtiTemplateMsgInetAddrParams.h:277
~DtRtiMsgParam()
Definition: rtiTemplateMsgInetAddrParams.h:33
void setOctetBoundary(unsigned prevBoundary)
Sets the octet boundary of the parameter in the message.
Definition: rtiTemplateMsgInetAddrParams.h:86
This file defines the DtRtiArrayMsgParam template which can be used to create a message parameter whi...
unsigned minSize()
Returns the minimum size of this parameter.
Definition: rtiTemplateMsgInetAddrParams.h:73
This file defines the DtRtiMsgParam template which can be used to produce template based message clas...
The template for an RTI message parameter.
Definition: rtiTemplateMsgParams.h:95
NetParamType * paramPtr()
Returns a pointer to location of this parameter in the message.
Definition: rtiTemplateMsgParams.h:166
MAKRti::DtInetAddr param() const
Gets the value of the parameter.
Definition: rtiTemplateMsgInetAddrParams.h:44
MAKRti::DtNetU128 * paramPtr()
Returns a pointer to location of this parameter in the message.
Definition: rtiTemplateMsgInetAddrParams.h:313
The base class for all templated RTI message parameters.
Definition: rtiTemplateMsgParams.h:32
unsigned getParams(MAKRti::DtInetAddr *buff) const
Populates the buffer with all of the parameter data in this parameter array.
Definition: rtiTemplateMsgInetAddrParams.h:212
bool getNextParam(ParamType &val) const
Gets the value of the next parameter item in the array.
Definition: rtiTemplateMsgArrayParams.h:211
unsigned myMutableNextParamIndex
The index to the next item to be retrieved by nextParam.
Definition: rtiTemplateMsgArrayParams.h:293
bool getFirstParam(MAKRti::DtInetAddr &addr) const
Gets the value of the first parameter item in the array and resets the index for getNextParam().
Definition: rtiTemplateMsgInetAddrParams.h:228
void print() const
Prints the parameter.
Definition: rtiTemplateMsgInetAddrParams.h:280
bool setParams(const ParamContainerType &container)
Sets the entire contents of the array.
Definition: rtiTemplateMsgInetAddrParams.h:170
DtRtiMsgParam< MAKRti::DtU32, MAKRti::DtNetU32 > * myFamilyParam
The parameter which points to the IP address family.
Definition: rtiTemplateMsgInetAddrParams.h:325
const void * endPtr() const
Definition: rtiTemplateMsgInetAddrParams.h:67
bool getNextParam(MAKRti::DtInetAddr &addr) const
Gets the value of the next parameter item in the array.
Definition: rtiTemplateMsgInetAddrParams.h:243
bool setParams(const MAKRti::DtInetAddr *addrs, unsigned num)
Sets the entire contents of the array.
Definition: rtiTemplateMsgInetAddrParams.h:144
DtRtiArrayMsgParam(const char *paramName, AllocatedMsgParamType *allocatedNumParam, DtRtiMsgParam< MAKRti::DtU32, MAKRti::DtNetU32 > *familyParam)
Definition: rtiTemplateMsgInetAddrParams.h:115
unsigned myNumUsed
The number of items currently used in the array.
Definition: rtiTemplateMsgInetAddrParams.h:328
void getParams(ParamContainerType &container) const
Populates the container with all of the parameter data in this parameter array.
Definition: rtiTemplateMsgInetAddrParams.h:198
unsigned numItems() const
Returns the number of items in this array.
Definition: rtiTemplateMsgInetAddrParams.h:274
The template for an RTI message parameter which is actually an array of items of the same type...
Definition: rtiTemplateMsgArrayParams.h:92
unsigned elementSize()
Same as minSize.
Definition: rtiTemplateMsgInetAddrParams.h:76
void getParam(MAKRti::DtInetAddr &addr) const
Gets the value of the parameter.
Definition: rtiTemplateMsgInetAddrParams.h:53
DtRtiMsgParam(const char *paramName)
Definition: rtiTemplateMsgParams.h:98
DtRtiMsgParam(const char *paramName, DtRtiMsgParam< MAKRti::DtU32, MAKRti::DtNetU32 > *familyParam)
Definition: rtiTemplateMsgInetAddrParams.h:29
virtual const char * name() const
Returns the parameter name.
Definition: rtiTemplateMsgParams.h:63
bool getFirstParam(ParamType &val) const
Gets the value of the first parameter item in the array and resets the index for getNextParam().
Definition: rtiTemplateMsgArrayParams.h:197
bool addParam(const MAKRti::DtInetAddr &addr)
Adds a new parameter data item to the array.
Definition: rtiTemplateMsgInetAddrParams.h:127
MAKRti::DtNetU128 * paramPtr()
Returns a pointer to location of this parameter in the message.
Definition: rtiTemplateMsgInetAddrParams.h:98
DtRtiArrayMsgParam(const char *paramName, AllocatedMsgParamType *allocatedNum)
Definition: rtiTemplateMsgArrayParams.h:95
void setParamRef(const MAKRti::DtInetAddr &addr)
Sets the value of the parameter.
Definition: rtiTemplateMsgInetAddrParams.h:36
const MAKRti::DtNetU128 * paramPtr() const
Definition: rtiTemplateMsgInetAddrParams.h:99
void * endPtr()
Returns a pointer to location just after this parameter in the message.
Definition: rtiTemplateMsgInetAddrParams.h:256
void * endPtr()
Returns a pointer to location just after this parameter in the message.
Definition: rtiTemplateMsgInetAddrParams.h:62

Document ID: Generated on Thu May 11 15:55:32 EDT 2023 from SVN revision 254743
Copyright © 2005-2020 MAK Technologies Inc. All Rights Reserved (www.mak.com)