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 | { |
Matthew Barth | 177fe98 | 2020-05-26 11:05:19 -0500 | [diff] [blame] | 21 | 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 Spinler | 0ada59f | 2017-09-28 10:38:11 -0500 | [diff] [blame] | 28 | |
Matthew Barth | 177fe98 | 2020-05-26 11:05:19 -0500 | [diff] [blame] | 29 | /** |
| 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 Spinler | 0ada59f | 2017-09-28 10:38:11 -0500 | [diff] [blame] | 38 | |
Matthew Barth | 177fe98 | 2020-05-26 11:05:19 -0500 | [diff] [blame] | 39 | 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 Spinler | 0ada59f | 2017-09-28 10:38:11 -0500 | [diff] [blame] | 54 | }; |
| 55 | |
Matthew Barth | 177fe98 | 2020-05-26 11:05:19 -0500 | [diff] [blame] | 56 | } // namespace trust |
| 57 | } // namespace fan |
| 58 | } // namespace phosphor |