Fix incorrect initialization of evdev

Fixes openbmc/openbmc#1799

Change-Id: I81662ede88d1a05db48686ec57aab969c8dea27a
Signed-off-by: Vishwanatha Subbanna <vishwa@linux.vnet.ibm.com>
diff --git a/monitor.cpp b/monitor.cpp
index dfd9987..632506b 100644
--- a/monitor.cpp
+++ b/monitor.cpp
@@ -91,10 +91,6 @@
     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 @@
          *  @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 @@
               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 @@
 
     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 @@
 
     const std::string emptyTarget = "";
     Monitor gpio(DEVICE, code, value, emptyTarget,
-                 eventP, callbackHandler);
+                 eventP, callbackHandler, false);
 
     // Pump the data in the middle
     int count = 0;