diff options
-rw-r--r-- | monitor.cpp | 4 | ||||
-rw-r--r-- | monitor.hpp | 10 | ||||
-rw-r--r-- | test/utest.cpp | 4 |
3 files changed, 11 insertions, 7 deletions
diff --git a/monitor.cpp b/monitor.cpp index dfd9987..632506b 100644 --- a/monitor.cpp +++ b/monitor.cpp @@ -91,10 +91,6 @@ int Monitor::processEvents(sd_event_source* es, int fd, log<level::INFO>("GPIO line altered"); auto monitor = static_cast<Monitor*>(userData); - // Initialize libevdev for this. Doing it here enables - // gtest to use this infrastructure on arbitrary device - // than /dev/input/ - monitor->initEvDev(); monitor->analyzeEvent(); return 0; } diff --git a/monitor.hpp b/monitor.hpp index 68bf447..bffb1d4 100644 --- a/monitor.hpp +++ b/monitor.hpp @@ -66,13 +66,15 @@ class Monitor * @param[in] event - sd_event handler * @param[in] handler - IO callback handler. Defaults to one in this * class + * @param[in] useEvDev - Whether to use EvDev to retrieve events */ Monitor(const std::string& path, decltype(input_event::code) key, decltype(input_event::value) polarity, const std::string& target, EventPtr& event, - sd_event_io_handler_t handler = Monitor::processEvents) + sd_event_io_handler_t handler = Monitor::processEvents, + bool useEvDev = true) : path(path), key(key), polarity(polarity), @@ -81,6 +83,12 @@ class Monitor callbackHandler(handler), fd(openDevice()) { + if (useEvDev) + { + // If we are asked to use EvDev, do that initialization. + initEvDev(); + } + // And register callback handler when FD has some data registerCallback(); } diff --git a/test/utest.cpp b/test/utest.cpp index 78e1b7e..3728244 100644 --- a/test/utest.cpp +++ b/test/utest.cpp @@ -70,7 +70,7 @@ TEST_F(GpioTest, noEventIn3Seconds) const std::string emptyTarget = ""; Monitor gpio(DEVICE, code, value, emptyTarget, - eventP, callbackHandler); + eventP, callbackHandler, false); // Waiting 3 seconds and check if the completion status is set int count = 0; @@ -99,7 +99,7 @@ TEST_F(GpioTest, pumpDataAndExpectCallBack) const std::string emptyTarget = ""; Monitor gpio(DEVICE, code, value, emptyTarget, - eventP, callbackHandler); + eventP, callbackHandler, false); // Pump the data in the middle int count = 0; |