diff options
author | Brad Bishop <bradleyb@fuzziesquirrel.com> | 2017-06-14 21:14:32 -0400 |
---|---|---|
committer | Patrick Williams <patrick@stwcx.xyz> | 2017-08-02 20:18:19 +0000 |
commit | bfb8160710d95d208f7cb1565a97c2a909459d0c (patch) | |
tree | 12de3b1a97421b70abd4761ac23015fd5caf6646 /presence/fallback.hpp | |
parent | 5c5894878b09fdef8fcbee000f83283b73b8da64 (diff) | |
download | phosphor-fan-presence-bfb8160710d95d208f7cb1565a97c2a909459d0c.tar.gz phosphor-fan-presence-bfb8160710d95d208f7cb1565a97c2a909459d0c.zip |
presence: Add fallback redundancy policy
Add a fallback redundancy implementation of the RedundancyPolicy
interface.
The fallback policy associates multiple PresenceSensor instances
to a single fan, and "falls-back" on secondary sensor implementations
when the primary sensor cannot see the fan.
Change-Id: I6468d77d97b8916b3ff33bcd0cd28a102d1aaba1
Signed-off-by: Brad Bishop <bradleyb@fuzziesquirrel.com>
Diffstat (limited to 'presence/fallback.hpp')
-rw-r--r-- | presence/fallback.hpp | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/presence/fallback.hpp b/presence/fallback.hpp new file mode 100644 index 0000000..a1a5b29 --- /dev/null +++ b/presence/fallback.hpp @@ -0,0 +1,79 @@ +#pragma once + +#include <functional> +#include <vector> +#include "fan.hpp" +#include "rpolicy.hpp" + +namespace phosphor +{ +namespace fan +{ +namespace presence +{ + +class PresenceSensor; + +/** + * @class Fallback + * @brief Fallback redundancy policy. + * + * The fallback redundancy policy falls back to + * subsequent presence sensors when the active + * sensor indicates not present and a fallback + * sensor indicates the fan is present. + */ +class Fallback : public RedundancyPolicy +{ + public: + Fallback() = delete; + Fallback(const Fallback&) = default; + Fallback& operator=(const Fallback&) = default; + Fallback(Fallback&&) = default; + Fallback& operator=(Fallback&&) = default; + ~Fallback() = default; + + /** + * @brief Construct a fallback policy. + * + * @param[in] fan - The fan associated with the policy. + * @param[in] s - The set of sensors associated with the policy. + */ + Fallback( + const Fan& fan, + const std::vector<std::reference_wrapper<PresenceSensor>>& s) : + RedundancyPolicy(fan), sensors(s) + { + activeSensor = sensors.begin(); + } + + /** + * @brief stateChanged + * + * Update the inventory and execute the fallback + * policy. + * + * @param[in] present - The new presence state according + * to the active sensor. + */ + void stateChanged(bool present) override; + + /** + * @brief monitor + * + * Start monitoring the fan. + */ + void monitor() override; + + private: + + /** @brief All presence sensors in the redundancy set. */ + std::vector<std::reference_wrapper<PresenceSensor>> sensors; + + /** @brief The active presence sensor. */ + decltype(sensors)::iterator activeSensor; +}; + +} // namespace presence +} // namespace fan +} // namespace phosphor |