1fb35a325SMatt Spinler #pragma once 2*1a309f77SMatt Spinler 3*1a309f77SMatt Spinler #include "power_button_profile.hpp" 4*1a309f77SMatt Spinler 5fb35a325SMatt Spinler #include <sdbusplus/bus.hpp> 6fb35a325SMatt Spinler #include <sdbusplus/bus/match.hpp> 7fb35a325SMatt Spinler 8fb35a325SMatt Spinler namespace phosphor 9fb35a325SMatt Spinler { 10fb35a325SMatt Spinler namespace button 11fb35a325SMatt Spinler { 123bd1cfcbSNaveen Moses enum class PowerEvent 133bd1cfcbSNaveen Moses { 143bd1cfcbSNaveen Moses powerPressed, 15ab8dac51SNaveen Moses resetPressed, 16ab8dac51SNaveen Moses powerReleased, 17ab8dac51SNaveen Moses resetReleased 183bd1cfcbSNaveen Moses }; 19fb35a325SMatt Spinler /** 20fb35a325SMatt Spinler * @class Handler 21fb35a325SMatt Spinler * 22fb35a325SMatt Spinler * This class acts on the signals generated by the 23fb35a325SMatt Spinler * xyz.openbmc_project.Chassis.Buttons code when 24fb35a325SMatt Spinler * it detects button presses. 25fb35a325SMatt Spinler * 26fb35a325SMatt Spinler * There are 3 buttons supported - Power, ID, and Reset. 27fb35a325SMatt Spinler * As not all systems may implement each button, this class will 28fb35a325SMatt Spinler * check for that button on D-Bus before listening for its signals. 29fb35a325SMatt Spinler */ 30fb35a325SMatt Spinler class Handler 31fb35a325SMatt Spinler { 32fb35a325SMatt Spinler public: 33fb35a325SMatt Spinler Handler() = delete; 34fb35a325SMatt Spinler ~Handler() = default; 35fb35a325SMatt Spinler Handler(const Handler&) = delete; 36fb35a325SMatt Spinler Handler& operator=(const Handler&) = delete; 37fb35a325SMatt Spinler Handler(Handler&&) = delete; 38fb35a325SMatt Spinler Handler& operator=(Handler&&) = delete; 39fb35a325SMatt Spinler 40fb35a325SMatt Spinler /** 41fb35a325SMatt Spinler * @brief Constructor 42fb35a325SMatt Spinler * 43fb35a325SMatt Spinler * @param[in] bus - sdbusplus connection object 44fb35a325SMatt Spinler */ 459a529a69SPatrick Williams explicit Handler(sdbusplus::bus_t& bus); 46fb35a325SMatt Spinler 47fb35a325SMatt Spinler private: 48fb35a325SMatt Spinler /** 49963c65f3SMatt Spinler * @brief The handler for a power button press 50963c65f3SMatt Spinler * 51395c764cSDelphineCCChiu * It will do power action according to the pressing duration. 52963c65f3SMatt Spinler * 53963c65f3SMatt Spinler * @param[in] msg - sdbusplus message from signal 54963c65f3SMatt Spinler */ 559a529a69SPatrick Williams void powerReleased(sdbusplus::message_t& msg); 56963c65f3SMatt Spinler 57963c65f3SMatt Spinler /** 5869f93512SMatt Spinler * @brief The handler for an ID button press 5969f93512SMatt Spinler * 6069f93512SMatt Spinler * Toggles the ID LED group 6169f93512SMatt Spinler * 6269f93512SMatt Spinler * @param[in] msg - sdbusplus message from signal 6369f93512SMatt Spinler */ 649a529a69SPatrick Williams void idReleased(sdbusplus::message_t& msg); 6569f93512SMatt Spinler 6669f93512SMatt Spinler /** 6706a5bddfSMatt Spinler * @brief The handler for a reset button press 6806a5bddfSMatt Spinler * 6906a5bddfSMatt Spinler * Reboots the host if it is powered on. 7006a5bddfSMatt Spinler * 7106a5bddfSMatt Spinler * @param[in] msg - sdbusplus message from signal 7206a5bddfSMatt Spinler */ 739a529a69SPatrick Williams void resetReleased(sdbusplus::message_t& msg); 7406a5bddfSMatt Spinler 7506a5bddfSMatt Spinler /** 76a6d4e65dSNaveen Moses * @brief The handler for a OCP debug card host selector button press 77a6d4e65dSNaveen Moses * 78a6d4e65dSNaveen Moses * In multi host system increases host position by 1 up to max host 79a6d4e65dSNaveen Moses * position. 80a6d4e65dSNaveen Moses * 81a6d4e65dSNaveen Moses * @param[in] msg - sdbusplus message from signal 82a6d4e65dSNaveen Moses */ 83a6d4e65dSNaveen Moses 84e3b4e11fSPatrick Williams void debugHostSelectorReleased(sdbusplus::message_t& msg); 85a6d4e65dSNaveen Moses 86a6d4e65dSNaveen Moses /** 87963c65f3SMatt Spinler * @brief Checks if system is powered on 88963c65f3SMatt Spinler * 89963c65f3SMatt Spinler * @return true if powered on, false else 90963c65f3SMatt Spinler */ 913bd1cfcbSNaveen Moses bool poweredOn(size_t hostNumber) const; 92963c65f3SMatt Spinler 933bd1cfcbSNaveen Moses /* 94963c65f3SMatt Spinler * @return std::string - the D-Bus service name if found, else 95963c65f3SMatt Spinler * an empty string 96963c65f3SMatt Spinler */ 97963c65f3SMatt Spinler std::string getService(const std::string& path, 98963c65f3SMatt Spinler const std::string& interface) const; 99963c65f3SMatt Spinler 100963c65f3SMatt Spinler /** 1013bd1cfcbSNaveen Moses * @brief gets the valid host selector value in multi host 1023bd1cfcbSNaveen Moses * system 1033bd1cfcbSNaveen Moses * 1043bd1cfcbSNaveen Moses * @return size_t throws exception if host selector position is 1053bd1cfcbSNaveen Moses * invalid or not available. 1063bd1cfcbSNaveen Moses */ 1073bd1cfcbSNaveen Moses 1083bd1cfcbSNaveen Moses size_t getHostSelectorValue(); 109a6d4e65dSNaveen Moses /** 110a6d4e65dSNaveen Moses * @brief increases the host selector position property 111a6d4e65dSNaveen Moses * by 1 upto max host selector position 112a6d4e65dSNaveen Moses * 113a6d4e65dSNaveen Moses * @return void 114a6d4e65dSNaveen Moses */ 1153bd1cfcbSNaveen Moses 116a6d4e65dSNaveen Moses void increaseHostSelectorPosition(); 1173bd1cfcbSNaveen Moses /** 1183bd1cfcbSNaveen Moses * @brief checks if the system has multi host 1193bd1cfcbSNaveen Moses * based on the host selector property availability 1203bd1cfcbSNaveen Moses * 1213bd1cfcbSNaveen Moses * @return bool returns true if multi host system 1223bd1cfcbSNaveen Moses * else returns false. 1233bd1cfcbSNaveen Moses */ 1243bd1cfcbSNaveen Moses bool isMultiHost(); 1253bd1cfcbSNaveen Moses /** 1263bd1cfcbSNaveen Moses * @brief trigger the power ctrl event based on the 1273bd1cfcbSNaveen Moses * button press event type. 1283bd1cfcbSNaveen Moses * 1293bd1cfcbSNaveen Moses * @return void 1303bd1cfcbSNaveen Moses */ 131395c764cSDelphineCCChiu void handlePowerEvent(PowerEvent powerEventType, 132395c764cSDelphineCCChiu std::chrono::microseconds duration); 1333bd1cfcbSNaveen Moses 1343bd1cfcbSNaveen Moses /** 135fb35a325SMatt Spinler * @brief sdbusplus connection object 136fb35a325SMatt Spinler */ 1379a529a69SPatrick Williams sdbusplus::bus_t& bus; 138963c65f3SMatt Spinler 139963c65f3SMatt Spinler /** 140963c65f3SMatt Spinler * @brief Matches on the power button released signal 141963c65f3SMatt Spinler */ 142963c65f3SMatt Spinler std::unique_ptr<sdbusplus::bus::match_t> powerButtonReleased; 143963c65f3SMatt Spinler 144963c65f3SMatt Spinler /** 145963c65f3SMatt Spinler * @brief Matches on the power button long press released signal 146963c65f3SMatt Spinler */ 147ab8dac51SNaveen Moses std::unique_ptr<sdbusplus::bus::match_t> powerButtonLongPressed; 14806a5bddfSMatt Spinler 14906a5bddfSMatt Spinler /** 15069f93512SMatt Spinler * @brief Matches on the ID button released signal 15169f93512SMatt Spinler */ 15269f93512SMatt Spinler std::unique_ptr<sdbusplus::bus::match_t> idButtonReleased; 15369f93512SMatt Spinler 15469f93512SMatt Spinler /** 15506a5bddfSMatt Spinler * @brief Matches on the reset button released signal 15606a5bddfSMatt Spinler */ 15706a5bddfSMatt Spinler std::unique_ptr<sdbusplus::bus::match_t> resetButtonReleased; 158a6d4e65dSNaveen Moses 159a6d4e65dSNaveen Moses /** 160a6d4e65dSNaveen Moses * @brief Matches on the ocp debug host selector button released signal 161a6d4e65dSNaveen Moses */ 162a6d4e65dSNaveen Moses std::unique_ptr<sdbusplus::bus::match_t> debugHSButtonReleased; 163*1a309f77SMatt Spinler 164*1a309f77SMatt Spinler /** 165*1a309f77SMatt Spinler * @brief The custom power handler profile object. 166*1a309f77SMatt Spinler */ 167*1a309f77SMatt Spinler std::unique_ptr<PowerButtonProfile> powerButtonProfile; 168fb35a325SMatt Spinler }; 169fb35a325SMatt Spinler 170fb35a325SMatt Spinler } // namespace button 171fb35a325SMatt Spinler } // namespace phosphor 172