Brad Bishop | 878b964 | 2017-06-14 16:51:55 -0400 | [diff] [blame] | 1 | #pragma once |
Brad Bishop | 6174951 | 2017-07-25 19:02:15 -0400 | [diff] [blame] | 2 | #include <cstdint> |
Matt Spinler | c65d91d | 2021-04-21 13:09:49 -0500 | [diff] [blame] | 3 | #include <string> |
Brad Bishop | 878b964 | 2017-06-14 16:51:55 -0400 | [diff] [blame] | 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 | { |
Matthew Barth | 2d2caa3 | 2020-05-26 11:07:24 -0500 | [diff] [blame] | 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 | } |
Brad Bishop | 878b964 | 2017-06-14 16:51:55 -0400 | [diff] [blame] | 35 | |
Matthew Barth | 2d2caa3 | 2020-05-26 11:07:24 -0500 | [diff] [blame] | 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; |
Brad Bishop | 878b964 | 2017-06-14 16:51:55 -0400 | [diff] [blame] | 47 | |
Matthew Barth | 2d2caa3 | 2020-05-26 11:07:24 -0500 | [diff] [blame] | 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; |
Brad Bishop | 878b964 | 2017-06-14 16:51:55 -0400 | [diff] [blame] | 57 | |
Matthew Barth | 2d2caa3 | 2020-05-26 11:07:24 -0500 | [diff] [blame] | 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; |
Brad Bishop | 878b964 | 2017-06-14 16:51:55 -0400 | [diff] [blame] | 68 | |
Matthew Barth | 2d2caa3 | 2020-05-26 11:07:24 -0500 | [diff] [blame] | 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 | */ |
Patrick Williams | 61b7329 | 2023-05-10 07:50:12 -0500 | [diff] [blame] | 77 | virtual void fail() {} |
Brad Bishop | 6174951 | 2017-07-25 19:02:15 -0400 | [diff] [blame] | 78 | |
Matthew Barth | 2d2caa3 | 2020-05-26 11:07:24 -0500 | [diff] [blame] | 79 | friend bool operator==(const PresenceSensor& l, const PresenceSensor& r); |
Brad Bishop | 6174951 | 2017-07-25 19:02:15 -0400 | [diff] [blame] | 80 | |
Matt Spinler | c65d91d | 2021-04-21 13:09:49 -0500 | [diff] [blame] | 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 | |
Matthew Barth | 2d2caa3 | 2020-05-26 11:07:24 -0500 | [diff] [blame] | 88 | private: |
| 89 | /** @brief Unique sensor ID. */ |
| 90 | std::size_t id; |
Brad Bishop | 6174951 | 2017-07-25 19:02:15 -0400 | [diff] [blame] | 91 | |
Matthew Barth | 2d2caa3 | 2020-05-26 11:07:24 -0500 | [diff] [blame] | 92 | /** @brief The next unique sensor ID. */ |
| 93 | static std::size_t nextId; |
Brad Bishop | 878b964 | 2017-06-14 16:51:55 -0400 | [diff] [blame] | 94 | }; |
| 95 | |
Matthew Barth | 2d2caa3 | 2020-05-26 11:07:24 -0500 | [diff] [blame] | 96 | inline bool operator==(const PresenceSensor& l, const PresenceSensor& r) |
Brad Bishop | 6174951 | 2017-07-25 19:02:15 -0400 | [diff] [blame] | 97 | { |
| 98 | return l.id == r.id; |
| 99 | } |
| 100 | |
Brad Bishop | 878b964 | 2017-06-14 16:51:55 -0400 | [diff] [blame] | 101 | } // namespace presence |
| 102 | } // namespace fan |
| 103 | } // namespace phosphor |