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