1 /** 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 26 namespace 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 */ 37 class 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 { 59 buildIDMap(); 60 } 61 62 /** 63 * Returns the chassis in the system. 64 * 65 * @return chassis 66 */ 67 const std::vector<std::unique_ptr<Chassis>>& getChassis() const 68 { 69 return chassis; 70 } 71 72 /** 73 * Returns the IDMap for the system. 74 * 75 * The IDMap provides a mapping from string IDs to the associated Device, 76 * Rail, and Rule objects. 77 * 78 * @return IDMap 79 */ 80 const IDMap& getIDMap() const 81 { 82 return idMap; 83 } 84 85 /** 86 * Returns the rules used to monitor and control regulators in the system. 87 * 88 * @return rules 89 */ 90 const std::vector<std::unique_ptr<Rule>>& getRules() const 91 { 92 return rules; 93 } 94 95 private: 96 /** 97 * Builds the IDMap for the system. 98 * 99 * Adds the Device, Rail, and Rule objects in the system to the map. 100 */ 101 void buildIDMap(); 102 103 /** 104 * Rules used to monitor and control regulators in the system. 105 */ 106 std::vector<std::unique_ptr<Rule>> rules{}; 107 108 /** 109 * Chassis in the system. 110 */ 111 std::vector<std::unique_ptr<Chassis>> chassis{}; 112 113 /** 114 * Mapping from string IDs to the associated Device, Rail, and Rule objects. 115 */ 116 IDMap idMap{}; 117 }; 118 119 } // namespace phosphor::power::regulators 120