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