Matt Spinler | fb35a32 | 2018-11-26 14:30:30 -0600 | [diff] [blame] | 1 | #pragma once |
Matt Spinler | fb35a32 | 2018-11-26 14:30:30 -0600 | [diff] [blame] | 2 | #include <sdbusplus/bus.hpp> |
| 3 | #include <sdbusplus/bus/match.hpp> |
| 4 | |
| 5 | namespace phosphor |
| 6 | { |
| 7 | namespace button |
| 8 | { |
Naveen Moses | 3bd1cfc | 2022-02-14 18:04:20 +0530 | [diff] [blame] | 9 | enum class PowerEvent |
| 10 | { |
| 11 | powerPressed, |
| 12 | longPowerPressed, |
Naveen Moses | ab8dac5 | 2022-07-15 19:32:27 +0530 | [diff] [blame^] | 13 | resetPressed, |
| 14 | powerReleased, |
| 15 | longPowerReleased, |
| 16 | resetReleased |
Naveen Moses | 3bd1cfc | 2022-02-14 18:04:20 +0530 | [diff] [blame] | 17 | }; |
Matt Spinler | fb35a32 | 2018-11-26 14:30:30 -0600 | [diff] [blame] | 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 | */ |
George Liu | 94afa4b | 2022-06-20 13:36:43 +0800 | [diff] [blame] | 44 | explicit Handler(sdbusplus::bus::bus& bus); |
Matt Spinler | fb35a32 | 2018-11-26 14:30:30 -0600 | [diff] [blame] | 45 | |
| 46 | private: |
| 47 | /** |
Matt Spinler | 963c65f | 2018-11-26 14:46:41 -0600 | [diff] [blame] | 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 | */ |
Naveen Moses | ab8dac5 | 2022-07-15 19:32:27 +0530 | [diff] [blame^] | 55 | void powerReleased(sdbusplus::message::message& msg); |
Matt Spinler | 963c65f | 2018-11-26 14:46:41 -0600 | [diff] [blame] | 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::message& msg); |
| 66 | |
| 67 | /** |
Matt Spinler | 69f9351 | 2018-11-26 14:55:58 -0600 | [diff] [blame] | 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 | */ |
Naveen Moses | ab8dac5 | 2022-07-15 19:32:27 +0530 | [diff] [blame^] | 74 | void idReleased(sdbusplus::message::message& msg); |
Matt Spinler | 69f9351 | 2018-11-26 14:55:58 -0600 | [diff] [blame] | 75 | |
| 76 | /** |
Matt Spinler | 06a5bdd | 2018-11-26 14:50:48 -0600 | [diff] [blame] | 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 | */ |
Naveen Moses | ab8dac5 | 2022-07-15 19:32:27 +0530 | [diff] [blame^] | 83 | void resetReleased(sdbusplus::message::message& msg); |
Matt Spinler | 06a5bdd | 2018-11-26 14:50:48 -0600 | [diff] [blame] | 84 | |
| 85 | /** |
Matt Spinler | 963c65f | 2018-11-26 14:46:41 -0600 | [diff] [blame] | 86 | * @brief Checks if system is powered on |
| 87 | * |
| 88 | * @return true if powered on, false else |
| 89 | */ |
Naveen Moses | 3bd1cfc | 2022-02-14 18:04:20 +0530 | [diff] [blame] | 90 | bool poweredOn(size_t hostNumber) const; |
Matt Spinler | 963c65f | 2018-11-26 14:46:41 -0600 | [diff] [blame] | 91 | |
Naveen Moses | 3bd1cfc | 2022-02-14 18:04:20 +0530 | [diff] [blame] | 92 | /* |
Matt Spinler | 963c65f | 2018-11-26 14:46:41 -0600 | [diff] [blame] | 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 | /** |
Naveen Moses | 3bd1cfc | 2022-02-14 18:04:20 +0530 | [diff] [blame] | 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 | /** |
Matt Spinler | fb35a32 | 2018-11-26 14:30:30 -0600 | [diff] [blame] | 126 | * @brief sdbusplus connection object |
| 127 | */ |
| 128 | sdbusplus::bus::bus& bus; |
Matt Spinler | 963c65f | 2018-11-26 14:46:41 -0600 | [diff] [blame] | 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 | */ |
Naveen Moses | ab8dac5 | 2022-07-15 19:32:27 +0530 | [diff] [blame^] | 138 | std::unique_ptr<sdbusplus::bus::match_t> powerButtonLongPressed; |
Matt Spinler | 06a5bdd | 2018-11-26 14:50:48 -0600 | [diff] [blame] | 139 | |
| 140 | /** |
Matt Spinler | 69f9351 | 2018-11-26 14:55:58 -0600 | [diff] [blame] | 141 | * @brief Matches on the ID button released signal |
| 142 | */ |
| 143 | std::unique_ptr<sdbusplus::bus::match_t> idButtonReleased; |
| 144 | |
| 145 | /** |
Matt Spinler | 06a5bdd | 2018-11-26 14:50:48 -0600 | [diff] [blame] | 146 | * @brief Matches on the reset button released signal |
| 147 | */ |
| 148 | std::unique_ptr<sdbusplus::bus::match_t> resetButtonReleased; |
Matt Spinler | fb35a32 | 2018-11-26 14:30:30 -0600 | [diff] [blame] | 149 | }; |
| 150 | |
| 151 | } // namespace button |
| 152 | } // namespace phosphor |