blob: f678658a67be531ce13a490bcafbdd37f8c828ea [file] [log] [blame]
Shawn McCarneyc3991f12020-04-05 13:16:06 -05001/**
2 * Copyright © 2020 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 "chassis.hpp"
19#include "id_map.hpp"
20#include "rule.hpp"
21
22#include <memory>
23#include <utility>
24#include <vector>
25
26namespace phosphor::power::regulators
27{
28
29/**
30 * @class System
31 *
32 * The computer system being controlled and monitored by the BMC.
33 *
34 * The system contains one or more chassis. Chassis are large enclosures that
35 * can be independently powered off and on by the BMC.
36 */
37class System
38{
39 public:
40 // Specify which compiler-generated methods we want
41 System() = delete;
42 System(const System&) = delete;
43 System(System&&) = delete;
44 System& operator=(const System&) = delete;
45 System& operator=(System&&) = delete;
46 ~System() = default;
47
48 /**
49 * Constructor.
50 *
51 * @param rules rules used to monitor and control regulators in the system
52 * @param chassis chassis in the system
53 */
54 explicit System(std::vector<std::unique_ptr<Rule>> rules,
55 std::vector<std::unique_ptr<Chassis>> chassis) :
56 rules{std::move(rules)},
57 chassis{std::move(chassis)}
58 {
Shawn McCarneydb0b8332020-04-06 14:13:04 -050059 buildIDMap();
Shawn McCarneyc3991f12020-04-05 13:16:06 -050060 }
61
62 /**
Shawn McCarney5b19ea52020-06-02 18:52:56 -050063 * Close the regulator devices in the system.
64 */
65 void closeDevices();
66
67 /**
Shawn McCarney2af52892020-04-14 11:54:45 -050068 * Configure the regulator devices in the system.
69 *
70 * This method should be called during the boot before regulators are
71 * enabled.
72 */
73 void configure();
74
75 /**
Shawn McCarneyc3991f12020-04-05 13:16:06 -050076 * Returns the chassis in the system.
77 *
78 * @return chassis
79 */
80 const std::vector<std::unique_ptr<Chassis>>& getChassis() const
81 {
82 return chassis;
83 }
84
85 /**
86 * Returns the IDMap for the system.
87 *
88 * The IDMap provides a mapping from string IDs to the associated Device,
89 * Rail, and Rule objects.
90 *
91 * @return IDMap
92 */
93 const IDMap& getIDMap() const
94 {
95 return idMap;
96 }
97
98 /**
99 * Returns the rules used to monitor and control regulators in the system.
100 *
101 * @return rules
102 */
103 const std::vector<std::unique_ptr<Rule>>& getRules() const
104 {
105 return rules;
106 }
107
Bob King8e2294d2020-07-14 17:41:31 +0800108 /**
109 * Monitors the sensors for the voltage rails produced by this system, if
110 * any.
111 *
112 * This method should be called once per second.
113 */
114 void monitorSensors();
115
Shawn McCarneyc3991f12020-04-05 13:16:06 -0500116 private:
117 /**
Shawn McCarneydb0b8332020-04-06 14:13:04 -0500118 * Builds the IDMap for the system.
119 *
120 * Adds the Device, Rail, and Rule objects in the system to the map.
121 */
122 void buildIDMap();
123
124 /**
Shawn McCarneyc3991f12020-04-05 13:16:06 -0500125 * Rules used to monitor and control regulators in the system.
126 */
127 std::vector<std::unique_ptr<Rule>> rules{};
128
129 /**
130 * Chassis in the system.
131 */
132 std::vector<std::unique_ptr<Chassis>> chassis{};
133
134 /**
135 * Mapping from string IDs to the associated Device, Rail, and Rule objects.
136 */
137 IDMap idMap{};
138};
139
140} // namespace phosphor::power::regulators