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 friend bool operator==(const PresenceSensor& l, const PresenceSensor& r); 80 81 /** 82 * @brief Called when this presence sensor doesn't agree with other ones. 83 * 84 * @param[in] fanInventoryPath - The fan inventory D-Bus object path. 85 */ 86 virtual void logConflict(const std::string& fanInventoryPath) const = 0; 87 88 private: 89 /** @brief Unique sensor ID. */ 90 std::size_t id; 91 92 /** @brief The next unique sensor ID. */ 93 static std::size_t nextId; 94 }; 95 96 inline bool operator==(const PresenceSensor& l, const PresenceSensor& r) 97 { 98 return l.id == r.id; 99 } 100 101 } // namespace presence 102 } // namespace fan 103 } // namespace phosphor 104