blob: 8ce2d7e0922bdd3ed75f826d6e6c5f41ffbc349c [file] [log] [blame]
Brad Bishop878b9642017-06-14 16:51:55 -04001#pragma once
Brad Bishop61749512017-07-25 19:02:15 -04002#include <cstdint>
Brad Bishop878b9642017-06-14 16:51:55 -04003
4namespace phosphor
5{
6namespace fan
7{
8namespace presence
9{
10
11/**
12 * @class PresenceSensor
13 * @brief PresenceSensor interface.
14 *
15 * Provide concrete implementations of PresenceSensor to realize
16 * new presence detection methods.
17 *
18 * Note that implementations drive the inventory update process via
19 * a redundancy policy (rpolicy.hpp) - it is not enough to implement
20 * the interfaces below.
21 */
22class PresenceSensor
23{
Matthew Barth2d2caa32020-05-26 11:07:24 -050024 public:
25 PresenceSensor(const PresenceSensor&) = default;
26 PresenceSensor& operator=(const PresenceSensor&) = default;
27 PresenceSensor(PresenceSensor&&) = default;
28 PresenceSensor& operator=(PresenceSensor&&) = default;
29 virtual ~PresenceSensor() = default;
30 PresenceSensor() : id(nextId)
31 {
32 nextId++;
33 }
Brad Bishop878b9642017-06-14 16:51:55 -040034
Matthew Barth2d2caa32020-05-26 11:07:24 -050035 /**
36 * @brief start
37 *
38 * Implementations should peform any preparation
39 * for detecting presence. Typical implementations
40 * might register signal callbacks or start
41 * a polling loop.
42 *
43 * @return The state of the sensor.
44 */
45 virtual bool start() = 0;
Brad Bishop878b9642017-06-14 16:51:55 -040046
Matthew Barth2d2caa32020-05-26 11:07:24 -050047 /**
48 * @brief stop
49 *
50 * Implementations should stop issuing presence
51 * state change notifications. Typical implementations
52 * might de-register signal callbacks or terminate
53 * polling loops.
54 */
55 virtual void stop() = 0;
Brad Bishop878b9642017-06-14 16:51:55 -040056
Matthew Barth2d2caa32020-05-26 11:07:24 -050057 /**
58 * @brief Check the sensor.
59 *
60 * Implementations should perform an offline (the start
61 * method has not been invoked) query of the presence
62 * state.
63 *
64 * @return The state of the sensor.
65 */
66 virtual bool present() = 0;
Brad Bishop878b9642017-06-14 16:51:55 -040067
Matthew Barth2d2caa32020-05-26 11:07:24 -050068 /**
69 * @brief Mark the sensor as failed.
70 *
71 * Implementations should log an an event if the
72 * system policy requires it.
73 *
74 * Provide a default noop implementation.
75 */
76 virtual void fail()
77 {}
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
Matthew Barth2d2caa32020-05-26 11:07:24 -050081 private:
82 /** @brief Unique sensor ID. */
83 std::size_t id;
Brad Bishop61749512017-07-25 19:02:15 -040084
Matthew Barth2d2caa32020-05-26 11:07:24 -050085 /** @brief The next unique sensor ID. */
86 static std::size_t nextId;
Brad Bishop878b9642017-06-14 16:51:55 -040087};
88
Matthew Barth2d2caa32020-05-26 11:07:24 -050089inline bool operator==(const PresenceSensor& l, const PresenceSensor& r)
Brad Bishop61749512017-07-25 19:02:15 -040090{
91 return l.id == r.id;
92}
93
Brad Bishop878b9642017-06-14 16:51:55 -040094} // namespace presence
95} // namespace fan
96} // namespace phosphor