blob: 6a802d2fdd7d5b4cc96a219a5031654f5bcbb4e4 [file] [log] [blame]
Matthew Barth070ee3c2021-01-29 09:58: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
24namespace phosphor::fan::control::json
25{
26
27using json = nlohmann::json;
28
29/**
30 * @class MissingOwnerTarget - Action to set a target when an owner is missing
31 *
32 * Sets the fans to a configured target when any service owner associated to the
33 * group is missing. Once all services are functional and providing all the
34 * group data again, active fan target changes are allowed.
35 */
36class MissingOwnerTarget :
37 public ActionBase,
38 public ActionRegister<MissingOwnerTarget>
39{
40 public:
41 /* Name of this action */
Matthew Barth55ed9012021-10-21 11:48:18 -050042 static constexpr auto name = "set_target_on_missing_owner";
Matthew Barth070ee3c2021-01-29 09:58:16 -060043
44 MissingOwnerTarget() = delete;
45 MissingOwnerTarget(const MissingOwnerTarget&) = delete;
46 MissingOwnerTarget(MissingOwnerTarget&&) = delete;
47 MissingOwnerTarget& operator=(const MissingOwnerTarget&) = delete;
48 MissingOwnerTarget& operator=(MissingOwnerTarget&&) = delete;
49 ~MissingOwnerTarget() = default;
50
51 /**
52 * @brief Set target on an owner missing
53 *
Matthew Barthbfd7e1b2021-02-04 14:25:47 -060054 * @param[in] jsonObj - JSON configuration of this action
Matthew Barth19c77492021-04-08 10:06:06 -050055 * @param[in] groups - Groups of dbus objects the action uses
Matthew Barth070ee3c2021-01-29 09:58:16 -060056 */
Matthew Barth19c77492021-04-08 10:06:06 -050057 MissingOwnerTarget(const json& jsonObj, const std::vector<Group>& groups);
Matthew Barth070ee3c2021-01-29 09:58:16 -060058
59 /**
60 * @brief Run the action
61 *
62 * Updates the services of the group, then determines if any of the
63 * services hosting the members of the group are not owned on dbus
64 * resulting in the zone's target being set/held at the configured target.
65 *
66 * @param[in] zone - Zone to run the action on
Matthew Barth070ee3c2021-01-29 09:58:16 -060067 */
Matthew Barth6d2476c2021-04-08 10:48:57 -050068 void run(Zone& zone) override;
Matthew Barth070ee3c2021-01-29 09:58:16 -060069
70 private:
71 /* Target for this action */
72 uint64_t _target;
73
74 /**
75 * @brief Parse and set the target
76 *
77 * @param[in] jsonObj - JSON object for the action
78 *
79 * Sets the target to use when running the action
80 */
81 void setTarget(const json& jsonObj);
82};
83
84} // namespace phosphor::fan::control::json