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 "action.hpp"
19 
20 #include <memory>
21 #include <utility>
22 #include <vector>
23 
24 namespace phosphor::power::regulators
25 {
26 
27 // Forward declarations to avoid circular dependencies
28 class Chassis;
29 class Device;
30 class Rail;
31 class System;
32 
33 /**
34  * @class SensorMonitoring
35  *
36  * Defines how to read the sensors for a voltage rail, such as voltage output,
37  * current output, and temperature.
38  *
39  * Sensor values are measured, actual values rather than target values.
40  *
41  * Sensors are read once per second.  The sensor values are stored on D-Bus,
42  * making them available to external interfaces like Redfish.
43  *
44  * Sensors are read by executing actions, such as PMBusReadSensorAction.  To
45  * read multiple sensors for a rail, multiple actions need to be executed.
46  */
47 class SensorMonitoring
48 {
49   public:
50     // Specify which compiler-generated methods we want
51     SensorMonitoring() = delete;
52     SensorMonitoring(const SensorMonitoring&) = delete;
53     SensorMonitoring(SensorMonitoring&&) = delete;
54     SensorMonitoring& operator=(const SensorMonitoring&) = delete;
55     SensorMonitoring& operator=(SensorMonitoring&&) = delete;
56     ~SensorMonitoring() = default;
57 
58     /**
59      * Constructor.
60      *
61      * @param actions actions that read the sensors for a rail
62      */
63     explicit SensorMonitoring(std::vector<std::unique_ptr<Action>> actions) :
64         actions{std::move(actions)}
65     {
66     }
67 
68     /**
69      * Executes the actions to read the sensors for a rail.
70      *
71      * @param system system that contains the chassis
72      * @param chassis chassis that contains the device
73      * @param device device that contains the rail
74      * @param rail rail associated with the sensors
75      */
76     void execute(System& system, Chassis& chassis, Device& device, Rail& rail);
77 
78     /**
79      * Returns the actions that read the sensors for a rail.
80      *
81      * @return actions
82      */
83     const std::vector<std::unique_ptr<Action>>& getActions() const
84     {
85         return actions;
86     }
87 
88   private:
89     /**
90      * Actions that read the sensors for a rail.
91      */
92     std::vector<std::unique_ptr<Action>> actions{};
93 };
94 
95 } // namespace phosphor::power::regulators
96