forked from openbmc/witherspoon-pfault-analysis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
device_monitor.hpp
82 lines (72 loc) · 1.83 KB
/
device_monitor.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#pragma once
#include "device.hpp"
#include <phosphor-logging/log.hpp>
#include <sdbusplus/bus.hpp>
#include <sdbusplus/server.hpp>
#include <sdeventplus/clock.hpp>
#include <sdeventplus/event.hpp>
#include <sdeventplus/utility/timer.hpp>
namespace witherspoon
{
namespace power
{
using namespace phosphor::logging;
/**
* @class DeviceMonitor
*
* Monitors a power device for faults by calling Device::analyze()
* on an interval. Do the monitoring by calling run().
* May be overridden to provide more functionality.
*/
class DeviceMonitor
{
public:
DeviceMonitor() = delete;
~DeviceMonitor() = default;
DeviceMonitor(const DeviceMonitor&) = delete;
DeviceMonitor& operator=(const DeviceMonitor&) = delete;
DeviceMonitor(DeviceMonitor&&) = delete;
DeviceMonitor& operator=(DeviceMonitor&&) = delete;
/**
* Constructor
*
* @param[in] d - device to monitor
* @param[in] e - event object
* @param[in] i - polling interval in ms
*/
DeviceMonitor(std::unique_ptr<Device>&& d, const sdeventplus::Event& e,
std::chrono::milliseconds i) :
device(std::move(d)),
timer(e, std::bind(&DeviceMonitor::analyze, this), i)
{
}
/**
* Starts the timer to monitor the device on an interval.
*/
virtual int run()
{
return timer.get_event().loop();
}
protected:
/**
* Analyzes the device for faults
*
* Runs in the timer callback
*
* Override if desired
*/
virtual void analyze()
{
device->analyze();
}
/**
* The device to run the analysis on
*/
std::unique_ptr<Device> device;
/**
* The timer that runs fault check polls.
*/
sdeventplus::utility::Timer<sdeventplus::ClockId::Monotonic> timer;
};
} // namespace power
} // namespace witherspoon