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 DEASSERT = 0;
18 
19 /** @class Physical
20  *  @brief Responsible for applying actions on a particular physical LED
21  */
22 class Physical :
23     public sdbusplus::server::object::object<
24         sdbusplus::xyz::openbmc_project::Led::server::Physical>
25 {
26   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;
33 
34     /** @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
42      * @param[in] color     - led color name
43      */
44     Physical(sdbusplus::bus::bus& bus, const std::string& objPath,
45              SysfsLed& led, const std::string& color = "") :
46 
47         sdbusplus::server::object::object<
48             sdbusplus::xyz::openbmc_project::Led::server::Physical>(
49             bus, objPath.c_str(), true),
50         led(led)
51     {
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 
56         // Read led color from enviroment and set it in DBus.
57         setLedColor(color);
58 
59         // 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 
70   private:
71     /** @brief Associated LED implementation
72      */
73     SysfsLed& led;
74 
75     /** @brief The value that will assert the LED */
76     unsigned long assert;
77 
78     /** @brief reads sysfs and then setsup the parameteres accordingly
79      *
80      *  @return None
81      */
82     void setInitialState();
83 
84     /** @brief Applies the user triggered action on the LED
85      *   by writing to sysfs
86      *
87      *  @param [in] current - Current state of LED
88      *  @param [in] request - Requested state
89      *
90      *  @return None
91      */
92     void driveLED(Action current, Action request);
93 
94     /** @brief Sets the LED to either ON or OFF state
95      *
96      *  @param [in] action - Requested action. Could be OFF or ON
97      *  @return None
98      */
99     void stableStateOperation(Action action);
100 
101     /** @brief Sets the LED to BLINKING
102      *
103      *  @return None
104      */
105     void blinkOperation();
106 
107     /** @brief set led color property in DBus
108      *
109      *  @param[in] color - led color name
110      */
111     void setLedColor(const std::string& color);
112 };
113 
114 } // namespace led
115 } // namespace phosphor
116