Matt Spinler | fb35a32 | 2018-11-26 14:30:30 -0600 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include <sdbusplus/bus.hpp> |
| 4 | #include <sdbusplus/bus/match.hpp> |
| 5 | |
| 6 | namespace phosphor |
| 7 | { |
| 8 | namespace button |
| 9 | { |
| 10 | |
| 11 | /** |
| 12 | * @class Handler |
| 13 | * |
| 14 | * This class acts on the signals generated by the |
| 15 | * xyz.openbmc_project.Chassis.Buttons code when |
| 16 | * it detects button presses. |
| 17 | * |
| 18 | * There are 3 buttons supported - Power, ID, and Reset. |
| 19 | * As not all systems may implement each button, this class will |
| 20 | * check for that button on D-Bus before listening for its signals. |
| 21 | */ |
| 22 | class Handler |
| 23 | { |
| 24 | public: |
| 25 | Handler() = delete; |
| 26 | ~Handler() = default; |
| 27 | Handler(const Handler&) = delete; |
| 28 | Handler& operator=(const Handler&) = delete; |
| 29 | Handler(Handler&&) = delete; |
| 30 | Handler& operator=(Handler&&) = delete; |
| 31 | |
| 32 | /** |
| 33 | * @brief Constructor |
| 34 | * |
| 35 | * @param[in] bus - sdbusplus connection object |
| 36 | */ |
| 37 | Handler(sdbusplus::bus::bus& bus); |
| 38 | |
| 39 | private: |
| 40 | /** |
Matt Spinler | 963c65f | 2018-11-26 14:46:41 -0600 | [diff] [blame] | 41 | * @brief The handler for a power button press |
| 42 | * |
| 43 | * It will power on the system if it's currently off, |
| 44 | * else it will soft power it off. |
| 45 | * |
| 46 | * @param[in] msg - sdbusplus message from signal |
| 47 | */ |
| 48 | void powerPressed(sdbusplus::message::message& msg); |
| 49 | |
| 50 | /** |
| 51 | * @brief The handler for a long power button press |
| 52 | * |
| 53 | * If the system is currently powered on, it will |
| 54 | * perform an immediate power off. |
| 55 | * |
| 56 | * @param[in] msg - sdbusplus message from signal |
| 57 | */ |
| 58 | void longPowerPressed(sdbusplus::message::message& msg); |
| 59 | |
| 60 | /** |
Matt Spinler | 69f9351 | 2018-11-26 14:55:58 -0600 | [diff] [blame] | 61 | * @brief The handler for an ID button press |
| 62 | * |
| 63 | * Toggles the ID LED group |
| 64 | * |
| 65 | * @param[in] msg - sdbusplus message from signal |
| 66 | */ |
| 67 | void idPressed(sdbusplus::message::message& msg); |
| 68 | |
| 69 | /** |
Matt Spinler | 06a5bdd | 2018-11-26 14:50:48 -0600 | [diff] [blame] | 70 | * @brief The handler for a reset button press |
| 71 | * |
| 72 | * Reboots the host if it is powered on. |
| 73 | * |
| 74 | * @param[in] msg - sdbusplus message from signal |
| 75 | */ |
| 76 | void resetPressed(sdbusplus::message::message& msg); |
| 77 | |
| 78 | /** |
Matt Spinler | 963c65f | 2018-11-26 14:46:41 -0600 | [diff] [blame] | 79 | * @brief Checks if system is powered on |
| 80 | * |
| 81 | * @return true if powered on, false else |
| 82 | */ |
| 83 | bool poweredOn() const; |
| 84 | |
| 85 | /** |
| 86 | * @brief Returns the service name for an object |
| 87 | * |
| 88 | * @param[in] path - the object path |
| 89 | * @param[in] interface - the interface name |
| 90 | * |
| 91 | * @return std::string - the D-Bus service name if found, else |
| 92 | * an empty string |
| 93 | */ |
| 94 | std::string getService(const std::string& path, |
| 95 | const std::string& interface) const; |
| 96 | |
| 97 | /** |
Matt Spinler | fb35a32 | 2018-11-26 14:30:30 -0600 | [diff] [blame] | 98 | * @brief sdbusplus connection object |
| 99 | */ |
| 100 | sdbusplus::bus::bus& bus; |
Matt Spinler | 963c65f | 2018-11-26 14:46:41 -0600 | [diff] [blame] | 101 | |
| 102 | /** |
| 103 | * @brief Matches on the power button released signal |
| 104 | */ |
| 105 | std::unique_ptr<sdbusplus::bus::match_t> powerButtonReleased; |
| 106 | |
| 107 | /** |
| 108 | * @brief Matches on the power button long press released signal |
| 109 | */ |
| 110 | std::unique_ptr<sdbusplus::bus::match_t> powerButtonLongPressReleased; |
Matt Spinler | 06a5bdd | 2018-11-26 14:50:48 -0600 | [diff] [blame] | 111 | |
| 112 | /** |
Matt Spinler | 69f9351 | 2018-11-26 14:55:58 -0600 | [diff] [blame] | 113 | * @brief Matches on the ID button released signal |
| 114 | */ |
| 115 | std::unique_ptr<sdbusplus::bus::match_t> idButtonReleased; |
| 116 | |
| 117 | /** |
Matt Spinler | 06a5bdd | 2018-11-26 14:50:48 -0600 | [diff] [blame] | 118 | * @brief Matches on the reset button released signal |
| 119 | */ |
| 120 | std::unique_ptr<sdbusplus::bus::match_t> resetButtonReleased; |
Matt Spinler | fb35a32 | 2018-11-26 14:30:30 -0600 | [diff] [blame] | 121 | }; |
| 122 | |
| 123 | } // namespace button |
| 124 | } // namespace phosphor |