blob: 03430f9039620dd46f93b5930690fa17647add1d [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
Kuiying Wanga9d39e32018-08-14 13:47:32 +080017#include "reset_button.hpp"
18
Patrick Venture0d9377d2018-11-01 19:34:59 -070019#include "xyz/openbmc_project/Chassis/Buttons/Reset/server.hpp"
20
Naveen Mosesa1af3292021-12-15 11:47:01 +053021// add the button iface class to registry
22static ButtonIFRegister<ResetButton> buttonRegister;
23
Kuiying Wanga9d39e32018-08-14 13:47:32 +080024void ResetButton::simPress()
25{
26 pressed();
27}
Naveen Mosesa1af3292021-12-15 11:47:01 +053028
George Liu94afa4b2022-06-20 13:36:43 +080029void ResetButton::handleEvent(sd_event_source* /* es */, int fd,
30 uint32_t /* revents */)
Naveen Mosesa1af3292021-12-15 11:47:01 +053031{
32 int n = -1;
33 char buf = '0';
34
35 n = ::lseek(fd, 0, SEEK_SET);
36
37 if (n < 0)
38 {
39 phosphor::logging::log<phosphor::logging::level::ERR>(
40 "RESET_BUTTON: lseek error!");
41
42 return;
43 }
44
45 n = ::read(fd, &buf, sizeof(buf));
46 if (n < 0)
47 {
48 phosphor::logging::log<phosphor::logging::level::ERR>(
49 "RESET_BUTTON: read error!");
50 return;
51 }
52
53 if (buf == '0')
54 {
55 phosphor::logging::log<phosphor::logging::level::DEBUG>(
56 "RESET_BUTTON: pressed");
57 // emit pressed signal
58 pressed();
59 }
60 else
61 {
62 phosphor::logging::log<phosphor::logging::level::DEBUG>(
63 "RESET_BUTTON: released");
64 // released
65 released();
66 }
67
68 return;
69}