blob: 3e9c9e4dae5f80a83a71d648a112651fef415b3d [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"
21#include "gpio.hpp"
Patrick Venture0d9377d2018-11-01 19:34:59 -070022#include "xyz/openbmc_project/Chassis/Buttons/ID/server.hpp"
23#include "xyz/openbmc_project/Chassis/Common/error.hpp"
Kuiying Wanga9d39e32018-08-14 13:47:32 +080024
Patrick Venture0d9377d2018-11-01 19:34:59 -070025#include <unistd.h>
26
27#include <phosphor-logging/elog-errors.hpp>
28
Naveen Mosesa1af3292021-12-15 11:47:01 +053029static constexpr std::string_view ID_BUTTON = "ID_BTN";
Kuiying Wanga9d39e32018-08-14 13:47:32 +080030
George Liu5b98f4d2022-06-20 13:31:14 +080031class IDButton :
32 public sdbusplus::server::object::object<
33 sdbusplus::xyz::openbmc_project::Chassis::Buttons::server::ID>,
34 public ButtonIface
Kuiying Wanga9d39e32018-08-14 13:47:32 +080035{
Naveen Mosesa1af3292021-12-15 11:47:01 +053036 public:
Patrick Venture0d9377d2018-11-01 19:34:59 -070037 IDButton(sdbusplus::bus::bus& bus, const char* path, EventPtr& event,
Naveen Mosesa1af3292021-12-15 11:47:01 +053038 buttonConfig& buttonCfg) :
Kuiying Wanga9d39e32018-08-14 13:47:32 +080039 sdbusplus::server::object::object<
40 sdbusplus::xyz::openbmc_project::Chassis::Buttons::server::ID>(
41 bus, path),
Naveen Mosesa1af3292021-12-15 11:47:01 +053042 ButtonIface(bus, event, buttonCfg)
Kuiying Wanga9d39e32018-08-14 13:47:32 +080043 {
Naveen Mosesa1af3292021-12-15 11:47:01 +053044 init();
Kuiying Wanga9d39e32018-08-14 13:47:32 +080045 }
46
47 ~IDButton()
48 {
Naveen Mosesa1af3292021-12-15 11:47:01 +053049 deInit();
Kuiying Wanga9d39e32018-08-14 13:47:32 +080050 }
51
52 void simPress() override;
53
Naveen Mosesa1af3292021-12-15 11:47:01 +053054 static constexpr std::string_view getFormFactorName()
Matt Spinler8605bdf2018-11-05 14:55:46 -060055 {
56 return ID_BUTTON;
57 }
Naveen Mosesa1af3292021-12-15 11:47:01 +053058 static constexpr const char* getDbusObjectPath()
Kuiying Wanga9d39e32018-08-14 13:47:32 +080059 {
Naveen Mosesa1af3292021-12-15 11:47:01 +053060 return ID_DBUS_OBJECT_NAME;
Kuiying Wanga9d39e32018-08-14 13:47:32 +080061 }
62
Naveen Mosesa1af3292021-12-15 11:47:01 +053063 void handleEvent(sd_event_source* es, int fd, uint32_t revents) override;
Kuiying Wanga9d39e32018-08-14 13:47:32 +080064};