VR-Forces 4.6.1 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;
17 
18 #if DtHLA
19 namespace makVrfVrlinkExtToolkit
20 {
21  class DtReflectedExtendedAttributesObjectList;
22  class DtReflectedExtendedAttributesObject;
23 }
24 #endif
25 
26 #include <vl/globalObjectDesignator.h>
28 #include <vrfutil/propertyUtils.h>
29 #include <vlutil/vlPrint.h>
30 #include <vlutil/vlPrintUtil.h>
31 
34 {
35 private:
37 
42 
43 public:
44 
45  DtVrfStatePropertyPrinter(DtExerciseConn* exConn);
47 
48  virtual bool init(DtSmsLoader* smsLoader);
49 
50 protected:
51 
53 
54  template<class ReflectedObjType, class StateRepType>
55  static void objectAddedCallback(ReflectedObjType* object, void* usr);
56 
57  template<class ReflectedObjType, class StateRepType>
58  void processObjectAdded(ReflectedObjType* object);
60 
62 
63  template<class ReflectedObjType, class StateRepType>
64  static void objectUpdatedCallback(ReflectedObjType* object, void* usr);
65 
66  template<class ReflectedObjType, class StateRepType>
67  void processObjectUpdated(ReflectedObjType* object);
69 
71 
72  template<class ReflectedObjType, class StateRepType>
73  static void objectRemovedCallback(ReflectedObjType* object, void* usr);
74 
75  template<class ReflectedObjType, class StateRepType>
76  void processObjectRemoved(ReflectedObjType* object);
78 
79 protected:
80 
81  DtExerciseConn* myExConn;
85 #if DtHLA
87 #endif
88 
90  std::map<DtGlobalObjectDesignator, DtTime> myLastUpdateTimes;
91 };
92 
94 
95 template<class StateRepType>
96 void printStateRepBasicInfo(StateRepType* stateRep)
97 {
98  DtPrintAttribute(DtInfo, "EntityId", stateRep->entityId().string());
99  DtPrintAttribute(DtInfo, "EntityType", stateRep->entityType().string());
100 }
101 
102 template<>
104 {
105  DtPrintAttribute(DtInfo, "EnvironmentProcessId", stateRep->environmentalProcessID().string());
106  DtPrintAttribute(DtInfo, "EnvironmentType", stateRep->environmentType().string());
107 }
109 
110 template<class ReflectedObjType, class StateRepType>
111 void DtVrfStatePropertyPrinter::objectAddedCallback(ReflectedObjType* object, void* usr)
112 {
113  static_cast<DtVrfStatePropertyPrinter*>(usr)->
114  processObjectAdded<ReflectedObjType, StateRepType>(object);
115 }
116 
117 template<class ReflectedObjType, class StateRepType>
118 void DtVrfStatePropertyPrinter::processObjectAdded(ReflectedObjType* object)
119 {
120  if (object)
121  {
122  object->addPostUpdateCallback(objectUpdatedCallback<ReflectedObjType, StateRepType>, this);
123  myLastUpdateTimes[object->globalId()] = 0;
124  processObjectUpdated<ReflectedObjType, StateRepType>(object);
125  }
126 }
127 
128 template<class ReflectedObjType, class StateRepType>
129 void DtVrfStatePropertyPrinter::objectUpdatedCallback(ReflectedObjType* object, void* usr)
130 {
131  static_cast<DtVrfStatePropertyPrinter*>(usr)->
132  processObjectUpdated<ReflectedObjType, StateRepType>(object);
133 }
134 
135 template<class ReflectedObjType, class StateRepType>
137 {
138  if (object)
139  {
140  bool headerPrinted = false;
141 
142  DtTime lastUpdateTime = myLastUpdateTimes[object->globalId()];
143 
144  StateRepType* sr = dynamic_cast<StateRepType*>(object->stateRep());
145  if (sr)
146  {
147  // Iterate over all attributes, printing only those attributes which have been
148  // updated since last we checked
149  std::vector<DtReaderWriterRegistryData *>::const_iterator propIter =
150  sr->stateProperties().registry().registryData().begin();
151  std::vector<DtReaderWriterRegistryData *>::const_iterator propEnd =
152  sr->stateProperties().registry().registryData().end();
153  for (; propIter != propEnd; ++propIter)
154  {
155  DtReaderWriter* propRw = (*propIter)->readerWriter();
156  if (propRw->wasUpdatedSince(lastUpdateTime))
157  {
158  DtPropertyInterface* prop = propRw->property();
159 
160  if (prop)
161  {
162  if (!headerPrinted)
163  {
164  DtInfo << "****************************************" << std::endl;
165  DtInfo << "****** Updated State Properties *******" << std::endl;
166  DtInfo << "****************************************" << std::endl;
167  printStateRepBasicInfo<StateRepType>(sr);
168 
169  headerPrinted = true;
170  }
171 
172  DtInfo << prop->stringRep() << std::endl;
173  }
174  }
175  }
176  }
177 
178  myLastUpdateTimes[object->globalId()] = myClock.absRealTime();
179  }
180 }
181 
182 template<class ReflectedObjType, class StateRepType>
183 void DtVrfStatePropertyPrinter::objectRemovedCallback(ReflectedObjType* object, void* usr)
184 {
185  static_cast<DtVrfStatePropertyPrinter*>(usr)->
186  processObjectRemoved<ReflectedObjType, StateRepType>(object);
187 }
188 
189 template<class ReflectedObjType, class StateRepType>
191 {
192  if (object)
193  {
194  object->removePostUpdateCallback(objectUpdatedCallback<ReflectedObjType, StateRepType>, this);
195  }
196 }

Document ID: Generated on Wed Jul 25 16:57:45 EDT 2018 from SVN revision 190790
Copyright © 2005-2018 VT MÄK. All Rights Reserved (www.mak.com)