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 79 friend bool operator==(const PresenceSensor& l, const PresenceSensor& r); 80 81 private: 82 /** @brief Unique sensor ID. */ 83 std::size_t id; 84 85 /** @brief The next unique sensor ID. */ 86 static std::size_t nextId; 87 }; 88 89 inline bool operator==(const PresenceSensor& l, const PresenceSensor& r) 90 { 91 return l.id == r.id; 92 } 93 94 } // namespace presence 95 } // namespace fan 96 } // namespace phosphor 97