George Liu | c777bef | 2020-11-23 17:04:21 +0800 | [diff] [blame] | 1 | #pragma once |
| 2 | |
George Liu | 87fd11c | 2020-11-23 16:40:14 +0800 | [diff] [blame] | 3 | #include "group.hpp" |
George Liu | c777bef | 2020-11-23 17:04:21 +0800 | [diff] [blame] | 4 | #include "manager.hpp" |
| 5 | |
| 6 | #include <sdeventplus/utility/timer.hpp> |
| 7 | |
George Liu | b615162 | 2020-11-23 18:16:18 +0800 | [diff] [blame^] | 8 | #include <queue> |
George Liu | c777bef | 2020-11-23 17:04:21 +0800 | [diff] [blame] | 9 | #include <vector> |
| 10 | |
| 11 | namespace phosphor |
| 12 | { |
| 13 | namespace led |
| 14 | { |
| 15 | |
| 16 | /** @class LampTest |
| 17 | * @brief Manager LampTest feature |
| 18 | */ |
| 19 | class LampTest |
| 20 | { |
| 21 | public: |
| 22 | LampTest() = delete; |
| 23 | ~LampTest() = default; |
| 24 | LampTest(const LampTest&) = delete; |
| 25 | LampTest& operator=(const LampTest&) = delete; |
| 26 | LampTest(LampTest&&) = default; |
| 27 | LampTest& operator=(LampTest&&) = default; |
| 28 | |
| 29 | /** @brief Constructs LED LampTest |
| 30 | * |
| 31 | * Constructs timer and when the timeout occurs, the stop method is called |
| 32 | * back to stop timer and also end the lamp test. |
| 33 | * |
| 34 | * @param[in] event - sd event handler |
| 35 | * @param[in] manager - reference to manager instance |
| 36 | */ |
| 37 | LampTest(const sdeventplus::Event& event, Manager& manager) : |
| 38 | timer(event, std::bind(std::mem_fn(&LampTest::timeOutHandler), this)), |
George Liu | 87fd11c | 2020-11-23 16:40:14 +0800 | [diff] [blame] | 39 | manager(manager), groupObj(NULL) |
George Liu | c777bef | 2020-11-23 17:04:21 +0800 | [diff] [blame] | 40 | {} |
| 41 | |
| 42 | /** @brief the lamp test request handler |
| 43 | * |
George Liu | 87fd11c | 2020-11-23 16:40:14 +0800 | [diff] [blame] | 44 | * @param[in] group - Pointer to Group object |
George Liu | c777bef | 2020-11-23 17:04:21 +0800 | [diff] [blame] | 45 | * @param[in] value - true: start lamptest |
| 46 | * false: stop lamptest |
| 47 | * @return |
| 48 | */ |
George Liu | 87fd11c | 2020-11-23 16:40:14 +0800 | [diff] [blame] | 49 | void requestHandler(Group* group, bool value); |
George Liu | c777bef | 2020-11-23 17:04:21 +0800 | [diff] [blame] | 50 | |
George Liu | b615162 | 2020-11-23 18:16:18 +0800 | [diff] [blame^] | 51 | /** @brief Update physical LEDs states during lamp test and the lamp test is |
| 52 | * running |
| 53 | * |
| 54 | * @param[in] ledsAssert - LEDs that are to be asserted newly or to a |
| 55 | * different state |
| 56 | * @param[in] ledsDeAssert - LEDs that are to be Deasserted |
| 57 | * |
| 58 | * @return Is running lamp test, true running |
| 59 | */ |
| 60 | bool processLEDUpdates(const Manager::group& ledsAssert, |
| 61 | const Manager::group& ledsDeAssert); |
| 62 | |
George Liu | c777bef | 2020-11-23 17:04:21 +0800 | [diff] [blame] | 63 | private: |
| 64 | /** @brief Timer used for LEDs lamp test period */ |
| 65 | sdeventplus::utility::Timer<sdeventplus::ClockId::Monotonic> timer; |
| 66 | |
| 67 | /** @brief Reference to Manager object */ |
| 68 | Manager& manager; |
| 69 | |
George Liu | 87fd11c | 2020-11-23 16:40:14 +0800 | [diff] [blame] | 70 | /** DBusHandler class handles the D-Bus operations */ |
| 71 | DBusHandler dBusHandler; |
| 72 | |
| 73 | /** @brief Pointer to Group object */ |
| 74 | Group* groupObj; |
| 75 | |
| 76 | /** all the Physical paths */ |
| 77 | std::vector<std::string> physicalLEDPaths; |
| 78 | |
George Liu | b615162 | 2020-11-23 18:16:18 +0800 | [diff] [blame^] | 79 | /** @brief Queue to save LED states during lamp test */ |
| 80 | std::queue<std::pair<Manager::group, Manager::group>> |
| 81 | updatedLEDsDuringLampTest; |
| 82 | |
| 83 | /** @brief Get state of the lamp test operation */ |
| 84 | bool isLampTestRunning{false}; |
| 85 | |
| 86 | /** @brief Physical LED states prior to lamp test */ |
| 87 | Manager::group physicalLEDStatesPriorToLampTest; |
| 88 | |
George Liu | c777bef | 2020-11-23 17:04:21 +0800 | [diff] [blame] | 89 | /** @brief Start and restart lamp test depending on what is the current |
| 90 | * state. */ |
| 91 | void start(); |
| 92 | |
| 93 | /** @brief Stop lamp test. */ |
| 94 | void stop(); |
| 95 | |
| 96 | /** @brief This method gets called when the lamp test procedure is done as |
| 97 | * part of timeout. */ |
| 98 | void timeOutHandler(); |
George Liu | b615162 | 2020-11-23 18:16:18 +0800 | [diff] [blame^] | 99 | |
| 100 | /** @brief Restore the physical LEDs states after the lamp test finishes */ |
| 101 | void restorePhysicalLedStates(); |
| 102 | |
| 103 | /** @brief Store the physical LEDs states before the lamp test start */ |
| 104 | void storePhysicalLEDsStates(); |
| 105 | |
| 106 | /** @brief Returns action enum based on string |
| 107 | * |
| 108 | * @param[in] str - Action string |
| 109 | * |
| 110 | * @return enumeration equivalent of the passed in string |
| 111 | */ |
| 112 | Layout::Action getActionFromString(const std::string& str); |
George Liu | c777bef | 2020-11-23 17:04:21 +0800 | [diff] [blame] | 113 | }; |
| 114 | |
| 115 | } // namespace led |
| 116 | } // namespace phosphor |