1 /** 2 * Copyright © 2021 IBM Corporation 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 #pragma once 17 18 #include "../zone.hpp" 19 #include "action.hpp" 20 #include "group.hpp" 21 22 #include <nlohmann/json.hpp> 23 24 #include <optional> 25 26 namespace phosphor::fan::control::json 27 { 28 29 using json = nlohmann::json; 30 31 /** 32 * @class NetTargetDecrease - Action to determine the net target decrease to 33 * request 34 * 35 * Calculates the net target decrease to be requested based on the value of each 36 * property given within a group. The net target decrease is the minimum delta 37 * determined from all of the properties of the group. This net target decrease 38 * is the decrease change that's requested to the current target of a zone. 39 */ 40 class NetTargetDecrease : 41 public ActionBase, 42 public ActionRegister<NetTargetDecrease> 43 { 44 public: 45 /* Name of this action */ 46 static constexpr auto name = "set_net_decrease_target"; 47 48 NetTargetDecrease() = delete; 49 NetTargetDecrease(const NetTargetDecrease&) = delete; 50 NetTargetDecrease(NetTargetDecrease&&) = delete; 51 NetTargetDecrease& operator=(const NetTargetDecrease&) = delete; 52 NetTargetDecrease& operator=(NetTargetDecrease&&) = delete; 53 ~NetTargetDecrease() = default; 54 55 /** 56 * @brief Determine/Set the net target decrease 57 * 58 * @param[in] jsonObj - JSON configuration of this action 59 * @param[in] groups - Groups of dbus objects the action uses 60 */ 61 NetTargetDecrease(const json& jsonObj, const std::vector<Group>& groups); 62 63 /** 64 * @brief Run the action 65 * 66 * Determines the net target decrease delta to be requested based on the 67 * property values of the group of dbus objects and requests this target 68 * decrease on the zone. The property values of the group is compared to 69 * the configured state value to determine if an decrease delta should be 70 * requested. For boolean & string values, the configured delta is 71 * requested when a property of the group equals the configured state. For 72 * integer & double values, the configured delta is multiplied by the 73 * difference in property value and the configured state resulting in a net 74 * target decrease for each group member. After all members of the group of 75 * dbus objects are processed, the minimum net target decrease calculated is 76 * requested on the zone. 77 * 78 * @param[in] zone - Zone to run the action on 79 */ 80 void run(Zone& zone) override; 81 82 private: 83 /* State the members must be at to decrease the target */ 84 PropertyVariantType _state; 85 86 /* Decrease delta for this action */ 87 uint64_t _delta; 88 89 /** 90 * @brief Parse and set the state 91 * 92 * @param[in] jsonObj - JSON object for the action 93 * 94 * Sets the state to compare members to 95 */ 96 void setState(const json& jsonObj); 97 98 /** 99 * @brief Parse and set the delta 100 * 101 * @param[in] jsonObj - JSON object for the action 102 * 103 * Sets the decrease delta to use when running the action 104 */ 105 void setDelta(const json& jsonObj); 106 }; 107 108 } // namespace phosphor::fan::control::json 109