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