blob: 4691d1e343eaed47549d2d1434539be8d1f39685 [file] [log] [blame]
Matt Spinlerabf8da32017-04-27 14:08:45 -05001#pragma once
2
3#include <chrono>
4#include <sdbusplus/bus.hpp>
5#include <sdbusplus/server.hpp>
Matt Spinlere824f982017-05-11 10:07:55 -05006#include "event.hpp"
Matt Spinlera9406a72017-04-27 14:29:24 -05007#include "timer.hpp"
Matt Spinlerabf8da32017-04-27 14:08:45 -05008
9namespace phosphor
10{
11namespace fan
12{
13namespace monitor
14{
15
16class Fan;
17
18
19/**
20 * @class TachSensor
21 *
22 * This class represents the sensor that reads a tach value.
23 * It may also support a Target, which is the property used to
24 * set a speed. Since it doesn't necessarily have a Target, it
25 * won't for sure know if it is running too slow, so it leaves
26 * that determination to other code.
27 *
28 * This class has a parent Fan object that knows about all
29 * sensors for that fan.
30 */
31class TachSensor
32{
33 public:
34
35 TachSensor() = delete;
36 TachSensor(const TachSensor&) = delete;
Brad Bishopfa0766e2017-07-30 15:42:10 -040037 // TachSensor is not moveable since the this pointer is used as systemd
38 // callback context.
39 TachSensor(TachSensor&&) = delete;
Matt Spinlerabf8da32017-04-27 14:08:45 -050040 TachSensor& operator=(const TachSensor&) = delete;
Brad Bishopfa0766e2017-07-30 15:42:10 -040041 TachSensor& operator=(TachSensor&&) = delete;
Matt Spinlerabf8da32017-04-27 14:08:45 -050042 ~TachSensor() = default;
43
44 /**
45 * @brief Constructor
46 *
47 * @param[in] bus - the dbus object
48 * @param[in] fan - the parent fan object
49 * @param[in] id - the id of the sensor
50 * @param[in] hasTarget - if the sensor supports
51 * setting the speed
52 * @param[in] timeout - Normal timeout value to use
Matt Spinlera9406a72017-04-27 14:29:24 -050053 * @param[in] events - sd_event pointer
Matt Spinlerabf8da32017-04-27 14:08:45 -050054 */
55 TachSensor(sdbusplus::bus::bus& bus,
56 Fan& fan,
57 const std::string& id,
58 bool hasTarget,
Matt Spinlera9406a72017-04-27 14:29:24 -050059 size_t timeout,
Matt Spinlere824f982017-05-11 10:07:55 -050060 phosphor::fan::event::EventPtr& events);
Matt Spinlerabf8da32017-04-27 14:08:45 -050061
62 /**
63 * @brief Returns the target speed value
64 */
65 inline uint64_t getTarget() const
66 {
67 return _tachTarget;
68 }
69
70 /**
71 * @brief Returns the input speed value
72 */
73 inline int64_t getInput() const
74 {
75 return _tachInput;
76 }
77
78 /**
79 * @brief Returns true if sensor has a target
80 */
81 inline bool hasTarget() const
82 {
83 return _hasTarget;
84 }
85
86 /**
87 * Returns true if the hardware behind this
88 * sensor is considered working OK/functional.
89 */
90 inline bool functional() const
91 {
92 return _functional;
93 }
94
95 /**
96 * Sets functional status
97 */
98 inline void setFunctional(bool functional)
99 {
100 _functional = functional;
101 }
102
Matt Spinlera9406a72017-04-27 14:29:24 -0500103 /**
104 * Returns the timer object for this sensor
105 */
106 inline phosphor::fan::util::Timer& getTimer()
107 {
108 return _timer;
109 }
110
111 /**
112 * @brief Returns the timeout value to use for the sensor
113 */
114 std::chrono::microseconds getTimeout();
115
Matt Spinlerce75b512017-07-26 15:10:48 -0500116 /**
117 * Returns the sensor name
118 */
119 inline const std::string& name() const
120 {
121 return _name;
122 };
123
Matt Spinlerabf8da32017-04-27 14:08:45 -0500124 private:
125
126 /**
Matt Spinlerebaae612017-04-27 14:21:48 -0500127 * @brief Returns the match string to use for matching
128 * on a properties changed signal.
129 */
130 std::string getMatchString(const std::string& interface);
131
132 /**
Matt Spinlerebaae612017-04-27 14:21:48 -0500133 * @brief Reads the Target property and stores in _tachTarget.
134 * Also calls Fan::tachChanged().
135 *
136 * @param[in] msg - the dbus message
Matt Spinlerebaae612017-04-27 14:21:48 -0500137 */
Brad Bishop771659f2017-07-30 19:52:21 -0400138 void handleTargetChange(sdbusplus::message::message& msg);
Matt Spinlerebaae612017-04-27 14:21:48 -0500139
140 /**
141 * @brief Reads the Value property and stores in _tachInput.
142 * Also calls Fan::tachChanged().
143 *
144 * @param[in] msg - the dbus message
Matt Spinlerebaae612017-04-27 14:21:48 -0500145 */
Brad Bishop771659f2017-07-30 19:52:21 -0400146 void handleTachChange(sdbusplus::message::message& msg);
Matt Spinlerebaae612017-04-27 14:21:48 -0500147
148
149 /**
Matt Spinlerabf8da32017-04-27 14:08:45 -0500150 * @brief the dbus object
151 */
152 sdbusplus::bus::bus& _bus;
153
154 /**
155 * @brief Reference to the parent Fan object
156 */
157 Fan& _fan;
158
159 /**
160 * @brief The name of the sensor, including the full path
161 *
162 * For example /xyz/openbmc_project/sensors/fan_tach/fan0
163 */
164 const std::string _name;
165
166 /**
167 * @brief If functional (not too slow). The parent
168 * fan object sets this.
169 */
170 bool _functional = true;
171
172 /**
173 * @brief If the sensor has a Target property (can set speed)
174 */
175 const bool _hasTarget;
176
177 /**
178 * @brief The input speed, from the Value dbus property
179 */
180 int64_t _tachInput = 0;
181
182 /**
183 * @brief The current target speed, from the Target dbus property
184 * (if applicable)
185 */
186 uint64_t _tachTarget = 0;
187
188 /**
189 * @brief The timeout value to use
190 */
191 const size_t _timeout;
Matt Spinlerebaae612017-04-27 14:21:48 -0500192
193 /**
Matt Spinlera9406a72017-04-27 14:29:24 -0500194 * The timer object
195 */
196 phosphor::fan::util::Timer _timer;
197
198 /**
Matt Spinlerebaae612017-04-27 14:21:48 -0500199 * @brief The match object for the Value properties changed signal
200 */
201 std::unique_ptr<sdbusplus::server::match::match> tachSignal;
202
203 /**
204 * @brief The match object for the Target properties changed signal
205 */
206 std::unique_ptr<sdbusplus::server::match::match> targetSignal;
Matt Spinlerabf8da32017-04-27 14:08:45 -0500207};
208
209}
210}
211}