xref: /openbmc/phosphor-fan-presence/presence/psensor.hpp (revision 5593560b1e1a7785a491d4650c4f3f61ffdaba90)
1 #pragma once
2 
3 namespace phosphor
4 {
5 namespace fan
6 {
7 namespace presence
8 {
9 
10 /**
11  * @class PresenceSensor
12  * @brief PresenceSensor interface.
13  *
14  * Provide concrete implementations of PresenceSensor to realize
15  * new presence detection methods.
16  *
17  * Note that implementations drive the inventory update process via
18  * a redundancy policy (rpolicy.hpp) - it is not enough to implement
19  * the interfaces below.
20  */
21 class PresenceSensor
22 {
23     public:
24         PresenceSensor(const PresenceSensor&) = default;
25         PresenceSensor& operator=(const PresenceSensor&) = default;
26         PresenceSensor(PresenceSensor&&) = default;
27         PresenceSensor& operator=(PresenceSensor&&) = default;
28         virtual ~PresenceSensor() = default;
29         PresenceSensor() = default;
30 
31         /**
32          * @brief start
33          *
34          * Implementations should peform any preparation
35          * for detecting presence.  Typical implementations
36          * might register signal callbacks or start
37          * a polling loop.
38          *
39          * @return The state of the sensor.
40          */
41         virtual bool start() = 0;
42 
43         /**
44          * @brief stop
45          *
46          * Implementations should stop issuing presence
47          * state change notifications.  Typical implementations
48          * might de-register signal callbacks or terminate
49          * polling loops.
50          */
51         virtual void stop() = 0;
52 
53         /**
54          * @brief Check the sensor.
55          *
56          * Implementations should perform an offline (the start
57          * method has not been invoked) query of the presence
58          * state.
59          *
60          * @return The state of the sensor.
61          */
62         virtual bool present() = 0;
63 
64         /**
65          * @brief Mark the sensor as failed.
66          *
67          * Implementations should log an an event if the
68          * system policy requires it.
69          *
70          * Provide a default noop implementation.
71          */
72         virtual void fail() {}
73 };
74 
75 } // namespace presence
76 } // namespace fan
77 } // namespace phosphor
78