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 18a1af329fSNaveen Moses #include "button_factory.hpp" 19a1af329fSNaveen Moses #include "button_interface.hpp" 20a9d39e30SKuiying Wang #include "common.hpp" 21*15c60e2fSDelphine CC Chiu #include "config.hpp" 22a9d39e30SKuiying Wang #include "gpio.hpp" 230d9377d2SPatrick Venture #include "xyz/openbmc_project/Chassis/Buttons/Power/server.hpp" 240d9377d2SPatrick Venture #include "xyz/openbmc_project/Chassis/Common/error.hpp" 250d9377d2SPatrick Venture 260d9377d2SPatrick Venture #include <unistd.h> 270d9377d2SPatrick Venture 280d9377d2SPatrick Venture #include <phosphor-logging/elog-errors.hpp> 29a9d39e30SKuiying Wang 305b98f4dbSGeorge Liu #include <chrono> 315b98f4dbSGeorge Liu 32a1af329fSNaveen Moses static constexpr std::string_view POWER_BUTTON = "POWER_BUTTON"; 33a9d39e30SKuiying Wang 345b98f4dbSGeorge Liu class PowerButton : 359a529a69SPatrick Williams public sdbusplus::server::object_t< 36a1af329fSNaveen Moses sdbusplus::xyz::openbmc_project::Chassis::Buttons::server::Power>, 37a1af329fSNaveen Moses public ButtonIface 38a9d39e30SKuiying Wang { 39a1af329fSNaveen Moses public: PowerButton(sdbusplus::bus_t & bus,const char * path,EventPtr & event,ButtonConfig & buttonCfg)409a529a69SPatrick Williams PowerButton(sdbusplus::bus_t& bus, const char* path, EventPtr& event, 41ccd7db05SDelphine CC Chiu ButtonConfig& buttonCfg) : 429a529a69SPatrick Williams sdbusplus::server::object_t< 43a9d39e30SKuiying Wang sdbusplus::xyz::openbmc_project::Chassis::Buttons::server::Power>( 44a9d39e30SKuiying Wang bus, path), 45a1af329fSNaveen Moses ButtonIface(bus, event, buttonCfg) 46a9d39e30SKuiying Wang { 47a1af329fSNaveen Moses init(); 48a9d39e30SKuiying Wang } 49a9d39e30SKuiying Wang ~PowerButton()50a9d39e30SKuiying Wang ~PowerButton() 51a9d39e30SKuiying Wang { 52a1af329fSNaveen Moses deInit(); 53a9d39e30SKuiying Wang } 54a9d39e30SKuiying Wang 55a9d39e30SKuiying Wang void simPress() override; 56a9d39e30SKuiying Wang void simLongPress() override; 57a9d39e30SKuiying Wang getFormFactorName()58a1af329fSNaveen Moses static constexpr std::string_view getFormFactorName() 598605bdffSMatt Spinler { 608605bdffSMatt Spinler return POWER_BUTTON; 618605bdffSMatt Spinler } getDbusObjectPath()62a1af329fSNaveen Moses static constexpr const char* getDbusObjectPath() 6393894f6eSMatt Spinler { 64a1af329fSNaveen Moses return POWER_DBUS_OBJECT_NAME; 6593894f6eSMatt Spinler } 66a1af329fSNaveen Moses void updatePressedTime(); 67a1af329fSNaveen Moses auto getPressTime() const; 68a1af329fSNaveen Moses void handleEvent(sd_event_source* es, int fd, uint32_t revents) override; 6993894f6eSMatt Spinler 70a1af329fSNaveen Moses protected: 7193894f6eSMatt Spinler decltype(std::chrono::steady_clock::now()) pressedTime; 72a9d39e30SKuiying Wang }; 73