blob: a780a2e35b04db94f8bcd9269ff04ac1089be10a [file] [log] [blame]
Matthew Barthdc776c82021-02-25 16:06:16 -06001/**
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
26namespace phosphor::fan::control::json
27{
28
29using json = nlohmann::json;
30
31/**
32 * @class NetTargetIncrease - Action to determine the net target increase to
33 * request
34 *
35 * Calculates the net target increase to be requested based on the value of each
36 * property given within a group. The net target increase is the maximum delta
37 * determined from all of the properties of the group. This net target increase
38 * is the increase change that's requested to the current target of a zone.
39 */
40class NetTargetIncrease :
41 public ActionBase,
42 public ActionRegister<NetTargetIncrease>
43{
44 public:
45 /* Name of this action */
Matthew Barth89147522021-08-25 14:40:56 -050046 static constexpr auto name = "set_net_increase_target";
Matthew Barthdc776c82021-02-25 16:06:16 -060047
48 NetTargetIncrease() = delete;
49 NetTargetIncrease(const NetTargetIncrease&) = delete;
50 NetTargetIncrease(NetTargetIncrease&&) = delete;
51 NetTargetIncrease& operator=(const NetTargetIncrease&) = delete;
52 NetTargetIncrease& operator=(NetTargetIncrease&&) = delete;
53 ~NetTargetIncrease() = default;
54
55 /**
56 * @brief Determine/Set the net target increase
57 *
58 * @param[in] jsonObj - JSON configuration of this action
Matthew Barth19c77492021-04-08 10:06:06 -050059 * @param[in] groups - Groups of dbus objects the action uses
Matthew Barthdc776c82021-02-25 16:06:16 -060060 */
Matthew Barth19c77492021-04-08 10:06:06 -050061 NetTargetIncrease(const json& jsonObj, const std::vector<Group>& groups);
Matthew Barthdc776c82021-02-25 16:06:16 -060062
63 /**
64 * @brief Run the action
65 *
66 * Determines the net target increase delta to be requested based on the
67 * property values of the group of dbus objects and requests this target
68 * increase on the zone. The property values of the group is compared to
69 * the configured state value to determine if an increase 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 increase for each group member. After all members of the group of
75 * dbus objects are processed, the maximum net target increase calculated is
76 * requested on the zone.
77 *
Matt Spinlerbabe3122021-08-06 09:01:38 -050078 * The state value can be specified as number in the JSON, or as a Manager
79 * parameter that another action will have set.
80 *
Matthew Barthdc776c82021-02-25 16:06:16 -060081 * @param[in] zone - Zone to run the action on
Matthew Barthdc776c82021-02-25 16:06:16 -060082 */
Matthew Barth6d2476c2021-04-08 10:48:57 -050083 void run(Zone& zone) override;
Matthew Barthdc776c82021-02-25 16:06:16 -060084
85 private:
Matt Spinlerbabe3122021-08-06 09:01:38 -050086 /* State the members must be at to increase the target */
Matthew Barthdc776c82021-02-25 16:06:16 -060087 PropertyVariantType _state;
88
Matt Spinlerbabe3122021-08-06 09:01:38 -050089 /**
90 * The Manager parameter to use to get the state value if that
91 * was the method specified in the JSON.
92 */
93 std::string _stateParameter;
94
Matthew Barthdc776c82021-02-25 16:06:16 -060095 /* Increase delta for this action */
96 uint64_t _delta;
97
98 /**
99 * @brief Parse and set the state
100 *
101 * @param[in] jsonObj - JSON object for the action
102 *
103 * Sets the state to compare members to
104 */
105 void setState(const json& jsonObj);
106
107 /**
108 * @brief Parse and set the delta
109 *
110 * @param[in] jsonObj - JSON object for the action
111 *
112 * Sets the increase delta to use when running the action
113 */
114 void setDelta(const json& jsonObj);
115};
116
117} // namespace phosphor::fan::control::json