189c2fa14SMatthew Barth /** 289c2fa14SMatthew Barth * Copyright © 2021 IBM Corporation 389c2fa14SMatthew Barth * 489c2fa14SMatthew Barth * Licensed under the Apache License, Version 2.0 (the "License"); 589c2fa14SMatthew Barth * you may not use this file except in compliance with the License. 689c2fa14SMatthew Barth * You may obtain a copy of the License at 789c2fa14SMatthew Barth * 889c2fa14SMatthew Barth * http://www.apache.org/licenses/LICENSE-2.0 989c2fa14SMatthew Barth * 1089c2fa14SMatthew Barth * Unless required by applicable law or agreed to in writing, software 1189c2fa14SMatthew Barth * distributed under the License is distributed on an "AS IS" BASIS, 1289c2fa14SMatthew Barth * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1389c2fa14SMatthew Barth * See the License for the specific language governing permissions and 1489c2fa14SMatthew Barth * limitations under the License. 1589c2fa14SMatthew Barth */ 1689c2fa14SMatthew Barth #pragma once 1789c2fa14SMatthew Barth 1889c2fa14SMatthew Barth #include "../zone.hpp" 1989c2fa14SMatthew Barth #include "action.hpp" 2089c2fa14SMatthew Barth #include "group.hpp" 2189c2fa14SMatthew Barth 2289c2fa14SMatthew Barth #include <nlohmann/json.hpp> 2389c2fa14SMatthew Barth 2489c2fa14SMatthew Barth namespace phosphor::fan::control::json 2589c2fa14SMatthew Barth { 2689c2fa14SMatthew Barth 2789c2fa14SMatthew Barth using json = nlohmann::json; 2889c2fa14SMatthew Barth 2989c2fa14SMatthew Barth /** 3089c2fa14SMatthew Barth * @class CountStateTarget - Action to set a target when members are at a state 3189c2fa14SMatthew Barth * 3289c2fa14SMatthew Barth * Sets the fans to a configured target when a number of members within the 3389c2fa14SMatthew Barth * group are at a configured state. Once the number of members at the given 3489c2fa14SMatthew Barth * state falls below the configured count, active fan target changes are 3589c2fa14SMatthew Barth * allowed. 3689c2fa14SMatthew Barth */ 3789c2fa14SMatthew Barth class CountStateTarget : 3889c2fa14SMatthew Barth public ActionBase, 3989c2fa14SMatthew Barth public ActionRegister<CountStateTarget> 4089c2fa14SMatthew Barth { 4189c2fa14SMatthew Barth public: 4289c2fa14SMatthew Barth /* Name of this action */ 43bab94f29SMatthew Barth static constexpr auto name = "count_state_before_target"; 4489c2fa14SMatthew Barth 4589c2fa14SMatthew Barth CountStateTarget() = delete; 4689c2fa14SMatthew Barth CountStateTarget(const CountStateTarget&) = delete; 4789c2fa14SMatthew Barth CountStateTarget(CountStateTarget&&) = delete; 4889c2fa14SMatthew Barth CountStateTarget& operator=(const CountStateTarget&) = delete; 4989c2fa14SMatthew Barth CountStateTarget& operator=(CountStateTarget&&) = delete; 5089c2fa14SMatthew Barth ~CountStateTarget() = default; 5189c2fa14SMatthew Barth 5289c2fa14SMatthew Barth /** 5389c2fa14SMatthew Barth * @brief Set target when a number of members are at a given state 5489c2fa14SMatthew Barth * 5589c2fa14SMatthew Barth * @param[in] jsonObj - JSON configuration of this action 5619c77494SMatthew Barth * @param[in] groups - Groups of dbus objects the action uses 5789c2fa14SMatthew Barth */ 5819c77494SMatthew Barth CountStateTarget(const json& jsonObj, const std::vector<Group>& groups); 5989c2fa14SMatthew Barth 6089c2fa14SMatthew Barth /** 6189c2fa14SMatthew Barth * @brief Run the action 6289c2fa14SMatthew Barth * 6389c2fa14SMatthew Barth * Counts the number of members within a group are equal to a given state 6489c2fa14SMatthew Barth * and when the number of members are at or above the given state, the fans 6589c2fa14SMatthew Barth * within the zone are set to the configured target. The fans are held at 6689c2fa14SMatthew Barth * the configured target until the number of members equal to the given 6789c2fa14SMatthew Barth * state fall below the provided count. 6889c2fa14SMatthew Barth * 6989c2fa14SMatthew Barth * @param[in] zone - Zone to run the action on 7089c2fa14SMatthew Barth */ 716d2476c9SMatthew Barth void run(Zone& zone) override; 7289c2fa14SMatthew Barth 7389c2fa14SMatthew Barth private: 7489c2fa14SMatthew Barth /* Number of group members */ 7589c2fa14SMatthew Barth size_t _count; 7689c2fa14SMatthew Barth 7789c2fa14SMatthew Barth /* State the members must be at to set the target */ 7889c2fa14SMatthew Barth PropertyVariantType _state; 7989c2fa14SMatthew Barth 8089c2fa14SMatthew Barth /* Target for this action */ 8189c2fa14SMatthew Barth uint64_t _target; 8289c2fa14SMatthew Barth 83*82a7d0b8SMatthew Barth /* Unique id of this action */ 84*82a7d0b8SMatthew Barth size_t _id; 85*82a7d0b8SMatthew Barth 8689c2fa14SMatthew Barth /** 8789c2fa14SMatthew Barth * @brief Parse and set the count 8889c2fa14SMatthew Barth * 8989c2fa14SMatthew Barth * @param[in] jsonObj - JSON object for the action 9089c2fa14SMatthew Barth * 9189c2fa14SMatthew Barth * Sets the number of members that must equal the state 9289c2fa14SMatthew Barth */ 9389c2fa14SMatthew Barth void setCount(const json& jsonObj); 9489c2fa14SMatthew Barth 9589c2fa14SMatthew Barth /** 9689c2fa14SMatthew Barth * @brief Parse and set the state 9789c2fa14SMatthew Barth * 9889c2fa14SMatthew Barth * @param[in] jsonObj - JSON object for the action 9989c2fa14SMatthew Barth * 10089c2fa14SMatthew Barth * Sets the state for each member to equal to set the target 10189c2fa14SMatthew Barth */ 10289c2fa14SMatthew Barth void setState(const json& jsonObj); 10389c2fa14SMatthew Barth 10489c2fa14SMatthew Barth /** 10589c2fa14SMatthew Barth * @brief Parse and set the target 10689c2fa14SMatthew Barth * 10789c2fa14SMatthew Barth * @param[in] jsonObj - JSON object for the action 10889c2fa14SMatthew Barth * 10989c2fa14SMatthew Barth * Sets the target to use when running the action 11089c2fa14SMatthew Barth */ 11189c2fa14SMatthew Barth void setTarget(const json& jsonObj); 11289c2fa14SMatthew Barth }; 11389c2fa14SMatthew Barth 11489c2fa14SMatthew Barth } // namespace phosphor::fan::control::json 115