blob: db8efa22266be2883574035714d3f71f9698a647 [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
Matt Spinlerc65d91d2021-04-21 13:09:49 -050074 /**
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 Barth2d2caa32020-05-26 11:07:24 -050081 private:
82 /**
83 * @brief Get the policy associated with this sensor.
84 */
85 virtual RedundancyPolicy& getPolicy() = 0;
Brad Bishopdd62e362017-06-14 16:54:03 -040086
Matthew Barth2d2caa32020-05-26 11:07:24 -050087 /**
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 Barthad2cd242020-08-13 13:36:19 -050093 void
94 propertiesChanged(size_t sensor,
95 const phosphor::fan::util::Properties<double>& props);
Brad Bishopdd62e362017-06-14 16:54:03 -040096
Matthew Barth2d2caa32020-05-26 11:07:24 -050097 /**
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 Williamscb356d42022-07-22 19:26:53 -0500103 void propertiesChanged(size_t sensor, sdbusplus::message_t& msg);
Brad Bishopdd62e362017-06-14 16:54:03 -0400104
Matthew Barth2d2caa32020-05-26 11:07:24 -0500105 /** @brief array of tach sensors dbus matches, and tach values. */
Patrick Williamscb356d42022-07-22 19:26:53 -0500106 std::vector<std::tuple<std::string,
107 std::unique_ptr<sdbusplus::bus::match_t>, double>>
Matthew Barth2d2caa32020-05-26 11:07:24 -0500108 state;
Brad Bishopdd62e362017-06-14 16:54:03 -0400109
Matthew Barth2d2caa32020-05-26 11:07:24 -0500110 /** The current state of the sensor. */
111 bool currentState;
Brad Bishopdd62e362017-06-14 16:54:03 -0400112};
113
114} // namespace presence
115} // namespace fan
116} // namespace phosphor