1 #pragma once 2 3 #include "fan.hpp" 4 #include "power_state.hpp" 5 6 #include <nlohmann/json.hpp> 7 #include <sdbusplus/bus.hpp> 8 #include <sdbusplus/bus/match.hpp> 9 #include <sdeventplus/clock.hpp> 10 #include <sdeventplus/utility/timer.hpp> 11 12 namespace phosphor::fan::presence 13 { 14 class PresenceSensor; 15 16 /** 17 * @class ErrorReporter 18 * 19 * This class will create event logs for missing fans. The logs are 20 * created after a fan has been missing for an amount of time 21 * specified in the JSON config file while power is on. 22 * 23 * The timers to create event logs are not started when power is off. 24 * When power is turned on, the timers for any missing fans will be 25 * be started. If any timers are running when power is turned off, 26 * they will be stopped. 27 */ 28 class ErrorReporter 29 { 30 public: 31 ErrorReporter() = delete; 32 ~ErrorReporter() = default; 33 ErrorReporter(const ErrorReporter&) = delete; 34 ErrorReporter& operator=(const ErrorReporter&) = delete; 35 ErrorReporter(ErrorReporter&&) = delete; 36 ErrorReporter& operator=(ErrorReporter&&) = delete; 37 38 /** 39 * @brief Constructor 40 * 41 * @param[in] bus - The sdbusplus bus object 42 * @param[in] fans - The fans for this configuration 43 */ 44 ErrorReporter( 45 sdbusplus::bus_t& bus, 46 const std::vector<std::tuple< 47 Fan, std::vector<std::unique_ptr<PresenceSensor>>>>& fans); 48 49 private: 50 /** 51 * @brief The propertiesChanged callback for the interface that 52 * contains the Present property of a fan. 53 * 54 * Will start the timer to create an event log if power is on. 55 * 56 * @param[in] msg - The payload of the propertiesChanged signal 57 */ 58 void presenceChanged(sdbusplus::message_t& msg); 59 60 /** 61 * @brief The callback function called by the PowerState class 62 * when the power state changes. 63 * 64 * Will start timers for missing fans if power is on, and stop 65 * them when power changes to off. 66 * 67 * @param[in] powerState - The new power state 68 */ 69 void powerStateChanged(bool powerState); 70 71 /** 72 * @brief Called when the fan missing timer expires to create 73 * an event log for a missing fan. 74 * 75 * @param[in] fanPath - The D-Bus path of the missing fan. 76 */ 77 void fanMissingTimerExpired(const std::string& fanPath); 78 79 /** 80 * @brief Checks if the fan missing timer for a fan needs to 81 * either be started or stopped based on the power and 82 * presence states. 83 * 84 * @param[in] fanPath - The D-Bus path of the fan 85 */ 86 void checkFan(const std::string& fanPath); 87 88 /** 89 * @brief Reference to the D-Bus connection object. 90 */ 91 sdbusplus::bus_t& _bus; 92 93 /** 94 * @brief The connection to the event loop for the timer. 95 */ 96 sdeventplus::Event _event; 97 98 /** 99 * @brief The propertiesChanged match objects. 100 */ 101 std::vector<sdbusplus::bus::match_t> _matches; 102 103 /** 104 * @brief Base class pointer to the power state implementation. 105 */ 106 std::shared_ptr<PowerState> _powerState; 107 108 /** 109 * @brief The map of fan paths to their presence states. 110 */ 111 std::map<std::string, bool> _fanStates; 112 113 /** 114 * @brief The map of fan paths to their Timer objects with 115 * the timer expiration time. 116 */ 117 std::map<std::string, 118 std::tuple<std::unique_ptr<sdeventplus::utility::Timer< 119 sdeventplus::ClockId::Monotonic>>, 120 std::chrono::seconds>> 121 _fanMissingTimers; 122 }; 123 124 } // namespace phosphor::fan::presence 125