Refactor MDRV2 class to allow more than one

Refactored the main MDRV2 class to allow more than one object of this
class to exist at the same time. All hardcoded paths have been made
parameters to the constructor, so that they can be varied at runtime as
needed, to avoid overlap.

Also did some necessary internal cleanups to facilitate this.

Tested: Created multiple copies of the MDRV2 object at the same time,
it worked, all appeared on D-Bus, under distinct object paths and
inventory paths. Destructed the MDRV2 object, it disappeared from
D-Bus, constructed it again, it came back.

https://gist.github.com/Krellan/6930bc2ed1ac16b93afcc3a12c02e545

Change-Id: Icd1ebf50086b526cf0cff149eb8ddc59da78f0a9
Signed-off-by: Josh Lehan <krellan@google.com>
diff --git a/src/smbios-ipmi-blobs/handler.cpp b/src/smbios-ipmi-blobs/handler.cpp
index 3763762..fb8111a 100644
--- a/src/smbios-ipmi-blobs/handler.cpp
+++ b/src/smbios-ipmi-blobs/handler.cpp
@@ -15,6 +15,7 @@
 #include <algorithm>
 #include <cstdint>
 #include <ctime>
+#include <filesystem>
 #include <fstream>
 #include <memory>
 #include <string>
@@ -34,7 +35,7 @@
     bool status = false;
     sdbusplus::bus_t bus = sdbusplus::bus_t(ipmid_get_sd_bus_connection());
     sdbusplus::message_t method =
-        bus.new_method_call(mdrV2Service, phosphor::smbios::mdrV2Path,
+        bus.new_method_call(mdrV2Service, phosphor::smbios::defaultObjectPath,
                             mdrV2Interface, "AgentSynchronizeData");
 
     try
@@ -48,7 +49,8 @@
             "Error Sync data with service",
             phosphor::logging::entry("ERROR=%s", e.what()),
             phosphor::logging::entry("SERVICE=%s", mdrV2Service),
-            phosphor::logging::entry("PATH=%s", phosphor::smbios::mdrV2Path));
+            phosphor::logging::entry("PATH=%s",
+                                     phosphor::smbios::defaultObjectPath));
         return false;
     }
 
@@ -191,24 +193,27 @@
     /* Clear the commit_error bit. */
     blobPtr->state &= ~blobs::StateFlags::commit_error;
 
+    std::string defaultDir =
+        std::filesystem::path(mdrDefaultFile).parent_path();
+
     MDRSMBIOSHeader mdrHdr;
     mdrHdr.dirVer = mdrDirVersion;
     mdrHdr.mdrType = mdrTypeII;
     mdrHdr.timestamp = std::time(nullptr);
     mdrHdr.dataSize = blobPtr->buffer.size();
-    if (access(smbiosPath, F_OK) == -1)
+    if (access(defaultDir.c_str(), F_OK) == -1)
     {
-        int flag = mkdir(smbiosPath, S_IRWXU);
+        int flag = mkdir(defaultDir.c_str(), S_IRWXU);
         if (flag != 0)
         {
             phosphor::logging::log<phosphor::logging::level::ERR>(
-                "create folder failed for writting smbios file");
+                "create folder failed for writing smbios file");
             blobPtr->state |= blobs::StateFlags::commit_error;
             return false;
         }
     }
 
-    std::ofstream smbiosFile(mdrType2File,
+    std::ofstream smbiosFile(mdrDefaultFile,
                              std::ios_base::binary | std::ios_base::trunc);
     if (!smbiosFile.good())
     {