PEL: Update bmc & platform dump status in SRC section

With every PEL creation, the status of bmc and platform dumps -
Hardware and Hypervisor would be checked and status bits in SRC
section updated accordingly.

Change-Id: I3ec7626611cf330f2ce235a97ee3046c0d32b6ab
Signed-off-by: Sumit Kumar <sumit_kumar@in.ibm.com>
diff --git a/extensions/openpower-pels/data_interface.cpp b/extensions/openpower-pels/data_interface.cpp
index f8b701f..393c2fe 100644
--- a/extensions/openpower-pels/data_interface.cpp
+++ b/extensions/openpower-pels/data_interface.cpp
@@ -22,6 +22,7 @@
 #include <fmt/format.h>
 
 #include <fstream>
+#include <iterator>
 #include <phosphor-logging/log.hpp>
 #include <xyz/openbmc_project/State/Boot/Progress/server.hpp>
 
@@ -80,6 +81,8 @@
     "xyz.openbmc_project.State.Decorator.OperationalStatus";
 constexpr auto logSetting = "xyz.openbmc_project.Logging.Settings";
 constexpr auto association = "xyz.openbmc_project.Association.Definitions";
+constexpr auto dumpEntry = "xyz.openbmc_project.Dump.Entry";
+constexpr auto dumpProgress = "xyz.openbmc_project.Common.Progress";
 } // namespace interface
 
 using namespace sdbusplus::xyz::openbmc_project::State::Boot::server;
@@ -617,5 +620,72 @@
     return ret;
 }
 
+std::vector<bool>
+    DataInterface::checkDumpStatus(const std::vector<std::string>& type) const
+{
+    DBusSubTree subtree;
+    std::vector<bool> result(type.size(), false);
+
+    // Query GetSubTree for the availability of dump interface
+    auto method = _bus.new_method_call(service_name::objectMapper,
+                                       object_path::objectMapper,
+                                       interface::objectMapper, "GetSubTree");
+    method.append(std::string{"/"}, 0,
+                  std::vector<std::string>{interface::dumpEntry});
+    auto reply = _bus.call(method);
+
+    reply.read(subtree);
+
+    if (subtree.empty())
+    {
+        return result;
+    }
+
+    std::vector<bool>::iterator itDumpStatus = result.begin();
+    uint8_t count = 0;
+    for (const auto& [path, serviceInfo] : subtree)
+    {
+        const auto& service = serviceInfo.begin()->first;
+        // Check for dump type on the object path
+        for (const auto& it : type)
+        {
+            if (path.find(it) != std::string::npos)
+            {
+                DBusValue value, progress;
+
+                // If dump type status is already available go for next path
+                if (*itDumpStatus)
+                {
+                    break;
+                }
+
+                // Check for valid dump to be available if following
+                // conditions are met for the dump entry path -
+                // Offloaded == false and Status == Completed
+                getProperty(service, path, interface::dumpEntry, "Offloaded",
+                            value);
+                getProperty(service, path, interface::dumpProgress, "Status",
+                            progress);
+                auto offload = std::get<bool>(value);
+                auto status = std::get<std::string>(progress);
+                if (!offload && (status.find("Completed") != std::string::npos))
+                {
+                    *itDumpStatus = true;
+                    count++;
+                    if (count >= type.size())
+                    {
+                        return result;
+                    }
+                    break;
+                }
+            }
+            itDumpStatus++;
+        }
+        itDumpStatus = result.begin();
+    }
+
+    return result;
+}
+
 } // namespace pels
 } // namespace openpower