blob: efe3c790b9261b5ed171f21beba669092e2760d6 [file] [log] [blame]
Brad Bishop00b52082017-07-25 19:52:22 -04001#pragma once
2
Brad Bishop00b52082017-07-25 19:52:22 -04003#include "fan.hpp"
4#include "rpolicy.hpp"
5
Matthew Barth2d2caa32020-05-26 11:07:24 -05006#include <functional>
7#include <vector>
8
Brad Bishop00b52082017-07-25 19:52:22 -04009namespace phosphor
10{
11namespace fan
12{
13namespace presence
14{
15
16class PresenceSensor;
17
18/**
19 * @class AnyOf
20 * @brief AnyOf redundancy policy.
21 *
22 * The any of redundancy policy monitors all sensor
23 * states in the redundancy set and reports true when any
24 * sensor in the set reports true.
25 */
26class AnyOf : public RedundancyPolicy
27{
Matthew Barth2d2caa32020-05-26 11:07:24 -050028 public:
29 AnyOf() = delete;
30 AnyOf(const AnyOf&) = default;
31 AnyOf& operator=(const AnyOf&) = default;
32 AnyOf(AnyOf&&) = default;
33 AnyOf& operator=(AnyOf&&) = default;
34 ~AnyOf() = default;
Brad Bishop00b52082017-07-25 19:52:22 -040035
Matthew Barth2d2caa32020-05-26 11:07:24 -050036 /**
37 * @brief Construct an any of bitwise 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 AnyOf(const Fan& fan,
43 const std::vector<std::reference_wrapper<PresenceSensor>>& s);
Brad Bishop00b52082017-07-25 19:52:22 -040044
Matthew Barth2d2caa32020-05-26 11:07:24 -050045 /**
46 * @brief stateChanged
47 *
48 * Update the inventory and execute the fallback
49 * policy.
50 *
51 * @param[in] present - The new presence state according
52 * to the specified sensor.
53 * @param[in] sensor - The sensor reporting the new state.
54 */
55 void stateChanged(bool present, PresenceSensor& sensor) override;
Brad Bishop00b52082017-07-25 19:52:22 -040056
Matthew Barth2d2caa32020-05-26 11:07:24 -050057 /**
58 * @brief monitor
59 *
60 * Start monitoring the fan.
61 */
62 void monitor() override;
Brad Bishop00b52082017-07-25 19:52:22 -040063
Matthew Barth2d2caa32020-05-26 11:07:24 -050064 private:
65 /** @brief All presence sensors in the redundancy set. */
66 std::vector<std::tuple<std::reference_wrapper<PresenceSensor>, bool>> state;
Brad Bishop00b52082017-07-25 19:52:22 -040067};
68
69} // namespace presence
70} // namespace fan
71} // namespace phosphor