1 #pragma once 2 3 #include "psensor.hpp" 4 #include "sdbusplus.hpp" 5 6 #include <sdbusplus/bus/match.hpp> 7 #include <sdbusplus/message.hpp> 8 9 #include <string> 10 #include <vector> 11 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 { 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; 42 43 /** 44 * @brief ctor 45 * 46 * @param[in] sensors - Fan tach sensors for this psensor. 47 */ 48 Tach(const std::vector<std::string>& sensors); 49 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; 59 60 /** 61 * @brief stop 62 * 63 * De-register dbus signal callbacks. 64 */ 65 void stop() override; 66 67 /** 68 * @brief Check the sensor. 69 * 70 * Query the tach speeds. 71 */ 72 bool present() override; 73 74 private: 75 /** 76 * @brief Get the policy associated with this sensor. 77 */ 78 virtual RedundancyPolicy& getPolicy() = 0; 79 80 /** 81 * @brief Properties changed handler for tach sensor updates. 82 * 83 * @param[in] sensor - The sensor that changed. 84 * @param[in] props - The properties that changed. 85 */ 86 void 87 propertiesChanged(size_t sensor, 88 const phosphor::fan::util::Properties<double>& props); 89 90 /** 91 * @brief Properties changed handler for tach sensor updates. 92 * 93 * @param[in] sensor - The sensor that changed. 94 * @param[in] msg - The sdbusplus signal message. 95 */ 96 void propertiesChanged(size_t sensor, sdbusplus::message::message& msg); 97 98 /** @brief array of tach sensors dbus matches, and tach values. */ 99 std::vector<std::tuple< 100 std::string, std::unique_ptr<sdbusplus::bus::match::match>, double>> 101 state; 102 103 /** The current state of the sensor. */ 104 bool currentState; 105 }; 106 107 } // namespace presence 108 } // namespace fan 109 } // namespace phosphor 110