xref: /openbmc/bmcweb/redfish-core/include/registries_selector.hpp (revision 19ea2864f50b082773496767b2bc0778e716eef2)
1 #pragma once
2 #include "registries.hpp"
3 #include "registries/base_message_registry.hpp"
4 #include "registries/heartbeat_event_message_registry.hpp"
5 #include "registries/openbmc_message_registry.hpp"
6 #include "registries/resource_event_message_registry.hpp"
7 #include "registries/task_event_message_registry.hpp"
8 #include "registries/telemetry_message_registry.hpp"
9 
10 #include <optional>
11 #include <span>
12 #include <string_view>
13 
14 namespace redfish::registries
15 {
16 struct HeaderAndUrl
17 {
18     const Header& header;
19     const char* url;
20 };
21 
22 inline std::optional<registries::HeaderAndUrl>
23     getRegistryHeaderAndUrlFromPrefix(std::string_view registryName)
24 {
25     if (base::header.registryPrefix == registryName)
26     {
27         return HeaderAndUrl{base::header, base::url};
28     }
29     if (heartbeat_event::header.registryPrefix == registryName)
30     {
31         return HeaderAndUrl{heartbeat_event::header, heartbeat_event::url};
32     }
33     if (openbmc::header.registryPrefix == registryName)
34     {
35         return HeaderAndUrl{openbmc::header, openbmc::url};
36     }
37     if (resource_event::header.registryPrefix == registryName)
38     {
39         return HeaderAndUrl{resource_event::header, resource_event::url};
40     }
41     if (task_event::header.registryPrefix == registryName)
42     {
43         return HeaderAndUrl{task_event::header, task_event::url};
44     }
45     if (telemetry::header.registryPrefix == registryName)
46     {
47         return HeaderAndUrl{telemetry::header, telemetry::url};
48     }
49     return std::nullopt;
50 }
51 
52 inline std::span<const MessageEntry>
53     getRegistryFromPrefix(std::string_view registryName)
54 {
55     if (base::header.registryPrefix == registryName)
56     {
57         return {base::registry};
58     }
59     if (heartbeat_event::header.registryPrefix == registryName)
60     {
61         return {heartbeat_event::registry};
62     }
63     if (openbmc::header.registryPrefix == registryName)
64     {
65         return {openbmc::registry};
66     }
67     if (resource_event::header.registryPrefix == registryName)
68     {
69         return {resource_event::registry};
70     }
71     if (task_event::header.registryPrefix == registryName)
72     {
73         return {task_event::registry};
74     }
75     if (telemetry::header.registryPrefix == registryName)
76     {
77         return {telemetry::registry};
78     }
79     return {openbmc::registry};
80 }
81 } // namespace redfish::registries
82