Matt Spinler | fb35a32 | 2018-11-26 14:30:30 -0600 | [diff] [blame] | 1 | #pragma once |
Matt Spinler | 1a309f7 | 2023-04-04 13:12:19 -0500 | [diff] [blame] | 2 | |
| 3 | #include "power_button_profile.hpp" |
| 4 | |
Matt Spinler | fb35a32 | 2018-11-26 14:30:30 -0600 | [diff] [blame] | 5 | #include <sdbusplus/bus.hpp> |
| 6 | #include <sdbusplus/bus/match.hpp> |
| 7 | |
| 8 | namespace phosphor |
| 9 | { |
| 10 | namespace button |
| 11 | { |
Naveen Moses | 3bd1cfc | 2022-02-14 18:04:20 +0530 | [diff] [blame] | 12 | enum class PowerEvent |
| 13 | { |
| 14 | powerPressed, |
Naveen Moses | ab8dac5 | 2022-07-15 19:32:27 +0530 | [diff] [blame] | 15 | resetPressed, |
| 16 | powerReleased, |
Naveen Moses | ab8dac5 | 2022-07-15 19:32:27 +0530 | [diff] [blame] | 17 | resetReleased |
Naveen Moses | 3bd1cfc | 2022-02-14 18:04:20 +0530 | [diff] [blame] | 18 | }; |
Matt Spinler | fb35a32 | 2018-11-26 14:30:30 -0600 | [diff] [blame] | 19 | /** |
| 20 | * @class Handler |
| 21 | * |
| 22 | * This class acts on the signals generated by the |
| 23 | * xyz.openbmc_project.Chassis.Buttons code when |
| 24 | * it detects button presses. |
| 25 | * |
| 26 | * There are 3 buttons supported - Power, ID, and Reset. |
| 27 | * As not all systems may implement each button, this class will |
| 28 | * check for that button on D-Bus before listening for its signals. |
| 29 | */ |
| 30 | class Handler |
| 31 | { |
| 32 | public: |
| 33 | Handler() = delete; |
| 34 | ~Handler() = default; |
| 35 | Handler(const Handler&) = delete; |
| 36 | Handler& operator=(const Handler&) = delete; |
| 37 | Handler(Handler&&) = delete; |
| 38 | Handler& operator=(Handler&&) = delete; |
| 39 | |
| 40 | /** |
| 41 | * @brief Constructor |
| 42 | * |
| 43 | * @param[in] bus - sdbusplus connection object |
| 44 | */ |
Patrick Williams | 9a529a6 | 2022-07-22 19:26:54 -0500 | [diff] [blame] | 45 | explicit Handler(sdbusplus::bus_t& bus); |
Matt Spinler | fb35a32 | 2018-11-26 14:30:30 -0600 | [diff] [blame] | 46 | |
| 47 | private: |
| 48 | /** |
Matt Spinler | 963c65f | 2018-11-26 14:46:41 -0600 | [diff] [blame] | 49 | * @brief The handler for a power button press |
| 50 | * |
DelphineCCChiu | 395c764 | 2023-04-19 10:46:47 +0800 | [diff] [blame] | 51 | * It will do power action according to the pressing duration. |
Matt Spinler | 963c65f | 2018-11-26 14:46:41 -0600 | [diff] [blame] | 52 | * |
| 53 | * @param[in] msg - sdbusplus message from signal |
| 54 | */ |
Patrick Williams | 9a529a6 | 2022-07-22 19:26:54 -0500 | [diff] [blame] | 55 | void powerReleased(sdbusplus::message_t& msg); |
Matt Spinler | 963c65f | 2018-11-26 14:46:41 -0600 | [diff] [blame] | 56 | |
| 57 | /** |
Matt Spinler | 69f9351 | 2018-11-26 14:55:58 -0600 | [diff] [blame] | 58 | * @brief The handler for an ID button press |
| 59 | * |
| 60 | * Toggles the ID LED group |
| 61 | * |
| 62 | * @param[in] msg - sdbusplus message from signal |
| 63 | */ |
Patrick Williams | 9a529a6 | 2022-07-22 19:26:54 -0500 | [diff] [blame] | 64 | void idReleased(sdbusplus::message_t& msg); |
Matt Spinler | 69f9351 | 2018-11-26 14:55:58 -0600 | [diff] [blame] | 65 | |
| 66 | /** |
Matt Spinler | 06a5bdd | 2018-11-26 14:50:48 -0600 | [diff] [blame] | 67 | * @brief The handler for a reset button press |
| 68 | * |
| 69 | * Reboots the host if it is powered on. |
| 70 | * |
| 71 | * @param[in] msg - sdbusplus message from signal |
| 72 | */ |
Patrick Williams | 9a529a6 | 2022-07-22 19:26:54 -0500 | [diff] [blame] | 73 | void resetReleased(sdbusplus::message_t& msg); |
Matt Spinler | 06a5bdd | 2018-11-26 14:50:48 -0600 | [diff] [blame] | 74 | |
| 75 | /** |
Naveen Moses | a6d4e65 | 2022-04-13 19:27:25 +0530 | [diff] [blame] | 76 | * @brief The handler for a OCP debug card host selector button press |
| 77 | * |
| 78 | * In multi host system increases host position by 1 up to max host |
| 79 | * position. |
| 80 | * |
| 81 | * @param[in] msg - sdbusplus message from signal |
| 82 | */ |
| 83 | |
Patrick Williams | e3b4e11 | 2022-11-26 09:41:58 -0600 | [diff] [blame] | 84 | void debugHostSelectorReleased(sdbusplus::message_t& msg); |
Naveen Moses | a6d4e65 | 2022-04-13 19:27:25 +0530 | [diff] [blame] | 85 | |
| 86 | /** |
Matt Spinler | 963c65f | 2018-11-26 14:46:41 -0600 | [diff] [blame] | 87 | * @brief Checks if system is powered on |
| 88 | * |
| 89 | * @return true if powered on, false else |
| 90 | */ |
Naveen Moses | 3bd1cfc | 2022-02-14 18:04:20 +0530 | [diff] [blame] | 91 | bool poweredOn(size_t hostNumber) const; |
Matt Spinler | 963c65f | 2018-11-26 14:46:41 -0600 | [diff] [blame] | 92 | |
Naveen Moses | 3bd1cfc | 2022-02-14 18:04:20 +0530 | [diff] [blame] | 93 | /* |
Matt Spinler | 963c65f | 2018-11-26 14:46:41 -0600 | [diff] [blame] | 94 | * @return std::string - the D-Bus service name if found, else |
| 95 | * an empty string |
| 96 | */ |
| 97 | std::string getService(const std::string& path, |
| 98 | const std::string& interface) const; |
| 99 | |
| 100 | /** |
Naveen Moses | 3bd1cfc | 2022-02-14 18:04:20 +0530 | [diff] [blame] | 101 | * @brief gets the valid host selector value in multi host |
| 102 | * system |
| 103 | * |
| 104 | * @return size_t throws exception if host selector position is |
| 105 | * invalid or not available. |
| 106 | */ |
| 107 | |
| 108 | size_t getHostSelectorValue(); |
Naveen Moses | a6d4e65 | 2022-04-13 19:27:25 +0530 | [diff] [blame] | 109 | /** |
| 110 | * @brief increases the host selector position property |
| 111 | * by 1 upto max host selector position |
| 112 | * |
| 113 | * @return void |
| 114 | */ |
Naveen Moses | 3bd1cfc | 2022-02-14 18:04:20 +0530 | [diff] [blame] | 115 | |
Naveen Moses | a6d4e65 | 2022-04-13 19:27:25 +0530 | [diff] [blame] | 116 | void increaseHostSelectorPosition(); |
Naveen Moses | 3bd1cfc | 2022-02-14 18:04:20 +0530 | [diff] [blame] | 117 | /** |
| 118 | * @brief checks if the system has multi host |
| 119 | * based on the host selector property availability |
| 120 | * |
| 121 | * @return bool returns true if multi host system |
| 122 | * else returns false. |
| 123 | */ |
| 124 | bool isMultiHost(); |
| 125 | /** |
| 126 | * @brief trigger the power ctrl event based on the |
| 127 | * button press event type. |
| 128 | * |
| 129 | * @return void |
| 130 | */ |
DelphineCCChiu | 395c764 | 2023-04-19 10:46:47 +0800 | [diff] [blame] | 131 | void handlePowerEvent(PowerEvent powerEventType, |
| 132 | std::chrono::microseconds duration); |
Naveen Moses | 3bd1cfc | 2022-02-14 18:04:20 +0530 | [diff] [blame] | 133 | |
| 134 | /** |
Matt Spinler | fb35a32 | 2018-11-26 14:30:30 -0600 | [diff] [blame] | 135 | * @brief sdbusplus connection object |
| 136 | */ |
Patrick Williams | 9a529a6 | 2022-07-22 19:26:54 -0500 | [diff] [blame] | 137 | sdbusplus::bus_t& bus; |
Matt Spinler | 963c65f | 2018-11-26 14:46:41 -0600 | [diff] [blame] | 138 | |
| 139 | /** |
| 140 | * @brief Matches on the power button released signal |
| 141 | */ |
| 142 | std::unique_ptr<sdbusplus::bus::match_t> powerButtonReleased; |
| 143 | |
| 144 | /** |
| 145 | * @brief Matches on the power button long press released signal |
| 146 | */ |
Naveen Moses | ab8dac5 | 2022-07-15 19:32:27 +0530 | [diff] [blame] | 147 | std::unique_ptr<sdbusplus::bus::match_t> powerButtonLongPressed; |
Matt Spinler | 06a5bdd | 2018-11-26 14:50:48 -0600 | [diff] [blame] | 148 | |
| 149 | /** |
Matt Spinler | 69f9351 | 2018-11-26 14:55:58 -0600 | [diff] [blame] | 150 | * @brief Matches on the ID button released signal |
| 151 | */ |
| 152 | std::unique_ptr<sdbusplus::bus::match_t> idButtonReleased; |
| 153 | |
| 154 | /** |
Matt Spinler | 06a5bdd | 2018-11-26 14:50:48 -0600 | [diff] [blame] | 155 | * @brief Matches on the reset button released signal |
| 156 | */ |
| 157 | std::unique_ptr<sdbusplus::bus::match_t> resetButtonReleased; |
Naveen Moses | a6d4e65 | 2022-04-13 19:27:25 +0530 | [diff] [blame] | 158 | |
| 159 | /** |
| 160 | * @brief Matches on the ocp debug host selector button released signal |
| 161 | */ |
| 162 | std::unique_ptr<sdbusplus::bus::match_t> debugHSButtonReleased; |
Matt Spinler | 1a309f7 | 2023-04-04 13:12:19 -0500 | [diff] [blame] | 163 | |
| 164 | /** |
| 165 | * @brief The custom power handler profile object. |
| 166 | */ |
| 167 | std::unique_ptr<PowerButtonProfile> powerButtonProfile; |
Matt Spinler | fb35a32 | 2018-11-26 14:30:30 -0600 | [diff] [blame] | 168 | }; |
| 169 | |
| 170 | } // namespace button |
| 171 | } // namespace phosphor |