diff options
Diffstat (limited to 'control')
-rw-r--r-- | control/preconditions.hpp | 43 | ||||
-rw-r--r-- | control/types.hpp | 13 | ||||
-rw-r--r-- | control/zone.cpp | 68 | ||||
-rw-r--r-- | control/zone.hpp | 6 |
4 files changed, 92 insertions, 38 deletions
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<PrecondGroup>&& 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<void(sdbusplus::bus::bus&, Zone&)>; using Action = std::function<void(Zone&, const Group&)>; +constexpr auto pcPathPos = 0; +constexpr auto pcIntfPos = 1; +constexpr auto pcPropPos = 2; +constexpr auto pcValuePos = 3; +using PrecondGroup = std::tuple<std::string, + std::string, + std::string, + PropertyVariantType>; + constexpr auto signaturePos = 0; constexpr auto handlerObjPos = 1; using PropertyChange = std::tuple<std::string, Handler>; @@ -49,7 +58,9 @@ using PropertyChange = std::tuple<std::string, Handler>; constexpr auto groupPos = 0; constexpr auto actionPos = 1; constexpr auto propChangeListPos = 2; -using SetSpeedEvent = std::tuple<Group, Action, std::vector<PropertyChange>>; +using SetSpeedEvent = std::tuple<Group, + Action, + std::vector<PropertyChange>>; 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<setSpeedEventsPos>(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<setSpeedEventsPos>(def)) + // Get the current value for each property + for (auto& entry : std::get<groupPos>(event)) { - // Get the current value for each property - for (auto& entry : std::get<groupPos>(event)) - { - refreshProperty(_bus, - entry.first, - std::get<intfPos>(entry.second), - std::get<propPos>(entry.second)); - } - // Setup signal matches for property change events - for (auto& prop : std::get<propChangeListPos>(event)) - { - _signalEvents.emplace_back( - std::make_unique<EventData>( - EventData - { - std::get<groupPos>(event), - std::get<handlerObjPos>(prop), - std::get<actionPos>(event) - })); - _matches.emplace_back( - _bus, - std::get<signaturePos>(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<actionPos>(event)(*this, - std::get<groupPos>(event)); + refreshProperty(_bus, + entry.first, + std::get<intfPos>(entry.second), + std::get<propPos>(entry.second)); + } + // Setup signal matches for property change events + for (auto& prop : std::get<propChangeListPos>(event)) + { + _signalEvents.emplace_back( + std::make_unique<EventData>( + EventData + { + std::get<groupPos>(event), + std::get<handlerObjPos>(prop), + std::get<actionPos>(event) + })); + _matches.emplace_back( + _bus, + std::get<signaturePos>(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<actionPos>(event)(*this, + std::get<groupPos>(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<sdbusplus::server::match::match> _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 |