1a9d39e30SKuiying Wang /* 2a9d39e30SKuiying Wang // Copyright (c) 2018 Intel Corporation 3a9d39e30SKuiying Wang // 4a9d39e30SKuiying Wang // Licensed under the Apache License, Version 2.0 (the "License"); 5a9d39e30SKuiying Wang // you may not use this file except in compliance with the License. 6a9d39e30SKuiying Wang // You may obtain a copy of the License at 7a9d39e30SKuiying Wang // 8a9d39e30SKuiying Wang // http://www.apache.org/licenses/LICENSE-2.0 9a9d39e30SKuiying Wang // 10a9d39e30SKuiying Wang // Unless required by applicable law or agreed to in writing, software 11a9d39e30SKuiying Wang // distributed under the License is distributed on an "AS IS" BASIS, 12a9d39e30SKuiying Wang // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13a9d39e30SKuiying Wang // See the License for the specific language governing permissions and 14a9d39e30SKuiying Wang // limitations under the License. 15a9d39e30SKuiying Wang */ 16a9d39e30SKuiying Wang 17a9d39e30SKuiying Wang #pragma once 18d6a1bae7SGeorge Liu #include "config.h" 19d6a1bae7SGeorge Liu 20a1af329fSNaveen Moses #include "button_factory.hpp" 21a1af329fSNaveen Moses #include "button_interface.hpp" 22a9d39e30SKuiying Wang #include "common.hpp" 23a9d39e30SKuiying Wang #include "gpio.hpp" 240d9377d2SPatrick Venture #include "xyz/openbmc_project/Chassis/Buttons/Power/server.hpp" 250d9377d2SPatrick Venture #include "xyz/openbmc_project/Chassis/Common/error.hpp" 260d9377d2SPatrick Venture 270d9377d2SPatrick Venture #include <unistd.h> 280d9377d2SPatrick Venture 290d9377d2SPatrick Venture #include <phosphor-logging/elog-errors.hpp> 30a9d39e30SKuiying Wang 315b98f4dbSGeorge Liu #include <chrono> 325b98f4dbSGeorge Liu 33a1af329fSNaveen Moses static constexpr std::string_view POWER_BUTTON = "POWER_BUTTON"; 34a9d39e30SKuiying Wang 355b98f4dbSGeorge Liu class PowerButton : 36*9a529a69SPatrick Williams public sdbusplus::server::object_t< 37a1af329fSNaveen Moses sdbusplus::xyz::openbmc_project::Chassis::Buttons::server::Power>, 38a1af329fSNaveen Moses public ButtonIface 39a9d39e30SKuiying Wang { 40a1af329fSNaveen Moses public: 41*9a529a69SPatrick Williams PowerButton(sdbusplus::bus_t& bus, const char* path, EventPtr& event, 42a1af329fSNaveen Moses buttonConfig& buttonCfg) : 43*9a529a69SPatrick Williams sdbusplus::server::object_t< 44a9d39e30SKuiying Wang sdbusplus::xyz::openbmc_project::Chassis::Buttons::server::Power>( 45a9d39e30SKuiying Wang bus, path), 46a1af329fSNaveen Moses ButtonIface(bus, event, buttonCfg) 47a9d39e30SKuiying Wang { 48a1af329fSNaveen Moses init(); 49a9d39e30SKuiying Wang } 50a9d39e30SKuiying Wang 51a9d39e30SKuiying Wang ~PowerButton() 52a9d39e30SKuiying Wang { 53a1af329fSNaveen Moses deInit(); 54a9d39e30SKuiying Wang } 55a9d39e30SKuiying Wang 56a9d39e30SKuiying Wang void simPress() override; 57a9d39e30SKuiying Wang void simLongPress() override; 58a9d39e30SKuiying Wang 59a1af329fSNaveen Moses static constexpr std::string_view getFormFactorName() 608605bdffSMatt Spinler { 618605bdffSMatt Spinler return POWER_BUTTON; 628605bdffSMatt Spinler } 63a1af329fSNaveen Moses static constexpr const char* getDbusObjectPath() 6493894f6eSMatt Spinler { 65a1af329fSNaveen Moses return POWER_DBUS_OBJECT_NAME; 6693894f6eSMatt Spinler } 67a1af329fSNaveen Moses void updatePressedTime(); 68a1af329fSNaveen Moses auto getPressTime() const; 69a1af329fSNaveen Moses void handleEvent(sd_event_source* es, int fd, uint32_t revents) override; 7093894f6eSMatt Spinler 71a1af329fSNaveen Moses protected: 7293894f6eSMatt Spinler decltype(std::chrono::steady_clock::now()) pressedTime; 73a9d39e30SKuiying Wang }; 74