sensor: to enable testing receive hwmonio interface pointer

The sensor objects all share a reference to the mainloop's ioAccess
object.  To enable testing, the sensor object needs to expect the base
pointer to this object.

Change-Id: I1d7f2841528776c8d4f1166e20874ddeb4b8554a
Signed-off-by: Patrick Venture <venture@google.com>
diff --git a/mainloop.cpp b/mainloop.cpp
index 29bd378..b6d44b7 100644
--- a/mainloop.cpp
+++ b/mainloop.cpp
@@ -148,8 +148,9 @@
         return {};
     }
 
+    /* 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");
diff --git a/sensor.cpp b/sensor.cpp
index 5c97e0c..2a2148c 100644
--- a/sensor.cpp
+++ b/sensor.cpp
@@ -36,7 +36,8 @@
 
 // todo: this can be simplified once we move to the double interface
 Sensor::Sensor(const SensorSet::key_type& sensor,
-               const hwmonio::HwmonIO& ioAccess, const std::string& devPath) :
+               const hwmonio::HwmonIOInterface* ioAccess,
+               const std::string& devPath) :
     sensor(sensor),
     ioAccess(ioAccess), devPath(devPath)
 {
@@ -148,9 +149,9 @@
 
         // Retry for up to a second if device is busy
         // or has a transient error.
-        val = ioAccess.read(sensor.first, sensor.second, hwmon::entry::cinput,
-                            std::get<size_t>(retryIO),
-                            std::get<std::chrono::milliseconds>(retryIO));
+        val = ioAccess->read(sensor.first, sensor.second, hwmon::entry::cinput,
+                             std::get<size_t>(retryIO),
+                             std::get<std::chrono::milliseconds>(retryIO));
 
         lockGpio();
         val = adjustValue(val);
@@ -199,14 +200,14 @@
     std::string entry = hwmon::entry::fault;
 
     auto sysfsFullPath =
-        sysfs::make_sysfs_path(ioAccess.path(), faultName, faultID, entry);
+        sysfs::make_sysfs_path(ioAccess->path(), faultName, faultID, entry);
     if (fs::exists(sysfsFullPath))
     {
         bool functional = true;
         try
         {
-            uint32_t fault = ioAccess.read(faultName, faultID, entry,
-                                           hwmonio::retries, hwmonio::delay);
+            uint32_t fault = ioAccess->read(faultName, faultID, entry,
+                                            hwmonio::retries, hwmonio::delay);
             if (fault != 0)
             {
                 functional = false;
diff --git a/sensor.hpp b/sensor.hpp
index 37cf035..3bcfc82 100644
--- a/sensor.hpp
+++ b/sensor.hpp
@@ -6,6 +6,7 @@
 
 #include <chrono>
 #include <gpioplus/handle.hpp>
+#include <memory>
 #include <unordered_set>
 
 namespace sensor
@@ -42,7 +43,7 @@
      * @param[in] devPath - Device sysfs path
      */
     explicit Sensor(const SensorSet::key_type& sensor,
-                    const hwmonio::HwmonIO& ioAccess,
+                    const hwmonio::HwmonIOInterface* ioAccess,
                     const std::string& devPath);
 
     /**
@@ -128,7 +129,7 @@
     SensorSet::key_type sensor;
 
     /** @brief Hwmon sysfs access. */
-    const hwmonio::HwmonIO& ioAccess;
+    const hwmonio::HwmonIOInterface* ioAccess;
 
     /** @brief Physical device sysfs path. */
     const std::string& devPath;