VR-Forces 5.0.3 Developer's Guide
 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 #if !DtLEGION
12 class DtExerciseConn;
13 class DtClock;
17 class DtSmsLoader;
19 
20 #if DtHLA
21 namespace makVrfVrlinkExtToolkit
22 {
23  class DtReflectedExtendedAttributesObjectList;
24  class DtReflectedExtendedAttributesObject;
25 }
26 #endif
27 
28 #include <vl/globalObjectDesignator.h>
31 #include <vlutil/vlPrint.h>
32 #include <vlutil/vlPrintUtil.h>
33 
36 {
37 private:
39 
44 
45 public:
46 
49 
50  virtual bool init(DtSmsLoader* smsLoader);
51 
52 protected:
53 
55 
56  template<class ReflectedObjType, class StateRepType>
57  static void objectAddedCallback(ReflectedObjType* object, void* usr);
58 
59  template<class ReflectedObjType, class StateRepType>
60  void processObjectAdded(ReflectedObjType* object);
62 
64 
65  template<class ReflectedObjType, class StateRepType>
66  static void objectUpdatedCallback(ReflectedObjType* object, void* usr);
67 
68  template<class ReflectedObjType, class StateRepType>
69  void processObjectUpdated(ReflectedObjType* object);
71 
73 
74  template<class ReflectedObjType, class StateRepType>
75  static void objectRemovedCallback(ReflectedObjType* object, void* usr);
76 
77  template<class ReflectedObjType, class StateRepType>
78  void processObjectRemoved(ReflectedObjType* object);
80 
81  DtExerciseConn* exerciseConn();
82 
83 protected:
84 
89 #if DtHLA
91 #endif
92 
94  std::map<DtGlobalObjectDesignator, DtTime> myLastUpdateTimes;
95 };
96 
98 
99 template<class StateRepType>
100 void printStateRepBasicInfo(StateRepType* stateRep)
101 {
102  DtPrintAttribute(DtInfo, "EntityId", stateRep->entityId().string());
103  DtPrintAttribute(DtInfo, "EntityType", stateRep->entityType().string());
104 }
105 
106 template<>
108 {
109  DtPrintAttribute(DtInfo, "EnvironmentProcessId", stateRep->environmentalProcessID().string());
110  DtPrintAttribute(DtInfo, "EnvironmentType", stateRep->environmentType().string());
111 }
113 
114 template<class ReflectedObjType, class StateRepType>
115 void DtVrfStatePropertyPrinter::objectAddedCallback(ReflectedObjType* object, void* usr)
116 {
117  static_cast<DtVrfStatePropertyPrinter*>(usr)->
118  processObjectAdded<ReflectedObjType, StateRepType>(object);
119 }
120 
121 template<class ReflectedObjType, class StateRepType>
122 void DtVrfStatePropertyPrinter::processObjectAdded(ReflectedObjType* object)
123 {
124  if (object)
125  {
126  object->addPostUpdateCallback(objectUpdatedCallback<ReflectedObjType, StateRepType>, this);
127  myLastUpdateTimes[object->globalId()] = 0;
128  processObjectUpdated<ReflectedObjType, StateRepType>(object);
129  }
130 }
131 
132 template<class ReflectedObjType, class StateRepType>
133 void DtVrfStatePropertyPrinter::objectUpdatedCallback(ReflectedObjType* object, void* usr)
134 {
135  static_cast<DtVrfStatePropertyPrinter*>(usr)->
136  processObjectUpdated<ReflectedObjType, StateRepType>(object);
137 }
138 
139 template<class ReflectedObjType, class StateRepType>
141 {
142  if (object)
143  {
144  bool headerPrinted = false;
145 
146  DtTime lastUpdateTime = myLastUpdateTimes[object->globalId()];
147 
148  StateRepType* sr = dynamic_cast<StateRepType*>(object->stateRep());
149  if (sr)
150  {
151  // Iterate over all attributes, printing only those attributes which have been
152  // updated since last we checked
153  std::vector<DtReaderWriterRegistryData *>::const_iterator propIter =
154  sr->stateProperties().registry().registryData().begin();
155  std::vector<DtReaderWriterRegistryData *>::const_iterator propEnd =
156  sr->stateProperties().registry().registryData().end();
157  for (; propIter != propEnd; ++propIter)
158  {
159  DtReaderWriter* propRw = (*propIter)->readerWriter();
160  if (propRw->wasUpdatedSince(lastUpdateTime))
161  {
162  DtPropertyInterface* prop = propRw->property();
163 
164  if (prop)
165  {
166  if (!headerPrinted)
167  {
168  DtInfo << "****************************************" << std::endl;
169  DtInfo << "****** Updated State Properties *******" << std::endl;
170  DtInfo << "****************************************" << std::endl;
171  printStateRepBasicInfo<StateRepType>(sr);
172 
173  headerPrinted = true;
174  }
175 
176  DtInfo << prop->stringRep() << std::endl;
177  }
178  }
179  }
180  }
181 
182  myLastUpdateTimes[object->globalId()] = myClock.absRealTime();
183  }
184 }
185 
186 template<class ReflectedObjType, class StateRepType>
187 void DtVrfStatePropertyPrinter::objectRemovedCallback(ReflectedObjType* object, void* usr)
188 {
189  static_cast<DtVrfStatePropertyPrinter*>(usr)->
190  processObjectRemoved<ReflectedObjType, StateRepType>(object);
191 }
192 
193 template<class ReflectedObjType, class StateRepType>
195 {
196  if (object)
197  {
198  object->removePostUpdateCallback(objectUpdatedCallback<ReflectedObjType, StateRepType>, this);
199  }
200 }
201 #endif
DtVrfStatePropertyPrinter & operator=(const DtVrfStatePropertyPrinter &orig)
Not implemented.
virtual DtString stringRep(const DtString &root="") const =0
DtReflectedVrfControlObjectList * myReflectedControlObjectList
Definition: vrfStatePropertyPrinter.h:88
DtReflectedVrfExtEntityList * myReflectedEntityList
Definition: vrfStatePropertyPrinter.h:86
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:90
void processObjectRemoved(ReflectedObjType *object)
Callback for the removal of objects.
Definition: vrfStatePropertyPrinter.h:194
Definition: reflectedVrfExtEntityList.h:23
Definition: readerWriter.h:85
void printStateRepBasicInfo(StateRepType *stateRep)
Prints some basic identifying information about the state rep.
Definition: vrfStatePropertyPrinter.h:100
void printStateRepBasicInfo< DtControlObjectRepository >(DtControlObjectRepository *stateRep)
Prints some basic identifying information about the state rep.
Definition: vrfStatePropertyPrinter.h:107
Interface class used to define minimal interface for a property. The DtPropertyInterface class provid...
Definition: propertyInterface.h:48
Contains the DtExtEntityStateRepository class.
Registers for all state property updates and prints the current state.
Definition: vrfStatePropertyPrinter.h:35
DtExerciseConn * exerciseConn()
DtControlObjectRepository class extends the DtControlObjectBaseRepository to be able to handle extend...
Definition: controlObjectRepository.h:27
virtual bool init(DtSmsLoader *smsLoader)
The DtCommunicationManager class is a convenience class that will create both the DtNetworkInterfaceM...
Definition: communicationManager.h:51
DtClock myClock
Definition: vrfStatePropertyPrinter.h:93
void processObjectUpdated(ReflectedObjType *object)
Callback for the update of objects.
Definition: vrfStatePropertyPrinter.h:140
void processObjectAdded(ReflectedObjType *object)
Callback for the addition of new objects.
Definition: vrfStatePropertyPrinter.h:122
virtual DtPropertyInterface * property()
Returns a PropertyInterface pointer of the ReaderWriter. Returns 0 by default, must by overridden by ...
DtCommunicationManager * myEventManager
Definition: vrfStatePropertyPrinter.h:85
Definition: smsLoader.h:19
Definition: reflectedVrfExtControlObjectList.h:23
DtReflectedVrfExtAggregateList * myReflectedAggregateList
Definition: vrfStatePropertyPrinter.h:87
static void objectUpdatedCallback(ReflectedObjType *object, void *usr)
Callback for the update of objects.
Definition: vrfStatePropertyPrinter.h:133
virtual ~DtVrfStatePropertyPrinter()
static void objectAddedCallback(ReflectedObjType *object, void *usr)
Callback for the addition of new objects.
Definition: vrfStatePropertyPrinter.h:115
static void objectRemovedCallback(ReflectedObjType *object, void *usr)
Callback for the removal of objects.
Definition: vrfStatePropertyPrinter.h:187
std::map< DtGlobalObjectDesignator, DtTime > myLastUpdateTimes
Definition: vrfStatePropertyPrinter.h:94
Definition: reflectedVrfExtAggregateList.h:23

Document ID: Generated on Thu Jun 1 17:58:13 EDT 2023 from SVN revision 255404
Copyright © 2005-2021 MAK Technologies. All Rights Reserved (www.mak.com)