1 #pragma once 2 #include <sdbusplus/bus.hpp> 3 #include <sdbusplus/bus/match.hpp> 4 5 namespace phosphor 6 { 7 namespace button 8 { 9 enum class PowerEvent 10 { 11 powerPressed, 12 longPowerPressed, 13 resetPressed, 14 powerReleased, 15 longPowerReleased, 16 resetReleased 17 }; 18 /** 19 * @class Handler 20 * 21 * This class acts on the signals generated by the 22 * xyz.openbmc_project.Chassis.Buttons code when 23 * it detects button presses. 24 * 25 * There are 3 buttons supported - Power, ID, and Reset. 26 * As not all systems may implement each button, this class will 27 * check for that button on D-Bus before listening for its signals. 28 */ 29 class Handler 30 { 31 public: 32 Handler() = delete; 33 ~Handler() = default; 34 Handler(const Handler&) = delete; 35 Handler& operator=(const Handler&) = delete; 36 Handler(Handler&&) = delete; 37 Handler& operator=(Handler&&) = delete; 38 39 /** 40 * @brief Constructor 41 * 42 * @param[in] bus - sdbusplus connection object 43 */ 44 explicit Handler(sdbusplus::bus_t& bus); 45 46 private: 47 /** 48 * @brief The handler for a power button press 49 * 50 * It will power on the system if it's currently off, 51 * else it will soft power it off. 52 * 53 * @param[in] msg - sdbusplus message from signal 54 */ 55 void powerReleased(sdbusplus::message_t& msg); 56 57 /** 58 * @brief The handler for a long power button press 59 * 60 * If the system is currently powered on, it will 61 * perform an immediate power off. 62 * 63 * @param[in] msg - sdbusplus message from signal 64 */ 65 void longPowerPressed(sdbusplus::message_t& msg); 66 67 /** 68 * @brief The handler for an ID button press 69 * 70 * Toggles the ID LED group 71 * 72 * @param[in] msg - sdbusplus message from signal 73 */ 74 void idReleased(sdbusplus::message_t& msg); 75 76 /** 77 * @brief The handler for a reset button press 78 * 79 * Reboots the host if it is powered on. 80 * 81 * @param[in] msg - sdbusplus message from signal 82 */ 83 void resetReleased(sdbusplus::message_t& msg); 84 85 /** 86 * @brief Checks if system is powered on 87 * 88 * @return true if powered on, false else 89 */ 90 bool poweredOn(size_t hostNumber) const; 91 92 /* 93 * @return std::string - the D-Bus service name if found, else 94 * an empty string 95 */ 96 std::string getService(const std::string& path, 97 const std::string& interface) const; 98 99 /** 100 * @brief gets the valid host selector value in multi host 101 * system 102 * 103 * @return size_t throws exception if host selector position is 104 * invalid or not available. 105 */ 106 107 size_t getHostSelectorValue(); 108 109 /** 110 * @brief checks if the system has multi host 111 * based on the host selector property availability 112 * 113 * @return bool returns true if multi host system 114 * else returns false. 115 */ 116 bool isMultiHost(); 117 /** 118 * @brief trigger the power ctrl event based on the 119 * button press event type. 120 * 121 * @return void 122 */ 123 void handlePowerEvent(PowerEvent powerEventType); 124 125 /** 126 * @brief sdbusplus connection object 127 */ 128 sdbusplus::bus_t& bus; 129 130 /** 131 * @brief Matches on the power button released signal 132 */ 133 std::unique_ptr<sdbusplus::bus::match_t> powerButtonReleased; 134 135 /** 136 * @brief Matches on the power button long press released signal 137 */ 138 std::unique_ptr<sdbusplus::bus::match_t> powerButtonLongPressed; 139 140 /** 141 * @brief Matches on the ID button released signal 142 */ 143 std::unique_ptr<sdbusplus::bus::match_t> idButtonReleased; 144 145 /** 146 * @brief Matches on the reset button released signal 147 */ 148 std::unique_ptr<sdbusplus::bus::match_t> resetButtonReleased; 149 }; 150 151 } // namespace button 152 } // namespace phosphor 153