blob: cc09705f544c59900cfe6604512f355e7907f263 [file] [log] [blame]
Matthew Barth45c44ea2021-03-03 13:16:14 -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 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 */
40class NetTargetDecrease :
41 public ActionBase,
42 public ActionRegister<NetTargetDecrease>
43{
44 public:
45 /* Name of this action */
46 static constexpr auto name = "set_net_decrease_speed";
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 */
60 explicit NetTargetDecrease(const json& jsonObj);
61
62 /**
63 * @brief Run the action
64 *
65 * Determines the net target decrease delta to be requested based on the
66 * property values of the group of dbus objects and requests this target
67 * decrease on the zone. The property values of the group is compared to
68 * the configured state value to determine if an decrease 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 decrease for each group member. After all members of the group of
74 * dbus objects are processed, the minimum net target decrease 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 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