summaryrefslogtreecommitdiffstats
path: root/monitor.cpp
diff options
context:
space:
mode:
authorGunnar Mills <gmills@us.ibm.com>2017-07-27 15:22:42 -0500
committerGunnar Mills <gmills@us.ibm.com>2017-07-28 12:34:51 -0500
commit9925857a9ef0e47f105a21186a809a3b094461b3 (patch)
tree481de329c30d097c96e6aab93af86fff0f1d12e6 /monitor.cpp
parent835dfb8877fd2e78281e22b8b08dc29e0e9ef5a5 (diff)
downloadphosphor-gpio-monitor-9925857a9ef0e47f105a21186a809a3b094461b3.tar.gz
phosphor-gpio-monitor-9925857a9ef0e47f105a21186a809a3b094461b3.zip
Refactor GPIO Monitor class
Refactor the GPIO Monitor class to use a common class, Evdev, to inherit from. Evdev does the basic libevdev handling. Change-Id: I427aa9720b0bbbea0284c0babcc03ece92e55f5e Signed-off-by: Gunnar Mills <gmills@us.ibm.com>
Diffstat (limited to 'monitor.cpp')
-rw-r--r--monitor.cpp55
1 files changed, 1 insertions, 54 deletions
diff --git a/monitor.cpp b/monitor.cpp
index 632506b..5bc4742 100644
--- a/monitor.cpp
+++ b/monitor.cpp
@@ -31,59 +31,6 @@ constexpr auto SYSTEMD_INTERFACE = "org.freedesktop.systemd1.Manager";
using namespace phosphor::logging;
-// Populate the file descriptor for passed in device
-int Monitor::openDevice()
-{
- using namespace phosphor::logging;
-
- int fd = open(path.c_str(), O_RDONLY | O_NONBLOCK);
- if (fd < 0)
- {
- log<level::ERR>("Failed to open device",
- entry("PATH=%s", path.c_str()));
- throw std::runtime_error("Failed to open device");
- }
- return fd;
-}
-
-// Attaches the FD to event loop and registers the callback handler
-void Monitor::registerCallback()
-{
- decltype(eventSource.get()) sourcePtr = nullptr;
- auto r = sd_event_add_io(event.get(), &sourcePtr, (fd)(),
- EPOLLIN, callbackHandler, this);
- eventSource.reset(sourcePtr);
-
- if (r < 0)
- {
- log<level::ERR>("Failed to register callback handler",
- entry("ERROR=%s", strerror(-r)));
- throw std::runtime_error("Failed to register callback handler");
- }
-}
-
-// Initializes the event device with the fd
-void Monitor::initEvDev()
-{
- if (device)
- {
- // Init can be done only once per device
- return;
- }
-
- struct libevdev* evdev = nullptr;
- auto rc = libevdev_new_from_fd((fd)(), &evdev);
- if (rc < 0)
- {
- log<level::ERR>("Failed to initialize evdev");
- throw std::runtime_error("Failed to initialize evdev");
- }
-
- // Packing in the unique_ptr
- device.reset(evdev);
- evdev = nullptr;
-}
-
// Callback handler when there is an activity on the FD
int Monitor::processEvents(sd_event_source* es, int fd,
uint32_t revents, void* userData)
@@ -107,7 +54,7 @@ void Monitor::analyzeEvent()
while (rc >= 0)
{
// Wait until no more events are available on the device.
- rc = libevdev_next_event(device.get(),
+ rc = libevdev_next_event(devicePtr.get(),
LIBEVDEV_READ_FLAG_NORMAL, &ev);
if (rc < 0)
{
OpenPOWER on IntegriCloud