Sui Chen | d1d411f | 2022-04-10 23:09:36 -0700 | [diff] [blame] | 1 | #include "registries.hpp" |
| 2 | |
| 3 | #include "registries/base_message_registry.hpp" |
| 4 | #include "registries/openbmc_message_registry.hpp" |
Michal Orzel | 8698760 | 2024-06-24 08:19:49 +0200 | [diff] [blame^] | 5 | #include "registries/telemetry_message_registry.hpp" |
Sui Chen | d1d411f | 2022-04-10 23:09:36 -0700 | [diff] [blame] | 6 | #include "str_utility.hpp" |
| 7 | |
Ed Tanous | f0b59af | 2024-03-20 13:38:04 -0700 | [diff] [blame] | 8 | #include <algorithm> |
| 9 | #include <cstring> |
Ed Tanous | 3544d2a | 2023-08-06 18:12:20 -0700 | [diff] [blame] | 10 | #include <ranges> |
Ed Tanous | f0b59af | 2024-03-20 13:38:04 -0700 | [diff] [blame] | 11 | #include <span> |
Sui Chen | d1d411f | 2022-04-10 23:09:36 -0700 | [diff] [blame] | 12 | #include <string> |
Ed Tanous | f0b59af | 2024-03-20 13:38:04 -0700 | [diff] [blame] | 13 | #include <string_view> |
Sui Chen | d1d411f | 2022-04-10 23:09:36 -0700 | [diff] [blame] | 14 | #include <vector> |
| 15 | |
| 16 | namespace redfish::registries |
| 17 | { |
| 18 | |
| 19 | const Message* getMessageFromRegistry(const std::string& messageKey, |
| 20 | std::span<const MessageEntry> registry) |
| 21 | { |
Ed Tanous | 3544d2a | 2023-08-06 18:12:20 -0700 | [diff] [blame] | 22 | std::span<const MessageEntry>::iterator messageIt = std::ranges::find_if( |
| 23 | registry, [&messageKey](const MessageEntry& messageEntry) { |
Patrick Williams | 5a39f77 | 2023-10-20 11:20:21 -0500 | [diff] [blame] | 24 | return std::strcmp(messageEntry.first, messageKey.c_str()) == 0; |
| 25 | }); |
Sui Chen | d1d411f | 2022-04-10 23:09:36 -0700 | [diff] [blame] | 26 | if (messageIt != registry.end()) |
| 27 | { |
| 28 | return &messageIt->second; |
| 29 | } |
| 30 | |
| 31 | return nullptr; |
| 32 | } |
| 33 | |
| 34 | const Message* getMessage(std::string_view messageID) |
| 35 | { |
| 36 | // Redfish MessageIds are in the form |
| 37 | // RegistryName.MajorVersion.MinorVersion.MessageKey, so parse it to find |
| 38 | // the right Message |
| 39 | std::vector<std::string> fields; |
| 40 | fields.reserve(4); |
| 41 | bmcweb::split(fields, messageID, '.'); |
| 42 | const std::string& registryName = fields[0]; |
| 43 | const std::string& messageKey = fields[3]; |
| 44 | |
| 45 | // Find the right registry and check it for the MessageKey |
| 46 | if (std::string(base::header.registryPrefix) == registryName) |
| 47 | { |
| 48 | return getMessageFromRegistry( |
| 49 | messageKey, std::span<const MessageEntry>(base::registry)); |
| 50 | } |
| 51 | if (std::string(openbmc::header.registryPrefix) == registryName) |
| 52 | { |
| 53 | return getMessageFromRegistry( |
| 54 | messageKey, std::span<const MessageEntry>(openbmc::registry)); |
| 55 | } |
Michal Orzel | 8698760 | 2024-06-24 08:19:49 +0200 | [diff] [blame^] | 56 | if (std::string(telemetry::header.registryPrefix) == registryName) |
| 57 | { |
| 58 | return getMessageFromRegistry( |
| 59 | messageKey, std::span<const MessageEntry>(telemetry::registry)); |
| 60 | } |
Sui Chen | d1d411f | 2022-04-10 23:09:36 -0700 | [diff] [blame] | 61 | return nullptr; |
| 62 | } |
| 63 | |
| 64 | } // namespace redfish::registries |