blob: ef0d7b09349a93bd367b92c49dd4ba1c0f4452f0 [file] [log] [blame]
George Liuc777bef2020-11-23 17:04:21 +08001#pragma once
2
George Liu87fd11c2020-11-23 16:40:14 +08003#include "group.hpp"
George Liuc777bef2020-11-23 17:04:21 +08004#include "manager.hpp"
5
6#include <sdeventplus/utility/timer.hpp>
7
George Liub6151622020-11-23 18:16:18 +08008#include <queue>
George Liuc777bef2020-11-23 17:04:21 +08009#include <vector>
10
11namespace phosphor
12{
13namespace led
14{
15
16/** @class LampTest
17 * @brief Manager LampTest feature
18 */
19class 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 Liu87fd11c2020-11-23 16:40:14 +080039 manager(manager), groupObj(NULL)
George Liuc777bef2020-11-23 17:04:21 +080040 {}
41
42 /** @brief the lamp test request handler
43 *
George Liu87fd11c2020-11-23 16:40:14 +080044 * @param[in] group - Pointer to Group object
George Liuc777bef2020-11-23 17:04:21 +080045 * @param[in] value - true: start lamptest
46 * false: stop lamptest
47 * @return
48 */
George Liu87fd11c2020-11-23 16:40:14 +080049 void requestHandler(Group* group, bool value);
George Liuc777bef2020-11-23 17:04:21 +080050
George Liub6151622020-11-23 18:16:18 +080051 /** @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 Liuc777bef2020-11-23 17:04:21 +080063 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 Liu87fd11c2020-11-23 16:40:14 +080070 /** 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 Liub6151622020-11-23 18:16:18 +080079 /** @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 Liuc777bef2020-11-23 17:04:21 +080089 /** @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 Liub6151622020-11-23 18:16:18 +080099
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 Liuc777bef2020-11-23 17:04:21 +0800113};
114
115} // namespace led
116} // namespace phosphor