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     /**
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 
81   private:
82     /**
83      * @brief Get the policy associated with this sensor.
84      */
85     virtual RedundancyPolicy& getPolicy() = 0;
86 
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      */
93     void
94         propertiesChanged(size_t sensor,
95                           const phosphor::fan::util::Properties<double>& props);
96 
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      */
103     void propertiesChanged(size_t sensor, sdbusplus::message::message& msg);
104 
105     /** @brief array of tach sensors dbus matches, and tach values. */
106     std::vector<std::tuple<
107         std::string, std::unique_ptr<sdbusplus::bus::match::match>, double>>
108         state;
109 
110     /** The current state of the sensor. */
111     bool currentState;
112 };
113 
114 } // namespace presence
115 } // namespace fan
116 } // namespace phosphor
117