1 #include "debugHostSelector_button.hpp"
2 // add the button iface class to registry
3 static ButtonIFRegister<DebugHostSelector> buttonRegister;
4 using namespace phosphor::logging;
5 
simPress()6 void DebugHostSelector::simPress()
7 {
8     pressed();
9 }
10 
simRelease()11 void DebugHostSelector::simRelease()
12 {
13     released();
14 }
15 
simLongPress()16 void DebugHostSelector::simLongPress()
17 {
18     pressedLong();
19 }
20 
21 /**
22  * @brief This method is called from sd-event provided callback function
23  * callbackHandler if platform specific event handling is needed then a
24  * derived class instance with its specific event handling logic along with
25  * init() function can be created to override the default event handling
26  */
27 
handleEvent(sd_event_source *,int fd,uint32_t)28 void DebugHostSelector::handleEvent(sd_event_source* /* es */, int fd,
29                                     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         lg2::error("GPIO fd lseek error!  : {FORM_FACTOR_TYPE}",
39                    "FORM_FACTOR_TYPE", getFormFactorType());
40         return;
41     }
42 
43     n = ::read(fd, &buf, sizeof(buf));
44     if (n < 0)
45     {
46         lg2::error("GPIO fd read error!  : {FORM_FACTOR_TYPE}",
47                    "FORM_FACTOR_TYPE", getFormFactorType());
48         throw sdbusplus::xyz::openbmc_project::Chassis::Common::Error::
49             IOError();
50     }
51 
52     if (buf == '0')
53     {
54         lg2::info("Button pressed : {FORM_FACTOR_TYPE}", "FORM_FACTOR_TYPE",
55                   getFormFactorType());
56         // emit pressed signal
57         pressed();
58     }
59     else
60     {
61         lg2::info("Button released{FORM_FACTOR_TYPE}", "FORM_FACTOR_TYPE",
62                   getFormFactorType());
63         // emit released signal
64         released();
65     }
66 }
67