Matt Spinler | abf8da3 | 2017-04-27 14:08:45 -0500 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include <chrono> |
| 4 | #include <sdbusplus/bus.hpp> |
| 5 | #include <sdbusplus/server.hpp> |
Matt Spinler | e824f98 | 2017-05-11 10:07:55 -0500 | [diff] [blame] | 6 | #include "event.hpp" |
Matt Spinler | a9406a7 | 2017-04-27 14:29:24 -0500 | [diff] [blame] | 7 | #include "timer.hpp" |
Matt Spinler | abf8da3 | 2017-04-27 14:08:45 -0500 | [diff] [blame] | 8 | |
| 9 | namespace phosphor |
| 10 | { |
| 11 | namespace fan |
| 12 | { |
| 13 | namespace monitor |
| 14 | { |
| 15 | |
| 16 | class 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 | */ |
| 31 | class TachSensor |
| 32 | { |
| 33 | public: |
| 34 | |
| 35 | TachSensor() = delete; |
| 36 | TachSensor(const TachSensor&) = delete; |
Brad Bishop | fa0766e | 2017-07-30 15:42:10 -0400 | [diff] [blame] | 37 | // TachSensor is not moveable since the this pointer is used as systemd |
| 38 | // callback context. |
| 39 | TachSensor(TachSensor&&) = delete; |
Matt Spinler | abf8da3 | 2017-04-27 14:08:45 -0500 | [diff] [blame] | 40 | TachSensor& operator=(const TachSensor&) = delete; |
Brad Bishop | fa0766e | 2017-07-30 15:42:10 -0400 | [diff] [blame] | 41 | TachSensor& operator=(TachSensor&&) = delete; |
Matt Spinler | abf8da3 | 2017-04-27 14:08:45 -0500 | [diff] [blame] | 42 | ~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 Spinler | a9406a7 | 2017-04-27 14:29:24 -0500 | [diff] [blame] | 53 | * @param[in] events - sd_event pointer |
Matt Spinler | abf8da3 | 2017-04-27 14:08:45 -0500 | [diff] [blame] | 54 | */ |
| 55 | TachSensor(sdbusplus::bus::bus& bus, |
| 56 | Fan& fan, |
| 57 | const std::string& id, |
| 58 | bool hasTarget, |
Matt Spinler | a9406a7 | 2017-04-27 14:29:24 -0500 | [diff] [blame] | 59 | size_t timeout, |
Matt Spinler | e824f98 | 2017-05-11 10:07:55 -0500 | [diff] [blame] | 60 | phosphor::fan::event::EventPtr& events); |
Matt Spinler | abf8da3 | 2017-04-27 14:08:45 -0500 | [diff] [blame] | 61 | |
| 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 Spinler | a9406a7 | 2017-04-27 14:29:24 -0500 | [diff] [blame] | 103 | /** |
| 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 Spinler | ce75b51 | 2017-07-26 15:10:48 -0500 | [diff] [blame] | 116 | /** |
| 117 | * Returns the sensor name |
| 118 | */ |
| 119 | inline const std::string& name() const |
| 120 | { |
| 121 | return _name; |
| 122 | }; |
| 123 | |
Matt Spinler | abf8da3 | 2017-04-27 14:08:45 -0500 | [diff] [blame] | 124 | private: |
| 125 | |
| 126 | /** |
Matt Spinler | ebaae61 | 2017-04-27 14:21:48 -0500 | [diff] [blame] | 127 | * @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 Spinler | ebaae61 | 2017-04-27 14:21:48 -0500 | [diff] [blame] | 133 | * @brief Reads the Target property and stores in _tachTarget. |
| 134 | * Also calls Fan::tachChanged(). |
| 135 | * |
| 136 | * @param[in] msg - the dbus message |
Matt Spinler | ebaae61 | 2017-04-27 14:21:48 -0500 | [diff] [blame] | 137 | */ |
Brad Bishop | 771659f | 2017-07-30 19:52:21 -0400 | [diff] [blame] | 138 | void handleTargetChange(sdbusplus::message::message& msg); |
Matt Spinler | ebaae61 | 2017-04-27 14:21:48 -0500 | [diff] [blame] | 139 | |
| 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 Spinler | ebaae61 | 2017-04-27 14:21:48 -0500 | [diff] [blame] | 145 | */ |
Brad Bishop | 771659f | 2017-07-30 19:52:21 -0400 | [diff] [blame] | 146 | void handleTachChange(sdbusplus::message::message& msg); |
Matt Spinler | ebaae61 | 2017-04-27 14:21:48 -0500 | [diff] [blame] | 147 | |
| 148 | |
| 149 | /** |
Matt Spinler | abf8da3 | 2017-04-27 14:08:45 -0500 | [diff] [blame] | 150 | * @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 Spinler | ebaae61 | 2017-04-27 14:21:48 -0500 | [diff] [blame] | 192 | |
| 193 | /** |
Matt Spinler | a9406a7 | 2017-04-27 14:29:24 -0500 | [diff] [blame] | 194 | * The timer object |
| 195 | */ |
| 196 | phosphor::fan::util::Timer _timer; |
| 197 | |
| 198 | /** |
Matt Spinler | ebaae61 | 2017-04-27 14:21:48 -0500 | [diff] [blame] | 199 | * @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 Spinler | abf8da3 | 2017-04-27 14:08:45 -0500 | [diff] [blame] | 207 | }; |
| 208 | |
| 209 | } |
| 210 | } |
| 211 | } |