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 { 10*3bd1cfcbSNaveen Moses enum class PowerEvent 11*3bd1cfcbSNaveen Moses { 12*3bd1cfcbSNaveen Moses powerPressed, 13*3bd1cfcbSNaveen Moses longPowerPressed, 14*3bd1cfcbSNaveen Moses resetPressed 15*3bd1cfcbSNaveen Moses }; 16fb35a325SMatt Spinler /** 17fb35a325SMatt Spinler * @class Handler 18fb35a325SMatt Spinler * 19fb35a325SMatt Spinler * This class acts on the signals generated by the 20fb35a325SMatt Spinler * xyz.openbmc_project.Chassis.Buttons code when 21fb35a325SMatt Spinler * it detects button presses. 22fb35a325SMatt Spinler * 23fb35a325SMatt Spinler * There are 3 buttons supported - Power, ID, and Reset. 24fb35a325SMatt Spinler * As not all systems may implement each button, this class will 25fb35a325SMatt Spinler * check for that button on D-Bus before listening for its signals. 26fb35a325SMatt Spinler */ 27fb35a325SMatt Spinler class Handler 28fb35a325SMatt Spinler { 29fb35a325SMatt Spinler public: 30fb35a325SMatt Spinler Handler() = delete; 31fb35a325SMatt Spinler ~Handler() = default; 32fb35a325SMatt Spinler Handler(const Handler&) = delete; 33fb35a325SMatt Spinler Handler& operator=(const Handler&) = delete; 34fb35a325SMatt Spinler Handler(Handler&&) = delete; 35fb35a325SMatt Spinler Handler& operator=(Handler&&) = delete; 36fb35a325SMatt Spinler 37fb35a325SMatt Spinler /** 38fb35a325SMatt Spinler * @brief Constructor 39fb35a325SMatt Spinler * 40fb35a325SMatt Spinler * @param[in] bus - sdbusplus connection object 41fb35a325SMatt Spinler */ 42fb35a325SMatt Spinler Handler(sdbusplus::bus::bus& bus); 43fb35a325SMatt Spinler 44fb35a325SMatt Spinler private: 45fb35a325SMatt Spinler /** 46963c65f3SMatt Spinler * @brief The handler for a power button press 47963c65f3SMatt Spinler * 48963c65f3SMatt Spinler * It will power on the system if it's currently off, 49963c65f3SMatt Spinler * else it will soft power it off. 50963c65f3SMatt Spinler * 51963c65f3SMatt Spinler * @param[in] msg - sdbusplus message from signal 52963c65f3SMatt Spinler */ 53963c65f3SMatt Spinler void powerPressed(sdbusplus::message::message& msg); 54963c65f3SMatt Spinler 55963c65f3SMatt Spinler /** 56963c65f3SMatt Spinler * @brief The handler for a long power button press 57963c65f3SMatt Spinler * 58963c65f3SMatt Spinler * If the system is currently powered on, it will 59963c65f3SMatt Spinler * perform an immediate power off. 60963c65f3SMatt Spinler * 61963c65f3SMatt Spinler * @param[in] msg - sdbusplus message from signal 62963c65f3SMatt Spinler */ 63963c65f3SMatt Spinler void longPowerPressed(sdbusplus::message::message& msg); 64963c65f3SMatt Spinler 65963c65f3SMatt Spinler /** 6669f93512SMatt Spinler * @brief The handler for an ID button press 6769f93512SMatt Spinler * 6869f93512SMatt Spinler * Toggles the ID LED group 6969f93512SMatt Spinler * 7069f93512SMatt Spinler * @param[in] msg - sdbusplus message from signal 7169f93512SMatt Spinler */ 7269f93512SMatt Spinler void idPressed(sdbusplus::message::message& msg); 7369f93512SMatt Spinler 7469f93512SMatt Spinler /** 7506a5bddfSMatt Spinler * @brief The handler for a reset button press 7606a5bddfSMatt Spinler * 7706a5bddfSMatt Spinler * Reboots the host if it is powered on. 7806a5bddfSMatt Spinler * 7906a5bddfSMatt Spinler * @param[in] msg - sdbusplus message from signal 8006a5bddfSMatt Spinler */ 8106a5bddfSMatt Spinler void resetPressed(sdbusplus::message::message& msg); 8206a5bddfSMatt Spinler 8306a5bddfSMatt Spinler /** 84963c65f3SMatt Spinler * @brief Checks if system is powered on 85963c65f3SMatt Spinler * 86963c65f3SMatt Spinler * @return true if powered on, false else 87963c65f3SMatt Spinler */ 88*3bd1cfcbSNaveen Moses bool poweredOn(size_t hostNumber) const; 89963c65f3SMatt Spinler 90*3bd1cfcbSNaveen Moses /* 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 /** 98*3bd1cfcbSNaveen Moses * @brief gets the valid host selector value in multi host 99*3bd1cfcbSNaveen Moses * system 100*3bd1cfcbSNaveen Moses * 101*3bd1cfcbSNaveen Moses * @return size_t throws exception if host selector position is 102*3bd1cfcbSNaveen Moses * invalid or not available. 103*3bd1cfcbSNaveen Moses */ 104*3bd1cfcbSNaveen Moses 105*3bd1cfcbSNaveen Moses size_t getHostSelectorValue(); 106*3bd1cfcbSNaveen Moses 107*3bd1cfcbSNaveen Moses /** 108*3bd1cfcbSNaveen Moses * @brief checks if the system has multi host 109*3bd1cfcbSNaveen Moses * based on the host selector property availability 110*3bd1cfcbSNaveen Moses * 111*3bd1cfcbSNaveen Moses * @return bool returns true if multi host system 112*3bd1cfcbSNaveen Moses * else returns false. 113*3bd1cfcbSNaveen Moses */ 114*3bd1cfcbSNaveen Moses bool isMultiHost(); 115*3bd1cfcbSNaveen Moses /** 116*3bd1cfcbSNaveen Moses * @brief trigger the power ctrl event based on the 117*3bd1cfcbSNaveen Moses * button press event type. 118*3bd1cfcbSNaveen Moses * 119*3bd1cfcbSNaveen Moses * @return void 120*3bd1cfcbSNaveen Moses */ 121*3bd1cfcbSNaveen Moses void handlePowerEvent(PowerEvent powerEventType); 122*3bd1cfcbSNaveen Moses 123*3bd1cfcbSNaveen Moses /** 124fb35a325SMatt Spinler * @brief sdbusplus connection object 125fb35a325SMatt Spinler */ 126fb35a325SMatt Spinler sdbusplus::bus::bus& bus; 127963c65f3SMatt Spinler 128963c65f3SMatt Spinler /** 129963c65f3SMatt Spinler * @brief Matches on the power button released signal 130963c65f3SMatt Spinler */ 131963c65f3SMatt Spinler std::unique_ptr<sdbusplus::bus::match_t> powerButtonReleased; 132963c65f3SMatt Spinler 133963c65f3SMatt Spinler /** 134963c65f3SMatt Spinler * @brief Matches on the power button long press released signal 135963c65f3SMatt Spinler */ 136963c65f3SMatt Spinler std::unique_ptr<sdbusplus::bus::match_t> powerButtonLongPressReleased; 13706a5bddfSMatt Spinler 13806a5bddfSMatt Spinler /** 13969f93512SMatt Spinler * @brief Matches on the ID button released signal 14069f93512SMatt Spinler */ 14169f93512SMatt Spinler std::unique_ptr<sdbusplus::bus::match_t> idButtonReleased; 14269f93512SMatt Spinler 14369f93512SMatt Spinler /** 14406a5bddfSMatt Spinler * @brief Matches on the reset button released signal 14506a5bddfSMatt Spinler */ 14606a5bddfSMatt Spinler std::unique_ptr<sdbusplus::bus::match_t> resetButtonReleased; 147fb35a325SMatt Spinler }; 148fb35a325SMatt Spinler 149fb35a325SMatt Spinler } // namespace button 150fb35a325SMatt Spinler } // namespace phosphor 151