From 6fa181c781e59961e61f9cf5755ed220c2428c16 Mon Sep 17 00:00:00 2001 From: Matt Spinler Date: Wed, 27 Sep 2017 16:24:45 -0500 Subject: monitor: Move timer ops into TachSensor Upcoming commits will touch the TachSensor timer outside of the Fan class, and it will be cleaner to encapsulate the operations in TachSensor. Change-Id: I8584c44eb5dbe6bb93191a006d20dfc37596eeb3 Signed-off-by: Matt Spinler --- monitor/fan.cpp | 8 +++----- monitor/tach_sensor.hpp | 27 ++++++++++++++++++++++++--- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/monitor/fan.cpp b/monitor/fan.cpp index 054c67d..a2e0386 100644 --- a/monitor/fan.cpp +++ b/monitor/fan.cpp @@ -27,7 +27,6 @@ namespace monitor { using namespace phosphor::logging; -using TimerType = phosphor::fan::util::Timer::TimerType; constexpr auto INVENTORY_PATH = "/xyz/openbmc_project/inventory"; constexpr auto INVENTORY_INTF = "xyz.openbmc_project.Inventory.Manager"; @@ -90,8 +89,7 @@ void Fan::tachChanged() void Fan::tachChanged(TachSensor& sensor) { - auto& timer = sensor.getTimer(); - auto running = timer.running(); + auto running = sensor.timerRunning(); //If this sensor is out of range at this moment, start //its timer, at the end of which the inventory @@ -103,7 +101,7 @@ void Fan::tachChanged(TachSensor& sensor) { if (sensor.functional() && !running) { - timer.start(sensor.getTimeout(), TimerType::oneshot); + sensor.startTimer(); } } else @@ -115,7 +113,7 @@ void Fan::tachChanged(TachSensor& sensor) if (running) { - timer.stop(); + sensor.stopTimer(); } //If the fan was nonfunctional and enough sensors are now OK, diff --git a/monitor/tach_sensor.hpp b/monitor/tach_sensor.hpp index 4691d1e..60a55e3 100644 --- a/monitor/tach_sensor.hpp +++ b/monitor/tach_sensor.hpp @@ -101,11 +101,32 @@ class TachSensor } /** - * Returns the timer object for this sensor + * @brief Says if the timer is running or not + * + * @return bool - if timer is currently running + */ + inline bool timerRunning() + { + return _timer.running(); + } + + /** + * @brief Starts the timer for the amount of time + * specified in the constructor + */ + inline void startTimer() + { + _timer.start( + getTimeout(), + phosphor::fan::util::Timer::TimerType::oneshot); + } + + /** + * @brief Stops the timer */ - inline phosphor::fan::util::Timer& getTimer() + inline void stopTimer() { - return _timer; + _timer.stop(); } /** -- cgit v1.2.1