CARMA C++
PagerMonitor.h
Go to the documentation of this file.
1 // $Id: PagerMonitor.h,v 1.1 2010/12/13 21:06:31 eml Exp $
2 
3 #ifndef SZA_UTIL_PAGERMONITOR_H
4 #define SZA_UTIL_PAGERMONITOR_H
5 
17 #include "carma/szautil/MonitorPoint.h"
18 #include "carma/szautil/MonitorPointManager.h"
20 
21 #include <string>
22 #include <vector>
23 
24 namespace sza {
25  namespace util {
26 
39  class PagerMonitor {
40  public:
41 
45  struct RegSpec {
46 
47  RegSpec(std::string name,
48  double min=0, double max=0, bool isDelta=false,
49  unsigned nFrame=PagerMonitor::defaultNframe_,
50  bool isOutOfRange=false);
51 
52  RegSpec(ArrayDataFrameManager* fm,
53  RegDescription& desc, MonitorPoint* mp, bool outOfRange);
54 
55  RegSpec(RegSpec& regSpec);
56 
57  RegSpec(const RegSpec& regSpec);
58 
59  // A pointer to the block descriptor for this register
60 
61  RegMapBlock* block_;
62 
63  // The range of this register
64 
65  CoordRange range_;
66 
67  // A pointer to the start of the data for this register in the
68  // source data frame
69 
70  void* sourcePtr_;
71 
72  // A monitor point associated with this register
73 
74  MonitorPoint* mp_;
75 
76  // Other members needed for external pusposes
77 
78  std::string name_;
79  bool isDelta_;
80  bool isOutOfRange_;
81  unsigned nFrame_;
82  double min_;
83  double max_;
84 
85  // A method for copying this register into the destination
86  // frame
87 
88  void copyRegister();
89  };
90 
94  PagerMonitor();
95  PagerMonitor(ArrayDataFrameManager* source);
96 
100  virtual ~PagerMonitor();
101 
102  void setHandler(MONITOR_CONDITION_HANDLER(*handler), void* arg=0);
103 
108  // Add a monitor point to activate the pager when a register
109  // goes out of the specified range
110 
111  std::vector<PagerMonitor::RegSpec>
112  addOutOfRangeMonitorPoint(std::string regSpec,
113  double min, double max,
114  bool delta=false,
115  unsigned nFrame=defaultNframe_,
116  std::string comment="");
117 
118  // Add a monitor point to activate the pager when a register
119  // goes into the specified range
120 
121  std::vector<PagerMonitor::RegSpec>
122  addInRangeMonitorPoint(std::string regSpec,
123  double min, double max,
124  bool delta=false,
125  unsigned nFrame=defaultNframe_,
126  std::string comment="");
127 
128  // And add monitor points associated with a register
129  // specification
130 
131  std::vector<PagerMonitor::RegSpec>
132  addMonitorPoint(std::string regSpec,
133  DataTypeTruthFn fn,
134  DataType& min,
135  DataType& max,
136  bool delta,
137  unsigned nFrame,
138  bool outOfRange,
139  std::string comment);
140 
141  // Remove a monitor point
142 
143  void remMonitorPoint(std::string regSpec);
144 
145  // A method to call to check registers
146 
147  void checkRegisters();
148 
149  // Reset all monitor points
150 
151  void reset();
152 
153  // Clear this manager of all monitor points
154 
155  void clear();
156 
157  // List all monitor points
158 
159  void list();
160 
161  // Return a list of all monitor points
162 
163  std::vector<PagerMonitor::RegSpec> getRegs();
164 
165  // Return a list of all monitor points
166 
167  std::vector<std::string> getList(bool sort=false);
168 
169  // Return a formatted printout of a single monitor point
170 
171  std::vector<std::string> format(std::string regSpec);
172 
173  // Output operator
174 
175  friend std::ostream& operator<<(std::ostream& os, PagerMonitor& pm);
176 
177  // Lock/unlock this object
178 
179  inline void lock() {
180  guard_.lock();
181  }
182 
183  inline void unlock() {
184  guard_.unlock();
185  }
186 
187  private:
188 
189  // A pointer to the data frame that is the source of the latest
190  // data
191 
192  ArrayDataFrameManager* source_;
193 
194  // A destination frame, into which pager registers will be
195  // copied. This will be copy constructed from the input data
196  // frame manager.
197 
198  ArrayDataFrameManager dest_;
199 
200  // The monitor point manager
201 
202  MonitorPointManager mpManager_;
203 
204  // The default number of frames for which the condition must be
205  // met before activating the pager
206 
207  static unsigned defaultNframe_;
208 
209  // A handler to be called when a monitor condition is met
210 
211  MONITOR_CONDITION_HANDLER(*handler_);
212 
213  void* arg_;
214 
215  // A vector of monitor points
216 
217  std::vector<PagerMonitor::RegSpec> registers_;
218 
219  // A mutex variable for protecting this object
220 
221  Mutex guard_;
222 
223  }; // End class PagerMonitor
224 
225  } // End namespace util
226 } // End namespace sza
227 
228 
229 
230 #endif // End #ifndef SZA_UTIL_PAGERMONITOR_H
A class for managing operations on DataType objects which return booleans.
PagerMonitor()
Constructor.
Tagged: Sun Oct 24 17:05:09 PDT 2004.
Tagged: Sat Mar 20 05:20:30 UTC 2004.
A struct for handling information about a single register.
Definition: PagerMonitor.h:45
Tagged: Mon Sep 27 21:37:46 UTC 2004.
std::vector< PagerMonitor::RegSpec > addOutOfRangeMonitorPoint(std::string regSpec, double min, double max, bool delta=false, unsigned nFrame=defaultNframe_, std::string comment="")
Methods to add a register to be monitored.
virtual ~PagerMonitor()
Destructor.
A class for monitoring registers to activate the pager.
Definition: PagerMonitor.h:39
Enumerate data types.
Definition: DataType.h:28