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 17 #include "reset_button.hpp" 18 19 #include "xyz/openbmc_project/Chassis/Buttons/Reset/server.hpp" 20 21 // add the button iface class to registry 22 static ButtonIFRegister<ResetButton> buttonRegister; 23 24 void ResetButton::simPress() 25 { 26 pressed(); 27 } 28 29 void ResetButton::handleEvent(sd_event_source* /* es */, int fd, 30 uint32_t /* revents */) 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 } 70