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 /** 41*963c65f3SMatt Spinler * @brief The handler for a power button press 42*963c65f3SMatt Spinler * 43*963c65f3SMatt Spinler * It will power on the system if it's currently off, 44*963c65f3SMatt Spinler * else it will soft power it off. 45*963c65f3SMatt Spinler * 46*963c65f3SMatt Spinler * @param[in] msg - sdbusplus message from signal 47*963c65f3SMatt Spinler */ 48*963c65f3SMatt Spinler void powerPressed(sdbusplus::message::message& msg); 49*963c65f3SMatt Spinler 50*963c65f3SMatt Spinler /** 51*963c65f3SMatt Spinler * @brief The handler for a long power button press 52*963c65f3SMatt Spinler * 53*963c65f3SMatt Spinler * If the system is currently powered on, it will 54*963c65f3SMatt Spinler * perform an immediate power off. 55*963c65f3SMatt Spinler * 56*963c65f3SMatt Spinler * @param[in] msg - sdbusplus message from signal 57*963c65f3SMatt Spinler */ 58*963c65f3SMatt Spinler void longPowerPressed(sdbusplus::message::message& msg); 59*963c65f3SMatt Spinler 60*963c65f3SMatt Spinler /** 61*963c65f3SMatt Spinler * @brief Checks if system is powered on 62*963c65f3SMatt Spinler * 63*963c65f3SMatt Spinler * @return true if powered on, false else 64*963c65f3SMatt Spinler */ 65*963c65f3SMatt Spinler bool poweredOn() const; 66*963c65f3SMatt Spinler 67*963c65f3SMatt Spinler /** 68*963c65f3SMatt Spinler * @brief Returns the service name for an object 69*963c65f3SMatt Spinler * 70*963c65f3SMatt Spinler * @param[in] path - the object path 71*963c65f3SMatt Spinler * @param[in] interface - the interface name 72*963c65f3SMatt Spinler * 73*963c65f3SMatt Spinler * @return std::string - the D-Bus service name if found, else 74*963c65f3SMatt Spinler * an empty string 75*963c65f3SMatt Spinler */ 76*963c65f3SMatt Spinler std::string getService(const std::string& path, 77*963c65f3SMatt Spinler const std::string& interface) const; 78*963c65f3SMatt Spinler 79*963c65f3SMatt Spinler /** 80fb35a325SMatt Spinler * @brief sdbusplus connection object 81fb35a325SMatt Spinler */ 82fb35a325SMatt Spinler sdbusplus::bus::bus& bus; 83*963c65f3SMatt Spinler 84*963c65f3SMatt Spinler /** 85*963c65f3SMatt Spinler * @brief Matches on the power button released signal 86*963c65f3SMatt Spinler */ 87*963c65f3SMatt Spinler std::unique_ptr<sdbusplus::bus::match_t> powerButtonReleased; 88*963c65f3SMatt Spinler 89*963c65f3SMatt Spinler /** 90*963c65f3SMatt Spinler * @brief Matches on the power button long press released signal 91*963c65f3SMatt Spinler */ 92*963c65f3SMatt Spinler std::unique_ptr<sdbusplus::bus::match_t> powerButtonLongPressReleased; 93fb35a325SMatt Spinler }; 94fb35a325SMatt Spinler 95fb35a325SMatt Spinler } // namespace button 96fb35a325SMatt Spinler } // namespace phosphor 97