blob: 280ef1ceb4d8e9b75ea588d53c9d0d2d984977ae [file] [log] [blame]
Brad Bishopbfb81602017-06-14 21:14:32 -04001#pragma once
2
3#include <functional>
4#include <vector>
5#include "fan.hpp"
6#include "rpolicy.hpp"
7
8namespace phosphor
9{
10namespace fan
11{
12namespace presence
13{
14
15class PresenceSensor;
16
17/**
18 * @class Fallback
19 * @brief Fallback redundancy policy.
20 *
21 * The fallback redundancy policy falls back to
22 * subsequent presence sensors when the active
23 * sensor indicates not present and a fallback
24 * sensor indicates the fan is present.
25 */
26class Fallback : public RedundancyPolicy
27{
28 public:
29 Fallback() = delete;
30 Fallback(const Fallback&) = default;
31 Fallback& operator=(const Fallback&) = default;
32 Fallback(Fallback&&) = default;
33 Fallback& operator=(Fallback&&) = default;
34 ~Fallback() = default;
35
36 /**
37 * @brief Construct a fallback policy.
38 *
39 * @param[in] fan - The fan associated with the policy.
40 * @param[in] s - The set of sensors associated with the policy.
41 */
42 Fallback(
43 const Fan& fan,
44 const std::vector<std::reference_wrapper<PresenceSensor>>& s) :
45 RedundancyPolicy(fan), sensors(s)
46 {
47 activeSensor = sensors.begin();
48 }
49
50 /**
51 * @brief stateChanged
52 *
53 * Update the inventory and execute the fallback
54 * policy.
55 *
56 * @param[in] present - The new presence state according
57 * to the active sensor.
Brad Bishop11083ec2017-07-25 19:08:53 -040058 * @param[in] sensor - The sensor that changed state.
Brad Bishopbfb81602017-06-14 21:14:32 -040059 */
Brad Bishop11083ec2017-07-25 19:08:53 -040060 void stateChanged(bool present, PresenceSensor& sensor) override;
Brad Bishopbfb81602017-06-14 21:14:32 -040061
62 /**
63 * @brief monitor
64 *
65 * Start monitoring the fan.
66 */
67 void monitor() override;
68
69 private:
70
71 /** @brief All presence sensors in the redundancy set. */
72 std::vector<std::reference_wrapper<PresenceSensor>> sensors;
73
74 /** @brief The active presence sensor. */
75 decltype(sensors)::iterator activeSensor;
76};
77
78} // namespace presence
79} // namespace fan
80} // namespace phosphor