regs: Get JSON configuration data filename from dbus

Retrieve the JSON configuration data filename from the service on dbus
hosting the predefined path, interface and system identifier property.
The system identifier property's value is used as the direct JSON
configuration data filename with the `.json` extension added.

Tested:
    A string representing the filename is retrieved from dbus

Signed-off-by: Matthew Barth <msbarth@us.ibm.com>
Change-Id: Ib9a5227439045cd027125e9dd3ead377be19acba
diff --git a/phosphor-regulators/src/manager.cpp b/phosphor-regulators/src/manager.cpp
index 15071d5..8b8134c 100644
--- a/phosphor-regulators/src/manager.cpp
+++ b/phosphor-regulators/src/manager.cpp
@@ -16,6 +16,8 @@
 
 #include "manager.hpp"
 
+#include "utility.hpp"
+
 #include <sdbusplus/bus.hpp>
 
 #include <chrono>
@@ -28,12 +30,18 @@
 {
 
 Manager::Manager(sdbusplus::bus::bus& bus, const sdeventplus::Event& event) :
-    ManagerObject(bus, objPath, true), bus(bus), eventLoop(event)
+    ManagerObject(bus, objPath, true), bus(bus), eventLoop(event), fileName("")
 {
-    // TODO get property (IM keyword)
-    // call parse json function
-    // TODO subscribe to interfacesadded (IM keyword)
-    // callback would call parse json function
+    // Attempt to get the filename property from dbus
+    setFileName(getFileNameDbus());
+
+    // TODO Subscribe to interfacesAdded signal for filename property
+    // Callback should set fileName and call parse json function
+
+    if (!fileName.empty())
+    {
+        // TODO Load & parse JSON configuration data file
+    }
 
     // Obtain dbus service name
     bus.request_name(busName);
@@ -74,6 +82,30 @@
     // TODO Reload and process the configuration data
 }
 
+const std::string Manager::getFileNameDbus()
+{
+    std::string fileName = "";
+    using namespace phosphor::power::util;
+
+    try
+    {
+        // Do not log an error when service or property are not found
+        auto service = getService(sysDbusPath, sysDbusIntf, bus, false);
+        if (!service.empty())
+        {
+            getProperty(sysDbusIntf, sysDbusProp, sysDbusPath, service, bus,
+                        fileName);
+        }
+    }
+    catch (const sdbusplus::exception::SdBusError&)
+    {
+        // File name property not available on dbus
+        fileName = "";
+    }
+
+    return fileName;
+}
+
 } // namespace regulators
 } // namespace power
 } // namespace phosphor
diff --git a/phosphor-regulators/src/manager.hpp b/phosphor-regulators/src/manager.hpp
index ab51a1d..eb0cef8 100644
--- a/phosphor-regulators/src/manager.hpp
+++ b/phosphor-regulators/src/manager.hpp
@@ -7,6 +7,8 @@
 #include <sdeventplus/source/signal.hpp>
 #include <sdeventplus/utility/timer.hpp>
 
+#include <algorithm>
+
 namespace phosphor::power::regulators
 {
 
@@ -83,6 +85,34 @@
      * List of event timers
      */
     std::vector<Timer> timers;
+
+    /**
+     * JSON configuration data filename
+     */
+    std::string fileName;
+
+    /**
+     * @brief Set the JSON configuration data filename
+     *
+     * @param[in] fName = filename without `.json` extension
+     */
+    inline void setFileName(const std::string& fName)
+    {
+        fileName = fName;
+        if (!fileName.empty())
+        {
+            // Replace all spaces with underscores
+            std::replace(fileName.begin(), fileName.end(), ' ', '_');
+            fileName.append(".json");
+        }
+    };
+
+    /**
+     * @brief Get the JSON configuration data filename from dbus
+     *
+     * @return - JSON configuration data filename
+     */
+    const std::string getFileNameDbus();
 };
 
 } // namespace phosphor::power::regulators
diff --git a/phosphor-regulators/src/meson.build b/phosphor-regulators/src/meson.build
index 9d82033..ef4bec8 100644
--- a/phosphor-regulators/src/meson.build
+++ b/phosphor-regulators/src/meson.build
@@ -1,5 +1,6 @@
 phosphor_regulators_include_directories = include_directories(
     '.',
+    '../..',
     'actions'
 )
 
@@ -46,7 +47,10 @@
         sdeventplus,
         stdplus
     ],
-    link_with: phosphor_regulators_library,
+    link_with: [
+        phosphor_regulators_library,
+        libpower
+    ],
     implicit_include_directories: false,
     include_directories: phosphor_regulators_include_directories,
     install: true