blob: 93fce7d5192969fdd7ae845d8ce66fa80f8cdf07 [file] [log] [blame]
Matt Spinler0ada59f2017-09-28 10:38:11 -05001#pragma once
2
3#include "trust_group.hpp"
4
5namespace phosphor
6{
7namespace fan
8{
9namespace trust
10{
11
12/**
13 * @class NonzeroSpeed
14 *
15 * A trust group where the sensors in the group are trusted as long
16 * as at least one of them has a nonzero speed. If all sensors
17 * have a speed of zero, then no sensor in the group is trusted.
18 */
19class NonzeroSpeed : public Group
20{
21 public:
22
23 NonzeroSpeed() = delete;
24 ~NonzeroSpeed() = default;
25 NonzeroSpeed(const NonzeroSpeed&) = delete;
26 NonzeroSpeed& operator=(const NonzeroSpeed&) = delete;
27 NonzeroSpeed(NonzeroSpeed&&) = default;
28 NonzeroSpeed& operator=(NonzeroSpeed&&) = default;
29
30 /**
31 * Constructor
32 *
33 * @param[in] names - the names of the sensors in the group
34 */
35 explicit NonzeroSpeed(const std::vector<std::string>& names) :
36 Group(names)
37 {
38 }
39
40 private:
41
42 /**
43 * Determines if the group is trusted by checking
44 * if any sensor has a nonzero speed. If all speeds
45 * are zero, then no sensors in the group are trusted.
46 *
47 * @return bool - if group is trusted or not
48 */
49 bool checkGroupTrust() override
50 {
51 return std::any_of(
52 _sensors.begin(),
53 _sensors.end(),
54 [](const auto& s)
55 {
Matthew Barth32affb92018-02-16 16:11:13 -060056 return s->getInput() != 0;
Matt Spinler0ada59f2017-09-28 10:38:11 -050057 });
58 }
59};
60
61}
62}
63}