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 /** 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 The handler for a reset button press 62 * 63 * Reboots the host if it is powered on. 64 * 65 * @param[in] msg - sdbusplus message from signal 66 */ 67 void resetPressed(sdbusplus::message::message& msg); 68 69 /** 70 * @brief Checks if system is powered on 71 * 72 * @return true if powered on, false else 73 */ 74 bool poweredOn() const; 75 76 /** 77 * @brief Returns the service name for an object 78 * 79 * @param[in] path - the object path 80 * @param[in] interface - the interface name 81 * 82 * @return std::string - the D-Bus service name if found, else 83 * an empty string 84 */ 85 std::string getService(const std::string& path, 86 const std::string& interface) const; 87 88 /** 89 * @brief sdbusplus connection object 90 */ 91 sdbusplus::bus::bus& bus; 92 93 /** 94 * @brief Matches on the power button released signal 95 */ 96 std::unique_ptr<sdbusplus::bus::match_t> powerButtonReleased; 97 98 /** 99 * @brief Matches on the power button long press released signal 100 */ 101 std::unique_ptr<sdbusplus::bus::match_t> powerButtonLongPressReleased; 102 103 /** 104 * @brief Matches on the reset button released signal 105 */ 106 std::unique_ptr<sdbusplus::bus::match_t> resetButtonReleased; 107 }; 108 109 } // namespace button 110 } // namespace phosphor 111