1fb35a325SMatt Spinler #pragma once 2fb35a325SMatt Spinler 3fb35a325SMatt Spinler #include <sdbusplus/bus.hpp> 4fb35a325SMatt Spinler #include <sdbusplus/bus/match.hpp> 5fb35a325SMatt Spinler 6fb35a325SMatt Spinler namespace phosphor 7fb35a325SMatt Spinler { 8fb35a325SMatt Spinler namespace button 9fb35a325SMatt Spinler { 10fb35a325SMatt Spinler 11fb35a325SMatt Spinler /** 12fb35a325SMatt Spinler * @class Handler 13fb35a325SMatt Spinler * 14fb35a325SMatt Spinler * This class acts on the signals generated by the 15fb35a325SMatt Spinler * xyz.openbmc_project.Chassis.Buttons code when 16fb35a325SMatt Spinler * it detects button presses. 17fb35a325SMatt Spinler * 18fb35a325SMatt Spinler * There are 3 buttons supported - Power, ID, and Reset. 19fb35a325SMatt Spinler * As not all systems may implement each button, this class will 20fb35a325SMatt Spinler * check for that button on D-Bus before listening for its signals. 21fb35a325SMatt Spinler */ 22fb35a325SMatt Spinler class Handler 23fb35a325SMatt Spinler { 24fb35a325SMatt Spinler public: 25fb35a325SMatt Spinler Handler() = delete; 26fb35a325SMatt Spinler ~Handler() = default; 27fb35a325SMatt Spinler Handler(const Handler&) = delete; 28fb35a325SMatt Spinler Handler& operator=(const Handler&) = delete; 29fb35a325SMatt Spinler Handler(Handler&&) = delete; 30fb35a325SMatt Spinler Handler& operator=(Handler&&) = delete; 31fb35a325SMatt Spinler 32fb35a325SMatt Spinler /** 33fb35a325SMatt Spinler * @brief Constructor 34fb35a325SMatt Spinler * 35fb35a325SMatt Spinler * @param[in] bus - sdbusplus connection object 36fb35a325SMatt Spinler */ 37fb35a325SMatt Spinler Handler(sdbusplus::bus::bus& bus); 38fb35a325SMatt Spinler 39fb35a325SMatt Spinler private: 40fb35a325SMatt Spinler /** 41963c65f3SMatt Spinler * @brief The handler for a power button press 42963c65f3SMatt Spinler * 43963c65f3SMatt Spinler * It will power on the system if it's currently off, 44963c65f3SMatt Spinler * else it will soft power it off. 45963c65f3SMatt Spinler * 46963c65f3SMatt Spinler * @param[in] msg - sdbusplus message from signal 47963c65f3SMatt Spinler */ 48963c65f3SMatt Spinler void powerPressed(sdbusplus::message::message& msg); 49963c65f3SMatt Spinler 50963c65f3SMatt Spinler /** 51963c65f3SMatt Spinler * @brief The handler for a long power button press 52963c65f3SMatt Spinler * 53963c65f3SMatt Spinler * If the system is currently powered on, it will 54963c65f3SMatt Spinler * perform an immediate power off. 55963c65f3SMatt Spinler * 56963c65f3SMatt Spinler * @param[in] msg - sdbusplus message from signal 57963c65f3SMatt Spinler */ 58963c65f3SMatt Spinler void longPowerPressed(sdbusplus::message::message& msg); 59963c65f3SMatt Spinler 60963c65f3SMatt Spinler /** 61*69f93512SMatt Spinler * @brief The handler for an ID button press 62*69f93512SMatt Spinler * 63*69f93512SMatt Spinler * Toggles the ID LED group 64*69f93512SMatt Spinler * 65*69f93512SMatt Spinler * @param[in] msg - sdbusplus message from signal 66*69f93512SMatt Spinler */ 67*69f93512SMatt Spinler void idPressed(sdbusplus::message::message& msg); 68*69f93512SMatt Spinler 69*69f93512SMatt Spinler /** 7006a5bddfSMatt Spinler * @brief The handler for a reset button press 7106a5bddfSMatt Spinler * 7206a5bddfSMatt Spinler * Reboots the host if it is powered on. 7306a5bddfSMatt Spinler * 7406a5bddfSMatt Spinler * @param[in] msg - sdbusplus message from signal 7506a5bddfSMatt Spinler */ 7606a5bddfSMatt Spinler void resetPressed(sdbusplus::message::message& msg); 7706a5bddfSMatt Spinler 7806a5bddfSMatt Spinler /** 79963c65f3SMatt Spinler * @brief Checks if system is powered on 80963c65f3SMatt Spinler * 81963c65f3SMatt Spinler * @return true if powered on, false else 82963c65f3SMatt Spinler */ 83963c65f3SMatt Spinler bool poweredOn() const; 84963c65f3SMatt Spinler 85963c65f3SMatt Spinler /** 86963c65f3SMatt Spinler * @brief Returns the service name for an object 87963c65f3SMatt Spinler * 88963c65f3SMatt Spinler * @param[in] path - the object path 89963c65f3SMatt Spinler * @param[in] interface - the interface name 90963c65f3SMatt Spinler * 91963c65f3SMatt Spinler * @return std::string - the D-Bus service name if found, else 92963c65f3SMatt Spinler * an empty string 93963c65f3SMatt Spinler */ 94963c65f3SMatt Spinler std::string getService(const std::string& path, 95963c65f3SMatt Spinler const std::string& interface) const; 96963c65f3SMatt Spinler 97963c65f3SMatt Spinler /** 98fb35a325SMatt Spinler * @brief sdbusplus connection object 99fb35a325SMatt Spinler */ 100fb35a325SMatt Spinler sdbusplus::bus::bus& bus; 101963c65f3SMatt Spinler 102963c65f3SMatt Spinler /** 103963c65f3SMatt Spinler * @brief Matches on the power button released signal 104963c65f3SMatt Spinler */ 105963c65f3SMatt Spinler std::unique_ptr<sdbusplus::bus::match_t> powerButtonReleased; 106963c65f3SMatt Spinler 107963c65f3SMatt Spinler /** 108963c65f3SMatt Spinler * @brief Matches on the power button long press released signal 109963c65f3SMatt Spinler */ 110963c65f3SMatt Spinler std::unique_ptr<sdbusplus::bus::match_t> powerButtonLongPressReleased; 11106a5bddfSMatt Spinler 11206a5bddfSMatt Spinler /** 113*69f93512SMatt Spinler * @brief Matches on the ID button released signal 114*69f93512SMatt Spinler */ 115*69f93512SMatt Spinler std::unique_ptr<sdbusplus::bus::match_t> idButtonReleased; 116*69f93512SMatt Spinler 117*69f93512SMatt Spinler /** 11806a5bddfSMatt Spinler * @brief Matches on the reset button released signal 11906a5bddfSMatt Spinler */ 12006a5bddfSMatt Spinler std::unique_ptr<sdbusplus::bus::match_t> resetButtonReleased; 121fb35a325SMatt Spinler }; 122fb35a325SMatt Spinler 123fb35a325SMatt Spinler } // namespace button 124fb35a325SMatt Spinler } // namespace phosphor 125