Add abstract factory to create button iface objects
A abstract factory class is implemented to return
the instance of button interface class based on the
button iface formfactor name provided as
parameter to the abstract factory createInstance
method.
Signed-off-by: Naveen Moses <naveen.mosess@hcl.com>
Change-Id: Ia791a2b6f52d09dd87da0e50a709fc72ac9d1bd7
diff --git a/src/id_button.cpp b/src/id_button.cpp
index c543556..71e8539 100644
--- a/src/id_button.cpp
+++ b/src/id_button.cpp
@@ -16,7 +16,47 @@
#include "id_button.hpp"
+// add the button iface class to registry
+static ButtonIFRegister<IDButton> buttonRegister;
+
void IDButton::simPress()
{
pressed();
-}
\ No newline at end of file
+}
+
+void IDButton::handleEvent(sd_event_source* es, int fd, uint32_t revents)
+{
+ int n = -1;
+ char buf = '0';
+ n = ::lseek(fd, 0, SEEK_SET);
+
+ if (n < 0)
+ {
+ phosphor::logging::log<phosphor::logging::level::ERR>(
+ (getFormFactorType() + " : lseek error!").c_str());
+ return;
+ }
+
+ n = ::read(fd, &buf, sizeof(buf));
+ if (n < 0)
+ {
+ phosphor::logging::log<phosphor::logging::level::ERR>(
+ (getFormFactorType() + " : read error!").c_str());
+ return;
+ }
+
+ if (buf == '0')
+ {
+ phosphor::logging::log<phosphor::logging::level::DEBUG>(
+ (getFormFactorType() + " : pressed").c_str());
+ // emit pressed signal
+ pressed();
+ }
+ else
+ {
+ phosphor::logging::log<phosphor::logging::level::DEBUG>(
+ (getFormFactorType() + " : released").c_str());
+ // released
+ released();
+ }
+}