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