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"
21a9d39e30SKuiying Wang #include "gpio.hpp"
220d9377d2SPatrick Venture #include "xyz/openbmc_project/Chassis/Buttons/Reset/server.hpp"
230d9377d2SPatrick Venture #include "xyz/openbmc_project/Chassis/Common/error.hpp"
240d9377d2SPatrick Venture 
250d9377d2SPatrick Venture #include <unistd.h>
260d9377d2SPatrick Venture 
270d9377d2SPatrick Venture #include <phosphor-logging/elog-errors.hpp>
28a9d39e30SKuiying Wang 
29a1af329fSNaveen Moses static constexpr std::string_view RESET_BUTTON = "RESET_BUTTON";
30a9d39e30SKuiying Wang 
31*5b98f4dbSGeorge Liu class ResetButton :
32*5b98f4dbSGeorge Liu     public sdbusplus::server::object::object<
33a1af329fSNaveen Moses         sdbusplus::xyz::openbmc_project::Chassis::Buttons::server::Reset>,
34a1af329fSNaveen Moses     public ButtonIface
35a9d39e30SKuiying Wang {
36a1af329fSNaveen Moses   public:
370d9377d2SPatrick Venture     ResetButton(sdbusplus::bus::bus& bus, const char* path, EventPtr& event,
38a1af329fSNaveen Moses                 buttonConfig& buttonCfg) :
39a9d39e30SKuiying Wang         sdbusplus::server::object::object<
40a9d39e30SKuiying Wang             sdbusplus::xyz::openbmc_project::Chassis::Buttons::server::Reset>(
41a9d39e30SKuiying Wang             bus, path),
42a1af329fSNaveen Moses         ButtonIface(bus, event, buttonCfg)
43a9d39e30SKuiying Wang     {
44a1af329fSNaveen Moses         init();
45a9d39e30SKuiying Wang     }
46a9d39e30SKuiying Wang 
47a9d39e30SKuiying Wang     ~ResetButton()
48a9d39e30SKuiying Wang     {
49a1af329fSNaveen Moses         deInit();
50a9d39e30SKuiying Wang     }
51a9d39e30SKuiying Wang 
52a9d39e30SKuiying Wang     void simPress() override;
53a9d39e30SKuiying Wang 
54a1af329fSNaveen Moses     static constexpr std::string_view getFormFactorName()
558605bdffSMatt Spinler     {
568605bdffSMatt Spinler         return RESET_BUTTON;
578605bdffSMatt Spinler     }
588605bdffSMatt Spinler 
59a1af329fSNaveen Moses     static constexpr const char* getDbusObjectPath()
60a9d39e30SKuiying Wang     {
61a1af329fSNaveen Moses         return RESET_DBUS_OBJECT_NAME;
62a9d39e30SKuiying Wang     }
63a9d39e30SKuiying Wang 
64a1af329fSNaveen Moses     void handleEvent(sd_event_source* es, int fd, uint32_t revents) override;
65a9d39e30SKuiying Wang };
66