10ada59f9SMatt Spinler #pragma once 20ada59f9SMatt Spinler 30ada59f9SMatt Spinler #include "trust_group.hpp" 40ada59f9SMatt Spinler 50ada59f9SMatt Spinler namespace phosphor 60ada59f9SMatt Spinler { 70ada59f9SMatt Spinler namespace fan 80ada59f9SMatt Spinler { 90ada59f9SMatt Spinler namespace trust 100ada59f9SMatt Spinler { 110ada59f9SMatt Spinler 120ada59f9SMatt Spinler /** 130ada59f9SMatt Spinler * @class NonzeroSpeed 140ada59f9SMatt Spinler * 150ada59f9SMatt Spinler * A trust group where the sensors in the group are trusted as long 160ada59f9SMatt Spinler * as at least one of them has a nonzero speed. If all sensors 170ada59f9SMatt Spinler * have a speed of zero, then no sensor in the group is trusted. 180ada59f9SMatt Spinler */ 190ada59f9SMatt Spinler class NonzeroSpeed : public Group 200ada59f9SMatt Spinler { 210ada59f9SMatt Spinler public: 220ada59f9SMatt Spinler NonzeroSpeed() = delete; 230ada59f9SMatt Spinler ~NonzeroSpeed() = default; 240ada59f9SMatt Spinler NonzeroSpeed(const NonzeroSpeed&) = delete; 250ada59f9SMatt Spinler NonzeroSpeed& operator=(const NonzeroSpeed&) = delete; 260ada59f9SMatt Spinler NonzeroSpeed(NonzeroSpeed&&) = default; 270ada59f9SMatt Spinler NonzeroSpeed& operator=(NonzeroSpeed&&) = default; 280ada59f9SMatt Spinler 290ada59f9SMatt Spinler /** 300ada59f9SMatt Spinler * Constructor 310ada59f9SMatt Spinler * 326f31d19bSMatthew Barth * @param[in] names - the names of the sensors and its inclusion in 336f31d19bSMatthew Barth * determining trust for the group 340ada59f9SMatt Spinler */ NonzeroSpeed(const std::vector<GroupDefinition> & names)356f31d19bSMatthew Barth explicit NonzeroSpeed(const std::vector<GroupDefinition>& names) : 360ada59f9SMatt Spinler Group(names) 37*177fe986SMatthew Barth {} 380ada59f9SMatt Spinler 390ada59f9SMatt Spinler private: 400ada59f9SMatt Spinler /** 410ada59f9SMatt Spinler * Determines if the group is trusted by checking 42c63ef39fSMatthew Barth * if any sensor included in the trust determination 43c63ef39fSMatthew Barth * has a nonzero speed. If all the speeds of these sensors 440ada59f9SMatt Spinler * are zero, then no sensors in the group are trusted. 450ada59f9SMatt Spinler * 460ada59f9SMatt Spinler * @return bool - if group is trusted or not 470ada59f9SMatt Spinler */ checkGroupTrust()480ada59f9SMatt Spinler bool checkGroupTrust() override 490ada59f9SMatt Spinler { 50*177fe986SMatthew Barth return std::any_of(_sensors.begin(), _sensors.end(), [](const auto& s) { 51c63ef39fSMatthew Barth return s.inTrust && s.sensor->getInput() != 0; 520ada59f9SMatt Spinler }); 530ada59f9SMatt Spinler } 540ada59f9SMatt Spinler }; 550ada59f9SMatt Spinler 56*177fe986SMatthew Barth } // namespace trust 57*177fe986SMatthew Barth } // namespace fan 58*177fe986SMatthew Barth } // namespace phosphor 59