blob: 9001579049f59a47115890ced5a37c51b09de2c3 [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{
Matthew Barth177fe982020-05-26 11:05:19 -050021 public:
22 NonzeroSpeed() = delete;
23 ~NonzeroSpeed() = default;
24 NonzeroSpeed(const NonzeroSpeed&) = delete;
25 NonzeroSpeed& operator=(const NonzeroSpeed&) = delete;
26 NonzeroSpeed(NonzeroSpeed&&) = default;
27 NonzeroSpeed& operator=(NonzeroSpeed&&) = default;
Matt Spinler0ada59f2017-09-28 10:38:11 -050028
Matthew Barth177fe982020-05-26 11:05:19 -050029 /**
30 * Constructor
31 *
32 * @param[in] names - the names of the sensors and its inclusion in
33 * determining trust for the group
34 */
35 explicit NonzeroSpeed(const std::vector<GroupDefinition>& names) :
36 Group(names)
37 {}
Matt Spinler0ada59f2017-09-28 10:38:11 -050038
Matthew Barth177fe982020-05-26 11:05:19 -050039 private:
40 /**
41 * Determines if the group is trusted by checking
42 * if any sensor included in the trust determination
43 * has a nonzero speed. If all the speeds of these sensors
44 * are zero, then no sensors in the group are trusted.
45 *
46 * @return bool - if group is trusted or not
47 */
48 bool checkGroupTrust() override
49 {
50 return std::any_of(_sensors.begin(), _sensors.end(), [](const auto& s) {
51 return s.inTrust && s.sensor->getInput() != 0;
52 });
53 }
Matt Spinler0ada59f2017-09-28 10:38:11 -050054};
55
Matthew Barth177fe982020-05-26 11:05:19 -050056} // namespace trust
57} // namespace fan
58} // namespace phosphor