xref: /openbmc/bmcweb/features/redfish/include/registries_selector.hpp (revision f7a26073cf8c70dfa1e121540b13c63af77c3dc1)
18dab0f58SEd Tanous #pragma once
2*f7a26073SMyung Bae #include "registries.hpp"
38dab0f58SEd Tanous #include "registries/base_message_registry.hpp"
4fb546105SMyung Bae #include "registries/heartbeat_event_message_registry.hpp"
58dab0f58SEd Tanous #include "registries/openbmc_message_registry.hpp"
6*f7a26073SMyung Bae #include "registries/resource_event_message_registry.hpp"
78dab0f58SEd Tanous #include "registries/task_event_message_registry.hpp"
8*f7a26073SMyung Bae #include "registries/telemetry_message_registry.hpp"
98dab0f58SEd Tanous 
10*f7a26073SMyung Bae #include <optional>
118dab0f58SEd Tanous #include <span>
128dab0f58SEd Tanous #include <string_view>
138dab0f58SEd Tanous 
148dab0f58SEd Tanous namespace redfish::registries
158dab0f58SEd Tanous {
16*f7a26073SMyung Bae struct HeaderAndUrl
178dab0f58SEd Tanous {
18*f7a26073SMyung Bae     const Header& header;
19*f7a26073SMyung Bae     const char* url;
20*f7a26073SMyung Bae };
21*f7a26073SMyung Bae 
22*f7a26073SMyung Bae inline std::optional<registries::HeaderAndUrl>
23*f7a26073SMyung Bae     getRegistryHeaderAndUrlFromPrefix(std::string_view registryName)
248dab0f58SEd Tanous {
25*f7a26073SMyung Bae     if (base::header.registryPrefix == registryName)
26*f7a26073SMyung Bae     {
27*f7a26073SMyung Bae         return HeaderAndUrl{base::header, base::url};
28*f7a26073SMyung Bae     }
29*f7a26073SMyung Bae     if (heartbeat_event::header.registryPrefix == registryName)
30*f7a26073SMyung Bae     {
31*f7a26073SMyung Bae         return HeaderAndUrl{heartbeat_event::header, heartbeat_event::url};
328dab0f58SEd Tanous     }
338dab0f58SEd Tanous     if (openbmc::header.registryPrefix == registryName)
348dab0f58SEd Tanous     {
35*f7a26073SMyung Bae         return HeaderAndUrl{openbmc::header, openbmc::url};
36*f7a26073SMyung Bae     }
37*f7a26073SMyung Bae     if (resource_event::header.registryPrefix == registryName)
38*f7a26073SMyung Bae     {
39*f7a26073SMyung Bae         return HeaderAndUrl{resource_event::header, resource_event::url};
40*f7a26073SMyung Bae     }
41*f7a26073SMyung Bae     if (task_event::header.registryPrefix == registryName)
42*f7a26073SMyung Bae     {
43*f7a26073SMyung Bae         return HeaderAndUrl{task_event::header, task_event::url};
44*f7a26073SMyung Bae     }
45*f7a26073SMyung Bae     if (telemetry::header.registryPrefix == registryName)
46*f7a26073SMyung Bae     {
47*f7a26073SMyung Bae         return HeaderAndUrl{telemetry::header, telemetry::url};
48*f7a26073SMyung Bae     }
49*f7a26073SMyung Bae     return std::nullopt;
50*f7a26073SMyung Bae }
51*f7a26073SMyung Bae 
52*f7a26073SMyung Bae inline std::span<const MessageEntry>
53*f7a26073SMyung Bae     getRegistryFromPrefix(std::string_view registryName)
54*f7a26073SMyung Bae {
55*f7a26073SMyung Bae     if (base::header.registryPrefix == registryName)
56*f7a26073SMyung Bae     {
57*f7a26073SMyung Bae         return {base::registry};
588dab0f58SEd Tanous     }
59fb546105SMyung Bae     if (heartbeat_event::header.registryPrefix == registryName)
60fb546105SMyung Bae     {
61fb546105SMyung Bae         return {heartbeat_event::registry};
62fb546105SMyung Bae     }
63*f7a26073SMyung Bae     if (openbmc::header.registryPrefix == registryName)
648dab0f58SEd Tanous     {
65*f7a26073SMyung Bae         return {openbmc::registry};
66*f7a26073SMyung Bae     }
67*f7a26073SMyung Bae     if (resource_event::header.registryPrefix == registryName)
68*f7a26073SMyung Bae     {
69*f7a26073SMyung Bae         return {resource_event::registry};
70*f7a26073SMyung Bae     }
71*f7a26073SMyung Bae     if (task_event::header.registryPrefix == registryName)
72*f7a26073SMyung Bae     {
73*f7a26073SMyung Bae         return {task_event::registry};
74*f7a26073SMyung Bae     }
75*f7a26073SMyung Bae     if (telemetry::header.registryPrefix == registryName)
76*f7a26073SMyung Bae     {
77*f7a26073SMyung Bae         return {telemetry::registry};
788dab0f58SEd Tanous     }
798dab0f58SEd Tanous     return {openbmc::registry};
808dab0f58SEd Tanous }
818dab0f58SEd Tanous } // namespace redfish::registries
82