VR-Forces 4.8 Class Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
vrfStatePropertyPrinter.h
Go to the documentation of this file.
1 /*******************************************************************************
2 ** Copyright (c) 2017 MAK Technologies, Inc.
3 ** All rights reserved.
4 *******************************************************************************/
5 
8 
9 #pragma once
10 
11 class DtExerciseConn;
12 class DtClock;
16 class DtSmsLoader;
18 
19 #if DtHLA
20 namespace makVrfVrlinkExtToolkit
21 {
22  class DtReflectedExtendedAttributesObjectList;
23  class DtReflectedExtendedAttributesObject;
24 }
25 #endif
26 
27 #include <vl/globalObjectDesignator.h>
30 #include <vlutil/vlPrint.h>
31 #include <vlutil/vlPrintUtil.h>
32 
35 {
36 private:
38 
43 
44 public:
45 
48 
49  virtual bool init(DtSmsLoader* smsLoader);
50 
51 protected:
52 
54 
55  template<class ReflectedObjType, class StateRepType>
56  static void objectAddedCallback(ReflectedObjType* object, void* usr);
57 
58  template<class ReflectedObjType, class StateRepType>
59  void processObjectAdded(ReflectedObjType* object);
61 
63 
64  template<class ReflectedObjType, class StateRepType>
65  static void objectUpdatedCallback(ReflectedObjType* object, void* usr);
66 
67  template<class ReflectedObjType, class StateRepType>
68  void processObjectUpdated(ReflectedObjType* object);
70 
72 
73  template<class ReflectedObjType, class StateRepType>
74  static void objectRemovedCallback(ReflectedObjType* object, void* usr);
75 
76  template<class ReflectedObjType, class StateRepType>
77  void processObjectRemoved(ReflectedObjType* object);
79 
80 protected:
81 
86 #if DtHLA
88 #endif
89 
91  std::map<DtGlobalObjectDesignator, DtTime> myLastUpdateTimes;
92 };
93 
95 
96 template<class StateRepType>
97 void printStateRepBasicInfo(StateRepType* stateRep)
98 {
99  DtPrintAttribute(DtInfo, "EntityId", stateRep->entityId().string());
100  DtPrintAttribute(DtInfo, "EntityType", stateRep->entityType().string());
101 }
102 
103 template<>
105 {
106  DtPrintAttribute(DtInfo, "EnvironmentProcessId", stateRep->environmentalProcessID().string());
107  DtPrintAttribute(DtInfo, "EnvironmentType", stateRep->environmentType().string());
108 }
110 
111 template<class ReflectedObjType, class StateRepType>
112 void DtVrfStatePropertyPrinter::objectAddedCallback(ReflectedObjType* object, void* usr)
113 {
114  static_cast<DtVrfStatePropertyPrinter*>(usr)->
115  processObjectAdded<ReflectedObjType, StateRepType>(object);
116 }
117 
118 template<class ReflectedObjType, class StateRepType>
119 void DtVrfStatePropertyPrinter::processObjectAdded(ReflectedObjType* object)
120 {
121  if (object)
122  {
123  object->addPostUpdateCallback(objectUpdatedCallback<ReflectedObjType, StateRepType>, this);
124  myLastUpdateTimes[object->globalId()] = 0;
125  processObjectUpdated<ReflectedObjType, StateRepType>(object);
126  }
127 }
128 
129 template<class ReflectedObjType, class StateRepType>
130 void DtVrfStatePropertyPrinter::objectUpdatedCallback(ReflectedObjType* object, void* usr)
131 {
132  static_cast<DtVrfStatePropertyPrinter*>(usr)->
133  processObjectUpdated<ReflectedObjType, StateRepType>(object);
134 }
135 
136 template<class ReflectedObjType, class StateRepType>
138 {
139  if (object)
140  {
141  bool headerPrinted = false;
142 
143  DtTime lastUpdateTime = myLastUpdateTimes[object->globalId()];
144 
145  StateRepType* sr = dynamic_cast<StateRepType*>(object->stateRep());
146  if (sr)
147  {
148  // Iterate over all attributes, printing only those attributes which have been
149  // updated since last we checked
150  std::vector<DtReaderWriterRegistryData *>::const_iterator propIter =
151  sr->stateProperties().registry().registryData().begin();
152  std::vector<DtReaderWriterRegistryData *>::const_iterator propEnd =
153  sr->stateProperties().registry().registryData().end();
154  for (; propIter != propEnd; ++propIter)
155  {
156  DtReaderWriter* propRw = (*propIter)->readerWriter();
157  if (propRw->wasUpdatedSince(lastUpdateTime))
158  {
159  DtPropertyInterface* prop = propRw->property();
160 
161  if (prop)
162  {
163  if (!headerPrinted)
164  {
165  DtInfo << "****************************************" << std::endl;
166  DtInfo << "****** Updated State Properties *******" << std::endl;
167  DtInfo << "****************************************" << std::endl;
168  printStateRepBasicInfo<StateRepType>(sr);
169 
170  headerPrinted = true;
171  }
172 
173  DtInfo << prop->stringRep() << std::endl;
174  }
175  }
176  }
177  }
178 
179  myLastUpdateTimes[object->globalId()] = myClock.absRealTime();
180  }
181 }
182 
183 template<class ReflectedObjType, class StateRepType>
184 void DtVrfStatePropertyPrinter::objectRemovedCallback(ReflectedObjType* object, void* usr)
185 {
186  static_cast<DtVrfStatePropertyPrinter*>(usr)->
187  processObjectRemoved<ReflectedObjType, StateRepType>(object);
188 }
189 
190 template<class ReflectedObjType, class StateRepType>
192 {
193  if (object)
194  {
195  object->removePostUpdateCallback(objectUpdatedCallback<ReflectedObjType, StateRepType>, this);
196  }
197 }
DtVrfStatePropertyPrinter & operator=(const DtVrfStatePropertyPrinter &orig)
virtual DtString stringRep(const DtString &root="") const =0
DtNetworkEventManager * myEventManager
Definition: vrfStatePropertyPrinter.h:82
DtReflectedVrfControlObjectList * myReflectedControlObjectList
Definition: vrfStatePropertyPrinter.h:85
DtReflectedVrfExtEntityList * myReflectedEntityList
Definition: vrfStatePropertyPrinter.h:83
virtual bool wasUpdatedSince(DtTime t) const
Can be implemented in subclasses to return true if an update occurred after the specified time...
DtVrfStatePropertyPrinter()
Not implemented.
makVrfVrlinkExtToolkit::DtReflectedExtendedAttributesObjectList * myReflectedExtendedAttributesList
Definition: vrfStatePropertyPrinter.h:87
void processObjectRemoved(ReflectedObjType *object)
Definition: vrfStatePropertyPrinter.h:191
Definition: reflectedVrfExtEntityList.h:23
Definition: readerWriter.h:85
void printStateRepBasicInfo(StateRepType *stateRep)
Prints some basic identifying information about the state rep.
Definition: vrfStatePropertyPrinter.h:97
void printStateRepBasicInfo< DtControlObjectRepository >(DtControlObjectRepository *stateRep)
Definition: vrfStatePropertyPrinter.h:104
Interface class used to define minimal interface for a property.
Definition: propertyInterface.h:48
Contains the DtExtEntityStateRepository class.
Registers for all state property updates and prints the current state.
Definition: vrfStatePropertyPrinter.h:34
DtControlObjectRepository class extends the DtControlObjectBaseRepository to be able to handle extend...
Definition: controlObjectRepository.h:27
virtual bool init(DtSmsLoader *smsLoader)
Definition: networkEventManager.h:40
DtClock myClock
Definition: vrfStatePropertyPrinter.h:90
void processObjectUpdated(ReflectedObjType *object)
Definition: vrfStatePropertyPrinter.h:137
void processObjectAdded(ReflectedObjType *object)
Definition: vrfStatePropertyPrinter.h:119
virtual DtPropertyInterface * property()
Definition: smsLoader.h:19
Definition: reflectedVrfExtControlObjectList.h:23
DtReflectedVrfExtAggregateList * myReflectedAggregateList
Definition: vrfStatePropertyPrinter.h:84
static void objectUpdatedCallback(ReflectedObjType *object, void *usr)
Callback for the update of objects.
Definition: vrfStatePropertyPrinter.h:130
virtual ~DtVrfStatePropertyPrinter()
static void objectAddedCallback(ReflectedObjType *object, void *usr)
Callback for the addition of new objects.
Definition: vrfStatePropertyPrinter.h:112
static void objectRemovedCallback(ReflectedObjType *object, void *usr)
Callback for the removal of objects.
Definition: vrfStatePropertyPrinter.h:184
std::map< DtGlobalObjectDesignator, DtTime > myLastUpdateTimes
Definition: vrfStatePropertyPrinter.h:91
Definition: reflectedVrfExtAggregateList.h:23

Document ID: Generated on Thu Aug 27 10:56:05 EDT 2020 from SVN revision 217100
Copyright © 2005-2020 MAK Technologies. All Rights Reserved (www.mak.com)