Refactor: move registries functions to their file
There were same functions from namespace 'registries' in
event_service_manager.hpp. Move them to registries.cpp/hpp.
Tested:
- Using Redfish Event Listener, test subscriptions and eventing.
- Redfish Service Validator passes
Change-Id: Id0912f6581637bb4117e67b138122c355256b561
Signed-off-by: Alexander Hansen <alexander.hansen@9elements.com>
Signed-off-by: Ed Tanous <ed@tanous.net>
diff --git a/redfish-core/include/event_service_manager.hpp b/redfish-core/include/event_service_manager.hpp
index 40854d5..a50c0d7 100644
--- a/redfish-core/include/event_service_manager.hpp
+++ b/redfish-core/include/event_service_manager.hpp
@@ -22,9 +22,6 @@
#include "metric_report.hpp"
#include "ossl_random.hpp"
#include "persistent_data.hpp"
-#include "registries.hpp"
-#include "registries_selector.hpp"
-#include "str_utility.hpp"
#include "subscription.hpp"
#include "utils/time_utils.hpp"
@@ -43,7 +40,6 @@
#include <format>
#include <fstream>
#include <memory>
-#include <span>
#include <string>
#include <string_view>
#include <utility>
@@ -70,45 +66,6 @@
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
static int fileWatchDesc = -1;
-namespace registries
-{
-inline const Message*
- getMsgFromRegistry(const std::string& messageKey,
- const std::span<const MessageEntry>& registry)
-{
- std::span<const MessageEntry>::iterator messageIt = std::ranges::find_if(
- registry, [&messageKey](const MessageEntry& messageEntry) {
- return messageKey == messageEntry.first;
- });
- if (messageIt != registry.end())
- {
- return &messageIt->second;
- }
-
- return nullptr;
-}
-
-inline const Message* formatMessage(std::string_view messageID)
-{
- // Redfish MessageIds are in the form
- // RegistryName.MajorVersion.MinorVersion.MessageKey, so parse it to find
- // the right Message
- std::vector<std::string> fields;
- fields.reserve(4);
-
- bmcweb::split(fields, messageID, '.');
- if (fields.size() != 4)
- {
- return nullptr;
- }
- const std::string& registryName = fields[0];
- const std::string& messageKey = fields[3];
-
- // Find the right registry and check it for the MessageKey
- return getMsgFromRegistry(messageKey, getRegistryFromPrefix(registryName));
-}
-} // namespace registries
-
class EventServiceManager
{
private:
diff --git a/redfish-core/lib/event_service.hpp b/redfish-core/lib/event_service.hpp
index a75da35..d415496 100644
--- a/redfish-core/lib/event_service.hpp
+++ b/redfish-core/lib/event_service.hpp
@@ -20,8 +20,11 @@
#include "http/utility.hpp"
#include "logging.hpp"
#include "query.hpp"
+#include "registries.hpp"
#include "registries/privilege_registry.hpp"
+#include "registries_selector.hpp"
#include "snmp_trap_event_clients.hpp"
+#include "utils/json_utils.hpp"
#include <boost/beast/http/fields.hpp>
#include <boost/system/error_code.hpp>
diff --git a/redfish-core/src/event_log.cpp b/redfish-core/src/event_log.cpp
index 5420549..cada5b7 100644
--- a/redfish-core/src/event_log.cpp
+++ b/redfish-core/src/event_log.cpp
@@ -15,7 +15,6 @@
*/
#include "event_log.hpp"
-#include "event_service_manager.hpp"
#include "logging.hpp"
#include "registries.hpp"
#include "str_utility.hpp"
@@ -127,7 +126,7 @@
const std::string& customText, nlohmann::json::object_t& logEntryJson)
{
// Get the Message from the MessageRegistry
- const registries::Message* message = registries::formatMessage(messageID);
+ const registries::Message* message = registries::getMessage(messageID);
if (message == nullptr)
{
diff --git a/redfish-core/src/registries.cpp b/redfish-core/src/registries.cpp
index a852f24..9ed261a 100644
--- a/redfish-core/src/registries.cpp
+++ b/redfish-core/src/registries.cpp
@@ -1,8 +1,6 @@
#include "registries.hpp"
-#include "registries/base_message_registry.hpp"
-#include "registries/openbmc_message_registry.hpp"
-#include "registries/telemetry_message_registry.hpp"
+#include "registries_selector.hpp"
#include "str_utility.hpp"
#include <algorithm>
@@ -39,26 +37,18 @@
std::vector<std::string> fields;
fields.reserve(4);
bmcweb::split(fields, messageID, '.');
+ if (fields.size() != 4)
+ {
+ return nullptr;
+ }
+
const std::string& registryName = fields[0];
const std::string& messageKey = fields[3];
// Find the right registry and check it for the MessageKey
- if (std::string(base::header.registryPrefix) == registryName)
- {
- return getMessageFromRegistry(
- messageKey, std::span<const MessageEntry>(base::registry));
- }
- if (std::string(openbmc::header.registryPrefix) == registryName)
- {
- return getMessageFromRegistry(
- messageKey, std::span<const MessageEntry>(openbmc::registry));
- }
- if (std::string(telemetry::header.registryPrefix) == registryName)
- {
- return getMessageFromRegistry(
- messageKey, std::span<const MessageEntry>(telemetry::registry));
- }
- return nullptr;
+ // Find the right registry and check it for the MessageKey
+ return getMessageFromRegistry(messageKey,
+ getRegistryFromPrefix(registryName));
}
} // namespace redfish::registries