1 #include "registries.hpp" 2 3 #include "registries/base_message_registry.hpp" 4 #include "registries/openbmc_message_registry.hpp" 5 #include "registries/telemetry_message_registry.hpp" 6 #include "str_utility.hpp" 7 8 #include <algorithm> 9 #include <cstring> 10 #include <ranges> 11 #include <span> 12 #include <string> 13 #include <string_view> 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 { 22 std::span<const MessageEntry>::iterator messageIt = std::ranges::find_if( 23 registry, [&messageKey](const MessageEntry& messageEntry) { 24 return std::strcmp(messageEntry.first, messageKey.c_str()) == 0; 25 }); 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 } 56 if (std::string(telemetry::header.registryPrefix) == registryName) 57 { 58 return getMessageFromRegistry( 59 messageKey, std::span<const MessageEntry>(telemetry::registry)); 60 } 61 return nullptr; 62 } 63 64 } // namespace redfish::registries 65