Matt Spinler | e812239 | 2020-09-24 13:22:18 -0500 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include "fan.hpp" |
Matt Spinler | 0dc85ee | 2020-09-24 14:07:02 -0500 | [diff] [blame] | 4 | #include "power_state.hpp" |
Matt Spinler | e812239 | 2020-09-24 13:22:18 -0500 | [diff] [blame] | 5 | |
| 6 | #include <nlohmann/json.hpp> |
| 7 | #include <sdbusplus/bus.hpp> |
Matt Spinler | 0dc85ee | 2020-09-24 14:07:02 -0500 | [diff] [blame] | 8 | #include <sdbusplus/bus/match.hpp> |
| 9 | #include <sdeventplus/clock.hpp> |
| 10 | #include <sdeventplus/utility/timer.hpp> |
Matt Spinler | e812239 | 2020-09-24 13:22:18 -0500 | [diff] [blame] | 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 |
Matt Spinler | e812239 | 2020-09-24 13:22:18 -0500 | [diff] [blame] | 42 | * @param[in] fans - The fans for this configuration |
| 43 | */ |
| 44 | ErrorReporter( |
Patrick Williams | cb356d4 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 45 | sdbusplus::bus_t& bus, |
Patrick Williams | dfddd64 | 2024-08-16 15:21:51 -0400 | [diff] [blame^] | 46 | const std::vector<std::tuple< |
| 47 | Fan, std::vector<std::unique_ptr<PresenceSensor>>>>& fans); |
Matt Spinler | e812239 | 2020-09-24 13:22:18 -0500 | [diff] [blame] | 48 | |
| 49 | private: |
| 50 | /** |
Matt Spinler | 0dc85ee | 2020-09-24 14:07:02 -0500 | [diff] [blame] | 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 | */ |
Patrick Williams | cb356d4 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 58 | void presenceChanged(sdbusplus::message_t& msg); |
Matt Spinler | 0dc85ee | 2020-09-24 14:07:02 -0500 | [diff] [blame] | 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 | /** |
Matt Spinler | e812239 | 2020-09-24 13:22:18 -0500 | [diff] [blame] | 89 | * @brief Reference to the D-Bus connection object. |
| 90 | */ |
Patrick Williams | cb356d4 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 91 | sdbusplus::bus_t& _bus; |
Matt Spinler | e812239 | 2020-09-24 13:22:18 -0500 | [diff] [blame] | 92 | |
| 93 | /** |
Matt Spinler | 0dc85ee | 2020-09-24 14:07:02 -0500 | [diff] [blame] | 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 | */ |
Patrick Williams | cb356d4 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 101 | std::vector<sdbusplus::bus::match_t> _matches; |
Matt Spinler | 0dc85ee | 2020-09-24 14:07:02 -0500 | [diff] [blame] | 102 | |
| 103 | /** |
| 104 | * @brief Base class pointer to the power state implementation. |
| 105 | */ |
Matt Spinler | 76e73c2 | 2021-04-21 11:03:05 -0500 | [diff] [blame] | 106 | std::shared_ptr<PowerState> _powerState; |
Matt Spinler | 0dc85ee | 2020-09-24 14:07:02 -0500 | [diff] [blame] | 107 | |
| 108 | /** |
Matt Spinler | 0dc85ee | 2020-09-24 14:07:02 -0500 | [diff] [blame] | 109 | * @brief The map of fan paths to their presence states. |
| 110 | */ |
| 111 | std::map<std::string, bool> _fanStates; |
| 112 | |
| 113 | /** |
Matt Spinler | 9e9f599 | 2020-09-30 08:29:24 -0500 | [diff] [blame] | 114 | * @brief The map of fan paths to their Timer objects with |
| 115 | * the timer expiration time. |
Matt Spinler | 0dc85ee | 2020-09-24 14:07:02 -0500 | [diff] [blame] | 116 | */ |
Matt Spinler | 9e9f599 | 2020-09-30 08:29:24 -0500 | [diff] [blame] | 117 | std::map<std::string, |
| 118 | std::tuple<std::unique_ptr<sdeventplus::utility::Timer< |
| 119 | sdeventplus::ClockId::Monotonic>>, |
| 120 | std::chrono::seconds>> |
Matt Spinler | 0dc85ee | 2020-09-24 14:07:02 -0500 | [diff] [blame] | 121 | _fanMissingTimers; |
Matt Spinler | e812239 | 2020-09-24 13:22:18 -0500 | [diff] [blame] | 122 | }; |
| 123 | |
| 124 | } // namespace phosphor::fan::presence |