LogService: Refactor dump entry parsing

Refactored common code for parsing dump entry information from D-Bus
response objects (shared by getDumpEntryCollection() and
getDumpEntryById()) into a new function parseDumpEntryFromDbusObject().
The parsing is similar to what is done by parseCrashdumpParameters().

This refactoring is being done in anticipation of adding additional
D-Bus property parsing for dump entries (without this refactoring,
code duplication will increase).

No noticeable client impact.

Tested:

Get dump entries individually and as a collection.
  Example commands:
  curl -k -H "X-Auth-Token: $token" -X GET http://${bmc}/redfish/v1/Managers/bmc/LogServices/FaultLog/Entries

  curl -k -H "X-Auth-Token: $token" -X GET
  http://${bmc}/redfish/v1/Managers/bmc/LogServices/FaultLog/Entries/1

  curl -k -H "X-Auth-Token: $token" -X GET http://${bmc}/redfish/v1/Managers/bmc/LogServices/Dump/Entries

  curl -k -H "X-Auth-Token: $token" -X GET http://${bmc}/redfish/v1/Managers/bmc/LogServices/Dump/Entries/1

Redfish Service Validator succeeded on the following URI trees:
/redfish/v1/Managers/bmc/LogServices/FaultLog
/redfish/v1/Managers/bmc/LogServices/Dump
/redfish/v1/Systems/system/LogServices/Dump

Signed-off-by: Claire Weinan <cweinan@google.com>
Change-Id: If67fb0c1f35175ae0e2968f8d7a52c13e66b1dc7
diff --git a/redfish-core/lib/log_services.hpp b/redfish-core/lib/log_services.hpp
index a10075a..6f46a7f 100644
--- a/redfish-core/lib/log_services.hpp
+++ b/redfish-core/lib/log_services.hpp
@@ -326,6 +326,69 @@
     return !redfishLogFiles.empty();
 }
 
