VR-Forces 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  DtPropertyInterface* prop = propRw->property();
161  if (prop && prop->hasReceivedUpdateSince(lastUpdateTime))
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  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 }
197 #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
DtVrfStatePropertyPrinter()
Not implemented.
makVrfVrlinkExtToolkit::DtReflectedExtendedAttributesObjectList * myReflectedExtendedAttributesList
Definition: vrfStatePropertyPrinter.h:90
void processObjectRemoved(ReflectedObjType *object)
Callback for the removal of objects.
Definition: vrfStatePropertyPrinter.h:190
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:53
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 ...
virtual bool hasReceivedUpdateSince(DtTime t) const =0
Returns true if an update was received remotely since the specified time.
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:183
std::map< DtGlobalObjectDesignator, DtTime > myLastUpdateTimes
Definition: vrfStatePropertyPrinter.h:94
Definition: reflectedVrfExtAggregateList.h:23

Document ID: Generated on Tue Sep 24 19:28:17 EDT 2024 from SVN revision 269799
Copyright © 2005-2024 MAK Technologies. All Rights Reserved (www.mak.com)