Matthew Barth | 0c4b157 | 2020-10-22 14:39:46 -0500 | [diff] [blame] | 1 | /** |
Matthew Barth | 41a3408 | 2021-01-27 15:31:48 -0600 | [diff] [blame] | 2 | * Copyright © 2021 IBM Corporation |
Matthew Barth | 0c4b157 | 2020-10-22 14:39:46 -0500 | [diff] [blame] | 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 | #include "default_floor.hpp" |
| 17 | |
Matthew Barth | 12cb125 | 2021-03-08 16:47:30 -0600 | [diff] [blame] | 18 | #include "../manager.hpp" |
| 19 | #include "../zone.hpp" |
| 20 | #include "group.hpp" |
Matthew Barth | 0c4b157 | 2020-10-22 14:39:46 -0500 | [diff] [blame] | 21 | |
| 22 | #include <nlohmann/json.hpp> |
| 23 | |
Matthew Barth | 41a3408 | 2021-01-27 15:31:48 -0600 | [diff] [blame] | 24 | #include <algorithm> |
Matthew Barth | 41a3408 | 2021-01-27 15:31:48 -0600 | [diff] [blame] | 25 | |
Matthew Barth | 0c4b157 | 2020-10-22 14:39:46 -0500 | [diff] [blame] | 26 | namespace phosphor::fan::control::json |
| 27 | { |
| 28 | |
| 29 | using json = nlohmann::json; |
| 30 | |
Matthew Barth | 19c7749 | 2021-04-08 10:06:06 -0500 | [diff] [blame] | 31 | DefaultFloor::DefaultFloor(const json& jsonObj, |
| 32 | const std::vector<Group>& groups) : |
| 33 | ActionBase(jsonObj, groups) |
Matthew Barth | 0c4b157 | 2020-10-22 14:39:46 -0500 | [diff] [blame] | 34 | { |
Matthew Barth | 41a3408 | 2021-01-27 15:31:48 -0600 | [diff] [blame] | 35 | // There are no JSON configuration parameters for this action |
Matthew Barth | 0c4b157 | 2020-10-22 14:39:46 -0500 | [diff] [blame] | 36 | } |
| 37 | |
Matthew Barth | 6d2476c | 2021-04-08 10:48:57 -0500 | [diff] [blame] | 38 | void DefaultFloor::run(Zone& zone) |
Matthew Barth | 0c4b157 | 2020-10-22 14:39:46 -0500 | [diff] [blame] | 39 | { |
Matthew Barth | 6d2476c | 2021-04-08 10:48:57 -0500 | [diff] [blame] | 40 | for (const auto& group : _groups) |
Matthew Barth | 41a3408 | 2021-01-27 15:31:48 -0600 | [diff] [blame] | 41 | { |
Matthew Barth | 6d2476c | 2021-04-08 10:48:57 -0500 | [diff] [blame] | 42 | const auto& members = group.getMembers(); |
| 43 | auto isMissingOwner = |
| 44 | std::any_of(members.begin(), members.end(), |
| 45 | [&intf = group.getInterface()](const auto& member) { |
Patrick Williams | dfddd64 | 2024-08-16 15:21:51 -0400 | [diff] [blame^] | 46 | return !Manager::hasOwner(member, intf); |
| 47 | }); |
Matthew Barth | 6d2476c | 2021-04-08 10:48:57 -0500 | [diff] [blame] | 48 | if (isMissingOwner) |
| 49 | { |
| 50 | zone.setFloor(zone.getDefaultFloor()); |
| 51 | } |
| 52 | // Update fan control floor change allowed |
| 53 | zone.setFloorChangeAllow(group.getName(), !isMissingOwner); |
Matthew Barth | 41a3408 | 2021-01-27 15:31:48 -0600 | [diff] [blame] | 54 | } |
Matthew Barth | 0c4b157 | 2020-10-22 14:39:46 -0500 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | } // namespace phosphor::fan::control::json |