event logs: introduce struct DbusEventLogEntry

This creates a partial representation of dbus interface
xyz.openbmc_project.Logging.Entry as a struct.

There is also a function to extract it from dbus.

Which helps to refactor function fillEventLogLogEntryFromPropertyMap
to be smaller.

Tested: not tested, simple refactoring. All the data types remain the
same as before.

Change-Id: Ib32cac967bde487b137ceaf845dfb682e605a175
Signed-off-by: Alexander Hansen <alexander.hansen@9elements.com>
diff --git a/redfish-core/include/utils/dbus_event_log_entry.hpp b/redfish-core/include/utils/dbus_event_log_entry.hpp
new file mode 100644
index 0000000..f5eb5f6
--- /dev/null
+++ b/redfish-core/include/utils/dbus_event_log_entry.hpp
@@ -0,0 +1,52 @@
+#pragma once
+
+#include "dbus_utility.hpp"
+#include "utils/dbus_utils.hpp"
+
+#include <optional>
+#include <string>
+
+namespace redfish
+{
+struct DbusEventLogEntry
+{
+    // represents a subset of an instance of dbus interface
+    // xyz.openbmc_project.Logging.Entry
+
+    uint32_t Id = 0;
+    std::string Message;
+    const std::string* Path = nullptr;
+    const std::string* Resolution = nullptr;
+    bool Resolved = false;
+    std::string ServiceProviderNotify;
+    std::string Severity;
+    uint64_t Timestamp = 0;
+    uint64_t UpdateTimestamp = 0;
+};
+
+inline std::optional<DbusEventLogEntry> fillDbusEventLogEntryFromPropertyMap(
+    const dbus::utility::DBusPropertiesMap& resp)
+{
+    DbusEventLogEntry entry;
+
+    // clang-format off
+    bool success = sdbusplus::unpackPropertiesNoThrow(
+        dbus_utils::UnpackErrorPrinter(), resp,
+        "Id", entry.Id,
+        "Message", entry.Message,
+        "Path", entry.Path,
+        "Resolution", entry.Resolution,
+        "Resolved", entry.Resolved,
+        "ServiceProviderNotify", entry.ServiceProviderNotify,
+        "Severity", entry.Severity,
+        "Timestamp", entry.Timestamp,
+        "UpdateTimestamp", entry.UpdateTimestamp
+    );
+    // clang-format on
+    if (!success)
+    {
+        return std::nullopt;
+    }
+    return entry;
+}
+} // namespace redfish
diff --git a/redfish-core/lib/log_services.hpp b/redfish-core/lib/log_services.hpp
index c8b01ea..639a314 100644
--- a/redfish-core/lib/log_services.hpp
+++ b/redfish-core/lib/log_services.hpp
@@ -30,6 +30,7 @@
 #include "registries/privilege_registry.hpp"
 #include "task.hpp"
 #include "task_messages.hpp"
+#include "utils/dbus_event_log_entry.hpp"
 #include "utils/dbus_utils.hpp"
 #include "utils/json_utils.hpp"
 #include "utils/time_utils.hpp"
@@ -1418,64 +1419,46 @@
     const dbus::utility::DBusPropertiesMap& resp,
     nlohmann::json& objectToFillOut)
 {
-    uint32_t id = 0;
-    uint64_t timestamp = 0;
-    uint64_t updateTimestamp = 0;
-    std::string severity;
-    std::string message;
-    const std::string* filePath = nullptr;
-    const std::string* resolution = nullptr;
-    bool resolved = false;
-    std::string notify;
-    // clang-format off
-    bool success = sdbusplus::unpackPropertiesNoThrow(
-        dbus_utils::UnpackErrorPrinter(), resp,
-        "Id", id,
-        "Message", message,
-        "Path", filePath,
-        "Resolution", resolution,
-        "Resolved", resolved,
-        "ServiceProviderNotify", notify,
-        "Severity", severity,
-        "Timestamp", timestamp,
-        "UpdateTimestamp", updateTimestamp
-    );
-    // clang-format on
+    std::optional<DbusEventLogEntry> optEntry =
+        fillDbusEventLogEntryFromPropertyMap(resp);
 
-    if (!success)
+    if (!optEntry.has_value())
     {
         messages::internalError(asyncResp->res);
         return;
     }
+    DbusEventLogEntry entry = optEntry.value();
 
     objectToFillOut["@odata.type"] = "#LogEntry.v1_9_0.LogEntry";
     objectToFillOut["@odata.id"] = boost::urls::format(
         "/redfish/v1/Systems/{}/LogServices/EventLog/Entries/{}",
-        BMCWEB_REDFISH_SYSTEM_URI_NAME, std::to_string(id));
+        BMCWEB_REDFISH_SYSTEM_URI_NAME, std::to_string(entry.Id));
     objectToFillOut["Name"] = "System Event Log Entry";
-    objectToFillOut["Id"] = std::to_string(id);
-    objectToFillOut["Message"] = message;
-    objectToFillOut["Resolved"] = resolved;
-    std::optional<bool> notifyAction = getProviderNotifyAction(notify);
+    objectToFillOut["Id"] = std::to_string(entry.Id);
+    objectToFillOut["Message"] = entry.Message;
+    objectToFillOut["Resolved"] = entry.Resolved;
+    std::optional<bool> notifyAction =
+        getProviderNotifyAction(entry.ServiceProviderNotify);
     if (notifyAction)
     {
         objectToFillOut["ServiceProviderNotified"] = *notifyAction;
     }
-    if ((resolution != nullptr) && !resolution->empty())
+    if ((entry.Resolution != nullptr) && !entry.Resolution->empty())
     {
-        objectToFillOut["Resolution"] = *resolution;
+        objectToFillOut["Resolution"] = *entry.Resolution;
     }
     objectToFillOut["EntryType"] = "Event";
-    objectToFillOut["Severity"] = translateSeverityDbusToRedfish(severity);
+    objectToFillOut["Severity"] =
+        translateSeverityDbusToRedfish(entry.Severity);
     objectToFillOut["Created"] =
-        redfish::time_utils::getDateTimeUintMs(timestamp);
+        redfish::time_utils::getDateTimeUintMs(entry.Timestamp);
     objectToFillOut["Modified"] =
-        redfish::time_utils::getDateTimeUintMs(updateTimestamp);
-    if (filePath != nullptr)
+        redfish::time_utils::getDateTimeUintMs(entry.UpdateTimestamp);
+    if (entry.Path != nullptr)
     {
         objectToFillOut["AdditionalDataURI"] = boost::urls::format(
             "/redfish/v1/Systems/{}/LogServices/EventLog/Entries/{}/attachment",
-            BMCWEB_REDFISH_SYSTEM_URI_NAME, std::to_string(id));
+            BMCWEB_REDFISH_SYSTEM_URI_NAME, std::to_string(entry.Id));
     }
 }