blob: f370ed46a86090cbd4641678509cfa290850f951 [file] [log] [blame]
Kuiying Wanga9d39e32018-08-14 13:47:32 +08001/*
2// Copyright (c) 2018 Intel Corporation
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15*/
16
17#pragma once
Naveen Mosesa1af3292021-12-15 11:47:01 +053018#include "button_factory.hpp"
19#include "button_interface.hpp"
Kuiying Wanga9d39e32018-08-14 13:47:32 +080020#include "common.hpp"
Delphine CC Chiu15c60e22024-04-12 13:01:32 -050021#include "config.hpp"
Kuiying Wanga9d39e32018-08-14 13:47:32 +080022#include "gpio.hpp"
Patrick Venture0d9377d2018-11-01 19:34:59 -070023#include "xyz/openbmc_project/Chassis/Buttons/Reset/server.hpp"
24#include "xyz/openbmc_project/Chassis/Common/error.hpp"
25
26#include <unistd.h>
27
28#include <phosphor-logging/elog-errors.hpp>
Kuiying Wanga9d39e32018-08-14 13:47:32 +080029
Rush Chen31ce3752024-11-08 14:57:27 +080030static constexpr auto RESET_BUTTON = "RESET_BUTTON";
Kuiying Wanga9d39e32018-08-14 13:47:32 +080031
George Liu5b98f4d2022-06-20 13:31:14 +080032class ResetButton :
Patrick Williams9a529a62022-07-22 19:26:54 -050033 public sdbusplus::server::object_t<
George Liu5b98f4d2022-06-20 13:31:14 +080034 sdbusplus::xyz::openbmc_project::Chassis::Buttons::server::Reset>,
35 public ButtonIface
Kuiying Wanga9d39e32018-08-14 13:47:32 +080036{
Naveen Mosesa1af3292021-12-15 11:47:01 +053037 public:
Patrick Williams9a529a62022-07-22 19:26:54 -050038 ResetButton(sdbusplus::bus_t& bus, const char* path, EventPtr& event,
Delphine CC Chiuccd7db02023-02-09 14:48:53 +080039 ButtonConfig& buttonCfg) :
Patrick Williams9a529a62022-07-22 19:26:54 -050040 sdbusplus::server::object_t<
Kuiying Wanga9d39e32018-08-14 13:47:32 +080041 sdbusplus::xyz::openbmc_project::Chassis::Buttons::server::Reset>(
42 bus, path),
Naveen Mosesa1af3292021-12-15 11:47:01 +053043 ButtonIface(bus, event, buttonCfg)
Kuiying Wanga9d39e32018-08-14 13:47:32 +080044 {
Naveen Mosesa1af3292021-12-15 11:47:01 +053045 init();
Kuiying Wanga9d39e32018-08-14 13:47:32 +080046 }
47
48 ~ResetButton()
49 {
Naveen Mosesa1af3292021-12-15 11:47:01 +053050 deInit();
Kuiying Wanga9d39e32018-08-14 13:47:32 +080051 }
52
53 void simPress() override;
54
Rush Chen31ce3752024-11-08 14:57:27 +080055 static constexpr std::string getFormFactorName()
Matt Spinler8605bdf2018-11-05 14:55:46 -060056 {
57 return RESET_BUTTON;
58 }
59
Rush Chen31ce3752024-11-08 14:57:27 +080060 static constexpr std::string getDbusObjectPath()
Kuiying Wanga9d39e32018-08-14 13:47:32 +080061 {
Naveen Mosesa1af3292021-12-15 11:47:01 +053062 return RESET_DBUS_OBJECT_NAME;
Kuiying Wanga9d39e32018-08-14 13:47:32 +080063 }
64
Naveen Mosesa1af3292021-12-15 11:47:01 +053065 void handleEvent(sd_event_source* es, int fd, uint32_t revents) override;
Kuiying Wanga9d39e32018-08-14 13:47:32 +080066};