blob: b96105a121233b308a97fa60a574f8840f4c7cda [file] [log] [blame] [edit]
#include "registries.hpp"
#include <algorithm>
#include <cstring>
#include <span> // NOLINT
#include <string>
#include <string_view>
#include <vector>
#include "str_utility.hpp"
#include "registries/base_message_registry.hpp"
#include "registries/openbmc_message_registry.hpp"
namespace redfish::registries {
const Message* getMessageFromRegistry(const std::string& message_key,
std::span<const MessageEntry> registry) {
std::span<const MessageEntry>::iterator message_it = std::find_if(
registry.begin(), registry.end(),
[&message_key](const MessageEntry& messageEntry) {
return std::strcmp(messageEntry.first, message_key.c_str()) == 0;
});
if (message_it != registry.end()) {
return &message_it->second;
}
return nullptr;
}
const Message* getMessage(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, '.');
const std::string& registry_name = fields[0];
const std::string& message_key = fields[3];
// Find the right registry and check it for the MessageKey
if (std::string(base::header.registryPrefix) == registry_name) {
return getMessageFromRegistry(
message_key, std::span<const MessageEntry>(base::registry));
}
if (std::string(openbmc::header.registryPrefix) == registry_name) {
return getMessageFromRegistry(
message_key, std::span<const MessageEntry>(openbmc::registry));
}
return nullptr;
}
} // namespace redfish::registries