From 8fd879fb7bb9ed34fe69581dc714b4158046519f Mon Sep 17 00:00:00 2001 From: "William A. Kennington III" Date: Tue, 30 Oct 2018 19:49:29 -0700 Subject: Remove timer in favor of sdeventplus/utility/timer This removes the custom timer implementation and moves to the sdeventplus utility. Functionally this should make no change Tested: Built and run through the unit test suite. Change-Id: Ib7ee90d489d5db72496aaaca91c3cf5490ad47d6 Signed-off-by: William A. Kennington III --- control/actions.cpp | 4 ---- control/types.hpp | 14 +++++++++----- control/zone.cpp | 42 ++++++++++++++++++++---------------------- control/zone.hpp | 13 ++++--------- 4 files changed, 33 insertions(+), 40 deletions(-) (limited to 'control') diff --git a/control/actions.cpp b/control/actions.cpp index 0267c10..25b6a09 100644 --- a/control/actions.cpp +++ b/control/actions.cpp @@ -41,10 +41,6 @@ Action call_actions_based_on_timer(TimerConf&& tConf, auto timer = zone.findTimer(group, actions); if (timer != std::end(zone.getTimerEvents())) { - if (std::get(*timer)->running()) - { - std::get(*timer)->stop(); - } zone.removeTimer(timer); } } diff --git a/control/types.hpp b/control/types.hpp index 967b0b4..239d00d 100644 --- a/control/types.hpp +++ b/control/types.hpp @@ -3,7 +3,8 @@ #include #include #include -#include "timer.hpp" +#include +#include namespace phosphor { @@ -64,7 +65,11 @@ using Service = std::tuple; constexpr auto intervalPos = 0; constexpr auto typePos = 1; -using TimerType = phosphor::fan::util::Timer::TimerType; +enum class TimerType +{ + oneshot, + repeating, +}; using TimerConf = std::tuple; @@ -89,9 +94,8 @@ using EventData = std::tuple>; constexpr auto timerEventDataPos = 0; constexpr auto timerTimerPos = 1; -using TimerEvent = - std::tuple, - std::unique_ptr>; +using Timer = sdeventplus::utility::Timer; +using TimerEvent = std::tuple, Timer>; constexpr auto signalEventDataPos = 0; constexpr auto signalMatchPos = 1; diff --git a/control/zone.cpp b/control/zone.cpp index 4531151..293945c 100644 --- a/control/zone.cpp +++ b/control/zone.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include #include "zone.hpp" #include "utility.hpp" @@ -72,10 +73,7 @@ Zone::Zone(Mode mode, initEvent(event); } // Start timer for fan speed decreases - if (!_decTimer.running() && _decInterval != seconds::zero()) - { - _decTimer.start(_decInterval, TimerType::repeating); - } + _decTimer.restart(_decInterval); } } @@ -238,14 +236,9 @@ void Zone::requestSpeedIncrease(uint64_t targetDelta) { requestTarget = _ceilingSpeed; } - // Cancel current timer countdown - if (_incTimer.running()) - { - _incTimer.stop(); - } setSpeed(requestTarget); - // Start timer countdown for fan speed increase - _incTimer.start(_incDelay, TimerType::oneshot); + // Retart timer countdown for fan speed increase + _incTimer.restartOnce(_incDelay); } } @@ -277,7 +270,7 @@ void Zone::decTimerExpired() // where no requested increases exist and // the increase timer is not running // (i.e. not in the middle of increasing) - if (decAllowed && _incSpeedDelta == 0 && !_incTimer.running()) + if (decAllowed && _incSpeedDelta == 0 && !_incTimer.isEnabled()) { auto requestTarget = getRequestSpeedBase(); // Request target speed should not start above ceiling @@ -449,26 +442,31 @@ void Zone::addTimer(const Group& group, const std::vector& actions, const TimerConf& tConf) { - // Associate event data with timer - auto data = std::make_unique( + auto eventData = std::make_unique( group, "", nullptr, actions ); - auto timer = std::make_unique( + Timer timer( _eventLoop, std::bind(&Zone::timerExpired, this, - std::cref(std::get(*data)), - std::cref(std::get>(*data))) - ); - if (!timer->running()) + std::cref(std::get(*eventData)), + std::cref(std::get>(*eventData)))); + if (std::get(tConf) == TimerType::repeating) + { + timer.restart(std::get(tConf)); + } + else if (std::get(tConf) == TimerType::oneshot) + { + timer.restartOnce(std::get(tConf)); + } + else { - timer->start(std::get(tConf), - std::get(tConf)); + throw std::invalid_argument("Invalid Timer Type"); } - _timerEvents.emplace_back(std::move(data), std::move(timer)); + _timerEvents.emplace_back(std::move(eventData), std::move(timer)); } void Zone::timerExpired(const Group& eventGroup, diff --git a/control/zone.hpp b/control/zone.hpp index d01e972..9c85655 100644 --- a/control/zone.hpp +++ b/control/zone.hpp @@ -1,14 +1,12 @@ #pragma once +#include #include #include -#include -#include -#include #include #include +#include #include "fan.hpp" #include "types.hpp" -#include "timer.hpp" namespace phosphor { @@ -423,9 +421,6 @@ class Zone */ inline void removeTimer(std::vector::iterator& teIter) { - assert(teIter != std::end(_timerEvents)); - std::get(*teIter).reset(); - std::get(*teIter).reset(); _timerEvents.erase(teIter); } @@ -547,12 +542,12 @@ class Zone /** * The increase timer object */ - phosphor::fan::util::Timer _incTimer; + Timer _incTimer; /** * The decrease timer object */ - phosphor::fan::util::Timer _decTimer; + Timer _decTimer; /** * Event loop used on set speed event timers -- cgit v1.2.1