summaryrefslogtreecommitdiffstats
path: root/monitor/nonzero_speed_trust.hpp
blob: 3d14adfabe0b102d4d6c9853a4acb46d38c1409b (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
#pragma once

#include "trust_group.hpp"

namespace phosphor
{
namespace fan
{
namespace trust
{

/**
 * @class NonzeroSpeed
 *
 * A trust group where the sensors in the group are trusted as long
 * as at least one of them has a nonzero speed.  If all sensors
 * have a speed of zero, then no sensor in the group is trusted.
 */
class NonzeroSpeed : public Group
{
    public:

        NonzeroSpeed() = delete;
        ~NonzeroSpeed() = default;
        NonzeroSpeed(const NonzeroSpeed&) = delete;
        NonzeroSpeed& operator=(const NonzeroSpeed&) = delete;
        NonzeroSpeed(NonzeroSpeed&&) = default;
        NonzeroSpeed& operator=(NonzeroSpeed&&) = default;

        /**
         * Constructor
         *
         * @param[in] names - the names of the sensors in the group
         */
        explicit NonzeroSpeed(const std::vector<std::string>& names) :
                Group(names)
        {
        }

    private:

        /**
         * Determines if the group is trusted by checking
         * if any sensor has a nonzero speed.  If all speeds
         * are zero, then no sensors in the group are trusted.
         *
         * @return bool - if group is trusted or not
         */
        bool checkGroupTrust() override
        {
            return std::any_of(
                    _sensors.begin(),
                    _sensors.end(),
                    [](const auto& s)
                    {
                        return s.get()->getInput() != 0;
                    });
        }
};

}
}
}
OpenPOWER on IntegriCloud