blob: b36d6e8e5ea2b0ee7d8163bbc2a19bb6ca74bbf5 [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
Patrick Williams97db22f2022-03-30 15:01:07 -050019using PhysicalIfaces = sdbusplus::server::object_t<
20 sdbusplus::xyz::openbmc_project::Led::server::Physical>;
Patrick Williams97db22f2022-03-30 15:01:07 -050021
Vishwanatha Subbannabda97eb2016-11-30 12:21:25 +053022/** @class Physical
23 * @brief Responsible for applying actions on a particular physical LED
24 */
Patrick Williams97db22f2022-03-30 15:01:07 -050025class Physical : public PhysicalIfaces
Vishwanatha Subbannabda97eb2016-11-30 12:21:25 +053026{
Andrew Jefferyc41bf5b2018-05-25 16:39:22 +093027 public:
28 Physical() = delete;
Andrew Jefferyc060c282023-02-07 15:54:43 +103029 ~Physical() override = default;
Andrew Jefferyc41bf5b2018-05-25 16:39:22 +093030 Physical(const Physical&) = delete;
31 Physical& operator=(const Physical&) = delete;
32 Physical(Physical&&) = delete;
33 Physical& operator=(Physical&&) = delete;
Vishwanatha Subbannabda97eb2016-11-30 12:21:25 +053034
Andrew Jefferyc41bf5b2018-05-25 16:39:22 +093035 /** @brief Constructs LED object. Argument 'true' says that we hold off
36 * from sending the signals since we need to do some house keeping and
37 * only when we finish that, we are considered active and can then
38 * broadcast the signal.
39 *
40 * @param[in] bus - system dbus handler
41 * @param[in] objPath - The Dbus path that hosts physical LED
42 * @param[in] ledPath - sysfs path where this LED is exported
Alexander Soldatov97ddb722019-04-16 09:10:00 +030043 * @param[in] color - led color name
Andrew Jefferyc41bf5b2018-05-25 16:39:22 +093044 */
Patrick Williamsff3d5382022-07-22 19:26:55 -050045 Physical(sdbusplus::bus_t& bus, const std::string& objPath, SysfsLed& led,
46 const std::string& color = "") :
Patrick Williams97db22f2022-03-30 15:01:07 -050047 PhysicalIfaces(bus, objPath.c_str(),
48 PhysicalIfaces::action::defer_emit),
Andrew Jeffery42e02d32018-05-24 13:34:05 +093049 led(led)
Andrew Jefferyc41bf5b2018-05-25 16:39:22 +093050 {
51 // Suppose this is getting launched as part of BMC reboot, then we
52 // need to save what the micro-controller currently has.
53 setInitialState();
54
Alexander Soldatov97ddb722019-04-16 09:10:00 +030055 // Read led color from enviroment and set it in DBus.
56 setLedColor(color);
57
Andrew Jefferyc41bf5b2018-05-25 16:39:22 +093058 // We are now ready.
59 emit_object_added();
60 }
61
62 /** @brief Overloaded State Property Setter function
63 *
64 * @param[in] value - One of OFF / ON / BLINK
65 * @return - Success or exception thrown
66 */
67 Action state(Action value) override;
68
Vishwanatha Subbannadb21bc02021-03-26 00:32:46 -050069 /** @brief Overriden State Property Getter function
70 *
71 * @return - One of OFF / ON / BLINK
72 */
73 Action state() const override;
74
Andrew Jefferyc41bf5b2018-05-25 16:39:22 +093075 private:
Andrew Jeffery42e02d32018-05-24 13:34:05 +093076 /** @brief Associated LED implementation
Andrew Jefferyc41bf5b2018-05-25 16:39:22 +093077 */
Andrew Jeffery42e02d32018-05-24 13:34:05 +093078 SysfsLed& led;
Andrew Jefferyc41bf5b2018-05-25 16:39:22 +093079
Andrew Jeffery5b1417b2019-03-18 17:20:37 +103080 /** @brief The value that will assert the LED */
Andrew Jeffery478d0a72023-02-07 15:57:12 +103081 unsigned long assert{};
Andrew Jeffery5b1417b2019-03-18 17:20:37 +103082
Andrew Jefferyc41bf5b2018-05-25 16:39:22 +093083 /** @brief reads sysfs and then setsup the parameteres accordingly
84 *
85 * @return None
86 */
87 void setInitialState();
88
89 /** @brief Applies the user triggered action on the LED
90 * by writing to sysfs
91 *
92 * @param [in] current - Current state of LED
93 * @param [in] request - Requested state
94 *
95 * @return None
96 */
97 void driveLED(Action current, Action request);
98
99 /** @brief Sets the LED to either ON or OFF state
100 *
101 * @param [in] action - Requested action. Could be OFF or ON
102 * @return None
103 */
104 void stableStateOperation(Action action);
105
106 /** @brief Sets the LED to BLINKING
107 *
108 * @return None
109 */
110 void blinkOperation();
Alexander Soldatov97ddb722019-04-16 09:10:00 +0300111
112 /** @brief set led color property in DBus
113 *
114 * @param[in] color - led color name
115 */
116 void setLedColor(const std::string& color);
Vishwanatha Subbannabda97eb2016-11-30 12:21:25 +0530117};
118
119} // namespace led
Andrew Jefferyc41bf5b2018-05-25 16:39:22 +0930120} // namespace phosphor