blob: 9f2654d8e96ab18996e80368b82e7307e6665f6f [file] [log] [blame]
Brad Bishopdd62e362017-06-14 16:54:03 -04001#pragma once
2
Brad Bishopdd62e362017-06-14 16:54:03 -04003#include "psensor.hpp"
4#include "sdbusplus.hpp"
5
Matthew Barth2d2caa32020-05-26 11:07:24 -05006#include <sdbusplus/bus/match.hpp>
7#include <sdbusplus/message.hpp>
8
9#include <string>
10#include <vector>
11
Brad Bishopdd62e362017-06-14 16:54:03 -040012namespace phosphor
13{
14namespace fan
15{
16namespace presence
17{
18class 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 */
27class Tach : public PresenceSensor
28{
Matthew Barth2d2caa32020-05-26 11:07:24 -050029 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 Bishopdd62e362017-06-14 16:54:03 -040042
Matthew Barth2d2caa32020-05-26 11:07:24 -050043 /**
44 * @brief ctor
45 *
46 * @param[in] sensors - Fan tach sensors for this psensor.
47 */
48 Tach(const std::vector<std::string>& sensors);
Brad Bishopdd62e362017-06-14 16:54:03 -040049
Matthew Barth2d2caa32020-05-26 11:07:24 -050050 /**
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 Bishopdd62e362017-06-14 16:54:03 -040059
Matthew Barth2d2caa32020-05-26 11:07:24 -050060 /**
61 * @brief stop
62 *
63 * De-register dbus signal callbacks.
64 */
65 void stop() override;
Brad Bishopdd62e362017-06-14 16:54:03 -040066
Matthew Barth2d2caa32020-05-26 11:07:24 -050067 /**
68 * @brief Check the sensor.
69 *
70 * Query the tach speeds.
71 */
72 bool present() override;
Brad Bishopdd62e362017-06-14 16:54:03 -040073
Matthew Barth2d2caa32020-05-26 11:07:24 -050074 private:
75 /**
76 * @brief Get the policy associated with this sensor.
77 */
78 virtual RedundancyPolicy& getPolicy() = 0;
Brad Bishopdd62e362017-06-14 16:54:03 -040079
Matthew Barth2d2caa32020-05-26 11:07:24 -050080 /**
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 propertiesChanged(
87 size_t sensor, const phosphor::fan::util::Properties<int64_t>& props);
Brad Bishopdd62e362017-06-14 16:54:03 -040088
Matthew Barth2d2caa32020-05-26 11:07:24 -050089 /**
90 * @brief Properties changed handler for tach sensor updates.
91 *
92 * @param[in] sensor - The sensor that changed.
93 * @param[in] msg - The sdbusplus signal message.
94 */
95 void propertiesChanged(size_t sensor, sdbusplus::message::message& msg);
Brad Bishopdd62e362017-06-14 16:54:03 -040096
Matthew Barth2d2caa32020-05-26 11:07:24 -050097 /** @brief array of tach sensors dbus matches, and tach values. */
98 std::vector<std::tuple<
99 std::string, std::unique_ptr<sdbusplus::bus::match::match>, int64_t>>
100 state;
Brad Bishopdd62e362017-06-14 16:54:03 -0400101
Matthew Barth2d2caa32020-05-26 11:07:24 -0500102 /** The current state of the sensor. */
103 bool currentState;
Brad Bishopdd62e362017-06-14 16:54:03 -0400104};
105
106} // namespace presence
107} // namespace fan
108} // namespace phosphor