summaryrefslogtreecommitdiffstats
path: root/control
diff options
context:
space:
mode:
Diffstat (limited to 'control')
-rw-r--r--control/actions.cpp25
-rw-r--r--control/zone.cpp49
-rw-r--r--control/zone.hpp14
3 files changed, 33 insertions, 55 deletions
diff --git a/control/actions.cpp b/control/actions.cpp
index 923b1cc..0267c10 100644
--- a/control/actions.cpp
+++ b/control/actions.cpp
@@ -33,30 +33,7 @@ Action call_actions_based_on_timer(TimerConf&& tConf,
zone.findTimer(group, actions) ==
std::end(zone.getTimerEvents()))
{
- // Associate event data with timer
- std::unique_ptr<EventData> eventData =
- std::make_unique<EventData>(
- group,
- "",
- nullptr,
- actions
- );
- // Create/start timer and associate event data with it
- std::unique_ptr<util::Timer> timer =
- std::make_unique<util::Timer>(
- zone.getEventLoop(),
- [&zone,
- actions = &actions,
- group = &group]()
- {
- zone.timerExpired(*group, *actions);
- });
- if (!timer->running())
- {
- timer->start(std::get<intervalPos>(tConf),
- std::get<typePos>(tConf));
- }
- zone.addTimer(std::move(eventData), std::move(timer));
+ zone.addTimer(group, actions, tConf);
}
else
{
diff --git a/control/zone.cpp b/control/zone.cpp
index 5f0c15d..ec0f944 100644
--- a/control/zone.cpp
+++ b/control/zone.cpp
@@ -335,29 +335,9 @@ void Zone::initEvent(const SetSpeedEvent& event)
auto timerConf = std::get<timerConfPos>(event);
if (std::get<intervalPos>(timerConf) != seconds(0))
{
- // Associate event data with timer
- std::unique_ptr<EventData> eventData =
- std::make_unique<EventData>(
- std::get<groupPos>(event),
- "",
- nullptr,
- std::get<actionsPos>(event)
- );
- std::unique_ptr<util::Timer> timer =
- std::make_unique<util::Timer>(
- _eventLoop,
- [this,
- action = &(std::get<actionsPos>(event)),
- group = &(std::get<groupPos>(event))]()
- {
- this->timerExpired(*group, *action);
- });
- if (!timer->running())
- {
- timer->start(std::get<intervalPos>(timerConf),
- std::get<typePos>(timerConf));
- }
- addTimer(std::move(eventData), std::move(timer));
+ addTimer(std::get<groupPos>(event),
+ std::get<actionsPos>(event),
+ timerConf);
}
// Run action functions for initial event state
std::for_each(
@@ -448,6 +428,29 @@ std::vector<TimerEvent>::iterator Zone::findTimer(
return _timerEvents.end();
}
+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>(
+ group,
+ "",
+ nullptr,
+ actions
+ );
+ auto timer = std::make_unique<util::Timer>(
+ _eventLoop,
+ std::bind(&Zone::timerExpired, this, group, actions)
+ );
+ if (!timer->running())
+ {
+ timer->start(std::get<intervalPos>(tConf),
+ std::get<typePos>(tConf));
+ }
+ _timerEvents.emplace_back(std::move(data), std::move(timer));
+}
+
void Zone::timerExpired(Group eventGroup, std::vector<Action> eventActions)
{
// Perform the actions
diff --git a/control/zone.hpp b/control/zone.hpp
index e035a64..4f4dfb6 100644
--- a/control/zone.hpp
+++ b/control/zone.hpp
@@ -367,15 +367,13 @@ class Zone
/**
* @brief Add a timer to the list of timer based events
*
- * @param[in] data - Event data for timer
- * @param[in] timer - Timer to be added
+ * @param[in] group - Group associated with a timer
+ * @param[in] actions - List of actions associated with a timer
+ * @param[in] tConf - Configuration for the new timer
*/
- inline void addTimer(
- std::unique_ptr<EventData>&& data,
- std::unique_ptr<phosphor::fan::util::Timer>&& timer)
- {
- _timerEvents.emplace_back(std::move(data), std::move(timer));
- };
+ void addTimer(const Group& group,
+ const std::vector<Action>& actions,
+ const TimerConf& tConf);
/**
* @brief Remove the given timer event
OpenPOWER on IntegriCloud