xref: /openbmc/phosphor-fan-presence/control/manager.cpp (revision 57352a312680c62f231f9c4496b636bad10ef743)
1e10416ecSMatt Spinler /**
2e10416ecSMatt Spinler  * Copyright © 2017 IBM Corporation
3e10416ecSMatt Spinler  *
4e10416ecSMatt Spinler  * Licensed under the Apache License, Version 2.0 (the "License");
5e10416ecSMatt Spinler  * you may not use this file except in compliance with the License.
6e10416ecSMatt Spinler  * You may obtain a copy of the License at
7e10416ecSMatt Spinler  *
8e10416ecSMatt Spinler  *     http://www.apache.org/licenses/LICENSE-2.0
9e10416ecSMatt Spinler  *
10e10416ecSMatt Spinler  * Unless required by applicable law or agreed to in writing, software
11e10416ecSMatt Spinler  * distributed under the License is distributed on an "AS IS" BASIS,
12e10416ecSMatt Spinler  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13e10416ecSMatt Spinler  * See the License for the specific language governing permissions and
14e10416ecSMatt Spinler  * limitations under the License.
15e10416ecSMatt Spinler  */
16*57352a31SMatt Spinler #include <algorithm>
17e10416ecSMatt Spinler #include "manager.hpp"
18e10416ecSMatt Spinler 
19e10416ecSMatt Spinler namespace phosphor
20e10416ecSMatt Spinler {
21e10416ecSMatt Spinler namespace fan
22e10416ecSMatt Spinler {
23e10416ecSMatt Spinler namespace control
24e10416ecSMatt Spinler {
25e10416ecSMatt Spinler 
26e10416ecSMatt Spinler Manager::Manager(sdbusplus::bus::bus& bus) :
27e10416ecSMatt Spinler     _bus(bus)
28e10416ecSMatt Spinler {
29*57352a31SMatt Spinler     //Create the appropriate Zone objects based on the
30*57352a31SMatt Spinler     //actual system configuration.
31*57352a31SMatt Spinler 
32*57352a31SMatt Spinler     //Find the 1 ZoneGroup that meets all of its conditions
33*57352a31SMatt Spinler     for (auto& group : _zoneLayouts)
34*57352a31SMatt Spinler     {
35*57352a31SMatt Spinler         auto& conditions = std::get<conditionListPos>(group);
36*57352a31SMatt Spinler 
37*57352a31SMatt Spinler         if (std::all_of(conditions.begin(), conditions.end(),
38*57352a31SMatt Spinler                         [](const auto& c)
39*57352a31SMatt Spinler                         {
40*57352a31SMatt Spinler                             //TODO: openbmc/openbmc#1500
41*57352a31SMatt Spinler                             //Still need to actually evaluate the conditions
42*57352a31SMatt Spinler                             return true;
43*57352a31SMatt Spinler                         }))
44*57352a31SMatt Spinler         {
45*57352a31SMatt Spinler             //Create a Zone object for each zone in this group
46*57352a31SMatt Spinler             auto& zones = std::get<zoneListPos>(group);
47*57352a31SMatt Spinler 
48*57352a31SMatt Spinler             for (auto& z : zones)
49*57352a31SMatt Spinler             {
50*57352a31SMatt Spinler                 _zones.emplace(std::get<zoneNumPos>(z),
51*57352a31SMatt Spinler                                std::make_unique<Zone>(_bus, z));
52*57352a31SMatt Spinler             }
53*57352a31SMatt Spinler 
54*57352a31SMatt Spinler             break;
55*57352a31SMatt Spinler         }
56*57352a31SMatt Spinler     }
57*57352a31SMatt Spinler 
58*57352a31SMatt Spinler     //Set to full since we don't know state of system yet.
59*57352a31SMatt Spinler     for (auto& z: _zones)
60*57352a31SMatt Spinler     {
61*57352a31SMatt Spinler         z.second->setFullSpeed();
62*57352a31SMatt Spinler     }
63e10416ecSMatt Spinler }
64e10416ecSMatt Spinler 
65e10416ecSMatt Spinler 
66e10416ecSMatt Spinler }
67e10416ecSMatt Spinler }
68e10416ecSMatt Spinler }
69