1 #pragma once
2 
3 #include "fan.hpp"
4 #include "rpolicy.hpp"
5 
6 #include <functional>
7 #include <vector>
8 
9 namespace phosphor
10 {
11 namespace fan
12 {
13 namespace presence
14 {
15 
16 class 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  */
26 class AnyOf : public RedundancyPolicy
27 {
28   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;
35 
36     /**
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);
44 
45     /**
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;
56 
57     /**
58      * @brief monitor
59      *
60      * Start monitoring the fan.
61      */
62     void monitor() override;
63 
64   private:
65     /** @brief All presence sensors in the redundancy set. */
66     std::vector<std::tuple<std::reference_wrapper<PresenceSensor>, bool>> state;
67 };
68 
69 } // namespace presence
70 } // namespace fan
71 } // namespace phosphor
72