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 { 103bd1cfcbSNaveen Moses enum class PowerEvent 113bd1cfcbSNaveen Moses { 123bd1cfcbSNaveen Moses powerPressed, 133bd1cfcbSNaveen Moses longPowerPressed, 143bd1cfcbSNaveen Moses resetPressed 153bd1cfcbSNaveen 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 */ 42*94afa4baSGeorge Liu explicit 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 */ 883bd1cfcbSNaveen Moses bool poweredOn(size_t hostNumber) const; 89963c65f3SMatt Spinler 903bd1cfcbSNaveen 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 /** 983bd1cfcbSNaveen Moses * @brief gets the valid host selector value in multi host 993bd1cfcbSNaveen Moses * system 1003bd1cfcbSNaveen Moses * 1013bd1cfcbSNaveen Moses * @return size_t throws exception if host selector position is 1023bd1cfcbSNaveen Moses * invalid or not available. 1033bd1cfcbSNaveen Moses */ 1043bd1cfcbSNaveen Moses 1053bd1cfcbSNaveen Moses size_t getHostSelectorValue(); 1063bd1cfcbSNaveen Moses 1073bd1cfcbSNaveen Moses /** 1083bd1cfcbSNaveen Moses * @brief checks if the system has multi host 1093bd1cfcbSNaveen Moses * based on the host selector property availability 1103bd1cfcbSNaveen Moses * 1113bd1cfcbSNaveen Moses * @return bool returns true if multi host system 1123bd1cfcbSNaveen Moses * else returns false. 1133bd1cfcbSNaveen Moses */ 1143bd1cfcbSNaveen Moses bool isMultiHost(); 1153bd1cfcbSNaveen Moses /** 1163bd1cfcbSNaveen Moses * @brief trigger the power ctrl event based on the 1173bd1cfcbSNaveen Moses * button press event type. 1183bd1cfcbSNaveen Moses * 1193bd1cfcbSNaveen Moses * @return void 1203bd1cfcbSNaveen Moses */ 1213bd1cfcbSNaveen Moses void handlePowerEvent(PowerEvent powerEventType); 1223bd1cfcbSNaveen Moses 1233bd1cfcbSNaveen 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