blob: c3e467e0c33f54349e7227d2b86ded6cd266b12f [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
29void ResetButton::handleEvent(sd_event_source* es, int fd, uint32_t revents)
30{
31 int n = -1;
32 char buf = '0';
33
34 n = ::lseek(fd, 0, SEEK_SET);
35
36 if (n < 0)
37 {
38 phosphor::logging::log<phosphor::logging::level::ERR>(
39 "RESET_BUTTON: lseek error!");
40
41 return;
42 }
43
44 n = ::read(fd, &buf, sizeof(buf));
45 if (n < 0)
46 {
47 phosphor::logging::log<phosphor::logging::level::ERR>(
48 "RESET_BUTTON: read error!");
49 return;
50 }
51
52 if (buf == '0')
53 {
54 phosphor::logging::log<phosphor::logging::level::DEBUG>(
55 "RESET_BUTTON: pressed");
56 // emit pressed signal
57 pressed();
58 }
59 else
60 {
61 phosphor::logging::log<phosphor::logging::level::DEBUG>(
62 "RESET_BUTTON: released");
63 // released
64 released();
65 }
66
67 return;
68}