blob: fcb02a5b3a41d4b580034e496d01183e77bcd6f9 [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 *
Shawn McCarney54b3ab92021-09-14 17:28:56 -050043 * Sensors are read repeatedly based on a timer. The sensor values are stored
44 * on D-Bus, making them available to external interfaces like Redfish.
Shawn McCarneybc47c1b2020-03-10 15:38:07 -050045 *
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)}
Adriana Kobylak0c9a33d2021-09-13 18:05:09 +000067 {}
Shawn McCarneybc47c1b2020-03-10 15:38:07 -050068
69 /**
Shawn McCarney17bac892021-05-08 07:55:52 -050070 * Clears all error history.
71 *
72 * All data on previously logged errors will be deleted. If errors occur
73 * again in the future they will be logged again.
74 *
75 * This method is normally called when the system is being powered on.
76 */
77 void clearErrorHistory()
78 {
79 errorHistory.clear();
80 errorCount = 0;
81 }
82
83 /**
Shawn McCarneybc47c1b2020-03-10 15:38:07 -050084 * Executes the actions to read the sensors for a rail.
Bob King833b8e02020-06-11 14:56:38 +080085 *
Bob King8a552922020-08-05 17:02:31 +080086 * @param services system services like error logging and the journal
Bob King833b8e02020-06-11 14:56:38 +080087 * @param system system that contains the chassis
88 * @param chassis chassis that contains the device
89 * @param device device that contains the rail
90 * @param rail rail associated with the sensors
Shawn McCarneybc47c1b2020-03-10 15:38:07 -050091 */
Bob King8a552922020-08-05 17:02:31 +080092 void execute(Services& services, System& system, Chassis& chassis,
93 Device& device, Rail& rail);
Shawn McCarneybc47c1b2020-03-10 15:38:07 -050094
95 /**
96 * Returns the actions that read the sensors for a rail.
97 *
98 * @return actions
99 */
100 const std::vector<std::unique_ptr<Action>>& getActions() const
101 {
102 return actions;
103 }
104
105 private:
106 /**
107 * Actions that read the sensors for a rail.
108 */
109 std::vector<std::unique_ptr<Action>> actions{};
Shawn McCarney17bac892021-05-08 07:55:52 -0500110
111 /**
112 * History of which error types have been logged.
113 *
114 * Since sensor monitoring runs repeatedly based on a timer, each error type
115 * is only logged once.
116 */
117 ErrorHistory errorHistory{};
118
119 /**
120 * Number of errors that have occurred.
121 */
122 unsigned int errorCount{0};
Shawn McCarneybc47c1b2020-03-10 15:38:07 -0500123};
124
125} // namespace phosphor::power::regulators