registries: make registration dynamic

Rather than having to manually hook code for registries, add a small
registration function to the registry header and use this registration
results throughout the registry interactions.

Tested:

Confirmed registries have same behavior.

```
$ curl -s -k https://localhost:18080/redfish/v1/Registries/ | jq '.Members | map(."@odata.id")'
[
  "/redfish/v1/Registries/Base",
  "/redfish/v1/Registries/HeartbeatEvent",
  "/redfish/v1/Registries/OpenBMC",
  "/redfish/v1/Registries/ResourceEvent",
  "/redfish/v1/Registries/TaskEvent",
  "/redfish/v1/Registries/Telemetry"
]
```

```
$ curl -s -k https://localhost:18080/redfish/v1/Registries/TaskEvent/TaskEvent | jq ".Messages | keys"
[
  "TaskAborted",
  "TaskCancelled",
  "TaskCompletedOK",
  "TaskCompletedWarning",
  "TaskPaused",
  "TaskProgressChanged",
  "TaskRemoved",
  "TaskResumed",
  "TaskStarted"
]
```

Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
Change-Id: Iaa355420736a2587d9da4e995208d579443ca9b8
diff --git a/redfish-core/src/registries.cpp b/redfish-core/src/registries.cpp
index 1549dd3..2a426bf 100644
--- a/redfish-core/src/registries.cpp
+++ b/redfish-core/src/registries.cpp
@@ -2,11 +2,17 @@
 // SPDX-FileCopyrightText: Copyright OpenBMC Authors
 #include "registries.hpp"
 
+// We need the registries_selector pulled into some cpp part so that the
+// registration hooks run.
+// NOLINTNEXTLINE(misc-include-cleaner)
 #include "registries_selector.hpp"
 #include "str_utility.hpp"
 
 #include <algorithm>
 #include <cstring>
+#include <functional>
+#include <map>
+#include <optional>
 #include <ranges>
 #include <span>
 #include <string>
@@ -16,6 +22,36 @@
 namespace redfish::registries
 {
 
+auto allRegistries() -> std::map<std::string, RegistryEntry>&
+{
+    static std::map<std::string, RegistryEntry> registries;
+    return registries;
+}
+
+auto getRegistryFromPrefix(const std::string& registryName)
+    -> std::optional<RegistryEntryRef>
+{
+    auto& registries = allRegistries();
+    if (auto it = registries.find(registryName); it != registries.end())
+    {
+        return std::ref(it->second);
+    }
+
+    return std::nullopt;
+}
+
+auto getRegistryMessagesFromPrefix(const std::string& registryName)
+    -> MessageEntries
+{
+    auto registry = getRegistryFromPrefix(registryName);
+    if (!registry)
+    {
+        return {};
+    }
+
+    return registry->get().entries;
+}
+
 const Message* getMessageFromRegistry(const std::string& messageKey,
                                       std::span<const MessageEntry> registry)
 {
@@ -48,9 +84,8 @@
     const std::string& messageKey = fields[3];
 
     // Find the right registry and check it for the MessageKey
-    // Find the right registry and check it for the MessageKey
     return getMessageFromRegistry(messageKey,
-                                  getRegistryFromPrefix(registryName));
+                                  getRegistryMessagesFromPrefix(registryName));
 }
 
 } // namespace redfish::registries