blob: d73be560e0be527d86f6d3a2e0fa69fc0b0d878b [file] [log] [blame]
Brad Bishop878b9642017-06-14 16:51:55 -04001#pragma once
Brad Bishop61749512017-07-25 19:02:15 -04002#include <cstdint>
Matt Spinlerc65d91d2021-04-21 13:09:49 -05003#include <string>
Brad Bishop878b9642017-06-14 16:51:55 -04004
5namespace phosphor
6{
7namespace fan
8{
9namespace presence
10{
11
12/**
13 * @class PresenceSensor
14 * @brief PresenceSensor interface.
15 *
16 * Provide concrete implementations of PresenceSensor to realize
17 * new presence detection methods.
18 *
19 * Note that implementations drive the inventory update process via
20 * a redundancy policy (rpolicy.hpp) - it is not enough to implement
21 * the interfaces below.
22 */
23class PresenceSensor
24{
Matthew Barth2d2caa32020-05-26 11:07:24 -050025 public:
26 PresenceSensor(const PresenceSensor&) = default;
27 PresenceSensor& operator=(const PresenceSensor&) = default;
28 PresenceSensor(PresenceSensor&&) = default;
29 PresenceSensor& operator=(PresenceSensor&&) = default;
30 virtual ~PresenceSensor() = default;
31 PresenceSensor() : id(nextId)
32 {
33 nextId++;
34 }
Brad Bishop878b9642017-06-14 16:51:55 -040035
Matthew Barth2d2caa32020-05-26 11:07:24 -050036 /**
37 * @brief start
38 *
39 * Implementations should peform any preparation
40 * for detecting presence. Typical implementations
41 * might register signal callbacks or start
42 * a polling loop.
43 *
44 * @return The state of the sensor.
45 */
46 virtual bool start() = 0;
Brad Bishop878b9642017-06-14 16:51:55 -040047
Matthew Barth2d2caa32020-05-26 11:07:24 -050048 /**
49 * @brief stop
50 *
51 * Implementations should stop issuing presence
52 * state change notifications. Typical implementations
53 * might de-register signal callbacks or terminate
54 * polling loops.
55 */
56 virtual void stop() = 0;
Brad Bishop878b9642017-06-14 16:51:55 -040057
Matthew Barth2d2caa32020-05-26 11:07:24 -050058 /**
59 * @brief Check the sensor.
60 *
61 * Implementations should perform an offline (the start
62 * method has not been invoked) query of the presence
63 * state.
64 *
65 * @return The state of the sensor.
66 */
67 virtual bool present() = 0;
Brad Bishop878b9642017-06-14 16:51:55 -040068
Matthew Barth2d2caa32020-05-26 11:07:24 -050069 /**
70 * @brief Mark the sensor as failed.
71 *
72 * Implementations should log an an event if the
73 * system policy requires it.
74 *
75 * Provide a default noop implementation.
76 */
Patrick Williams61b73292023-05-10 07:50:12 -050077 virtual void fail() {}
Brad Bishop61749512017-07-25 19:02:15 -040078
Matthew Barth2d2caa32020-05-26 11:07:24 -050079 friend bool operator==(const PresenceSensor& l, const PresenceSensor& r);
Brad Bishop61749512017-07-25 19:02:15 -040080
Matt Spinlerc65d91d2021-04-21 13:09:49 -050081 /**
82 * @brief Called when this presence sensor doesn't agree with other ones.
83 *
84 * @param[in] fanInventoryPath - The fan inventory D-Bus object path.
85 */
86 virtual void logConflict(const std::string& fanInventoryPath) const = 0;
87
Matthew Barth2d2caa32020-05-26 11:07:24 -050088 private:
89 /** @brief Unique sensor ID. */
90 std::size_t id;
Brad Bishop61749512017-07-25 19:02:15 -040091
Matthew Barth2d2caa32020-05-26 11:07:24 -050092 /** @brief The next unique sensor ID. */
93 static std::size_t nextId;
Brad Bishop878b9642017-06-14 16:51:55 -040094};
95
Matthew Barth2d2caa32020-05-26 11:07:24 -050096inline bool operator==(const PresenceSensor& l, const PresenceSensor& r)
Brad Bishop61749512017-07-25 19:02:15 -040097{
98 return l.id == r.id;
99}
100
Brad Bishop878b9642017-06-14 16:51:55 -0400101} // namespace presence
102} // namespace fan
103} // namespace phosphor