Kuiying Wang | a9d39e3 | 2018-08-14 13:47:32 +0800 | [diff] [blame] | 1 | /* |
| 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 Wang | a9d39e3 | 2018-08-14 13:47:32 +0800 | [diff] [blame] | 17 | #include "reset_button.hpp" |
| 18 | |
Patrick Venture | 0d9377d | 2018-11-01 19:34:59 -0700 | [diff] [blame] | 19 | #include "xyz/openbmc_project/Chassis/Buttons/Reset/server.hpp" |
| 20 | |
Naveen Moses | a1af329 | 2021-12-15 11:47:01 +0530 | [diff] [blame] | 21 | // add the button iface class to registry |
| 22 | static ButtonIFRegister<ResetButton> buttonRegister; |
| 23 | |
Kuiying Wang | a9d39e3 | 2018-08-14 13:47:32 +0800 | [diff] [blame] | 24 | void ResetButton::simPress() |
| 25 | { |
| 26 | pressed(); |
| 27 | } |
Naveen Moses | a1af329 | 2021-12-15 11:47:01 +0530 | [diff] [blame] | 28 | |
George Liu | 94afa4b | 2022-06-20 13:36:43 +0800 | [diff] [blame] | 29 | void ResetButton::handleEvent(sd_event_source* /* es */, int fd, |
| 30 | uint32_t /* revents */) |
Naveen Moses | a1af329 | 2021-12-15 11:47:01 +0530 | [diff] [blame] | 31 | { |
| 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 | } |