1 #pragma once 2 #include <cstdint> 3 4 namespace phosphor 5 { 6 namespace fan 7 { 8 namespace 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 */ 22 class PresenceSensor 23 { 24 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 } 34 35 /** 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; 46 47 /** 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; 56 57 /** 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; 67 68 /** 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 78 friend bool operator==(const PresenceSensor& l, const PresenceSensor& r); 79 80 private: 81 /** @brief Unique sensor ID. */ 82 std::size_t id; 83 84 /** @brief The next unique sensor ID. */ 85 static std::size_t nextId; 86 }; 87 88 inline bool operator==(const PresenceSensor& l, const PresenceSensor &r) 89 { 90 return l.id == r.id; 91 } 92 93 } // namespace presence 94 } // namespace fan 95 } // namespace phosphor 96