From f9201abb8ca5a30220b05f3bbaa2db9343699a80 Mon Sep 17 00:00:00 2001 From: Matthew Barth Date: Mon, 11 Sep 2017 16:07:58 -0500 Subject: Support a list of actions for a set speed event Each set speed event will contain a list of one-to-many actions to perform for the given event group's property. This reduces the amount of code generated and properly handles property changed events against the group. Change-Id: If2b8c0d0b8ecf6e1c974c43d96e1c6e9e952022b Signed-off-by: Matthew Barth --- control/zone.cpp | 72 +++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 53 insertions(+), 19 deletions(-) (limited to 'control/zone.cpp') diff --git a/control/zone.cpp b/control/zone.cpp index 4d31ecf..3eab42f 100644 --- a/control/zone.cpp +++ b/control/zone.cpp @@ -222,7 +222,7 @@ void Zone::initEvent(const SetSpeedEvent& event) { std::get(event), std::get(prop), - std::get(event) + std::get(event) } ); std::unique_ptr match = @@ -244,7 +244,7 @@ void Zone::initEvent(const SetSpeedEvent& event) std::make_unique( _sdEvents, [this, - action = &(std::get(event)), + action = &(std::get(event)), group = &(std::get(event))]() { this->timerExpired(*group, *action); @@ -256,9 +256,15 @@ void Zone::initEvent(const SetSpeedEvent& event) } _timerEvents.emplace_back(std::move(timer)); } - // Run action function for initial event state - std::get(event)(*this, - std::get(event)); + // Run action functions for initial event state + std::for_each( + std::get(event).begin(), + std::get(event).end(), + [this, &event](auto const& action) + { + action(*this, + std::get(event)); + }); } void Zone::removeEvent(const SetSpeedEvent& event) @@ -270,14 +276,31 @@ void Zone::removeEvent(const SetSpeedEvent& event) [&event](auto const& se) { auto seEventData = *std::get(se); - // TODO Use the action function target for comparison - return - ( - std::get(seEventData) == - std::get(event) && - std::get(seEventData).target_type().name() == - std::get(event).target_type().name() - ); + if (std::get(seEventData).size() != + std::get(event).size()) + { + return false; + } + else + { + // TODO openbmc/openbmc#2328 - Use the action function target + // for comparison + auto actsEqual = [](auto const& a1, + auto const& a2) + { + return a1.target_type().name() == + a2.target_type().name(); + }; + return + ( + std::get(seEventData) == + std::get(event) && + std::equal(std::get(event).begin(), + std::get(event).end(), + std::get(seEventData).begin(), + actsEqual) + ); + } }); if (it != std::end(_signalEvents)) { @@ -319,10 +342,15 @@ void Zone::getProperty(sdbusplus::bus::bus& bus, hostResponseMsg.read(value); } -void Zone::timerExpired(Group eventGroup, Action eventAction) +void Zone::timerExpired(Group eventGroup, std::vector eventActions) { - // Perform the action - eventAction(*this, eventGroup); + // Perform the actions + std::for_each(eventActions.begin(), + eventActions.end(), + [this, &eventGroup](auto const& action) + { + action(*this, eventGroup); + }); } void Zone::handleEvent(sdbusplus::message::message& msg, @@ -330,9 +358,15 @@ void Zone::handleEvent(sdbusplus::message::message& msg, { // Handle the callback std::get(*eventData)(_bus, msg, *this); - // Perform the action - std::get(*eventData)(*this, - std::get(*eventData)); + // Perform the actions + std::for_each( + std::get(*eventData).begin(), + std::get(*eventData).end(), + [this, &eventData](auto const& action) + { + action(*this, + std::get(*eventData)); + }); } } -- cgit v1.2.1