1 #pragma once 2 #include <cstdint> 3 #include <string> 4 5 namespace phosphor 6 { 7 namespace fan 8 { 9 namespace 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 */ 23 class PresenceSensor 24 { 25 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 } 35 36 /** 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; 47 48 /** 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; 57 58 /** 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; 68 69 /** 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 {} 79 80 friend bool operator==(const PresenceSensor& l, const PresenceSensor& r); 81 82 /** 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 89 private: 90 /** @brief Unique sensor ID. */ 91 std::size_t id; 92 93 /** @brief The next unique sensor ID. */ 94 static std::size_t nextId; 95 }; 96 97 inline bool operator==(const PresenceSensor& l, const PresenceSensor& r) 98 { 99 return l.id == r.id; 100 } 101 102 } // namespace presence 103 } // namespace fan 104 } // namespace phosphor 105