summaryrefslogtreecommitdiffstats
path: root/presence/fallback.hpp
blob: 280ef1ceb4d8e9b75ea588d53c9d0d2d984977ae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#pragma once

#include <functional>
#include <vector>
#include "fan.hpp"
#include "rpolicy.hpp"

namespace phosphor
{
namespace fan
{
namespace presence
{

class PresenceSensor;

/**
 * @class Fallback
 * @brief Fallback redundancy policy.
 *
 * The fallback redundancy policy falls back to
 * subsequent presence sensors when the active
 * sensor indicates not present and a fallback
 * sensor indicates the fan is present.
 */
class Fallback : public RedundancyPolicy
{
    public:
        Fallback() = delete;
        Fallback(const Fallback&) = default;
        Fallback& operator=(const Fallback&) = default;
        Fallback(Fallback&&) = default;
        Fallback& operator=(Fallback&&) = default;
        ~Fallback() = default;

        /**
         * @brief Construct a fallback policy.
         *
         * @param[in] fan - The fan associated with the policy.
         * @param[in] s - The set of sensors associated with the policy.
         */
        Fallback(
                const Fan& fan,
                const std::vector<std::reference_wrapper<PresenceSensor>>& s) :
            RedundancyPolicy(fan), sensors(s)
        {
            activeSensor = sensors.begin();
        }

        /**
         * @brief stateChanged
         *
         * Update the inventory and execute the fallback
         * policy.
         *
         * @param[in] present - The new presence state according
         *             to the active sensor.
         * @param[in] sensor - The sensor that changed state.
         */
        void stateChanged(bool present, PresenceSensor& sensor) override;

        /**
         * @brief monitor
         *
         * Start monitoring the fan.
         */
        void monitor() override;

    private:

        /** @brief All presence sensors in the redundancy set. */
        std::vector<std::reference_wrapper<PresenceSensor>> sensors;

        /** @brief The active presence sensor. */
        decltype(sensors)::iterator activeSensor;
};

} // namespace presence
} // namespace fan
} // namespace phosphor
OpenPOWER on IntegriCloud