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/preconditions.hpp | 22 +++++++++++---- control/types.hpp | 8 +++--- control/zone.cpp | 72 ++++++++++++++++++++++++++++++++++------------- control/zone.hpp | 8 +++--- 4 files changed, 78 insertions(+), 32 deletions(-) diff --git a/control/preconditions.hpp b/control/preconditions.hpp index 65eb0e2..f989f0d 100644 --- a/control/preconditions.hpp +++ b/control/preconditions.hpp @@ -28,7 +28,7 @@ namespace precondition * and either subscribe or unsubscribe a set speed event group. */ auto property_states_match(std::vector&& pg, - SetSpeedEvent&& sse) + std::vector&& sse) { return [pg = std::move(pg), sse = std::move(sse)](auto& zone, auto& group) @@ -56,13 +56,25 @@ auto property_states_match(std::vector&& pg, if (precondState == pg.size()) { - // Init the event when all the precondition(s) are true - zone.initEvent(sse); + // Init the events when all the precondition(s) are true + std::for_each( + sse.begin(), + sse.end(), + [&zone](auto const& entry) + { + zone.initEvent(entry); + }); } else { - // Unsubscribe the event signals when any precondition is false - zone.removeEvent(sse); + // Unsubscribe the events' signals when any precondition is false + std::for_each( + sse.begin(), + sse.end(), + [&zone](auto const& entry) + { + zone.removeEvent(entry); + }); zone.setFullSpeed(); } // Update group's fan control active allowed diff --git a/control/types.hpp b/control/types.hpp index b788ac5..a670810 100644 --- a/control/types.hpp +++ b/control/types.hpp @@ -61,18 +61,18 @@ constexpr auto handlerObjPos = 1; using PropertyChange = std::tuple; constexpr auto groupPos = 0; -constexpr auto actionPos = 1; +constexpr auto actionsPos = 1; constexpr auto timerPos = 2; constexpr auto propChangeListPos = 3; using SetSpeedEvent = std::tuple, Timer, std::vector>; constexpr auto eventGroupPos = 0; constexpr auto eventHandlerPos = 1; -constexpr auto eventActionPos = 2; -using EventData = std::tuple; +constexpr auto eventActionsPos = 2; +using EventData = std::tuple>; constexpr auto timerTimerPos = 0; using TimerEvent = std::tuple; 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)); + }); } } diff --git a/control/zone.hpp b/control/zone.hpp index cb1ce69..bc21b9f 100644 --- a/control/zone.hpp +++ b/control/zone.hpp @@ -243,12 +243,12 @@ class Zone /** * @brief Callback function for event timers that processes the given - * action for a group + * actions for a group * - * @param[in] eventGroup - Group to process action on - * @param[in] eventAction - Event action to run + * @param[in] eventGroup - Group to process actions on + * @param[in] eventActions - List of event actions to run */ - void timerExpired(Group eventGroup, Action eventAction); + void timerExpired(Group eventGroup, std::vector eventActions); private: -- cgit v1.2.1