diff options
author | Brad Bishop <bradleyb@fuzziesquirrel.com> | 2017-06-14 16:52:42 -0400 |
---|---|---|
committer | Patrick Williams <patrick@stwcx.xyz> | 2017-08-02 20:18:18 +0000 |
commit | 221b36b5a84e7e2d7488a6333e3d32982adae9aa (patch) | |
tree | 65fa61e07e26c47ad54d896707e36bf8fef8a009 | |
parent | 878b964ae36a54537c1b020e9493a8ac2505f7dc (diff) | |
download | phosphor-fan-presence-221b36b5a84e7e2d7488a6333e3d32982adae9aa.tar.gz phosphor-fan-presence-221b36b5a84e7e2d7488a6333e3d32982adae9aa.zip |
presence: Add redundancy policy interface
Add a redundancy policy interface class. Redundancy policies
introduce the concept of multiple presence sensors for a given
fan. A redundancy model implementation determines how the
distinct sensors making up the redundancy set are controlled
and how their feedbacks determine the overall fan presence state
reflected in the inventory.
Change-Id: Ibb5f71b3189dbb253bb669691e8016cda83a6ebb
Signed-off-by: Brad Bishop <bradleyb@fuzziesquirrel.com>
-rw-r--r-- | presence/rpolicy.hpp | 110 |
1 files changed, 110 insertions, 0 deletions
diff --git a/presence/rpolicy.hpp b/presence/rpolicy.hpp new file mode 100644 index 0000000..34beb77 --- /dev/null +++ b/presence/rpolicy.hpp @@ -0,0 +1,110 @@ +#pragma once + +#include "fan.hpp" + +namespace phosphor +{ +namespace fan +{ +namespace presence +{ + +/** + * @class RedundancyPolicy + * @brief Redundancy policy interface. + * + * Provide concrete implementations of RedundancyPolicy to realize + * new redundancy logic. + * + * A fan can have multiple ways to detect whether or not it is present. + * The redundancy policy encapsulates the logic to aggregate those + * inputs into a single yes or no the fan is present. + */ +class RedundancyPolicy +{ + public: + RedundancyPolicy(const RedundancyPolicy&) = default; + RedundancyPolicy& operator=(const RedundancyPolicy&) = default; + RedundancyPolicy(RedundancyPolicy&&) = default; + RedundancyPolicy& operator=(RedundancyPolicy&&) = default; + virtual ~RedundancyPolicy() = default; + + /** + * @brief Construct a new Redundancy Policy. + * + * @param[in] fan - The fan associated with this policy. + */ + explicit RedundancyPolicy(const Fan& f) : fan(f) {} + + /** + * @brief stateChanged + * + * Typically invoked by presence sensors to signify + * a change of presence. Implementations should update + * the inventory and execute their policy logic. + * + * @param[in] present - The new state of the sensor. + */ + virtual void stateChanged(bool present) = 0; + + /** + * @brief monitor + * + * Implementations should start monitoring the sensors + * associated with the fan. + */ + virtual void monitor() = 0; + + protected: + /** @brief Fan name and inventory path. */ + const Fan& fan; +}; + +/** + * @class PolicyAccess + * @brief Policy association. + * + * PolicyAccess can be used to associate a redundancy policy + * with something else. + * + * Wrap the type to be associated with a policy with PolicyAccess. + * + * @tparam T - The type to associate with a redundancy policy. + * @tparam Policy - An array type where the policy is stored. + */ +template <typename T, typename Policy> +class PolicyAccess : public T +{ + public: + PolicyAccess() = default; + PolicyAccess(const PolicyAccess&) = default; + PolicyAccess& operator=(const PolicyAccess&) = default; + PolicyAccess(PolicyAccess&&) = default; + PolicyAccess& operator=(PolicyAccess&&) = default; + ~PolicyAccess() = default; + + /** + * @brief Construct a new PolicyAccess wrapped object. + * + * @param[in] index - The array index in Policy. + * @tparam Args - Forwarded to wrapped type constructor. + */ + template <typename...Args> + PolicyAccess(size_t index, Args&&...args) : + T(std::forward<Args>(args)...), policy(index) {} + + private: + /** + * @brief Get the associated policy. + */ + RedundancyPolicy& getPolicy() override + { + return *Policy::get()[policy]; + } + + /** The associated policy index. */ + size_t policy; +}; +} // namespace presence +} // namespace fan +} // namespace phosphor |