Dynamic DBus EventLog handlers

In order to reuse handlers for DBus EventLog under Managers,
add an additional argument that specifies the redfish resource.

Tested: Code compiles. Redfish validation succeeds.
Additionally the curl output with and without the changes has been
diffed. No differences observed.

Change-Id: I13ec2f6e54f078b5b1064fb62c5561daa50f881a
Signed-off-by: Oliver Brewka <oliver.brewka@9elements.com>
diff --git a/redfish-core/include/utils/eventlog_utils.hpp b/redfish-core/include/utils/eventlog_utils.hpp
index 38bdb6a..1cbcc81 100644
--- a/redfish-core/include/utils/eventlog_utils.hpp
+++ b/redfish-core/include/utils/eventlog_utils.hpp
@@ -38,6 +38,7 @@
 #include <optional>
 #include <sstream>
 #include <string>
+#include <string_view>
 #include <utility>
 
 namespace redfish
@@ -556,13 +557,16 @@
 }
 
 inline void fillEventLogLogEntryFromDbusLogEntry(
-    const DbusEventLogEntry& entry, nlohmann::json& objectToFillOut)
+    const DbusEventLogEntry& entry, nlohmann::json& objectToFillOut,
+    const std::string& parentStr, const std::string_view childId,
+    const std::string& logEntryDescriptor)
 {
     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(entry.Id));
-    objectToFillOut["Name"] = "System Event Log Entry";
+    objectToFillOut["@odata.id"] =
+        boost::urls::format("/redfish/v1/{}/{}/LogServices/EventLog/Entries/{}",
+                            parentStr, childId, std::to_string(entry.Id));
+    objectToFillOut["Name"] =
+        std::format("{} Event Log Entry", logEntryDescriptor);
     objectToFillOut["Id"] = std::to_string(entry.Id);
     objectToFillOut["Message"] = entry.Message;
     objectToFillOut["Resolved"] = entry.Resolved;
@@ -586,14 +590,15 @@
     if (entry.Path != nullptr)
     {
         objectToFillOut["AdditionalDataURI"] = boost::urls::format(
-            "/redfish/v1/Systems/{}/LogServices/EventLog/Entries/{}/attachment",
-            BMCWEB_REDFISH_SYSTEM_URI_NAME, std::to_string(entry.Id));
+            "/redfish/v1/{}/{}/LogServices/EventLog/Entries/{}/attachment",
+            parentStr, childId, std::to_string(entry.Id));
     }
 }
 
 inline void afterLogEntriesGetManagedObjects(
     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
-    const boost::system::error_code& ec,
+    const std::string& parentStr, const std::string_view childId,
+    const std::string& logEntryDescriptor, const boost::system::error_code& ec,
     const dbus::utility::ManagedObjectType& resp)
 {
     if (ec)
@@ -633,8 +638,9 @@
             messages::internalError(asyncResp->res);
             return;
         }
-        fillEventLogLogEntryFromDbusLogEntry(*optEntry,
-                                             entriesArray.emplace_back());
+        fillEventLogLogEntryFromDbusLogEntry(
+            *optEntry, entriesArray.emplace_back(), parentStr, childId,
+            logEntryDescriptor);
     }
 
     redfish::json_util::sortJsonArrayByKey(entriesArray, "Id");
