Use hwmonio for attribute IO

Moves disparate error handling scenarios from the method doing the
IO to the call point.

Resolves openbmc/openbmc#2166

Change-Id: I3b6d2e175433dd8b2946ae60381901f2d7ca1798
Signed-off-by: Brad Bishop <bradleyb@fuzziesquirrel.com>
diff --git a/fan_speed.cpp b/fan_speed.cpp
index 459b9d0..5e4c9fc 100644
--- a/fan_speed.cpp
+++ b/fan_speed.cpp
@@ -2,6 +2,10 @@
 #include "hwmon.hpp"
 #include "sysfs.hpp"
 #include <experimental/filesystem>
+#include <phosphor-logging/elog-errors.hpp>
+#include <xyz/openbmc_project/Control/Device/error.hpp>
+
+using namespace phosphor::logging;
 
 namespace hwmon
 {
@@ -13,12 +17,25 @@
     if (curValue != value)
     {
         //Write target out to sysfs
-        curValue = sysfs::writeSysfsWithCallout(value,
-                                                sysfsRoot,
-                                                instance,
-                                                type,
-                                                id,
-                                                entry::target);
+        try
+        {
+            ioAccess.write(
+                    value,
+                    type,
+                    id,
+                    entry::target);
+        }
+        catch (const std::system_error& e)
+        {
+            using namespace sdbusplus::xyz::openbmc_project::Control::
+                Device::Error;
+            report<WriteFailure>(
+                    xyz::openbmc_project::Control::Device::
+                        WriteFailure::CALLOUT_ERRNO(e.code().value()),
+                    xyz::openbmc_project::Control::Device::
+                        WriteFailure::CALLOUT_DEVICE_PATH(devPath.c_str()));
+            exit(EXIT_FAILURE);
+        }
     }
 
     return FanSpeedObject::target(value);
@@ -29,8 +46,7 @@
 {
     namespace fs = std::experimental::filesystem;
 
-    auto path = sysfsRoot + "/" + instance;
-    auto fullPath = sysfs::make_sysfs_path(path,
+    auto fullPath = sysfs::make_sysfs_path(ioAccess.path(),
                                            type::pwm,
                                            id,
                                            entry::enable);
@@ -38,12 +54,25 @@
     if (fs::exists(fullPath))
     {
         //This class always uses RPM mode
-        sysfs::writeSysfsWithCallout(enable::rpmMode,
-                                     sysfsRoot,
-                                     instance,
-                                     type::pwm,
-                                     id,
-                                     entry::enable);
+        try
+        {
+            ioAccess.write(
+                    enable::rpmMode,
+                    type::pwm,
+                    id,
+                    entry::enable);
+        }
+        catch (const std::system_error& e)
+        {
+            using namespace sdbusplus::xyz::openbmc_project::Control::
+                Device::Error;
+            phosphor::logging::report<WriteFailure>(
+                    xyz::openbmc_project::Control::Device::
+                        WriteFailure::CALLOUT_ERRNO(e.code().value()),
+                    xyz::openbmc_project::Control::Device::
+                        WriteFailure::CALLOUT_DEVICE_PATH(devPath.c_str()));
+            exit(EXIT_FAILURE);
+        }
     }
 }