From ccc7770ecd6b758fcef98ce9e7cd585af3f3c77f Mon Sep 17 00:00:00 2001 From: Matthew Barth Date: Fri, 28 Jul 2017 13:43:04 -0500 Subject: Initial updates to support preconditions Any defined preconditions for a set speed event must be satisfied prior to configuring the event parameters for fan control. These preconditions will accept a list of group entries that include the value the group's property must be to have the precondition met for that group. Once all preconditions are met, the set speed event will be initialized and become active. Change-Id: Ia5555be55c5937c891af527bea63da1546655b2f Signed-off-by: Matthew Barth --- control/preconditions.hpp | 43 ++++++++++++++++++++++++++++++ control/types.hpp | 13 ++++++++- control/zone.cpp | 68 +++++++++++++++++++++++------------------------ control/zone.hpp | 6 ++--- 4 files changed, 92 insertions(+), 38 deletions(-) create mode 100644 control/preconditions.hpp (limited to 'control') diff --git a/control/preconditions.hpp b/control/preconditions.hpp new file mode 100644 index 0000000..61a2f50 --- /dev/null +++ b/control/preconditions.hpp @@ -0,0 +1,43 @@ +#pragma once + +namespace phosphor +{ +namespace fan +{ +namespace control +{ +namespace precondition +{ + +/** + * @brief A precondition to compare a group of property values and + * subscribe/unsubscribe a set speed event group + * @details Compares each entry within the precondition group to a given value + * that when each entry's property value matches the given value, the set speed + * event is then initialized. At any point a precondition entry's value no + * longer matches, the set speed event is removed from being active and fans + * are set to full speed. + * + * @param[in] pg - Precondition property group of property values + * @param[in] sse - Set speed event definition + * + * @return Lambda function + * A lambda function to compare precondition property value states + * and either subscribe or unsubscribe a set speed event group. + */ +auto property_states_match(std::vector&& pg, + SetSpeedEvent&& sse) +{ + return [pg = std::move(pg), + sse = std::move(sse)](auto& zone, auto& group) + { + // TODO Read/Compare given precondition entries + // TODO Only init the event when the precondition(s) are true + // TODO Remove the event properties when the precondition(s) are false + }; +} + +} // namespace precondition +} // namespace control +} // namespace fan +} // namespace phosphor diff --git a/control/types.hpp b/control/types.hpp index b6a031f..d45226f 100644 --- a/control/types.hpp +++ b/control/types.hpp @@ -42,6 +42,15 @@ using Handler = std::function; using Action = std::function; +constexpr auto pcPathPos = 0; +constexpr auto pcIntfPos = 1; +constexpr auto pcPropPos = 2; +constexpr auto pcValuePos = 3; +using PrecondGroup = std::tuple; + constexpr auto signaturePos = 0; constexpr auto handlerObjPos = 1; using PropertyChange = std::tuple; @@ -49,7 +58,9 @@ using PropertyChange = std::tuple; constexpr auto groupPos = 0; constexpr auto actionPos = 1; constexpr auto propChangeListPos = 2; -using SetSpeedEvent = std::tuple>; +using SetSpeedEvent = std::tuple>; constexpr auto eventGroupPos = 0; constexpr auto eventHandlerPos = 1; diff --git a/control/zone.cpp b/control/zone.cpp index 93a616a..4fb60cd 100644 --- a/control/zone.cpp +++ b/control/zone.cpp @@ -57,7 +57,11 @@ Zone::Zone(Mode mode, // Do not enable set speed events when in init mode if (mode != Mode::init) { - initEvents(def); + // Setup signal trigger for set speed events + for (auto& event : std::get(def)) + { + initEvent(event); + } // Start timer for fan speed decreases if (!_decTimer.running() && _decInterval != seconds::zero()) { @@ -168,42 +172,38 @@ void Zone::decTimerExpired() // Decrease timer is restarted since its repeating } -void Zone::initEvents(const ZoneDefinition& def) +void Zone::initEvent(const SetSpeedEvent& event) { - // Setup signal trigger for set speed events - for (auto& event : std::get(def)) + // Get the current value for each property + for (auto& entry : std::get(event)) { - // Get the current value for each property - for (auto& entry : std::get(event)) - { - refreshProperty(_bus, - entry.first, - std::get(entry.second), - std::get(entry.second)); - } - // Setup signal matches for property change events - for (auto& prop : std::get(event)) - { - _signalEvents.emplace_back( - std::make_unique( - EventData - { - std::get(event), - std::get(prop), - std::get(event) - })); - _matches.emplace_back( - _bus, - std::get(prop).c_str(), - std::bind(std::mem_fn(&Zone::handleEvent), - this, - std::placeholders::_1, - _signalEvents.back().get())); - } - // Run action function for initial event state - std::get(event)(*this, - std::get(event)); + refreshProperty(_bus, + entry.first, + std::get(entry.second), + std::get(entry.second)); + } + // Setup signal matches for property change events + for (auto& prop : std::get(event)) + { + _signalEvents.emplace_back( + std::make_unique( + EventData + { + std::get(event), + std::get(prop), + std::get(event) + })); + _matches.emplace_back( + _bus, + std::get(prop).c_str(), + std::bind(std::mem_fn(&Zone::handleEvent), + this, + std::placeholders::_1, + _signalEvents.back().get())); } + // Run action function for initial event state + std::get(event)(*this, + std::get(event)); } void Zone::refreshProperty(sdbusplus::bus::bus& bus, diff --git a/control/zone.hpp b/control/zone.hpp index 706d9c2..077bfcf 100644 --- a/control/zone.hpp +++ b/control/zone.hpp @@ -329,11 +329,11 @@ class Zone std::vector _matches; /** - * @brief Initialize all the set speed event properties and actions + * @brief Initialize a set speed event properties and actions * - * @param[in] def - zone definition containing set speed events + * @param[in] event - Set speed event */ - void initEvents(const ZoneDefinition& def); + void initEvent(const SetSpeedEvent& event); /** * @brief Refresh the given property's cached value -- cgit v1.2.1