summaryrefslogtreecommitdiffstats
path: root/control/zone.cpp
diff options
context:
space:
mode:
authorMatthew Barth <msbarth@us.ibm.com>2017-08-15 10:51:37 -0500
committerMatthew Barth <msbarth@us.ibm.com>2017-08-16 09:47:08 -0500
commit9014980aa76692cd7f08b5e69565133122c758cd (patch)
tree92caf9df963449625d513e8c1cc5c704681eb7f9 /control/zone.cpp
parent172f393696b967f23e1d166fc7eb952a11994c5d (diff)
downloadphosphor-fan-presence-9014980aa76692cd7f08b5e69565133122c758cd.tar.gz
phosphor-fan-presence-9014980aa76692cd7f08b5e69565133122c758cd.zip
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>
Diffstat (limited to 'control/zone.cpp')
-rw-r--r--control/zone.cpp30
1 files changed, 29 insertions, 1 deletions
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 @@ namespace control
{
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 @@ Zone::Zone(Mode mode,
_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 @@ void Zone::initEvent(const SetSpeedEvent& event)
);
_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 @@ void Zone::getProperty(sdbusplus::bus::bus& bus,
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)
{
OpenPOWER on IntegriCloud