mainloop: Make HwmonIO injectable dependency

HwmonIO was make into a interface object implementation.  This patch
transitions mainloop to receive a pointer to this interface to allow for
injection testing.

Signed-off-by: Patrick Venture <venture@google.com>
Change-Id: Iaa470fafccb42c4d7fbabac0dc92f96c8075faf2
diff --git a/mainloop.cpp b/mainloop.cpp
index 469a8d7..a5a818f 100644
--- a/mainloop.cpp
+++ b/mainloop.cpp
@@ -150,7 +150,7 @@
 
     /* Note: The sensor objects all share the same ioAccess object. */
     auto sensorObj =
-        std::make_unique<sensor::Sensor>(sensor.first, &_ioAccess, _devPath);
+        std::make_unique<sensor::Sensor>(sensor.first, _ioAccess, _devPath);
 
     // Get list of return codes for removing sensors on device
     auto devRmRCs = env::getEnv("REMOVERCS");
@@ -181,7 +181,7 @@
     catch (const std::system_error& e)
     {
         auto file =
-            sysfs::make_sysfs_path(_ioAccess.path(), sensor.first.first,
+            sysfs::make_sysfs_path(_ioAccess->path(), sensor.first.first,
                                    sensor.first.second, hwmon::entry::cinput);
 #ifndef REMOVE_ON_FAIL
         // Check sensorAdjusts for sensor removal RCs
@@ -250,11 +250,12 @@
 
 MainLoop::MainLoop(sdbusplus::bus::bus&& bus, const std::string& param,
                    const std::string& path, const std::string& devPath,
-                   const char* prefix, const char* root) :
+                   const char* prefix, const char* root,
+                   const hwmonio::HwmonIOInterface* ioIntf) :
     _bus(std::move(bus)),
     _manager(_bus, root), _pathParam(param), _hwmonRoot(), _instance(),
-    _devPath(devPath), _prefix(prefix), _root(root), _state(), _ioAccess(path),
-    _event(sdeventplus::Event::get_default()),
+    _devPath(devPath), _prefix(prefix), _root(root), _state(),
+    _ioAccess(ioIntf), _event(sdeventplus::Event::get_default()),
     _timer(_event, std::bind(&MainLoop::read, this))
 {
     // Strip off any trailing slashes.
@@ -380,7 +381,7 @@
                 auto it = obj.find(InterfaceType::STATUS);
                 if (it != obj.end())
                 {
-                    auto fault = _ioAccess.read(
+                    auto fault = _ioAccess->read(
                         i.first.first, i.first.second, hwmon::entry::fault,
                         hwmonio::retries, hwmonio::delay);
                     auto statusIface =
@@ -401,8 +402,9 @@
                     // RAII object for GPIO unlock / lock
                     sensor::GpioLock gpioLock(sensor->getGpio());
 
-                    value = _ioAccess.read(i.first.first, i.first.second, input,
-                                           hwmonio::retries, hwmonio::delay);
+                    value =
+                        _ioAccess->read(i.first.first, i.first.second, input,
+                                        hwmonio::retries, hwmonio::delay);
 
                     value = sensor->adjustValue(value);
                 }
@@ -436,7 +438,7 @@
             catch (const std::system_error& e)
             {
                 auto file = sysfs::make_sysfs_path(
-                    _ioAccess.path(), i.first.first, i.first.second,
+                    _ioAccess->path(), i.first.first, i.first.second,
                     hwmon::entry::cinput);
 #ifndef REMOVE_ON_FAIL
                 // Check sensorAdjusts for sensor removal RCs
@@ -526,7 +528,7 @@
 
                 // Sensor object added, erase entry from removal list
                 auto file = sysfs::make_sysfs_path(
-                    _ioAccess.path(), it->first.first, it->first.second,
+                    _ioAccess->path(), it->first.first, it->first.second,
                     hwmon::entry::cinput);
 
                 log<level::INFO>("Added sensor to dbus after successful read",