Matthew Barth | 070ee3c | 2021-01-29 09:58:16 -0600 | [diff] [blame] | 1 | /** |
| 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 | namespace phosphor::fan::control::json |
| 25 | { |
| 26 | |
| 27 | using 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 | */ |
| 36 | class MissingOwnerTarget : |
| 37 | public ActionBase, |
| 38 | public ActionRegister<MissingOwnerTarget> |
| 39 | { |
| 40 | public: |
| 41 | /* Name of this action */ |
| 42 | static constexpr auto name = "set_speed_on_missing_owner"; |
| 43 | |
| 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 Barth | bfd7e1b | 2021-02-04 14:25:47 -0600 | [diff] [blame^] | 54 | * @param[in] jsonObj - JSON configuration of this action |
Matthew Barth | 070ee3c | 2021-01-29 09:58:16 -0600 | [diff] [blame] | 55 | */ |
| 56 | explicit MissingOwnerTarget(const json& jsonObj); |
| 57 | |
| 58 | /** |
| 59 | * @brief Run the action |
| 60 | * |
| 61 | * Updates the services of the group, then determines if any of the |
| 62 | * services hosting the members of the group are not owned on dbus |
| 63 | * resulting in the zone's target being set/held at the configured target. |
| 64 | * |
| 65 | * @param[in] zone - Zone to run the action on |
| 66 | * @param[in] group - Group of dbus objects the action runs against |
| 67 | */ |
| 68 | void run(Zone& zone, const Group& group) override; |
| 69 | |
| 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 |