blob: b9e2cbd06c24acbf37f97fabe68a0ec303af0815 [file] [log] [blame]
Brad Bishopbfb81602017-06-14 21:14:32 -04001#pragma once
2
Brad Bishopbfb81602017-06-14 21:14:32 -04003#include "fan.hpp"
4#include "rpolicy.hpp"
5
Matthew Barth2d2caa32020-05-26 11:07:24 -05006#include <functional>
7#include <vector>
8
Brad Bishopbfb81602017-06-14 21:14:32 -04009namespace phosphor
10{
11namespace fan
12{
13namespace presence
14{
15
16class 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 */
27class Fallback : public RedundancyPolicy
28{
Matthew Barth2d2caa32020-05-26 11:07:24 -050029 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 Bishopbfb81602017-06-14 21:14:32 -040036
Matthew Barth2d2caa32020-05-26 11:07:24 -050037 /**
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.
Matt Spinlerbc4179e2022-10-04 15:15:06 -050042 * @param[in] e - EEPROM device instance
Matthew Barth2d2caa32020-05-26 11:07:24 -050043 */
44 Fallback(const Fan& fan,
Matt Spinlerbc4179e2022-10-04 15:15:06 -050045 const std::vector<std::reference_wrapper<PresenceSensor>>& s,
46 std::unique_ptr<EEPROMDevice> e) :
Patrick Williamsdfddd642024-08-16 15:21:51 -040047 RedundancyPolicy(fan, std::move(e)), sensors(s)
Matthew Barth2d2caa32020-05-26 11:07:24 -050048 {
49 activeSensor = sensors.begin();
50 }
Brad Bishopbfb81602017-06-14 21:14:32 -040051
Matthew Barth2d2caa32020-05-26 11:07:24 -050052 /**
Matt Spinler08bc72f2022-10-12 09:36:42 -050053 * @brief Construct a fallback policy.
54 *
55 * @param[in] fan - The fan associated with the policy.
56 * @param[in] s - The set of sensors associated with the policy.
57 */
58 Fallback(const Fan& fan,
59 const std::vector<std::reference_wrapper<PresenceSensor>>& s) :
60 Fallback(fan, s, nullptr)
61 {}
62
63 /**
Matthew Barth2d2caa32020-05-26 11:07:24 -050064 * @brief stateChanged
65 *
66 * Update the inventory and execute the fallback
67 * policy.
68 *
69 * @param[in] present - The new presence state according
70 * to the active sensor.
71 * @param[in] sensor - The sensor that changed state.
72 */
Mike Capps808d7fe2022-06-13 10:12:16 -040073 void stateChanged(bool present, PresenceSensor& /*sensor*/) override;
Brad Bishopbfb81602017-06-14 21:14:32 -040074
Matthew Barth2d2caa32020-05-26 11:07:24 -050075 /**
76 * @brief monitor
77 *
78 * Start monitoring the fan.
79 */
80 void monitor() override;
Brad Bishopbfb81602017-06-14 21:14:32 -040081
Matthew Barth2d2caa32020-05-26 11:07:24 -050082 private:
83 /** @brief All presence sensors in the redundancy set. */
84 std::vector<std::reference_wrapper<PresenceSensor>> sensors;
Brad Bishopbfb81602017-06-14 21:14:32 -040085
Matthew Barth2d2caa32020-05-26 11:07:24 -050086 /** @brief The active presence sensor. */
87 decltype(sensors)::iterator activeSensor;
Brad Bishopbfb81602017-06-14 21:14:32 -040088};
89
90} // namespace presence
91} // namespace fan
92} // namespace phosphor