xref: /openbmc/phosphor-fan-presence/monitor/nonzero_speed_trust.hpp (revision 6f31d19b704adf7302f924c1fbb80059fd3e7532)
1 #pragma once
2 
3 #include "trust_group.hpp"
4 
5 namespace phosphor
6 {
7 namespace fan
8 {
9 namespace 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  */
19 class 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 and its inclusion in
34          * determining trust for the group
35          */
36         explicit NonzeroSpeed(const std::vector<GroupDefinition>& names) :
37                 Group(names)
38         {
39         }
40 
41     private:
42 
43         /**
44          * Determines if the group is trusted by checking
45          * if any sensor has a nonzero speed.  If all speeds
46          * are zero, then no sensors in the group are trusted.
47          *
48          * @return bool - if group is trusted or not
49          */
50         bool checkGroupTrust() override
51         {
52             return std::any_of(
53                     _sensors.begin(),
54                     _sensors.end(),
55                     [](const auto& s)
56                     {
57                         return std::get<0>(s)->getInput() != 0;
58                     });
59         }
60 };
61 
62 }
63 }
64 }
65