blob: e465b1584cafabf813fce00c4e8295293d069f94 [file] [log] [blame]
Sui Chend1d411f2022-04-10 23:09:36 -07001#include "registries.hpp"
2
3#include "registries/base_message_registry.hpp"
4#include "registries/openbmc_message_registry.hpp"
5#include "str_utility.hpp"
6
Ed Tanous3544d2a2023-08-06 18:12:20 -07007#include <ranges>
Sui Chend1d411f2022-04-10 23:09:36 -07008#include <string>
9#include <vector>
10
11namespace redfish::registries
12{
13
14const Message* getMessageFromRegistry(const std::string& messageKey,
15 std::span<const MessageEntry> registry)
16{
Ed Tanous3544d2a2023-08-06 18:12:20 -070017 std::span<const MessageEntry>::iterator messageIt = std::ranges::find_if(
18 registry, [&messageKey](const MessageEntry& messageEntry) {
19 return std::strcmp(messageEntry.first, messageKey.c_str()) == 0;
Sui Chend1d411f2022-04-10 23:09:36 -070020 });
21 if (messageIt != registry.end())
22 {
23 return &messageIt->second;
24 }
25
26 return nullptr;
27}
28
29const Message* getMessage(std::string_view messageID)
30{
31 // Redfish MessageIds are in the form
32 // RegistryName.MajorVersion.MinorVersion.MessageKey, so parse it to find
33 // the right Message
34 std::vector<std::string> fields;
35 fields.reserve(4);
36 bmcweb::split(fields, messageID, '.');
37 const std::string& registryName = fields[0];
38 const std::string& messageKey = fields[3];
39
40 // Find the right registry and check it for the MessageKey
41 if (std::string(base::header.registryPrefix) == registryName)
42 {
43 return getMessageFromRegistry(
44 messageKey, std::span<const MessageEntry>(base::registry));
45 }
46 if (std::string(openbmc::header.registryPrefix) == registryName)
47 {
48 return getMessageFromRegistry(
49 messageKey, std::span<const MessageEntry>(openbmc::registry));
50 }
51 return nullptr;
52}
53
54} // namespace redfish::registries