Add timer option to run set speed event actions
For groups within set speed events where the property values of the
group may not signal its action to occur, an optional timer may be added
to the event. This timer is configured as a repeating timer on the
interval provided where upon timer expiration, the event's action is
run.
Change-Id: I4cbe8a0ab1b734bfc7828706a6515af7f6d78b52
Signed-off-by: Matthew Barth <msbarth@us.ibm.com>
diff --git a/control/zone.cpp b/control/zone.cpp
index cef375c..9670127 100644
--- a/control/zone.cpp
+++ b/control/zone.cpp
@@ -29,6 +29,7 @@
{
using namespace std::chrono;
+using namespace phosphor::fan;
using namespace phosphor::logging;
using InternalFailure = sdbusplus::xyz::openbmc_project::Common::
Error::InternalFailure;
@@ -45,7 +46,8 @@
_incDelay(std::get<incDelayPos>(def)),
_decInterval(std::get<decIntervalPos>(def)),
_incTimer(events, [this](){ this->incTimerExpired(); }),
- _decTimer(events, [this](){ this->decTimerExpired(); })
+ _decTimer(events, [this](){ this->decTimerExpired(); }),
+ _sdEvents(events)
{
auto& fanDefs = std::get<fanListPos>(def);
@@ -216,6 +218,26 @@
);
_signalEvents.emplace_back(std::move(eventData), std::move(match));
}
+ // Attach a timer to run the action of an event
+ auto eventTimer = std::get<timerPos>(event);
+ if (std::get<intervalPos>(eventTimer) != seconds(0))
+ {
+ std::unique_ptr<util::Timer> timer =
+ std::make_unique<util::Timer>(
+ _sdEvents,
+ [this,
+ action = &(std::get<actionPos>(event)),
+ group = &(std::get<groupPos>(event))]()
+ {
+ this->timerExpired(*group, *action);
+ });
+ if (!timer->running())
+ {
+ timer->start(std::get<intervalPos>(eventTimer),
+ util::Timer::TimerType::repeating);
+ }
+ _timerEvents.emplace_back(std::move(timer));
+ }
// Run action function for initial event state
std::get<actionPos>(event)(*this,
std::get<groupPos>(event));
@@ -279,6 +301,12 @@
hostResponseMsg.read(value);
}
+void Zone::timerExpired(Group eventGroup, Action eventAction)
+{
+ // Perform the action
+ eventAction(*this, eventGroup);
+}
+
void Zone::handleEvent(sdbusplus::message::message& msg,
const EventData* eventData)
{