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, |
Naveen Moses | ab8dac5 | 2022-07-15 19:32:27 +0530 | [diff] [blame] | 12 | resetPressed, |
| 13 | powerReleased, |
Naveen Moses | ab8dac5 | 2022-07-15 19:32:27 +0530 | [diff] [blame] | 14 | resetReleased |
Naveen Moses | 3bd1cfc | 2022-02-14 18:04:20 +0530 | [diff] [blame] | 15 | }; |
Matt Spinler | fb35a32 | 2018-11-26 14:30:30 -0600 | [diff] [blame] | 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 | */ |
Patrick Williams | 9a529a6 | 2022-07-22 19:26:54 -0500 | [diff] [blame] | 42 | explicit Handler(sdbusplus::bus_t& bus); |
Matt Spinler | fb35a32 | 2018-11-26 14:30:30 -0600 | [diff] [blame] | 43 | |
| 44 | private: |
| 45 | /** |
Matt Spinler | 963c65f | 2018-11-26 14:46:41 -0600 | [diff] [blame] | 46 | * @brief The handler for a power button press |
| 47 | * |
DelphineCCChiu | 395c764 | 2023-04-19 10:46:47 +0800 | [diff] [blame] | 48 | * It will do power action according to the pressing duration. |
Matt Spinler | 963c65f | 2018-11-26 14:46:41 -0600 | [diff] [blame] | 49 | * |
| 50 | * @param[in] msg - sdbusplus message from signal |
| 51 | */ |
Patrick Williams | 9a529a6 | 2022-07-22 19:26:54 -0500 | [diff] [blame] | 52 | void powerReleased(sdbusplus::message_t& msg); |
Matt Spinler | 963c65f | 2018-11-26 14:46:41 -0600 | [diff] [blame] | 53 | |
| 54 | /** |
Matt Spinler | 69f9351 | 2018-11-26 14:55:58 -0600 | [diff] [blame] | 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 | */ |
Patrick Williams | 9a529a6 | 2022-07-22 19:26:54 -0500 | [diff] [blame] | 61 | void idReleased(sdbusplus::message_t& msg); |
Matt Spinler | 69f9351 | 2018-11-26 14:55:58 -0600 | [diff] [blame] | 62 | |
| 63 | /** |
Matt Spinler | 06a5bdd | 2018-11-26 14:50:48 -0600 | [diff] [blame] | 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 | */ |
Patrick Williams | 9a529a6 | 2022-07-22 19:26:54 -0500 | [diff] [blame] | 70 | void resetReleased(sdbusplus::message_t& msg); |
Matt Spinler | 06a5bdd | 2018-11-26 14:50:48 -0600 | [diff] [blame] | 71 | |
| 72 | /** |
Naveen Moses | a6d4e65 | 2022-04-13 19:27:25 +0530 | [diff] [blame] | 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 | |
Patrick Williams | e3b4e11 | 2022-11-26 09:41:58 -0600 | [diff] [blame] | 81 | void debugHostSelectorReleased(sdbusplus::message_t& msg); |
Naveen Moses | a6d4e65 | 2022-04-13 19:27:25 +0530 | [diff] [blame] | 82 | |
| 83 | /** |
Matt Spinler | 963c65f | 2018-11-26 14:46:41 -0600 | [diff] [blame] | 84 | * @brief Checks if system is powered on |
| 85 | * |
| 86 | * @return true if powered on, false else |
| 87 | */ |
Naveen Moses | 3bd1cfc | 2022-02-14 18:04:20 +0530 | [diff] [blame] | 88 | bool poweredOn(size_t hostNumber) const; |
Matt Spinler | 963c65f | 2018-11-26 14:46:41 -0600 | [diff] [blame] | 89 | |
Naveen Moses | 3bd1cfc | 2022-02-14 18:04:20 +0530 | [diff] [blame] | 90 | /* |
Matt Spinler | 963c65f | 2018-11-26 14:46:41 -0600 | [diff] [blame] | 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 | /** |
Naveen Moses | 3bd1cfc | 2022-02-14 18:04:20 +0530 | [diff] [blame] | 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(); |
Naveen Moses | a6d4e65 | 2022-04-13 19:27:25 +0530 | [diff] [blame] | 106 | /** |
| 107 | * @brief increases the host selector position property |
| 108 | * by 1 upto max host selector position |
| 109 | * |
| 110 | * @return void |
| 111 | */ |
Naveen Moses | 3bd1cfc | 2022-02-14 18:04:20 +0530 | [diff] [blame] | 112 | |
Naveen Moses | a6d4e65 | 2022-04-13 19:27:25 +0530 | [diff] [blame] | 113 | void increaseHostSelectorPosition(); |
Naveen Moses | 3bd1cfc | 2022-02-14 18:04:20 +0530 | [diff] [blame] | 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 | */ |
DelphineCCChiu | 395c764 | 2023-04-19 10:46:47 +0800 | [diff] [blame] | 128 | void handlePowerEvent(PowerEvent powerEventType, |
| 129 | std::chrono::microseconds duration); |
Naveen Moses | 3bd1cfc | 2022-02-14 18:04:20 +0530 | [diff] [blame] | 130 | |
| 131 | /** |
Matt Spinler | fb35a32 | 2018-11-26 14:30:30 -0600 | [diff] [blame] | 132 | * @brief sdbusplus connection object |
| 133 | */ |
Patrick Williams | 9a529a6 | 2022-07-22 19:26:54 -0500 | [diff] [blame] | 134 | sdbusplus::bus_t& bus; |
Matt Spinler | 963c65f | 2018-11-26 14:46:41 -0600 | [diff] [blame] | 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 | */ |
Naveen Moses | ab8dac5 | 2022-07-15 19:32:27 +0530 | [diff] [blame] | 144 | std::unique_ptr<sdbusplus::bus::match_t> powerButtonLongPressed; |
Matt Spinler | 06a5bdd | 2018-11-26 14:50:48 -0600 | [diff] [blame] | 145 | |
| 146 | /** |
Matt Spinler | 69f9351 | 2018-11-26 14:55:58 -0600 | [diff] [blame] | 147 | * @brief Matches on the ID button released signal |
| 148 | */ |
| 149 | std::unique_ptr<sdbusplus::bus::match_t> idButtonReleased; |
| 150 | |
| 151 | /** |
Matt Spinler | 06a5bdd | 2018-11-26 14:50:48 -0600 | [diff] [blame] | 152 | * @brief Matches on the reset button released signal |
| 153 | */ |
| 154 | std::unique_ptr<sdbusplus::bus::match_t> resetButtonReleased; |
Naveen Moses | a6d4e65 | 2022-04-13 19:27:25 +0530 | [diff] [blame] | 155 | |
| 156 | /** |
| 157 | * @brief Matches on the ocp debug host selector button released signal |
| 158 | */ |
| 159 | std::unique_ptr<sdbusplus::bus::match_t> debugHSButtonReleased; |
Matt Spinler | fb35a32 | 2018-11-26 14:30:30 -0600 | [diff] [blame] | 160 | }; |
| 161 | |
| 162 | } // namespace button |
| 163 | } // namespace phosphor |