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