blob: 4242952086a5ca19f61c10c530529e32c8c77ab7 [file] [log] [blame]
Vishwanatha Subbannabda97eb2016-11-30 12:21:25 +05301#pragma once
2
Andrew Jeffery42e02d32018-05-24 13:34:05 +09303#include "sysfs.hpp"
4
Vishwanatha Subbannabda97eb2016-11-30 12:21:25 +05305#include <sdbusplus/bus.hpp>
6#include <sdbusplus/server/object.hpp>
Vishwanatha Subbannae0891732017-03-10 15:27:23 +05307#include <xyz/openbmc_project/Led/Physical/server.hpp>
Andrew Jeffery42e02d32018-05-24 13:34:05 +09308
George Liu61b90632020-06-22 10:55:13 +08009#include <fstream>
10#include <string>
11
Vishwanatha Subbannabda97eb2016-11-30 12:21:25 +053012namespace phosphor
13{
14namespace led
15{
Andrew Jeffery5b1417b2019-03-18 17:20:37 +103016/** @brief De-assert value */
Andrew Jefferyaee9c2c2018-05-25 14:05:40 +093017constexpr unsigned long DEASSERT = 0;
Vishwanatha Subbannabda97eb2016-11-30 12:21:25 +053018
19/** @class Physical
20 * @brief Responsible for applying actions on a particular physical LED
21 */
George Liu61b90632020-06-22 10:55:13 +080022class Physical :
23 public sdbusplus::server::object::object<
24 sdbusplus::xyz::openbmc_project::Led::server::Physical>
Vishwanatha Subbannabda97eb2016-11-30 12:21:25 +053025{
Andrew Jefferyc41bf5b2018-05-25 16:39:22 +093026 public:
27 Physical() = delete;
28 ~Physical() = default;
29 Physical(const Physical&) = delete;
30 Physical& operator=(const Physical&) = delete;
31 Physical(Physical&&) = delete;
32 Physical& operator=(Physical&&) = delete;
Vishwanatha Subbannabda97eb2016-11-30 12:21:25 +053033
Andrew Jefferyc41bf5b2018-05-25 16:39:22 +093034 /** @brief Constructs LED object. Argument 'true' says that we hold off
35 * from sending the signals since we need to do some house keeping and
36 * only when we finish that, we are considered active and can then
37 * broadcast the signal.
38 *
39 * @param[in] bus - system dbus handler
40 * @param[in] objPath - The Dbus path that hosts physical LED
41 * @param[in] ledPath - sysfs path where this LED is exported
Alexander Soldatov97ddb722019-04-16 09:10:00 +030042 * @param[in] color - led color name
Andrew Jefferyc41bf5b2018-05-25 16:39:22 +093043 */
44 Physical(sdbusplus::bus::bus& bus, const std::string& objPath,
Alexander Soldatov97ddb722019-04-16 09:10:00 +030045 SysfsLed& led, const std::string& color = "") :
Vishwanatha Subbannabda97eb2016-11-30 12:21:25 +053046
Andrew Jefferyc41bf5b2018-05-25 16:39:22 +093047 sdbusplus::server::object::object<
48 sdbusplus::xyz::openbmc_project::Led::server::Physical>(
49 bus, objPath.c_str(), true),
Andrew Jeffery42e02d32018-05-24 13:34:05 +093050 led(led)
Andrew Jefferyc41bf5b2018-05-25 16:39:22 +093051 {
52 // Suppose this is getting launched as part of BMC reboot, then we
53 // need to save what the micro-controller currently has.
54 setInitialState();
55
Alexander Soldatov97ddb722019-04-16 09:10:00 +030056 // Read led color from enviroment and set it in DBus.
57 setLedColor(color);
58
Andrew Jefferyc41bf5b2018-05-25 16:39:22 +093059 // We are now ready.
60 emit_object_added();
61 }
62
63 /** @brief Overloaded State Property Setter function
64 *
65 * @param[in] value - One of OFF / ON / BLINK
66 * @return - Success or exception thrown
67 */
68 Action state(Action value) override;
69
Vishwanatha Subbannadb21bc02021-03-26 00:32:46 -050070 /** @brief Overriden State Property Getter function
71 *
72 * @return - One of OFF / ON / BLINK
73 */
74 Action state() const override;
75
Andrew Jefferyc41bf5b2018-05-25 16:39:22 +093076 private:
Andrew Jeffery42e02d32018-05-24 13:34:05 +093077 /** @brief Associated LED implementation
Andrew Jefferyc41bf5b2018-05-25 16:39:22 +093078 */
Andrew Jeffery42e02d32018-05-24 13:34:05 +093079 SysfsLed& led;
Andrew Jefferyc41bf5b2018-05-25 16:39:22 +093080
Andrew Jeffery5b1417b2019-03-18 17:20:37 +103081 /** @brief The value that will assert the LED */
82 unsigned long assert;
83
Andrew Jefferyc41bf5b2018-05-25 16:39:22 +093084 /** @brief reads sysfs and then setsup the parameteres accordingly
85 *
86 * @return None
87 */
88 void setInitialState();
89
90 /** @brief Applies the user triggered action on the LED
91 * by writing to sysfs
92 *
93 * @param [in] current - Current state of LED
94 * @param [in] request - Requested state
95 *
96 * @return None
97 */
98 void driveLED(Action current, Action request);
99
100 /** @brief Sets the LED to either ON or OFF state
101 *
102 * @param [in] action - Requested action. Could be OFF or ON
103 * @return None
104 */
105 void stableStateOperation(Action action);
106
107 /** @brief Sets the LED to BLINKING
108 *
109 * @return None
110 */
111 void blinkOperation();
Alexander Soldatov97ddb722019-04-16 09:10:00 +0300112
113 /** @brief set led color property in DBus
114 *
115 * @param[in] color - led color name
116 */
117 void setLedColor(const std::string& color);
Vishwanatha Subbannabda97eb2016-11-30 12:21:25 +0530118};
119
120} // namespace led
Andrew Jefferyc41bf5b2018-05-25 16:39:22 +0930121} // namespace phosphor