blob: d6bad024c527747c0261b764c7e7f5a3724d2254 [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.
42 */
43 Fallback(const Fan& fan,
44 const std::vector<std::reference_wrapper<PresenceSensor>>& s) :
45 RedundancyPolicy(fan),
46 sensors(s)
47 {
48 activeSensor = sensors.begin();
49 }
Brad Bishopbfb81602017-06-14 21:14:32 -040050
Matthew Barth2d2caa32020-05-26 11:07:24 -050051 /**
52 * @brief stateChanged
53 *
54 * Update the inventory and execute the fallback
55 * policy.
56 *
57 * @param[in] present - The new presence state according
58 * to the active sensor.
59 * @param[in] sensor - The sensor that changed state.
60 */
Mike Capps808d7fe2022-06-13 10:12:16 -040061 void stateChanged(bool present, PresenceSensor& /*sensor*/) override;
Brad Bishopbfb81602017-06-14 21:14:32 -040062
Matthew Barth2d2caa32020-05-26 11:07:24 -050063 /**
64 * @brief monitor
65 *
66 * Start monitoring the fan.
67 */
68 void monitor() override;
Brad Bishopbfb81602017-06-14 21:14:32 -040069
Matthew Barth2d2caa32020-05-26 11:07:24 -050070 private:
71 /** @brief All presence sensors in the redundancy set. */
72 std::vector<std::reference_wrapper<PresenceSensor>> sensors;
Brad Bishopbfb81602017-06-14 21:14:32 -040073
Matthew Barth2d2caa32020-05-26 11:07:24 -050074 /** @brief The active presence sensor. */
75 decltype(sensors)::iterator activeSensor;
Brad Bishopbfb81602017-06-14 21:14:32 -040076};
77
78} // namespace presence
79} // namespace fan
80} // namespace phosphor