psu-ng: Add accessor to get GPIO line name

Update the utilities to give the line name for a GPIO.

Add accessor to power supply class to get the name of the presence GPIO
line.

Signed-off-by: B. J. Wyman <bjwyman@gmail.com>
Change-Id: Ic10fd81c6de024dbcb27088c5935ac9947af9465
diff --git a/phosphor-power-supply/power_supply.hpp b/phosphor-power-supply/power_supply.hpp
index 86eb926..f67d2a1 100644
--- a/phosphor-power-supply/power_supply.hpp
+++ b/phosphor-power-supply/power_supply.hpp
@@ -70,6 +70,18 @@
         return presenceGPIO.get();
     }
 
+    std::string getPresenceGPIOName() const
+    {
+        if (presenceGPIO != nullptr)
+        {
+            return presenceGPIO->getName();
+        }
+        else
+        {
+            return std::string();
+        }
+    }
+
     /**
      * Power supply specific function to analyze for faults/errors.
      *
diff --git a/phosphor-power-supply/test/mock.hpp b/phosphor-power-supply/test/mock.hpp
index 2731692..d494e14 100644
--- a/phosphor-power-supply/test/mock.hpp
+++ b/phosphor-power-supply/test/mock.hpp
@@ -54,6 +54,7 @@
 {
   public:
     MOCK_METHOD(int, read, (), (override));
+    MOCK_METHOD(std::string, getName, (), (const, override));
 };
 
 const UtilBase& getUtils();
diff --git a/phosphor-power-supply/util.cpp b/phosphor-power-supply/util.cpp
index f80bac7..5942ce7 100644
--- a/phosphor-power-supply/util.cpp
+++ b/phosphor-power-supply/util.cpp
@@ -31,6 +31,11 @@
     return std::make_unique<GPIOReader>(namedGpio);
 }
 
+std::string GPIOReader::getName() const
+{
+    return line.name();
+}
+
 int GPIOReader::read()
 {
     using namespace phosphor::logging;
diff --git a/phosphor-power-supply/util.hpp b/phosphor-power-supply/util.hpp
index 2203b92..da04020 100644
--- a/phosphor-power-supply/util.hpp
+++ b/phosphor-power-supply/util.hpp
@@ -121,6 +121,11 @@
      */
     int read() override;
 
+    /**
+     * @brief Returns the name of the GPIO, if not empty.
+     */
+    std::string getName() const override;
+
   private:
     gpiod::line line;
 };
diff --git a/phosphor-power-supply/util_base.hpp b/phosphor-power-supply/util_base.hpp
index 194ddff..7ae362c 100644
--- a/phosphor-power-supply/util_base.hpp
+++ b/phosphor-power-supply/util_base.hpp
@@ -43,6 +43,7 @@
     virtual ~GPIOInterface() = default;
 
     virtual int read() = 0;
+    virtual std::string getName() const = 0;
 };
 
 } // namespace phosphor::power::psu