145c44ea0SMatthew Barth /** 245c44ea0SMatthew Barth * Copyright © 2021 IBM Corporation 345c44ea0SMatthew Barth * 445c44ea0SMatthew Barth * Licensed under the Apache License, Version 2.0 (the "License"); 545c44ea0SMatthew Barth * you may not use this file except in compliance with the License. 645c44ea0SMatthew Barth * You may obtain a copy of the License at 745c44ea0SMatthew Barth * 845c44ea0SMatthew Barth * http://www.apache.org/licenses/LICENSE-2.0 945c44ea0SMatthew Barth * 1045c44ea0SMatthew Barth * Unless required by applicable law or agreed to in writing, software 1145c44ea0SMatthew Barth * distributed under the License is distributed on an "AS IS" BASIS, 1245c44ea0SMatthew Barth * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1345c44ea0SMatthew Barth * See the License for the specific language governing permissions and 1445c44ea0SMatthew Barth * limitations under the License. 1545c44ea0SMatthew Barth */ 1645c44ea0SMatthew Barth #pragma once 1745c44ea0SMatthew Barth 1845c44ea0SMatthew Barth #include "../zone.hpp" 1945c44ea0SMatthew Barth #include "action.hpp" 2045c44ea0SMatthew Barth #include "group.hpp" 2145c44ea0SMatthew Barth 2245c44ea0SMatthew Barth #include <nlohmann/json.hpp> 2345c44ea0SMatthew Barth 2445c44ea0SMatthew Barth #include <optional> 2545c44ea0SMatthew Barth 2645c44ea0SMatthew Barth namespace phosphor::fan::control::json 2745c44ea0SMatthew Barth { 2845c44ea0SMatthew Barth 2945c44ea0SMatthew Barth using json = nlohmann::json; 3045c44ea0SMatthew Barth 3145c44ea0SMatthew Barth /** 3245c44ea0SMatthew Barth * @class NetTargetDecrease - Action to determine the net target decrease to 3345c44ea0SMatthew Barth * request 3445c44ea0SMatthew Barth * 3545c44ea0SMatthew Barth * Calculates the net target decrease to be requested based on the value of each 3645c44ea0SMatthew Barth * property given within a group. The net target decrease is the minimum delta 3745c44ea0SMatthew Barth * determined from all of the properties of the group. This net target decrease 3845c44ea0SMatthew Barth * is the decrease change that's requested to the current target of a zone. 3945c44ea0SMatthew Barth */ 4045c44ea0SMatthew Barth class NetTargetDecrease : 4145c44ea0SMatthew Barth public ActionBase, 4245c44ea0SMatthew Barth public ActionRegister<NetTargetDecrease> 4345c44ea0SMatthew Barth { 4445c44ea0SMatthew Barth public: 4545c44ea0SMatthew Barth /* Name of this action */ 4689147526SMatthew Barth static constexpr auto name = "set_net_decrease_target"; 4745c44ea0SMatthew Barth 4845c44ea0SMatthew Barth NetTargetDecrease() = delete; 4945c44ea0SMatthew Barth NetTargetDecrease(const NetTargetDecrease&) = delete; 5045c44ea0SMatthew Barth NetTargetDecrease(NetTargetDecrease&&) = delete; 5145c44ea0SMatthew Barth NetTargetDecrease& operator=(const NetTargetDecrease&) = delete; 5245c44ea0SMatthew Barth NetTargetDecrease& operator=(NetTargetDecrease&&) = delete; 5345c44ea0SMatthew Barth ~NetTargetDecrease() = default; 5445c44ea0SMatthew Barth 5545c44ea0SMatthew Barth /** 5645c44ea0SMatthew Barth * @brief Determine/Set the net target decrease 5745c44ea0SMatthew Barth * 5845c44ea0SMatthew Barth * @param[in] jsonObj - JSON configuration of this action 5919c77494SMatthew Barth * @param[in] groups - Groups of dbus objects the action uses 6045c44ea0SMatthew Barth */ 6119c77494SMatthew Barth NetTargetDecrease(const json& jsonObj, const std::vector<Group>& groups); 6245c44ea0SMatthew Barth 6345c44ea0SMatthew Barth /** 6445c44ea0SMatthew Barth * @brief Run the action 6545c44ea0SMatthew Barth * 6645c44ea0SMatthew Barth * Determines the net target decrease delta to be requested based on the 6745c44ea0SMatthew Barth * property values of the group of dbus objects and requests this target 6845c44ea0SMatthew Barth * decrease on the zone. The property values of the group is compared to 6945c44ea0SMatthew Barth * the configured state value to determine if an decrease delta should be 7045c44ea0SMatthew Barth * requested. For boolean & string values, the configured delta is 7145c44ea0SMatthew Barth * requested when a property of the group equals the configured state. For 7245c44ea0SMatthew Barth * integer & double values, the configured delta is multiplied by the 7345c44ea0SMatthew Barth * difference in property value and the configured state resulting in a net 7445c44ea0SMatthew Barth * target decrease for each group member. After all members of the group of 7545c44ea0SMatthew Barth * dbus objects are processed, the minimum net target decrease calculated is 7645c44ea0SMatthew Barth * requested on the zone. 7745c44ea0SMatthew Barth * 78*20afdda3SMatthew Barth * The state value can be specified in the JSON, or as a Manager parameter 79*20afdda3SMatthew Barth * that another action will have set. 80*20afdda3SMatthew Barth * 8145c44ea0SMatthew Barth * @param[in] zone - Zone to run the action on 8245c44ea0SMatthew Barth */ 836d2476c9SMatthew Barth void run(Zone& zone) override; 8445c44ea0SMatthew Barth 8545c44ea0SMatthew Barth private: 8645c44ea0SMatthew Barth /* State the members must be at to decrease the target */ 8745c44ea0SMatthew Barth PropertyVariantType _state; 8845c44ea0SMatthew Barth 89*20afdda3SMatthew Barth /** 90*20afdda3SMatthew Barth * The Manager parameter to use to get the state value if that 91*20afdda3SMatthew Barth * was the method specified in the JSON. 92*20afdda3SMatthew Barth */ 93*20afdda3SMatthew Barth std::string _stateParameter; 94*20afdda3SMatthew Barth 9545c44ea0SMatthew Barth /* Decrease delta for this action */ 9645c44ea0SMatthew Barth uint64_t _delta; 9745c44ea0SMatthew Barth 9845c44ea0SMatthew Barth /** 9945c44ea0SMatthew Barth * @brief Parse and set the state 10045c44ea0SMatthew Barth * 10145c44ea0SMatthew Barth * @param[in] jsonObj - JSON object for the action 10245c44ea0SMatthew Barth * 10345c44ea0SMatthew Barth * Sets the state to compare members to 10445c44ea0SMatthew Barth */ 10545c44ea0SMatthew Barth void setState(const json& jsonObj); 10645c44ea0SMatthew Barth 10745c44ea0SMatthew Barth /** 10845c44ea0SMatthew Barth * @brief Parse and set the delta 10945c44ea0SMatthew Barth * 11045c44ea0SMatthew Barth * @param[in] jsonObj - JSON object for the action 11145c44ea0SMatthew Barth * 11245c44ea0SMatthew Barth * Sets the decrease delta to use when running the action 11345c44ea0SMatthew Barth */ 11445c44ea0SMatthew Barth void setDelta(const json& jsonObj); 11545c44ea0SMatthew Barth }; 11645c44ea0SMatthew Barth 11745c44ea0SMatthew Barth } // namespace phosphor::fan::control::json 118