From a9406a774a35c02fabc94ab842788dd9891f59e8 Mon Sep 17 00:00:00 2001 From: Matt Spinler Date: Thu, 27 Apr 2017 14:29:24 -0500 Subject: Add Timer support to TachSensor Add a Timer object to the TachSensor class Change-Id: I419b5712de9e8e94f2a08de84d13170e44c33c7a Signed-off-by: Matt Spinler --- monitor/fan.cpp | 15 ++++++++++++--- monitor/fan.hpp | 14 +++++++++++++- monitor/tach_sensor.cpp | 15 ++++++++++++--- monitor/tach_sensor.hpp | 23 ++++++++++++++++++++++- 4 files changed, 59 insertions(+), 8 deletions(-) diff --git a/monitor/fan.cpp b/monitor/fan.cpp index 852d2ba..7d657a0 100644 --- a/monitor/fan.cpp +++ b/monitor/fan.cpp @@ -44,10 +44,9 @@ Fan::Fan(sdbusplus::bus::bus& bus, *this, std::get(s), std::get(s), - std::get(def))); - + std::get(def), + events)); } - } @@ -123,6 +122,16 @@ bool Fan::outOfRange(const TachSensor& sensor) } +void Fan::timerExpired(TachSensor& sensor) +{ + sensor.setFunctional(false); + + //If the fan is currently functional, but too many + //contained sensors are now nonfunctional, update + //the whole fan nonfunctional. + //TODO +} + } } } diff --git a/monitor/fan.hpp b/monitor/fan.hpp index d79ae31..9aeccd2 100644 --- a/monitor/fan.hpp +++ b/monitor/fan.hpp @@ -70,7 +70,7 @@ class Fan * @brief Callback function for when an input sensor changes * * Starts a timer, where if it expires then the sensor - * was slow for too long and can be considered not functional. + * was out of range for too long and can be considered not functional. */ void tachChanged(TachSensor& sensor); @@ -79,6 +79,18 @@ class Fan */ void tachChanged(); + /** + * @brief The callback function for the timer + * + * Sets the sensor to not functional. + * If enough sensors are now not functional, + * updates the functional status of the whole + * fan in the inventory. + * + * @param[in] sensor - the sensor whose timer expired + */ + void timerExpired(TachSensor& sensor); + private: /** diff --git a/monitor/tach_sensor.cpp b/monitor/tach_sensor.cpp index c991bb6..806eed7 100644 --- a/monitor/tach_sensor.cpp +++ b/monitor/tach_sensor.cpp @@ -84,13 +84,14 @@ TachSensor::TachSensor(sdbusplus::bus::bus& bus, Fan& fan, const std::string& id, bool hasTarget, - size_t timeout) : - + size_t timeout, + std::shared_ptr& events) : _bus(bus), _fan(fan), _name(FAN_SENSOR_PATH + id), _hasTarget(hasTarget), - _timeout(timeout) + _timeout(timeout), + _timer(events, [this, &fan](){ fan.timerExpired(*this); }) { auto service = getService(); @@ -232,6 +233,14 @@ void TachSensor::handleTachChange(sdbusplus::message::message& msg, } +std::chrono::microseconds TachSensor::getTimeout() +{ + using namespace std::chrono; + + return duration_cast(seconds(_timeout)); +} + + } } } diff --git a/monitor/tach_sensor.hpp b/monitor/tach_sensor.hpp index 003763c..7a65b64 100644 --- a/monitor/tach_sensor.hpp +++ b/monitor/tach_sensor.hpp @@ -3,6 +3,7 @@ #include #include #include +#include "timer.hpp" namespace phosphor { @@ -46,12 +47,14 @@ class TachSensor * @param[in] hasTarget - if the sensor supports * setting the speed * @param[in] timeout - Normal timeout value to use + * @param[in] events - sd_event pointer */ TachSensor(sdbusplus::bus::bus& bus, Fan& fan, const std::string& id, bool hasTarget, - size_t timeout); + size_t timeout, + std::shared_ptr& events); /** * @brief Returns the target speed value @@ -94,6 +97,19 @@ class TachSensor _functional = functional; } + /** + * Returns the timer object for this sensor + */ + inline phosphor::fan::util::Timer& getTimer() + { + return _timer; + } + + /** + * @brief Returns the timeout value to use for the sensor + */ + std::chrono::microseconds getTimeout(); + private: /** @@ -196,6 +212,11 @@ class TachSensor */ const size_t _timeout; + /** + * The timer object + */ + phosphor::fan::util::Timer _timer; + /** * @brief The match object for the Value properties changed signal */ -- cgit v1.2.1