blob: 8c6a043ec1ff9d8fdb3893de3f3ccb656407811f [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 */
46 static constexpr auto name = "set_net_increase_speed";
47
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
59 */
60 explicit NetTargetIncrease(const json& jsonObj);
61
62 /**
63 * @brief Run the action
64 *
65 * Determines the net target increase delta to be requested based on the
66 * property values of the group of dbus objects and requests this target
67 * increase on the zone. The property values of the group is compared to
68 * the configured state value to determine if an increase delta should be
69 * requested. For boolean & string values, the configured delta is
70 * requested when a property of the group equals the configured state. For
71 * integer & double values, the configured delta is multiplied by the
72 * difference in property value and the configured state resulting in a net
73 * target increase for each group member. After all members of the group of
74 * dbus objects are processed, the maximum net target increase calculated is
75 * requested on the zone.
76 *
77 * @param[in] zone - Zone to run the action on
78 * @param[in] group - Group of dbus objects the action runs against
79 */
80 void run(Zone& zone, const Group& group) override;
81
82 private:
83 /* State the members must be at to increase the rarget */
84 PropertyVariantType _state;
85
86 /* Increase 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 increase delta to use when running the action
104 */
105 void setDelta(const json& jsonObj);
106};
107
108} // namespace phosphor::fan::control::json