Brad Bishop | dd62e36 | 2017-06-14 16:54:03 -0400 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Brad Bishop | dd62e36 | 2017-06-14 16:54:03 -0400 | [diff] [blame] | 3 | #include "psensor.hpp" |
| 4 | #include "sdbusplus.hpp" |
| 5 | |
Matthew Barth | 2d2caa3 | 2020-05-26 11:07:24 -0500 | [diff] [blame] | 6 | #include <sdbusplus/bus/match.hpp> |
| 7 | #include <sdbusplus/message.hpp> |
| 8 | |
| 9 | #include <string> |
| 10 | #include <vector> |
| 11 | |
Brad Bishop | dd62e36 | 2017-06-14 16:54:03 -0400 | [diff] [blame] | 12 | namespace phosphor |
| 13 | { |
| 14 | namespace fan |
| 15 | { |
| 16 | namespace presence |
| 17 | { |
| 18 | class RedundancyPolicy; |
| 19 | |
| 20 | /** |
| 21 | * @class Tach |
| 22 | * @brief Fan tach sensor presence implementation. |
| 23 | * |
| 24 | * The Tach class uses one or more tach speed indicators |
| 25 | * to determine presence state. |
| 26 | */ |
| 27 | class Tach : public PresenceSensor |
| 28 | { |
Matthew Barth | 2d2caa3 | 2020-05-26 11:07:24 -0500 | [diff] [blame] | 29 | public: |
| 30 | /** |
| 31 | * @brief |
| 32 | * |
| 33 | * Cannot move or copy due to this ptr as context |
| 34 | * for sdbus callbacks. |
| 35 | */ |
| 36 | Tach() = delete; |
| 37 | Tach(const Tach&) = delete; |
| 38 | Tach& operator=(const Tach&) = delete; |
| 39 | Tach(Tach&&) = delete; |
| 40 | Tach& operator=(Tach&&) = delete; |
| 41 | ~Tach() = default; |
Brad Bishop | dd62e36 | 2017-06-14 16:54:03 -0400 | [diff] [blame] | 42 | |
Matthew Barth | 2d2caa3 | 2020-05-26 11:07:24 -0500 | [diff] [blame] | 43 | /** |
| 44 | * @brief ctor |
| 45 | * |
| 46 | * @param[in] sensors - Fan tach sensors for this psensor. |
| 47 | */ |
| 48 | Tach(const std::vector<std::string>& sensors); |
Brad Bishop | dd62e36 | 2017-06-14 16:54:03 -0400 | [diff] [blame] | 49 | |
Matthew Barth | 2d2caa3 | 2020-05-26 11:07:24 -0500 | [diff] [blame] | 50 | /** |
| 51 | * @brief start |
| 52 | * |
| 53 | * Register for dbus signal callbacks on fan |
| 54 | * tach sensor change. Query initial tach speeds. |
| 55 | * |
| 56 | * @return The current sensor state. |
| 57 | */ |
| 58 | bool start() override; |
Brad Bishop | dd62e36 | 2017-06-14 16:54:03 -0400 | [diff] [blame] | 59 | |
Matthew Barth | 2d2caa3 | 2020-05-26 11:07:24 -0500 | [diff] [blame] | 60 | /** |
| 61 | * @brief stop |
| 62 | * |
| 63 | * De-register dbus signal callbacks. |
| 64 | */ |
| 65 | void stop() override; |
Brad Bishop | dd62e36 | 2017-06-14 16:54:03 -0400 | [diff] [blame] | 66 | |
Matthew Barth | 2d2caa3 | 2020-05-26 11:07:24 -0500 | [diff] [blame] | 67 | /** |
| 68 | * @brief Check the sensor. |
| 69 | * |
| 70 | * Query the tach speeds. |
| 71 | */ |
| 72 | bool present() override; |
Brad Bishop | dd62e36 | 2017-06-14 16:54:03 -0400 | [diff] [blame] | 73 | |
Matt Spinler | c65d91d | 2021-04-21 13:09:49 -0500 | [diff] [blame] | 74 | /** |
| 75 | * @brief Called when this presence sensor doesn't agree with other ones. |
| 76 | * |
| 77 | * @param[in] fanInventoryPath - The fan inventory D-Bus object path. |
| 78 | */ |
| 79 | void logConflict(const std::string& fanInventoryPath) const override; |
| 80 | |
Matthew Barth | 2d2caa3 | 2020-05-26 11:07:24 -0500 | [diff] [blame] | 81 | private: |
| 82 | /** |
| 83 | * @brief Get the policy associated with this sensor. |
| 84 | */ |
| 85 | virtual RedundancyPolicy& getPolicy() = 0; |
Brad Bishop | dd62e36 | 2017-06-14 16:54:03 -0400 | [diff] [blame] | 86 | |
Matthew Barth | 2d2caa3 | 2020-05-26 11:07:24 -0500 | [diff] [blame] | 87 | /** |
| 88 | * @brief Properties changed handler for tach sensor updates. |
| 89 | * |
| 90 | * @param[in] sensor - The sensor that changed. |
| 91 | * @param[in] props - The properties that changed. |
| 92 | */ |
Matthew Barth | ad2cd24 | 2020-08-13 13:36:19 -0500 | [diff] [blame] | 93 | void |
| 94 | propertiesChanged(size_t sensor, |
| 95 | const phosphor::fan::util::Properties<double>& props); |
Brad Bishop | dd62e36 | 2017-06-14 16:54:03 -0400 | [diff] [blame] | 96 | |
Matthew Barth | 2d2caa3 | 2020-05-26 11:07:24 -0500 | [diff] [blame] | 97 | /** |
| 98 | * @brief Properties changed handler for tach sensor updates. |
| 99 | * |
| 100 | * @param[in] sensor - The sensor that changed. |
| 101 | * @param[in] msg - The sdbusplus signal message. |
| 102 | */ |
Patrick Williams | cb356d4 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 103 | void propertiesChanged(size_t sensor, sdbusplus::message_t& msg); |
Brad Bishop | dd62e36 | 2017-06-14 16:54:03 -0400 | [diff] [blame] | 104 | |
Matthew Barth | 2d2caa3 | 2020-05-26 11:07:24 -0500 | [diff] [blame] | 105 | /** @brief array of tach sensors dbus matches, and tach values. */ |
Patrick Williams | cb356d4 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 106 | std::vector<std::tuple<std::string, |
| 107 | std::unique_ptr<sdbusplus::bus::match_t>, double>> |
Matthew Barth | 2d2caa3 | 2020-05-26 11:07:24 -0500 | [diff] [blame] | 108 | state; |
Brad Bishop | dd62e36 | 2017-06-14 16:54:03 -0400 | [diff] [blame] | 109 | |
Matthew Barth | 2d2caa3 | 2020-05-26 11:07:24 -0500 | [diff] [blame] | 110 | /** The current state of the sensor. */ |
| 111 | bool currentState; |
Brad Bishop | dd62e36 | 2017-06-14 16:54:03 -0400 | [diff] [blame] | 112 | }; |
| 113 | |
| 114 | } // namespace presence |
| 115 | } // namespace fan |
| 116 | } // namespace phosphor |