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 | /** |
| 61 | * @brief Checks if system is powered on |
| 62 | * |
| 63 | * @return true if powered on, false else |
| 64 | */ |
| 65 | bool poweredOn() const; |
| 66 | |
| 67 | /** |
| 68 | * @brief Returns the service name for an object |
| 69 | * |
| 70 | * @param[in] path - the object path |
| 71 | * @param[in] interface - the interface name |
| 72 | * |
| 73 | * @return std::string - the D-Bus service name if found, else |
| 74 | * an empty string |
| 75 | */ |
| 76 | std::string getService(const std::string& path, |
| 77 | const std::string& interface) const; |
| 78 | |
| 79 | /** |
Matt Spinler | fb35a32 | 2018-11-26 14:30:30 -0600 | [diff] [blame] | 80 | * @brief sdbusplus connection object |
| 81 | */ |
| 82 | sdbusplus::bus::bus& bus; |
Matt Spinler | 963c65f | 2018-11-26 14:46:41 -0600 | [diff] [blame^] | 83 | |
| 84 | /** |
| 85 | * @brief Matches on the power button released signal |
| 86 | */ |
| 87 | std::unique_ptr<sdbusplus::bus::match_t> powerButtonReleased; |
| 88 | |
| 89 | /** |
| 90 | * @brief Matches on the power button long press released signal |
| 91 | */ |
| 92 | std::unique_ptr<sdbusplus::bus::match_t> powerButtonLongPressReleased; |
Matt Spinler | fb35a32 | 2018-11-26 14:30:30 -0600 | [diff] [blame] | 93 | }; |
| 94 | |
| 95 | } // namespace button |
| 96 | } // namespace phosphor |