+inline void parseDumpEntryFromDbusObject(
+    const dbus::utility::ManagedItem& object, std::string& dumpStatus,
+    uint64_t& size, uint64_t& timestamp,
+    const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
+{
+    for (const auto& interfaceMap : object.second)
+    {
+        if (interfaceMap.first == "xyz.openbmc_project.Common.Progress")
+        {
+            for (const auto& propertyMap : interfaceMap.second)
+            {
+                if (propertyMap.first == "Status")
+                {
+                    const auto* status =
+                        std::get_if<std::string>(&propertyMap.second);
+                    if (status == nullptr)
+                    {
+                        messages::internalError(asyncResp->res);
+                        break;
+                    }
+                    dumpStatus = *status;
+                }
+            }
+        }
+        else if (interfaceMap.first == "xyz.openbmc_project.Dump.Entry")
+        {
+            for (const auto& propertyMap : interfaceMap.second)
+            {
+                if (propertyMap.first == "Size")
+                {
+                    const auto* sizePtr =
+                        std::get_if<uint64_t>(&propertyMap.second);
+                    if (sizePtr == nullptr)
+                    {
+                        messages::internalError(asyncResp->res);
+                        break;
+                    }
+                    size = *sizePtr;
+                    break;
+                }
+            }
+        }
+        else if (interfaceMap.first == "xyz.openbmc_project.Time.EpochTime")
+        {
+            for (const auto& propertyMap : interfaceMap.second)
+            {
+                if (propertyMap.first == "Elapsed")
+                {
+                    const uint64_t* usecsTimeStamp =
+                        std::get_if<uint64_t>(&propertyMap.second);
+                    if (usecsTimeStamp == nullptr)
+                    {
+                        messages::internalError(asyncResp->res);
+                        break;
+                    }
+                    timestamp = *usecsTimeStamp;
+                    break;
+                }
+            }
+        }
+    }
+}
+
 static std::string getDumpEntriesPath(const std::string& dumpType)
 {
     std::string entriesPath;
@@ -416,65 +479,8 @@
                 continue;
             }
 
-            for (auto& interfaceMap : object.second)
-            {
-                if (interfaceMap.first == "xyz.openbmc_project.Common.Progress")
-                {
-                    for (const auto& propertyMap : interfaceMap.second)
-                    {
-                        if (propertyMap.first == "Status")
-                        {
-                            const auto* status =
-                                std::get_if<std::string>(&propertyMap.second);
-                            if (status == nullptr)
-                            {
-                                messages::internalError(asyncResp->res);
-                                break;
-                            }
-                            dumpStatus = *status;
-                        }
-                    }
-                }
-                else if (interfaceMap.first == "xyz.openbmc_project.Dump.Entry")
-                {
-
-                    for (auto& propertyMap : interfaceMap.second)
-                    {
-                        if (propertyMap.first == "Size")
-                        {
-                            const auto* sizePtr =
-                                std::get_if<uint64_t>(&propertyMap.second);
-                            if (sizePtr == nullptr)
-                            {
-                                messages::internalError(asyncResp->res);
-                                break;
-                            }
-                            size = *sizePtr;
-                            break;
-                        }
-                    }
-                }
-                else if (interfaceMap.first ==
-                         "xyz.openbmc_project.Time.EpochTime")
-                {
-
-                    for (const auto& propertyMap : interfaceMap.second)
-                    {
-                        if (propertyMap.first == "Elapsed")
-                        {
-                            const uint64_t* usecsTimeStamp =
-                                std::get_if<uint64_t>(&propertyMap.second);
-                            if (usecsTimeStamp == nullptr)
-                            {
-                                messages::internalError(asyncResp->res);
-                                break;
-                            }
-                            timestamp = (*usecsTimeStamp / 1000 / 1000);
-                            break;
-                        }
-                    }
-                }
-            }
+            parseDumpEntryFromDbusObject(object, dumpStatus, size, timestamp,
+                                         asyncResp);
 
             if (dumpStatus !=
                     "xyz.openbmc_project.Common.Progress.OperationStatus.Completed" &&
@@ -553,63 +559,8 @@
             uint64_t size = 0;
             std::string dumpStatus;
 
-            for (const auto& interfaceMap : objectPath.second)
-            {
-                if (interfaceMap.first == "xyz.openbmc_project.Common.Progress")
-                {
-                    for (const auto& propertyMap : interfaceMap.second)
-                    {
-                        if (propertyMap.first == "Status")
-                        {
-                            const std::string* status =
-                                std::get_if<std::string>(&propertyMap.second);
-                            if (status == nullptr)
-                            {
-                                messages::internalError(asyncResp->res);
-                                break;
-                            }
-                            dumpStatus = *status;
-                        }
-                    }
-                }
-                else if (interfaceMap.first == "xyz.openbmc_project.Dump.Entry")
-                {
-                    for (const auto& propertyMap : interfaceMap.second)
-                    {
-                        if (propertyMap.first == "Size")
-                        {
-                            const uint64_t* sizePtr =
-                                std::get_if<uint64_t>(&propertyMap.second);
-                            if (sizePtr == nullptr)
-                            {
-                                messages::internalError(asyncResp->res);
-                                break;
-                            }
-                            size = *sizePtr;
-                            break;
-                        }
-                    }
-                }
-                else if (interfaceMap.first ==
-                         "xyz.openbmc_project.Time.EpochTime")
-                {
-                    for (const auto& propertyMap : interfaceMap.second)
-                    {
-                        if (propertyMap.first == "Elapsed")
-                        {
-                            const uint64_t* usecsTimeStamp =
-                                std::get_if<uint64_t>(&propertyMap.second);
-                            if (usecsTimeStamp == nullptr)
-                            {
-                                messages::internalError(asyncResp->res);
-                                break;
-                            }
-                            timestamp = *usecsTimeStamp / 1000 / 1000;
-                            break;
-                        }
-                    }
-                }
-            }
+            parseDumpEntryFromDbusObject(objectPath, dumpStatus, size,
+                                         timestamp, asyncResp);
 
             if (dumpStatus !=
                     "xyz.openbmc_project.Common.Progress.OperationStatus.Completed" &&