blob: 0254fb2b7864548419d27ca506d56c93a9944670 [file] [log] [blame]
Shawn McCarneybc47c1b2020-03-10 15:38:07 -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 "action.hpp"
Shawn McCarney17bac892021-05-08 07:55:52 -050019#include "error_history.hpp"
Bob King8a552922020-08-05 17:02:31 +080020#include "services.hpp"
Shawn McCarneybc47c1b2020-03-10 15:38:07 -050021
22#include <memory>
23#include <utility>
24#include <vector>
25
26namespace phosphor::power::regulators
27{
28
Bob King833b8e02020-06-11 14:56:38 +080029// Forward declarations to avoid circular dependencies
30class Chassis;
31class Device;
32class Rail;
33class System;
34
Shawn McCarneybc47c1b2020-03-10 15:38:07 -050035/**
36 * @class SensorMonitoring
37 *
38 * Defines how to read the sensors for a voltage rail, such as voltage output,
39 * current output, and temperature.
40 *
41 * Sensor values are measured, actual values rather than target values.
42 *
43 * Sensors are read once per second. The sensor values are stored on D-Bus,
44 * making them available to external interfaces like Redfish.
45 *
46 * Sensors are read by executing actions, such as PMBusReadSensorAction. To
47 * read multiple sensors for a rail, multiple actions need to be executed.
48 */
49class SensorMonitoring
50{
51 public:
52 // Specify which compiler-generated methods we want
53 SensorMonitoring() = delete;
54 SensorMonitoring(const SensorMonitoring&) = delete;
55 SensorMonitoring(SensorMonitoring&&) = delete;
56 SensorMonitoring& operator=(const SensorMonitoring&) = delete;
57 SensorMonitoring& operator=(SensorMonitoring&&) = delete;
58 ~SensorMonitoring() = default;
59
60 /**
61 * Constructor.
62 *
63 * @param actions actions that read the sensors for a rail
64 */
65 explicit SensorMonitoring(std::vector<std::unique_ptr<Action>> actions) :
66 actions{std::move(actions)}
67 {
68 }
69
70 /**
Shawn McCarney17bac892021-05-08 07:55:52 -050071 * Clears all error history.
72 *
73 * All data on previously logged errors will be deleted. If errors occur
74 * again in the future they will be logged again.
75 *
76 * This method is normally called when the system is being powered on.
77 */
78 void clearErrorHistory()
79 {
80 errorHistory.clear();
81 errorCount = 0;
82 }
83
84 /**
Shawn McCarneybc47c1b2020-03-10 15:38:07 -050085 * Executes the actions to read the sensors for a rail.
Bob King833b8e02020-06-11 14:56:38 +080086 *
Bob King8a552922020-08-05 17:02:31 +080087 * @param services system services like error logging and the journal
Bob King833b8e02020-06-11 14:56:38 +080088 * @param system system that contains the chassis
89 * @param chassis chassis that contains the device
90 * @param device device that contains the rail
91 * @param rail rail associated with the sensors
Shawn McCarneybc47c1b2020-03-10 15:38:07 -050092 */
Bob King8a552922020-08-05 17:02:31 +080093 void execute(Services& services, System& system, Chassis& chassis,
94 Device& device, Rail& rail);
Shawn McCarneybc47c1b2020-03-10 15:38:07 -050095
96 /**
97 * Returns the actions that read the sensors for a rail.
98 *
99 * @return actions
100 */
101 const std::vector<std::unique_ptr<Action>>& getActions() const
102 {
103 return actions;
104 }
105
106 private:
107 /**
108 * Actions that read the sensors for a rail.
109 */
110 std::vector<std::unique_ptr<Action>> actions{};
Shawn McCarney17bac892021-05-08 07:55:52 -0500111
112 /**
113 * History of which error types have been logged.
114 *
115 * Since sensor monitoring runs repeatedly based on a timer, each error type
116 * is only logged once.
117 */
118 ErrorHistory errorHistory{};
119
120 /**
121 * Number of errors that have occurred.
122 */
123 unsigned int errorCount{0};
Shawn McCarneybc47c1b2020-03-10 15:38:07 -0500124};
125
126} // namespace phosphor::power::regulators