Brad Bishop | bfb8160 | 2017-06-14 21:14:32 -0400 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Brad Bishop | bfb8160 | 2017-06-14 21:14:32 -0400 | [diff] [blame] | 3 | #include "fan.hpp" |
| 4 | #include "rpolicy.hpp" |
| 5 | |
Matthew Barth | 2d2caa3 | 2020-05-26 11:07:24 -0500 | [diff] [blame] | 6 | #include <functional> |
| 7 | #include <vector> |
| 8 | |
Brad Bishop | bfb8160 | 2017-06-14 21:14:32 -0400 | [diff] [blame] | 9 | namespace phosphor |
| 10 | { |
| 11 | namespace fan |
| 12 | { |
| 13 | namespace presence |
| 14 | { |
| 15 | |
| 16 | class PresenceSensor; |
| 17 | |
| 18 | /** |
| 19 | * @class Fallback |
| 20 | * @brief Fallback redundancy policy. |
| 21 | * |
| 22 | * The fallback redundancy policy falls back to |
| 23 | * subsequent presence sensors when the active |
| 24 | * sensor indicates not present and a fallback |
| 25 | * sensor indicates the fan is present. |
| 26 | */ |
| 27 | class Fallback : public RedundancyPolicy |
| 28 | { |
Matthew Barth | 2d2caa3 | 2020-05-26 11:07:24 -0500 | [diff] [blame] | 29 | public: |
| 30 | Fallback() = delete; |
| 31 | Fallback(const Fallback&) = default; |
| 32 | Fallback& operator=(const Fallback&) = default; |
| 33 | Fallback(Fallback&&) = default; |
| 34 | Fallback& operator=(Fallback&&) = default; |
| 35 | ~Fallback() = default; |
Brad Bishop | bfb8160 | 2017-06-14 21:14:32 -0400 | [diff] [blame] | 36 | |
Matthew Barth | 2d2caa3 | 2020-05-26 11:07:24 -0500 | [diff] [blame] | 37 | /** |
| 38 | * @brief Construct a fallback policy. |
| 39 | * |
| 40 | * @param[in] fan - The fan associated with the policy. |
| 41 | * @param[in] s - The set of sensors associated with the policy. |
| 42 | */ |
| 43 | Fallback(const Fan& fan, |
| 44 | const std::vector<std::reference_wrapper<PresenceSensor>>& s) : |
| 45 | RedundancyPolicy(fan), |
| 46 | sensors(s) |
| 47 | { |
| 48 | activeSensor = sensors.begin(); |
| 49 | } |
Brad Bishop | bfb8160 | 2017-06-14 21:14:32 -0400 | [diff] [blame] | 50 | |
Matthew Barth | 2d2caa3 | 2020-05-26 11:07:24 -0500 | [diff] [blame] | 51 | /** |
| 52 | * @brief stateChanged |
| 53 | * |
| 54 | * Update the inventory and execute the fallback |
| 55 | * policy. |
| 56 | * |
| 57 | * @param[in] present - The new presence state according |
| 58 | * to the active sensor. |
| 59 | * @param[in] sensor - The sensor that changed state. |
| 60 | */ |
Mike Capps | 808d7fe | 2022-06-13 10:12:16 -0400 | [diff] [blame^] | 61 | void stateChanged(bool present, PresenceSensor& /*sensor*/) override; |
Brad Bishop | bfb8160 | 2017-06-14 21:14:32 -0400 | [diff] [blame] | 62 | |
Matthew Barth | 2d2caa3 | 2020-05-26 11:07:24 -0500 | [diff] [blame] | 63 | /** |
| 64 | * @brief monitor |
| 65 | * |
| 66 | * Start monitoring the fan. |
| 67 | */ |
| 68 | void monitor() override; |
Brad Bishop | bfb8160 | 2017-06-14 21:14:32 -0400 | [diff] [blame] | 69 | |
Matthew Barth | 2d2caa3 | 2020-05-26 11:07:24 -0500 | [diff] [blame] | 70 | private: |
| 71 | /** @brief All presence sensors in the redundancy set. */ |
| 72 | std::vector<std::reference_wrapper<PresenceSensor>> sensors; |
Brad Bishop | bfb8160 | 2017-06-14 21:14:32 -0400 | [diff] [blame] | 73 | |
Matthew Barth | 2d2caa3 | 2020-05-26 11:07:24 -0500 | [diff] [blame] | 74 | /** @brief The active presence sensor. */ |
| 75 | decltype(sensors)::iterator activeSensor; |
Brad Bishop | bfb8160 | 2017-06-14 21:14:32 -0400 | [diff] [blame] | 76 | }; |
| 77 | |
| 78 | } // namespace presence |
| 79 | } // namespace fan |
| 80 | } // namespace phosphor |