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