1 #pragma once 2 3 #include "sysfs.hpp" 4 5 #include <sdbusplus/bus.hpp> 6 #include <sdbusplus/server/object.hpp> 7 #include <xyz/openbmc_project/Led/Physical/server.hpp> 8 9 #include <fstream> 10 #include <string> 11 12 namespace phosphor 13 { 14 namespace led 15 { 16 /** @brief De-assert value */ 17 constexpr unsigned long deasserted = 0; 18 19 using PhysicalIfaces = sdbusplus::server::object_t< 20 sdbusplus::xyz::openbmc_project::Led::server::Physical>; 21 22 /** @class Physical 23 * @brief Responsible for applying actions on a particular physical LED 24 */ 25 class Physical : public PhysicalIfaces 26 { 27 public: 28 Physical() = delete; 29 ~Physical() override = default; 30 Physical(const Physical&) = delete; 31 Physical& operator=(const Physical&) = delete; 32 Physical(Physical&&) = delete; 33 Physical& operator=(Physical&&) = delete; 34 35 /** @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 43 * @param[in] color - led color name 44 */ 45 Physical(sdbusplus::bus_t& bus, const std::string& objPath, SysfsLed& led, 46 const std::string& color = "") : 47 PhysicalIfaces(bus, objPath.c_str(), 48 PhysicalIfaces::action::defer_emit), 49 led(led) 50 { 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 55 // Read led color from enviroment and set it in DBus. 56 setLedColor(color); 57 58 // 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 69 /** @brief Overriden State Property Getter function 70 * 71 * @return - One of OFF / ON / BLINK 72 */ 73 Action state() const override; 74 75 private: 76 /** @brief Associated LED implementation 77 */ 78 SysfsLed& led; 79 80 /** @brief The value that will assert the LED */ 81 unsigned long assert{}; 82 83 /** @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(); 111 112 /** @brief set led color property in DBus 113 * 114 * @param[in] color - led color name 115 */ 116 void setLedColor(const std::string& color); 117 }; 118 119 } // namespace led 120 } // namespace phosphor 121