1 /**
2  * Copyright © 2019 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 "configuration.hpp"
19 #include "sensor_monitoring.hpp"
20 
21 #include <memory>
22 #include <string>
23 #include <utility>
24 
25 namespace phosphor::power::regulators
26 {
27 
28 /**
29  * @class Rail
30  *
31  * A voltage rail produced by a voltage regulator.
32  *
33  * Voltage regulators produce one or more rails.  Each rail typically provides a
34  * different output voltage level, such as 1.1V.
35  */
36 class Rail
37 {
38   public:
39     // Specify which compiler-generated methods we want
40     Rail() = delete;
41     Rail(const Rail&) = delete;
42     Rail(Rail&&) = delete;
43     Rail& operator=(const Rail&) = delete;
44     Rail& operator=(Rail&&) = delete;
45     ~Rail() = default;
46 
47     /**
48      * Constructor.
49      *
50      * @param id unique rail ID
51      * @param configuration configuration changes to apply to this rail, if any
52      * @param sensorMonitoring sensor monitoring for this rail, if any
53      */
54     explicit Rail(
55         const std::string& id,
56         std::unique_ptr<Configuration> configuration = nullptr,
57         std::unique_ptr<SensorMonitoring> sensorMonitoring = nullptr) :
58         id{id},
59         configuration{std::move(configuration)}, sensorMonitoring{std::move(
60                                                      sensorMonitoring)}
61     {
62     }
63 
64     /**
65      * Returns the configuration changes to apply to this rail, if any.
66      *
67      * @return Pointer to Configuration object.  Will equal nullptr if no
68      *         configuration changes are defined for this rail.
69      */
70     const std::unique_ptr<Configuration>& getConfiguration() const
71     {
72         return configuration;
73     }
74 
75     /**
76      * Returns the unique ID of this rail.
77      *
78      * @return rail ID
79      */
80     const std::string& getID() const
81     {
82         return id;
83     }
84 
85     /**
86      * Returns the sensor monitoring for this rail, if any.
87      *
88      * @return Pointer to SensorMonitoring object.  Will equal nullptr if no
89      *         sensor monitoring is defined for this rail.
90      */
91     const std::unique_ptr<SensorMonitoring>& getSensorMonitoring() const
92     {
93         return sensorMonitoring;
94     }
95 
96   private:
97     /**
98      * Unique ID of this rail.
99      */
100     const std::string id{};
101 
102     /**
103      * Configuration changes to apply to this rail, if any.  Set to nullptr if
104      * no configuration changes are defined for this rail.
105      */
106     std::unique_ptr<Configuration> configuration{};
107 
108     /**
109      * Sensor monitoring for this rail, if any.  Set to nullptr if no sensor
110      * monitoring is defined for this rail.
111      */
112     std::unique_ptr<SensorMonitoring> sensorMonitoring{};
113 };
114 
115 } // namespace phosphor::power::regulators
116