blob: 360cc17a04b9d2f51c891c4bf6df3e9e3e72e278 [file] [log] [blame]
Matthew Barth0c4b1572020-10-22 14:39:46 -05001/**
Matthew Barth41a34082021-01-27 15:31:48 -06002 * Copyright © 2021 IBM Corporation
Matthew Barth0c4b1572020-10-22 14:39:46 -05003 *
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 Barth12cb1252021-03-08 16:47:30 -060018#include "../manager.hpp"
19#include "../zone.hpp"
20#include "group.hpp"
Matthew Barth0c4b1572020-10-22 14:39:46 -050021
22#include <nlohmann/json.hpp>
23
Matthew Barth41a34082021-01-27 15:31:48 -060024#include <algorithm>
Matthew Barth41a34082021-01-27 15:31:48 -060025
Matthew Barth0c4b1572020-10-22 14:39:46 -050026namespace phosphor::fan::control::json
27{
28
29using json = nlohmann::json;
30
Matthew Barth19c77492021-04-08 10:06:06 -050031DefaultFloor::DefaultFloor(const json& jsonObj,
32 const std::vector<Group>& groups) :
33 ActionBase(jsonObj, groups)
Matthew Barth0c4b1572020-10-22 14:39:46 -050034{
Matthew Barth41a34082021-01-27 15:31:48 -060035 // There are no JSON configuration parameters for this action
Matthew Barth0c4b1572020-10-22 14:39:46 -050036}
37
Matthew Barth41a34082021-01-27 15:31:48 -060038void DefaultFloor::run(Zone& zone, const Group& group)
Matthew Barth0c4b1572020-10-22 14:39:46 -050039{
Matthew Barth12cb1252021-03-08 16:47:30 -060040 const auto& members = group.getMembers();
41 auto isMissingOwner =
42 std::any_of(members.begin(), members.end(),
43 [&intf = group.getInterface()](const auto& member) {
44 return !Manager::hasOwner(member, intf);
45 });
46 if (isMissingOwner)
Matthew Barth41a34082021-01-27 15:31:48 -060047 {
Matthew Barth12cb1252021-03-08 16:47:30 -060048 zone.setFloor(zone.getDefaultFloor());
Matthew Barth41a34082021-01-27 15:31:48 -060049 }
50 // Update fan control floor change allowed
Matthew Barth12cb1252021-03-08 16:47:30 -060051 zone.setFloorChangeAllow(group.getName(), !isMissingOwner);
Matthew Barth0c4b1572020-10-22 14:39:46 -050052}
53
54} // namespace phosphor::fan::control::json