xref: /openbmc/phosphor-fan-presence/control/json/actions/default_floor.cpp (revision dfddd648cb81b27492afead4e2346f5fcd1397cb)
10c4b1574SMatthew Barth /**
241a3408dSMatthew Barth  * Copyright © 2021 IBM Corporation
30c4b1574SMatthew Barth  *
40c4b1574SMatthew Barth  * Licensed under the Apache License, Version 2.0 (the "License");
50c4b1574SMatthew Barth  * you may not use this file except in compliance with the License.
60c4b1574SMatthew Barth  * You may obtain a copy of the License at
70c4b1574SMatthew Barth  *
80c4b1574SMatthew Barth  *     http://www.apache.org/licenses/LICENSE-2.0
90c4b1574SMatthew Barth  *
100c4b1574SMatthew Barth  * Unless required by applicable law or agreed to in writing, software
110c4b1574SMatthew Barth  * distributed under the License is distributed on an "AS IS" BASIS,
120c4b1574SMatthew Barth  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
130c4b1574SMatthew Barth  * See the License for the specific language governing permissions and
140c4b1574SMatthew Barth  * limitations under the License.
150c4b1574SMatthew Barth  */
160c4b1574SMatthew Barth #include "default_floor.hpp"
170c4b1574SMatthew Barth 
1812cb125aSMatthew Barth #include "../manager.hpp"
1912cb125aSMatthew Barth #include "../zone.hpp"
2012cb125aSMatthew Barth #include "group.hpp"
210c4b1574SMatthew Barth 
220c4b1574SMatthew Barth #include <nlohmann/json.hpp>
230c4b1574SMatthew Barth 
2441a3408dSMatthew Barth #include <algorithm>
2541a3408dSMatthew Barth 
260c4b1574SMatthew Barth namespace phosphor::fan::control::json
270c4b1574SMatthew Barth {
280c4b1574SMatthew Barth 
290c4b1574SMatthew Barth using json = nlohmann::json;
300c4b1574SMatthew Barth 
DefaultFloor(const json & jsonObj,const std::vector<Group> & groups)3119c77494SMatthew Barth DefaultFloor::DefaultFloor(const json& jsonObj,
3219c77494SMatthew Barth                            const std::vector<Group>& groups) :
3319c77494SMatthew Barth     ActionBase(jsonObj, groups)
340c4b1574SMatthew Barth {
3541a3408dSMatthew Barth     // There are no JSON configuration parameters for this action
360c4b1574SMatthew Barth }
370c4b1574SMatthew Barth 
run(Zone & zone)38*6d2476c9SMatthew Barth void DefaultFloor::run(Zone& zone)
39*6d2476c9SMatthew Barth {
40*6d2476c9SMatthew Barth     for (const auto& group : _groups)
410c4b1574SMatthew Barth     {
4212cb125aSMatthew Barth         const auto& members = group.getMembers();
4312cb125aSMatthew Barth         auto isMissingOwner =
4412cb125aSMatthew Barth             std::any_of(members.begin(), members.end(),
4512cb125aSMatthew Barth                         [&intf = group.getInterface()](const auto& member) {
4612cb125aSMatthew Barth                             return !Manager::hasOwner(member, intf);
4712cb125aSMatthew Barth                         });
4812cb125aSMatthew Barth         if (isMissingOwner)
4941a3408dSMatthew Barth         {
5012cb125aSMatthew Barth             zone.setFloor(zone.getDefaultFloor());
5141a3408dSMatthew Barth         }
5241a3408dSMatthew Barth         // Update fan control floor change allowed
5312cb125aSMatthew Barth         zone.setFloorChangeAllow(group.getName(), !isMissingOwner);
540c4b1574SMatthew Barth     }
55*6d2476c9SMatthew Barth }
560c4b1574SMatthew Barth 
570c4b1574SMatthew Barth } // namespace phosphor::fan::control::json
58