regulators: Add close method to Device class

Add a close method to the Device class.  This will be used to close all
devices in the system when monitoring is disabled.  Monitoring is
disabled when the system is being powered off.

Signed-off-by: Shawn McCarney <shawnmm@us.ibm.com>
Change-Id: I0712ad698ebbcac5d7b17a822443b94dda230429
diff --git a/phosphor-regulators/src/device.cpp b/phosphor-regulators/src/device.cpp
index dd662c9..b1a136b 100644
--- a/phosphor-regulators/src/device.cpp
+++ b/phosphor-regulators/src/device.cpp
@@ -17,8 +17,12 @@
 #include "device.hpp"
 
 #include "chassis.hpp"
+#include "exception_utils.hpp"
+#include "journal.hpp"
 #include "system.hpp"
 
+#include <exception>
+
 namespace phosphor::power::regulators
 {
 
@@ -34,6 +38,26 @@
     }
 }
 
+void Device::close()
+{
+    try
+    {
+        // Close I2C interface if it is open
+        if (i2cInterface->isOpen())
+        {
+            i2cInterface->close();
+        }
+    }
+    catch (const std::exception& e)
+    {
+        // Log error messages in journal
+        exception_utils::log(e);
+        journal::logErr("Unable to close device " + id);
+
+        // TODO: Create error log entry
+    }
+}
+
 void Device::configure(System& system, Chassis& chassis)
 {
     // If configuration changes are defined for this device, apply them