Shawn McCarney | 8a3afd7 | 2020-03-12 14:28:44 -0500 | [diff] [blame] | 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 "device.hpp" |
| 19 | |
| 20 | #include <memory> |
| 21 | #include <stdexcept> |
| 22 | #include <string> |
| 23 | #include <utility> |
| 24 | #include <vector> |
| 25 | |
| 26 | namespace phosphor::power::regulators |
| 27 | { |
| 28 | |
| 29 | /** |
| 30 | * @class Chassis |
| 31 | * |
| 32 | * A chassis within the system. |
| 33 | * |
| 34 | * Chassis are large enclosures that can be independently powered off and on by |
| 35 | * the BMC. Small and mid-sized systems may contain a single chassis. In a |
| 36 | * large rack-mounted system, each drawer may correspond to a chassis. |
| 37 | * |
| 38 | * A C++ Chassis object only needs to be created if the physical chassis |
| 39 | * contains regulators that need to be configured or monitored. |
| 40 | */ |
| 41 | class Chassis |
| 42 | { |
| 43 | public: |
| 44 | // Specify which compiler-generated methods we want |
| 45 | Chassis() = delete; |
| 46 | Chassis(const Chassis&) = delete; |
| 47 | Chassis(Chassis&&) = delete; |
| 48 | Chassis& operator=(const Chassis&) = delete; |
| 49 | Chassis& operator=(Chassis&&) = delete; |
| 50 | ~Chassis() = default; |
| 51 | |
| 52 | /** |
| 53 | * Constructor. |
| 54 | * |
| 55 | * Throws an exception if any of the input parameters are invalid. |
| 56 | * |
| 57 | * @param number Chassis number within the system. Chassis numbers start at |
| 58 | * 1 because chassis 0 represents the entire system. |
| 59 | * @param devices Devices within this chassis, if any. The vector should |
| 60 | * contain regulator devices and any related devices required |
| 61 | * to perform regulator operations. |
| 62 | */ |
| 63 | explicit Chassis(unsigned int number, |
| 64 | std::vector<std::unique_ptr<Device>> devices = |
| 65 | std::vector<std::unique_ptr<Device>>{}) : |
| 66 | number{number}, |
| 67 | devices{std::move(devices)} |
| 68 | { |
| 69 | if (number < 1) |
| 70 | { |
| 71 | throw std::invalid_argument{"Invalid chassis number: " + |
| 72 | std::to_string(number)}; |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * Returns the devices within this chassis, if any. |
| 78 | * |
| 79 | * The vector contains regulator devices and any related devices |
| 80 | * required to perform regulator operations. |
| 81 | * |
| 82 | * @return devices in chassis |
| 83 | */ |
| 84 | const std::vector<std::unique_ptr<Device>>& getDevices() const |
| 85 | { |
| 86 | return devices; |
| 87 | } |
| 88 | |
| 89 | /** |
| 90 | * Returns the chassis number within the system. |
| 91 | * |
| 92 | * @return chassis number |
| 93 | */ |
| 94 | unsigned int getNumber() const |
| 95 | { |
| 96 | return number; |
| 97 | } |
| 98 | |
| 99 | private: |
| 100 | /** |
| 101 | * Chassis number within the system. |
| 102 | * |
| 103 | * Chassis numbers start at 1 because chassis 0 represents the entire |
| 104 | * system. |
| 105 | */ |
| 106 | const unsigned int number{}; |
| 107 | |
| 108 | /** |
| 109 | * Devices within this chassis, if any. |
| 110 | * |
| 111 | * The vector contains regulator devices and any related devices |
| 112 | * required to perform regulator operations. |
| 113 | */ |
| 114 | std::vector<std::unique_ptr<Device>> devices{}; |
| 115 | }; |
| 116 | |
| 117 | } // namespace phosphor::power::regulators |