Add function to get PMBus device name

This will be used in the future to find a path
to certain sysfs files.

Change-Id: Ia919b2f954fddf7b97bd1c5025f7c54af942b318
Signed-off-by: Matt Spinler <spinler@us.ibm.com>
diff --git a/pmbus.cpp b/pmbus.cpp
index 47560a0..b68f6fb 100644
--- a/pmbus.cpp
+++ b/pmbus.cpp
@@ -68,6 +68,29 @@
     }
 }
 
+std::string PMBus::getDeviceName()
+{
+    std::string name;
+    std::ifstream file;
+    auto path = basePath / "name";
+
+    file.exceptions(std::ifstream::failbit |
+                    std::ifstream::badbit |
+                    std::ifstream::eofbit);
+    try
+    {
+        file.open(path);
+        file >> name;
+    }
+    catch (std::exception& e)
+    {
+        log<level::ERR>("Unable to read PMBus device name",
+                        entry("PATH=%s", path.c_str()));
+    }
+
+    return name;
+}
+
 bool PMBus::readBitInPage(const std::string& name,
                           size_t page,
                           Type type)
diff --git a/pmbus.hpp b/pmbus.hpp
index 187f383..9ab57c0 100644
--- a/pmbus.hpp
+++ b/pmbus.hpp
@@ -253,6 +253,15 @@
     private:
 
         /**
+         * Returns the device name
+         *
+         * This is found in the 'name' file in basePath.
+         *
+         * @return string - the device name
+         */
+        std::string getDeviceName();
+
+        /**
          * The sysfs device path
          */
         fs::path basePath;