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 #include "error_history.hpp" 20 #include "services.hpp" 21 22 #include <memory> 23 #include <utility> 24 #include <vector> 25 26 namespace phosphor::power::regulators 27 { 28 29 // Forward declarations to avoid circular dependencies 30 class Chassis; 31 class Device; 32 class Rail; 33 class System; 34 35 /** 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 repeatedly based on a timer. The sensor values are stored 44 * on D-Bus, 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 */ 49 class 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 * 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 /** 84 * Executes the actions to read the sensors for a rail. 85 * 86 * @param services system services like error logging and the journal 87 * @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 91 */ 92 void execute(Services& services, System& system, Chassis& chassis, 93 Device& device, Rail& rail); 94 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{}; 110 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 consecutive errors that have occurred. 121 */ 122 unsigned short errorCount{0}; 123 }; 124 125 } // namespace phosphor::power::regulators 126