summaryrefslogtreecommitdiffstats
path: root/control/zone.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'control/zone.cpp')
-rw-r--r--control/zone.cpp42
1 files changed, 20 insertions, 22 deletions
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 <phosphor-logging/log.hpp>
#include <phosphor-logging/elog.hpp>
#include <phosphor-logging/elog-errors.hpp>
+#include <stdexcept>
#include <xyz/openbmc_project/Common/error.hpp>
#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<Action>& actions,
const TimerConf& tConf)
{
- // Associate event data with timer
- auto data = std::make_unique<EventData>(
+ auto eventData = std::make_unique<EventData>(
group,
"",
nullptr,
actions
);
- auto timer = std::make_unique<util::Timer>(
+ Timer timer(
_eventLoop,
std::bind(&Zone::timerExpired,
this,
- std::cref(std::get<Group>(*data)),
- std::cref(std::get<std::vector<Action>>(*data)))
- );
- if (!timer->running())
+ std::cref(std::get<Group>(*eventData)),
+ std::cref(std::get<std::vector<Action>>(*eventData))));
+ if (std::get<TimerType>(tConf) == TimerType::repeating)
+ {
+ timer.restart(std::get<intervalPos>(tConf));
+ }
+ else if (std::get<TimerType>(tConf) == TimerType::oneshot)
+ {
+ timer.restartOnce(std::get<intervalPos>(tConf));
+ }
+ else
{
- timer->start(std::get<intervalPos>(tConf),
- std::get<typePos>(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,
OpenPOWER on IntegriCloud