Brad Bishop | 221b36b | 2017-06-14 16:52:42 -0400 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include "fan.hpp" |
| 4 | |
| 5 | namespace phosphor |
| 6 | { |
| 7 | namespace fan |
| 8 | { |
| 9 | namespace presence |
| 10 | { |
| 11 | |
Brad Bishop | 11083ec | 2017-07-25 19:08:53 -0400 | [diff] [blame] | 12 | class PresenceSensor; |
| 13 | |
Brad Bishop | 221b36b | 2017-06-14 16:52:42 -0400 | [diff] [blame] | 14 | /** |
| 15 | * @class RedundancyPolicy |
| 16 | * @brief Redundancy policy interface. |
| 17 | * |
| 18 | * Provide concrete implementations of RedundancyPolicy to realize |
| 19 | * new redundancy logic. |
| 20 | * |
| 21 | * A fan can have multiple ways to detect whether or not it is present. |
| 22 | * The redundancy policy encapsulates the logic to aggregate those |
| 23 | * inputs into a single yes or no the fan is present. |
| 24 | */ |
| 25 | class RedundancyPolicy |
| 26 | { |
Matthew Barth | 2d2caa3 | 2020-05-26 11:07:24 -0500 | [diff] [blame] | 27 | public: |
| 28 | RedundancyPolicy(const RedundancyPolicy&) = default; |
| 29 | RedundancyPolicy& operator=(const RedundancyPolicy&) = default; |
| 30 | RedundancyPolicy(RedundancyPolicy&&) = default; |
| 31 | RedundancyPolicy& operator=(RedundancyPolicy&&) = default; |
| 32 | virtual ~RedundancyPolicy() = default; |
Brad Bishop | 221b36b | 2017-06-14 16:52:42 -0400 | [diff] [blame] | 33 | |
Matthew Barth | 2d2caa3 | 2020-05-26 11:07:24 -0500 | [diff] [blame] | 34 | /** |
| 35 | * @brief Construct a new Redundancy Policy. |
| 36 | * |
| 37 | * @param[in] fan - The fan associated with this policy. |
| 38 | */ |
| 39 | explicit RedundancyPolicy(const Fan& f) : fan(f) |
| 40 | {} |
Brad Bishop | 221b36b | 2017-06-14 16:52:42 -0400 | [diff] [blame] | 41 | |
Matthew Barth | 2d2caa3 | 2020-05-26 11:07:24 -0500 | [diff] [blame] | 42 | /** |
| 43 | * @brief stateChanged |
| 44 | * |
| 45 | * Typically invoked by presence sensors to signify |
| 46 | * a change of presence. Implementations should update |
| 47 | * the inventory and execute their policy logic. |
| 48 | * |
| 49 | * @param[in] present - The new state of the sensor. |
| 50 | * @param[in] sensor - The sensor that changed state. |
| 51 | */ |
| 52 | virtual void stateChanged(bool present, PresenceSensor& sensor) = 0; |
Brad Bishop | 221b36b | 2017-06-14 16:52:42 -0400 | [diff] [blame] | 53 | |
Matthew Barth | 2d2caa3 | 2020-05-26 11:07:24 -0500 | [diff] [blame] | 54 | /** |
| 55 | * @brief monitor |
| 56 | * |
| 57 | * Implementations should start monitoring the sensors |
| 58 | * associated with the fan. |
| 59 | */ |
| 60 | virtual void monitor() = 0; |
Brad Bishop | 221b36b | 2017-06-14 16:52:42 -0400 | [diff] [blame] | 61 | |
Matthew Barth | 2d2caa3 | 2020-05-26 11:07:24 -0500 | [diff] [blame] | 62 | protected: |
| 63 | /** @brief Fan name and inventory path. */ |
| 64 | const Fan& fan; |
Brad Bishop | 221b36b | 2017-06-14 16:52:42 -0400 | [diff] [blame] | 65 | }; |
| 66 | |
| 67 | /** |
| 68 | * @class PolicyAccess |
| 69 | * @brief Policy association. |
| 70 | * |
| 71 | * PolicyAccess can be used to associate a redundancy policy |
| 72 | * with something else. |
| 73 | * |
| 74 | * Wrap the type to be associated with a policy with PolicyAccess. |
| 75 | * |
| 76 | * @tparam T - The type to associate with a redundancy policy. |
| 77 | * @tparam Policy - An array type where the policy is stored. |
| 78 | */ |
| 79 | template <typename T, typename Policy> |
| 80 | class PolicyAccess : public T |
| 81 | { |
Matthew Barth | 2d2caa3 | 2020-05-26 11:07:24 -0500 | [diff] [blame] | 82 | public: |
| 83 | PolicyAccess() = default; |
| 84 | PolicyAccess(const PolicyAccess&) = default; |
| 85 | PolicyAccess& operator=(const PolicyAccess&) = default; |
| 86 | PolicyAccess(PolicyAccess&&) = default; |
| 87 | PolicyAccess& operator=(PolicyAccess&&) = default; |
| 88 | ~PolicyAccess() = default; |
Brad Bishop | 221b36b | 2017-06-14 16:52:42 -0400 | [diff] [blame] | 89 | |
Matthew Barth | 2d2caa3 | 2020-05-26 11:07:24 -0500 | [diff] [blame] | 90 | /** |
| 91 | * @brief Construct a new PolicyAccess wrapped object. |
| 92 | * |
| 93 | * @param[in] index - The array index in Policy. |
| 94 | * @tparam Args - Forwarded to wrapped type constructor. |
| 95 | */ |
| 96 | template <typename... Args> |
| 97 | PolicyAccess(size_t index, Args&&... args) : |
| 98 | T(std::forward<Args>(args)...), policy(index) |
| 99 | {} |
Brad Bishop | 221b36b | 2017-06-14 16:52:42 -0400 | [diff] [blame] | 100 | |
Matthew Barth | 2d2caa3 | 2020-05-26 11:07:24 -0500 | [diff] [blame] | 101 | private: |
| 102 | /** |
| 103 | * @brief Get the associated policy. |
| 104 | */ |
| 105 | RedundancyPolicy& getPolicy() override |
| 106 | { |
| 107 | return *Policy::get()[policy]; |
| 108 | } |
Brad Bishop | 221b36b | 2017-06-14 16:52:42 -0400 | [diff] [blame] | 109 | |
Matthew Barth | 2d2caa3 | 2020-05-26 11:07:24 -0500 | [diff] [blame] | 110 | /** The associated policy index. */ |
| 111 | size_t policy; |
Brad Bishop | 221b36b | 2017-06-14 16:52:42 -0400 | [diff] [blame] | 112 | }; |
| 113 | } // namespace presence |
| 114 | } // namespace fan |
| 115 | } // namespace phosphor |