psu-ng: Create a shortName and use for tracing

Given the full inventory path, find and store off the short part of the
name (powersupply0) for use in various tracing messages.

Signed-off-by: Brandon Wyman <bjwyman@gmail.com>
Change-Id: I59906e9f5eabdae16b4d67dcf8e6d4146f7d0fe8
diff --git a/phosphor-power-supply/power_supply.hpp b/phosphor-power-supply/power_supply.hpp
index 7ef32f4..bc57a83 100644
--- a/phosphor-power-supply/power_supply.hpp
+++ b/phosphor-power-supply/power_supply.hpp
@@ -363,7 +363,7 @@
     }
 
     /**
-     * @brief Returns this power supplies inventory path.
+     * @brief Returns this power supply's inventory path.
      *
      * This can be used for error call outs.
      * Example:
@@ -375,6 +375,14 @@
     }
 
     /**
+     * @brief Returns the short name (last part of inventoryPath).
+     */
+    const std::string& getShortName() const
+    {
+        return shortName;
+    }
+
+    /**
      * @brief Returns the firmware revision version read from the power supply
      */
     const std::string& getFWVersion() const
@@ -643,6 +651,33 @@
     std::string inventoryPath;
 
     /**
+     * @brief Store the short name to avoid string processing.
+     *
+     * The short name will be something like powersupply1, the last part of the
+     * inventoryPath.
+     */
+    std::string shortName;
+
+    /**
+     * @brief Given a full inventory path, returns the last node of the path as
+     * the "short name"
+     */
+    std::string findShortName(const std::string& invPath)
+    {
+        auto const lastSlashPos = invPath.find_last_of('/');
+
+        if ((lastSlashPos == std::string::npos) ||
+            ((lastSlashPos + 1) == invPath.size()))
+        {
+            return invPath;
+        }
+        else
+        {
+            return invPath.substr(lastSlashPos + 1);
+        }
+    }
+
+    /**
      * @brief The libgpiod object for monitoring PSU presence
      */
     std::unique_ptr<GPIOInterfaceBase> presenceGPIO = nullptr;