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 resetPressed, 13 powerReleased, 14 resetReleased 15 }; 16 /** 17 * @class Handler 18 * 19 * This class acts on the signals generated by the 20 * xyz.openbmc_project.Chassis.Buttons code when 21 * it detects button presses. 22 * 23 * There are 3 buttons supported - Power, ID, and Reset. 24 * As not all systems may implement each button, this class will 25 * check for that button on D-Bus before listening for its signals. 26 */ 27 class Handler 28 { 29 public: 30 Handler() = delete; 31 ~Handler() = default; 32 Handler(const Handler&) = delete; 33 Handler& operator=(const Handler&) = delete; 34 Handler(Handler&&) = delete; 35 Handler& operator=(Handler&&) = delete; 36 37 /** 38 * @brief Constructor 39 * 40 * @param[in] bus - sdbusplus connection object 41 */ 42 explicit Handler(sdbusplus::bus_t& bus); 43 44 private: 45 /** 46 * @brief The handler for a power button press 47 * 48 * It will do power action according to the pressing duration. 49 * 50 * @param[in] msg - sdbusplus message from signal 51 */ 52 void powerReleased(sdbusplus::message_t& msg); 53 54 /** 55 * @brief The handler for an ID button press 56 * 57 * Toggles the ID LED group 58 * 59 * @param[in] msg - sdbusplus message from signal 60 */ 61 void idReleased(sdbusplus::message_t& msg); 62 63 /** 64 * @brief The handler for a reset button press 65 * 66 * Reboots the host if it is powered on. 67 * 68 * @param[in] msg - sdbusplus message from signal 69 */ 70 void resetReleased(sdbusplus::message_t& msg); 71 72 /** 73 * @brief The handler for a OCP debug card host selector button press 74 * 75 * In multi host system increases host position by 1 up to max host 76 * position. 77 * 78 * @param[in] msg - sdbusplus message from signal 79 */ 80 81 void debugHostSelectorReleased(sdbusplus::message_t& msg); 82 83 /** 84 * @brief Checks if system is powered on 85 * 86 * @return true if powered on, false else 87 */ 88 bool poweredOn(size_t hostNumber) const; 89 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 /** 98 * @brief gets the valid host selector value in multi host 99 * system 100 * 101 * @return size_t throws exception if host selector position is 102 * invalid or not available. 103 */ 104 105 size_t getHostSelectorValue(); 106 /** 107 * @brief increases the host selector position property 108 * by 1 upto max host selector position 109 * 110 * @return void 111 */ 112 113 void increaseHostSelectorPosition(); 114 /** 115 * @brief checks if the system has multi host 116 * based on the host selector property availability 117 * 118 * @return bool returns true if multi host system 119 * else returns false. 120 */ 121 bool isMultiHost(); 122 /** 123 * @brief trigger the power ctrl event based on the 124 * button press event type. 125 * 126 * @return void 127 */ 128 void handlePowerEvent(PowerEvent powerEventType, 129 std::chrono::microseconds duration); 130 131 /** 132 * @brief sdbusplus connection object 133 */ 134 sdbusplus::bus_t& bus; 135 136 /** 137 * @brief Matches on the power button released signal 138 */ 139 std::unique_ptr<sdbusplus::bus::match_t> powerButtonReleased; 140 141 /** 142 * @brief Matches on the power button long press released signal 143 */ 144 std::unique_ptr<sdbusplus::bus::match_t> powerButtonLongPressed; 145 146 /** 147 * @brief Matches on the ID button released signal 148 */ 149 std::unique_ptr<sdbusplus::bus::match_t> idButtonReleased; 150 151 /** 152 * @brief Matches on the reset button released signal 153 */ 154 std::unique_ptr<sdbusplus::bus::match_t> resetButtonReleased; 155 156 /** 157 * @brief Matches on the ocp debug host selector button released signal 158 */ 159 std::unique_ptr<sdbusplus::bus::match_t> debugHSButtonReleased; 160 }; 161 162 } // namespace button 163 } // namespace phosphor 164