blob: cc65fe008979676174f3e3a9fe787bd373bb5b79 [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 */
77 virtual void fail()
78 {}
Brad Bishop61749512017-07-25 19:02:15 -040079
Matthew Barth2d2caa32020-05-26 11:07:24 -050080 friend bool operator==(const PresenceSensor& l, const PresenceSensor& r);
Brad Bishop61749512017-07-25 19:02:15 -040081
Matt Spinlerc65d91d2021-04-21 13:09:49 -050082 /**
83 * @brief Called when this presence sensor doesn't agree with other ones.
84 *
85 * @param[in] fanInventoryPath - The fan inventory D-Bus object path.
86 */
87 virtual void logConflict(const std::string& fanInventoryPath) const = 0;
88
Matthew Barth2d2caa32020-05-26 11:07:24 -050089 private:
90 /** @brief Unique sensor ID. */
91 std::size_t id;
Brad Bishop61749512017-07-25 19:02:15 -040092
Matthew Barth2d2caa32020-05-26 11:07:24 -050093 /** @brief The next unique sensor ID. */
94 static std::size_t nextId;
Brad Bishop878b9642017-06-14 16:51:55 -040095};
96
Matthew Barth2d2caa32020-05-26 11:07:24 -050097inline bool operator==(const PresenceSensor& l, const PresenceSensor& r)
Brad Bishop61749512017-07-25 19:02:15 -040098{
99 return l.id == r.id;
100}
101
Brad Bishop878b9642017-06-14 16:51:55 -0400102} // namespace presence
103} // namespace fan
104} // namespace phosphor