CARMA C++
MonitorPoint.h
1 #ifndef SZA_UTIL_MONITORPOINT_H
2 #define SZA_UTIL_MONITORPOINT_H
3 
12 #include "carma/szautil/DataType.h"
14 
17 
18 #include "carma/szaarrayutils/szaregs.h"
19 
20 #include <list>
21 
22 #define MONITOR_CONDITION_HANDLER(fn) void (fn)(void* arg, bool satisfied, std::string message, std::string comment)
23 
24 namespace sza {
25  namespace util {
26 
27  class ArrayMapDataFrameManager;
28  class Coord;
29  class CoordRange;
30  class RegMapDataFrameManager;
31 
32  class MonitorPoint {
33  public:
34 
38  MonitorPoint(ArrayMapDataFrameManager* frame, ArrRegMap* regMap,
39  RegMapBlock* block, CoordRange* range=0);
40  MonitorPoint(ArrayMapDataFrameManager* frame, ArrRegMap* regMap,
41  RegMapBlock* block);
42  MonitorPoint(ArrayMapDataFrameManager* frame, ArrRegMap* regMap,
43  RegMapBlock* block, int index);
44 
45  void setTo(ArrayMapDataFrameManager* frame, ArrRegMap* regMap,
46  RegMapBlock* block, int index);
47  void setTo(ArrayMapDataFrameManager* frame, ArrRegMap* regMap,
48  RegMapBlock* block, CoordRange* range=0);
49 
50  MonitorPoint(RegMapDataFrameManager* frame, RegMapBlock* block, CoordRange* range=0);
51  MonitorPoint(RegMapDataFrameManager* frame, RegMapBlock* block);
52  MonitorPoint(RegMapDataFrameManager* frame, RegMapBlock* block, int index);
53 
54  void setTo(RegMapDataFrameManager* frame, RegMapBlock* block, int index);
55  void setTo(RegMapDataFrameManager* frame, RegMapBlock* block, CoordRange* range=0);
56 
57  void reset();
58 
62  virtual ~MonitorPoint();
63 
67  inline RegMapBlock* block() {
68  return block_;
69  }
70 
74  template <class type>
75  void writeReg(bool isSim, type var, sza::util::CoordRange* range=0)
76  {
77  CoordRange* rng = range==0 ? &coordRange_ : range;
78 
79  if(isArrMap_)
80  arrMapFm_->writeReg(regMap_, block_, var, rng);
81  else
82  regMapFm_->writeReg(block_, var, rng);
83 
84  // Only check handlers if the handler count is non-zero
85 
86  if(handlerCount_ > 0) {
87  dataType_ = var;
88 
89  // Only construct an AxisRange object if a non-default coordinate
90  // range was specified
91 
92  if(range==0)
93  checkHandlers(isSim, axisRange_);
94  else {
95  AxisRange axisRange(block_->axes_, range);
96  checkHandlers(isSim, axisRange);
97  }
98  }
99  }
100 
104  void writeDcReg(bool isSim, float f, sza::util::CoordRange* range=0);
105 
109  template <class type>
110  void readReg(type ptr, sza::util::CoordRange* range=0)
111  {
112  CoordRange* rng = range==0 ? &coordRange_ : range;
113 
114  if(isArrMap_)
115  arrMapFm_->readReg(regMap_, block_, ptr, rng);
116  else
117  regMapFm_->readReg(block_, ptr, rng);
118  }
119 
120  // Register a callback associated with a condition
121 
122  void registerConditionHandler(MONITOR_CONDITION_HANDLER(*handler),
123  void* arg,
124  std::string message,
125  std::string comment,
126  MonitorCondition& condition,
127  bool persistent,
128  CoordRange* coordRange=0);
129 
130  //-----------------------------------------------------------------------
131  // This struct will manage condition-handler associations.
132  //-----------------------------------------------------------------------
133 
134  struct ConditionHandler
135  {
136  MonitorCondition condition_;
137  MONITOR_CONDITION_HANDLER(*handler_);
138  void* arg_;
139  std::string message_;
140  std::string comment_;
141 
142  unsigned packetCount_;
143  unsigned stablePacketCount_;
144  unsigned giveUpPacketCount_;
145  bool isPersistent_;
146 
147  ConditionHandler();
148  ConditionHandler(const ConditionHandler& handler);
149  ConditionHandler(ConditionHandler& handler);
150  void operator=(ConditionHandler& handler);
151  void operator=(const ConditionHandler& handler);
152  bool operator==(const ConditionHandler& handler);
153  void callHandler(bool conditionWasMet);
154  bool checkCondition(bool isSim, DataType& dataType);
155  void reset();
156 
157  std::string format(std::string& reg);
158 
159  };
160 
161 
162  inline CoordRange coordRange() {
163  return coordRange_;
164  }
165 
166  inline AxisRange axisRange() {
167  return axisRange_;
168  }
169 
173  std::string format(std::string& reg);
174 
175  // Query the (first) condition for this monitor point. This is
176  // only meaningful if a single condition is registered for this
177  // monitor point
178 
179  bool isDelta();
180  unsigned nFrame();
181  double min();
182  double max();
183 
184  private:
185 
186  // The register map that represents this monitor point
187 
188  ArrRegMap* regMap_;
189 
190  // The register block that represents this monitor point
191 
192  RegMapBlock* block_;
193 
194  // Where applicable, a coordinate representation of the index
195  // into the register corresponding to this monitor point
196 
197  CoordRange coordRange_;
198 
199  // And an axis range iterator
200 
201  AxisRange axisRange_;
202 
203  // Where applicable, a pointer to the shared memory objects
204 
205  ArrayMapDataFrameManager* arrMapFm_;
206  RegMapDataFrameManager* regMapFm_;
207 
208  // True if this object is managing monitor points for an array
209  // map. False if managing monitor points for a reg map
210 
211  bool isArrMap_;
212 
213  // A utility object which will store the values of this monitor
214  // point
215 
216  DataType dataType_;
217 
218  // A vector of lists of handlers. The first dimension will
219  // index which element of this register, the second will be a
220  // list of handlers attached to this monitor point.
221 
222  public:
223  std::vector<std::list<ConditionHandler> > handlers_;
224 
225  private:
226 
227  // True if handlers are registered for this monitor point
228 
229  int handlerCount_;
230 
231  Mutex guard_;
232 
233  // See if a handler has been registered for this monitor point
234 
235  void checkHandlers(bool isSim, AxisRange& range);
236 
237  // Update the count of handlers for this monitor point
238 
239  void updateHandlerCount(int count);
240 
241  }; // End class MonitorPoint
242 
243  } // End namespace util
244 } // End namespace sza
245 
246 
247 #endif // End #ifndef SZA_UTIL_MONITORPOINT_H
Tagged: Tue Jun 22 22:32:16 UTC 2004.
Tagged: Wed Sep 1 03:59:25 UTC 2004.
Tagged: Sat Aug 14 13:12:19 UTC 2004.
Tagged: Sun Oct 24 17:05:09 PDT 2004.
Tagged: Tue Oct 5 13:18:11 PDT 2004.