CARMA C++
PDB_Monitor.h
1 /*
2  * CARMA Project Database Monitor System
3  *
4  * This class contains the shortest lived locking possible, so that it can be
5  * updated without causing any stalls anywhere else in the application.
6  *
7  * The scoped version automatically resets the method to "NONE" when it goes
8  * out of scope. This makes the code easier to understand. RAII is great.
9  */
10 
11 #ifndef PDB_MONITOR_H
12 #define PDB_MONITOR_H
13 
14 #include <carma/util/PthreadMutex.h>
15 
16 #include <boost/shared_ptr.hpp>
17 
18 #include <string>
19 #include <vector>
20 
21 // forward declaration
22 namespace carma {
23 namespace monitor {
24 class ProjectDatabaseManagerSubsystem;
25 } // namespace carma::monitor
26 } // namespace carma
27 
28 namespace carma {
29 namespace observertools {
30 
31 // forward declaration
32 class PDB_DB_Params;
33 
34 class PDB_Monitor {
35 public:
36  PDB_Monitor();
37 
38  void updateDBInfo(const PDB_DB_Params &db);
39  void setCurrentMethod(const std::string &method);
40  void writeToMonitorSystem(carma::monitor::ProjectDatabaseManagerSubsystem &mon) const;
41 
42 private:
43  struct PDB_Server_Info {
44  double timestamp;
45  std::string name;
46  int health;
47  std::string state;
48  int uptime;
49  int ping;
50  };
51 
52  std::vector<PDB_Server_Info> serverInfo_;
53 
54  std::string currentMethod_;
55  double currentMethodStart_;
56 
57  mutable carma::util::PthreadMutex mutex_;
58 };
59 
60 typedef boost::shared_ptr<PDB_Monitor> PDB_Monitor_Ptr;
61 
62 class PDB_Scoped_Monitor {
63 public:
64  PDB_Scoped_Monitor(const PDB_Monitor_Ptr mon, const std::string &method);
65  ~PDB_Scoped_Monitor();
66 private:
67  const PDB_Monitor_Ptr mon_;
68 };
69 
70 } // namespace carma::observertools
71 } // namespace carma
72 
73 #endif /* PDB_MONITOR_H */
74 
75 /* vim: set ts=8 sts=8 sw=8 noet tw=92: */
A simple wrapper class that makes use of ::pthread_mutex_t easier in a C++ world. ...
Definition: PthreadMutex.h:41