Matt Spinler | 0ada59f | 2017-09-28 10:38:11 -0500 | [diff] [blame] | 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 | * |
Matthew Barth | 6f31d19 | 2018-01-30 13:06:27 -0600 | [diff] [blame] | 33 | * @param[in] names - the names of the sensors and its inclusion in |
| 34 | * determining trust for the group |
Matt Spinler | 0ada59f | 2017-09-28 10:38:11 -0500 | [diff] [blame] | 35 | */ |
Matthew Barth | 6f31d19 | 2018-01-30 13:06:27 -0600 | [diff] [blame] | 36 | explicit NonzeroSpeed(const std::vector<GroupDefinition>& names) : |
Matt Spinler | 0ada59f | 2017-09-28 10:38:11 -0500 | [diff] [blame] | 37 | Group(names) |
| 38 | { |
| 39 | } |
| 40 | |
| 41 | private: |
| 42 | |
| 43 | /** |
| 44 | * Determines if the group is trusted by checking |
Matthew Barth | c63ef39 | 2018-02-16 13:06:36 -0600 | [diff] [blame] | 45 | * if any sensor included in the trust determination |
| 46 | * has a nonzero speed. If all the speeds of these sensors |
Matt Spinler | 0ada59f | 2017-09-28 10:38:11 -0500 | [diff] [blame] | 47 | * are zero, then no sensors in the group are trusted. |
| 48 | * |
| 49 | * @return bool - if group is trusted or not |
| 50 | */ |
| 51 | bool checkGroupTrust() override |
| 52 | { |
| 53 | return std::any_of( |
| 54 | _sensors.begin(), |
| 55 | _sensors.end(), |
| 56 | [](const auto& s) |
| 57 | { |
Matthew Barth | c63ef39 | 2018-02-16 13:06:36 -0600 | [diff] [blame] | 58 | return s.inTrust && s.sensor->getInput() != 0; |
Matt Spinler | 0ada59f | 2017-09-28 10:38:11 -0500 | [diff] [blame] | 59 | }); |
| 60 | } |
| 61 | }; |
| 62 | |
| 63 | } |
| 64 | } |
| 65 | } |