1fb35a325SMatt Spinler #pragma once 2fb35a325SMatt Spinler #include <sdbusplus/bus.hpp> 3fb35a325SMatt Spinler #include <sdbusplus/bus/match.hpp> 4fb35a325SMatt Spinler 5fb35a325SMatt Spinler namespace phosphor 6fb35a325SMatt Spinler { 7fb35a325SMatt Spinler namespace button 8fb35a325SMatt Spinler { 93bd1cfcbSNaveen Moses enum class PowerEvent 103bd1cfcbSNaveen Moses { 113bd1cfcbSNaveen Moses powerPressed, 12ab8dac51SNaveen Moses resetPressed, 13ab8dac51SNaveen Moses powerReleased, 14ab8dac51SNaveen Moses resetReleased 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 */ 429a529a69SPatrick Williams explicit Handler(sdbusplus::bus_t& bus); 43fb35a325SMatt Spinler 44fb35a325SMatt Spinler private: 45fb35a325SMatt Spinler /** 46963c65f3SMatt Spinler * @brief The handler for a power button press 47963c65f3SMatt Spinler * 48*395c764cSDelphineCCChiu * It will do power action according to the pressing duration. 49963c65f3SMatt Spinler * 50963c65f3SMatt Spinler * @param[in] msg - sdbusplus message from signal 51963c65f3SMatt Spinler */ 529a529a69SPatrick Williams void powerReleased(sdbusplus::message_t& msg); 53963c65f3SMatt Spinler 54963c65f3SMatt Spinler /** 5569f93512SMatt Spinler * @brief The handler for an ID button press 5669f93512SMatt Spinler * 5769f93512SMatt Spinler * Toggles the ID LED group 5869f93512SMatt Spinler * 5969f93512SMatt Spinler * @param[in] msg - sdbusplus message from signal 6069f93512SMatt Spinler */ 619a529a69SPatrick Williams void idReleased(sdbusplus::message_t& msg); 6269f93512SMatt Spinler 6369f93512SMatt Spinler /** 6406a5bddfSMatt Spinler * @brief The handler for a reset button press 6506a5bddfSMatt Spinler * 6606a5bddfSMatt Spinler * Reboots the host if it is powered on. 6706a5bddfSMatt Spinler * 6806a5bddfSMatt Spinler * @param[in] msg - sdbusplus message from signal 6906a5bddfSMatt Spinler */ 709a529a69SPatrick Williams void resetReleased(sdbusplus::message_t& msg); 7106a5bddfSMatt Spinler 7206a5bddfSMatt Spinler /** 73a6d4e65dSNaveen Moses * @brief The handler for a OCP debug card host selector button press 74a6d4e65dSNaveen Moses * 75a6d4e65dSNaveen Moses * In multi host system increases host position by 1 up to max host 76a6d4e65dSNaveen Moses * position. 77a6d4e65dSNaveen Moses * 78a6d4e65dSNaveen Moses * @param[in] msg - sdbusplus message from signal 79a6d4e65dSNaveen Moses */ 80a6d4e65dSNaveen Moses 81e3b4e11fSPatrick Williams void debugHostSelectorReleased(sdbusplus::message_t& msg); 82a6d4e65dSNaveen Moses 83a6d4e65dSNaveen Moses /** 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(); 106a6d4e65dSNaveen Moses /** 107a6d4e65dSNaveen Moses * @brief increases the host selector position property 108a6d4e65dSNaveen Moses * by 1 upto max host selector position 109a6d4e65dSNaveen Moses * 110a6d4e65dSNaveen Moses * @return void 111a6d4e65dSNaveen Moses */ 1123bd1cfcbSNaveen Moses 113a6d4e65dSNaveen Moses void increaseHostSelectorPosition(); 1143bd1cfcbSNaveen Moses /** 1153bd1cfcbSNaveen Moses * @brief checks if the system has multi host 1163bd1cfcbSNaveen Moses * based on the host selector property availability 1173bd1cfcbSNaveen Moses * 1183bd1cfcbSNaveen Moses * @return bool returns true if multi host system 1193bd1cfcbSNaveen Moses * else returns false. 1203bd1cfcbSNaveen Moses */ 1213bd1cfcbSNaveen Moses bool isMultiHost(); 1223bd1cfcbSNaveen Moses /** 1233bd1cfcbSNaveen Moses * @brief trigger the power ctrl event based on the 1243bd1cfcbSNaveen Moses * button press event type. 1253bd1cfcbSNaveen Moses * 1263bd1cfcbSNaveen Moses * @return void 1273bd1cfcbSNaveen Moses */ 128*395c764cSDelphineCCChiu void handlePowerEvent(PowerEvent powerEventType, 129*395c764cSDelphineCCChiu std::chrono::microseconds duration); 1303bd1cfcbSNaveen Moses 1313bd1cfcbSNaveen Moses /** 132fb35a325SMatt Spinler * @brief sdbusplus connection object 133fb35a325SMatt Spinler */ 1349a529a69SPatrick Williams sdbusplus::bus_t& bus; 135963c65f3SMatt Spinler 136963c65f3SMatt Spinler /** 137963c65f3SMatt Spinler * @brief Matches on the power button released signal 138963c65f3SMatt Spinler */ 139963c65f3SMatt Spinler std::unique_ptr<sdbusplus::bus::match_t> powerButtonReleased; 140963c65f3SMatt Spinler 141963c65f3SMatt Spinler /** 142963c65f3SMatt Spinler * @brief Matches on the power button long press released signal 143963c65f3SMatt Spinler */ 144ab8dac51SNaveen Moses std::unique_ptr<sdbusplus::bus::match_t> powerButtonLongPressed; 14506a5bddfSMatt Spinler 14606a5bddfSMatt Spinler /** 14769f93512SMatt Spinler * @brief Matches on the ID button released signal 14869f93512SMatt Spinler */ 14969f93512SMatt Spinler std::unique_ptr<sdbusplus::bus::match_t> idButtonReleased; 15069f93512SMatt Spinler 15169f93512SMatt Spinler /** 15206a5bddfSMatt Spinler * @brief Matches on the reset button released signal 15306a5bddfSMatt Spinler */ 15406a5bddfSMatt Spinler std::unique_ptr<sdbusplus::bus::match_t> resetButtonReleased; 155a6d4e65dSNaveen Moses 156a6d4e65dSNaveen Moses /** 157a6d4e65dSNaveen Moses * @brief Matches on the ocp debug host selector button released signal 158a6d4e65dSNaveen Moses */ 159a6d4e65dSNaveen Moses std::unique_ptr<sdbusplus::bus::match_t> debugHSButtonReleased; 160fb35a325SMatt Spinler }; 161fb35a325SMatt Spinler 162fb35a325SMatt Spinler } // namespace button 163fb35a325SMatt Spinler } // namespace phosphor 164