@@ -643,33 +649,48 @@
 }
 
 inline void dBusEventLogEntryCollection(
-    const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
+    const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
+    LogServiceParent parent)
 {
+    const std::string_view childId = getChildIdFromParent(parent);
+    const std::string parentStr = logServiceParentToString(parent);
+    const std::string logEntryDescriptor = getLogEntryDescriptor(parent);
+
+    if (parentStr.empty() || childId.empty() || logEntryDescriptor.empty())
+    {
+        messages::internalError(asyncResp->res);
+        return;
+    }
+
     // Collections don't include the static data added by SubRoute
     // because it has a duplicate entry for members
     asyncResp->res.jsonValue["@odata.type"] =
         "#LogEntryCollection.LogEntryCollection";
-    asyncResp->res.jsonValue["@odata.id"] =
-        std::format("/redfish/v1/Systems/{}/LogServices/EventLog/Entries",
-                    BMCWEB_REDFISH_SYSTEM_URI_NAME);
-    asyncResp->res.jsonValue["Name"] = "System Event Log Entries";
+    asyncResp->res.jsonValue["@odata.id"] = std::format(
+        "/redfish/v1/{}/{}/LogServices/EventLog/Entries", parentStr, childId);
+    asyncResp->res.jsonValue["Name"] =
+        std::format("{} Event Log Entries", logEntryDescriptor);
     asyncResp->res.jsonValue["Description"] =
-        "Collection of System Event Log Entries";
+        std::format("Collection of {} Event Log Entries", logEntryDescriptor);
 
     // DBus implementation of EventLog/Entries
     // Make call to Logging Service to find all log entry objects
     sdbusplus::message::object_path path("/xyz/openbmc_project/logging");
     dbus::utility::getManagedObjects(
         "xyz.openbmc_project.Logging", path,
-        [asyncResp](const boost::system::error_code& ec,
-                    const dbus::utility::ManagedObjectType& resp) {
-            afterLogEntriesGetManagedObjects(asyncResp, ec, resp);
+        [asyncResp, parentStr, childId,
+         logEntryDescriptor](const boost::system::error_code& ec,
+                             const dbus::utility::ManagedObjectType& resp) {
+            afterLogEntriesGetManagedObjects(asyncResp, parentStr, childId,
+                                             logEntryDescriptor, ec, resp);
         });
 }
 
 inline void afterDBusEventLogEntryGet(
     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
-    const std::string& entryID, const boost::system::error_code& ec,
+    const std::string& parentStr, const std::string_view childId,
+    const std::string& logEntryDescriptor, const std::string& entryID,
+    const boost::system::error_code& ec,
     const dbus::utility::DBusPropertiesMap& resp)
 {
     if (ec.value() == EBADR)
@@ -693,12 +714,25 @@
         return;
     }
 
-    fillEventLogLogEntryFromDbusLogEntry(*optEntry, asyncResp->res.jsonValue);
+    fillEventLogLogEntryFromDbusLogEntry(
+        *optEntry, asyncResp->res.jsonValue, parentStr, childId,
+        logEntryDescriptor);
 }
 
 inline void dBusEventLogEntryGet(
-    const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, std::string entryID)
+    const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
+    LogServiceParent parent, std::string entryID)
 {
+    const std::string parentStr = logServiceParentToString(parent);
+    const std::string_view childId = getChildIdFromParent(parent);
+    const std::string logEntryDescriptor = getLogEntryDescriptor(parent);
+
+    if (parentStr.empty() || childId.empty() || logEntryDescriptor.empty())
+    {
+        messages::internalError(asyncResp->res);
+        return;
+    }
+
     dbus::utility::escapePathForDbus(entryID);
 
     // DBus implementation of EventLog/Entries
@@ -706,7 +740,8 @@
     dbus::utility::getAllProperties(
         "xyz.openbmc_project.Logging",
         "/xyz/openbmc_project/logging/entry/" + entryID, "",
-        std::bind_front(afterDBusEventLogEntryGet, asyncResp, entryID));
+        std::bind_front(afterDBusEventLogEntryGet, asyncResp, parentStr,
+                        childId, logEntryDescriptor, entryID));
 }
 
 inline void dBusEventLogEntryPatch(
diff --git a/redfish-core/lib/systems_logservices_dbus_eventlog.hpp b/redfish-core/lib/systems_logservices_dbus_eventlog.hpp
index e087a57..e90ee09 100644
--- a/redfish-core/lib/systems_logservices_dbus_eventlog.hpp
+++ b/redfish-core/lib/systems_logservices_dbus_eventlog.hpp
@@ -50,8 +50,8 @@
                                    systemName);
         return;
     }
-
-    eventlog_utils::dBusEventLogEntryCollection(asyncResp);
+    eventlog_utils::dBusEventLogEntryCollection(
+        asyncResp, eventlog_utils::LogServiceParent::Systems);
 }
 
 inline void handleSystemsDBusEventLogEntryGet(
@@ -77,7 +77,8 @@
         return;
     }
 
-    eventlog_utils::dBusEventLogEntryGet(asyncResp, entryId);
+    eventlog_utils::dBusEventLogEntryGet(
+        asyncResp, eventlog_utils::LogServiceParent::Systems, entryId);
 }
 
 inline void handleSystemsDBusEventLogEntryPatch(