George Liu | c777bef | 2020-11-23 17:04:21 +0800 | [diff] [blame^] | 1 | #pragma once |
| 2 | |
| 3 | #include "manager.hpp" |
| 4 | |
| 5 | #include <sdeventplus/utility/timer.hpp> |
| 6 | |
| 7 | #include <vector> |
| 8 | |
| 9 | namespace phosphor |
| 10 | { |
| 11 | namespace led |
| 12 | { |
| 13 | |
| 14 | /** @class LampTest |
| 15 | * @brief Manager LampTest feature |
| 16 | */ |
| 17 | class LampTest |
| 18 | { |
| 19 | public: |
| 20 | LampTest() = delete; |
| 21 | ~LampTest() = default; |
| 22 | LampTest(const LampTest&) = delete; |
| 23 | LampTest& operator=(const LampTest&) = delete; |
| 24 | LampTest(LampTest&&) = default; |
| 25 | LampTest& operator=(LampTest&&) = default; |
| 26 | |
| 27 | /** @brief Constructs LED LampTest |
| 28 | * |
| 29 | * Constructs timer and when the timeout occurs, the stop method is called |
| 30 | * back to stop timer and also end the lamp test. |
| 31 | * |
| 32 | * @param[in] event - sd event handler |
| 33 | * @param[in] manager - reference to manager instance |
| 34 | */ |
| 35 | LampTest(const sdeventplus::Event& event, Manager& manager) : |
| 36 | timer(event, std::bind(std::mem_fn(&LampTest::timeOutHandler), this)), |
| 37 | manager(manager) |
| 38 | {} |
| 39 | |
| 40 | /** @brief the lamp test request handler |
| 41 | * |
| 42 | * @param[in] value - true: start lamptest |
| 43 | * false: stop lamptest |
| 44 | * @return |
| 45 | */ |
| 46 | void requestHandler(bool value); |
| 47 | |
| 48 | private: |
| 49 | /** @brief Timer used for LEDs lamp test period */ |
| 50 | sdeventplus::utility::Timer<sdeventplus::ClockId::Monotonic> timer; |
| 51 | |
| 52 | /** @brief Reference to Manager object */ |
| 53 | Manager& manager; |
| 54 | |
| 55 | /** @brief Start and restart lamp test depending on what is the current |
| 56 | * state. */ |
| 57 | void start(); |
| 58 | |
| 59 | /** @brief Stop lamp test. */ |
| 60 | void stop(); |
| 61 | |
| 62 | /** @brief This method gets called when the lamp test procedure is done as |
| 63 | * part of timeout. */ |
| 64 | void timeOutHandler(); |
| 65 | }; |
| 66 | |
| 67 | } // namespace led |
| 68 | } // namespace phosphor |