Skip to content

Commit 4a102cd

Browse files
williamspatrickedtanous
authored andcommitted
registries: make registration dynamic
Rather than having to manually hook code for registries, add a small registration function to the registry header and use this registration results throughout the registry interactions. Tested: Confirmed registries have same behavior. ``` $ curl -s -k https://localhost:18080/redfish/v1/Registries/ | jq '.Members | map(."@odata.id")' [ "/redfish/v1/Registries/Base", "/redfish/v1/Registries/HeartbeatEvent", "/redfish/v1/Registries/OpenBMC", "/redfish/v1/Registries/ResourceEvent", "/redfish/v1/Registries/TaskEvent", "/redfish/v1/Registries/Telemetry" ] ``` ``` $ curl -s -k https://localhost:18080/redfish/v1/Registries/TaskEvent/TaskEvent | jq ".Messages | keys" [ "TaskAborted", "TaskCancelled", "TaskCompletedOK", "TaskCompletedWarning", "TaskPaused", "TaskProgressChanged", "TaskRemoved", "TaskResumed", "TaskStarted" ] ``` Signed-off-by: Patrick Williams <patrick@stwcx.xyz> Change-Id: Iaa355420736a2587d9da4e995208d579443ca9b8
1 parent 5bfed26 commit 4a102cd

30 files changed

+536
-382
lines changed

redfish-core/include/registries.hpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
#include <charconv>
1212
#include <cstddef>
1313
#include <format>
14+
#include <functional>
15+
#include <map>
16+
#include <optional>
1417
#include <span>
1518
#include <string>
1619
#include <string_view>
@@ -43,6 +46,30 @@ struct Message
4346
const char* resolution;
4447
};
4548
using MessageEntry = std::pair<const char*, const Message>;
49+
using MessageEntries = std::span<const MessageEntry>;
50+
51+
struct RegistryEntry
52+
{
53+
const Header& header;
54+
const char* url;
55+
MessageEntries entries;
56+
};
57+
using RegistryEntryRef = std::reference_wrapper<RegistryEntry>;
58+
59+
auto allRegistries() -> std::map<std::string, RegistryEntry>&;
60+
61+
auto getRegistryFromPrefix(const std::string& registryName)
62+
-> std::optional<RegistryEntryRef>;
63+
64+
auto getRegistryMessagesFromPrefix(const std::string& registryName)
65+
-> MessageEntries;
66+
67+
template <typename T>
68+
void registerRegistry()
69+
{
70+
allRegistries().emplace(T::header.registryPrefix,
71+
RegistryEntry{T::header, T::url, T::registry});
72+
}
4673

4774
inline std::string fillMessageArgs(
4875
const std::span<const std::string_view> messageArgs, std::string_view msg)

redfish-core/include/registries/base_message_registry.hpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@
1717

1818
// clang-format off
1919

20-
namespace redfish::registries::base
20+
namespace redfish::registries
2121
{
22-
const Header header = {
22+
struct Base
23+
{
24+
static constexpr Header header = {
2325
"Copyright 2014-2024 DMTF. All rights reserved.",
2426
"#MessageRegistry.v1_6_2.MessageRegistry",
2527
1,
@@ -31,10 +33,11 @@ const Header header = {
3133
"Base",
3234
"DMTF",
3335
};
34-
constexpr const char* url =
36+
37+
static constexpr const char* url =
3538
"https://redfish.dmtf.org/registries/Base.1.19.0.json";
3639

37-
constexpr std::array registry =
40+
static constexpr std::array registry =
3841
{
3942
MessageEntry{
4043
"AccessDenied",
@@ -1479,4 +1482,9 @@ enum class Index
14791482
undeterminedFault = 112,
14801483
unrecognizedRequestBody = 113,
14811484
};
1482-
} // namespace redfish::registries::base
1485+
}; // struct base
1486+
1487+
[[gnu::constructor]] inline void registerBase()
1488+
{ registerRegistry<Base>(); }
1489+
1490+
} // namespace redfish::registries

redfish-core/include/registries/composition_message_registry.hpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@
1717

1818
// clang-format off
1919

20-
namespace redfish::registries::composition
20+
namespace redfish::registries
2121
{
22-
const Header header = {
22+
struct Composition
23+
{
24+
static constexpr Header header = {
2325
"Copyright 2019-2023 DMTF. All rights reserved.",
2426
"#MessageRegistry.v1_6_2.MessageRegistry",
2527
1,
@@ -31,10 +33,11 @@ const Header header = {
3133
"Composition",
3234
"DMTF",
3335
};
34-
constexpr const char* url =
36+
37+
static constexpr const char* url =
3538
"https://redfish.dmtf.org/registries/Composition.1.1.2.json";
3639

37-
constexpr std::array registry =
40+
static constexpr std::array registry =
3841
{
3942
MessageEntry{
4043
"ConstrainedResourceAlreadyReserved",
@@ -209,4 +212,9 @@ enum class Index
209212
specifiedResourceAlreadyReserved = 11,
210213
unableToProcessStanzaRequest = 12,
211214
};
212-
} // namespace redfish::registries::composition
215+
}; // struct composition
216+
217+
[[gnu::constructor]] inline void registerComposition()
218+
{ registerRegistry<Composition>(); }
219+
220+
} // namespace redfish::registries

redfish-core/include/registries/environmental_message_registry.hpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@
1717

1818
// clang-format off
1919

20-
namespace redfish::registries::environmental
20+
namespace redfish::registries
2121
{
22-
const Header header = {
22+
struct Environmental
23+
{
24+
static constexpr Header header = {
2325
"Copyright 2024 DMTF. All rights reserved.",
2426
"#MessageRegistry.v1_6_2.MessageRegistry",
2527
1,
@@ -31,10 +33,11 @@ const Header header = {
3133
"Environmental",
3234
"DMTF",
3335
};
34-
constexpr const char* url =
36+
37+
static constexpr const char* url =
3538
"https://redfish.dmtf.org/registries/Environmental.1.1.0.json";
3639

37-
constexpr std::array registry =
40+
static constexpr std::array registry =
3841
{
3942
MessageEntry{
4043
"FanFailed",
@@ -1280,4 +1283,9 @@ enum class Index
12801283
temperatureNormal = 85,
12811284
temperatureWarning = 86,
12821285
};
1283-
} // namespace redfish::registries::environmental
1286+
}; // struct environmental
1287+
1288+
[[gnu::constructor]] inline void registerEnvironmental()
1289+
{ registerRegistry<Environmental>(); }
1290+
1291+
} // namespace redfish::registries

redfish-core/include/registries/ethernet_fabric_message_registry.hpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@
1717

1818
// clang-format off
1919

20-
namespace redfish::registries::ethernet_fabric
20+
namespace redfish::registries
2121
{
22-
const Header header = {
22+
struct EthernetFabric
23+
{
24+
static constexpr Header header = {
2325
"Copyright 2020-2023 DMTF. All rights reserved.",
2426
"#MessageRegistry.v1_6_2.MessageRegistry",
2527
1,
@@ -31,10 +33,11 @@ const Header header = {
3133
"EthernetFabric",
3234
"DMTF",
3335
};
34-
constexpr const char* url =
36+
37+
static constexpr const char* url =
3538
"https://redfish.dmtf.org/registries/EthernetFabric.1.0.1.json";
3639

37-
constexpr std::array registry =
40+
static constexpr std::array registry =
3841
{
3942
MessageEntry{
4043
"LLDPInterfaceDisabled",
@@ -154,4 +157,9 @@ enum class Index
154157
mLAGPeerUp = 6,
155158
routingFailureThresholdExceeded = 7,
156159
};
157-
} // namespace redfish::registries::ethernet_fabric
160+
}; // struct ethernet_fabric
161+
162+
[[gnu::constructor]] inline void registerEthernetFabric()
163+
{ registerRegistry<EthernetFabric>(); }
164+
165+
} // namespace redfish::registries

redfish-core/include/registries/fabric_message_registry.hpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@
1717

1818
// clang-format off
1919

20-
namespace redfish::registries::fabric
20+
namespace redfish::registries
2121
{
22-
const Header header = {
22+
struct Fabric
23+
{
24+
static constexpr Header header = {
2325
"Copyright 2014-2023 DMTF. All rights reserved.",
2426
"#MessageRegistry.v1_6_2.MessageRegistry",
2527
1,
@@ -31,10 +33,11 @@ const Header header = {
3133
"Fabric",
3234
"DMTF",
3335
};
34-
constexpr const char* url =
36+
37+
static constexpr const char* url =
3538
"https://redfish.dmtf.org/registries/Fabric.1.0.2.json";
3639

37-
constexpr std::array registry =
40+
static constexpr std::array registry =
3841
{
3942
MessageEntry{
4043
"AddressPoolCreated",
@@ -634,4 +637,9 @@ enum class Index
634637
zoneModified = 40,
635638
zoneRemoved = 41,
636639
};
637-
} // namespace redfish::registries::fabric
640+
}; // struct fabric
641+
642+
[[gnu::constructor]] inline void registerFabric()
643+
{ registerRegistry<Fabric>(); }
644+
645+
} // namespace redfish::registries

redfish-core/include/registries/heartbeat_event_message_registry.hpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@
1717

1818
// clang-format off
1919

20-
namespace redfish::registries::heartbeat_event
20+
namespace redfish::registries
2121
{
22-
const Header header = {
22+
struct HeartbeatEvent
23+
{
24+
static constexpr Header header = {
2325
"Copyright 2021-2023 DMTF. All rights reserved.",
2426
"#MessageRegistry.v1_6_2.MessageRegistry",
2527
1,
@@ -31,10 +33,11 @@ const Header header = {
3133
"HeartbeatEvent",
3234
"DMTF",
3335
};
34-
constexpr const char* url =
36+
37+
static constexpr const char* url =
3538
"https://redfish.dmtf.org/registries/HeartbeatEvent.1.0.1.json";
3639

37-
constexpr std::array registry =
40+
static constexpr std::array registry =
3841
{
3942
MessageEntry{
4043
"RedfishServiceFunctional",
@@ -53,4 +56,9 @@ enum class Index
5356
{
5457
redfishServiceFunctional = 0,
5558
};
56-
} // namespace redfish::registries::heartbeat_event
59+
}; // struct heartbeat_event
60+
61+
[[gnu::constructor]] inline void registerHeartbeatEvent()
62+
{ registerRegistry<HeartbeatEvent>(); }
63+
64+
} // namespace redfish::registries

redfish-core/include/registries/job_event_message_registry.hpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@
1717

1818
// clang-format off
1919

20-
namespace redfish::registries::job_event
20+
namespace redfish::registries
2121
{
22-
const Header header = {
22+
struct JobEvent
23+
{
24+
static constexpr Header header = {
2325
"Copyright 2014-2023 DMTF in cooperation with the Storage Networking Industry Association (SNIA). All rights reserved.",
2426
"#MessageRegistry.v1_6_2.MessageRegistry",
2527
1,
@@ -31,10 +33,11 @@ const Header header = {
3133
"JobEvent",
3234
"DMTF",
3335
};
34-
constexpr const char* url =
36+
37+
static constexpr const char* url =
3538
"https://redfish.dmtf.org/registries/JobEvent.1.0.1.json";
3639

37-
constexpr std::array registry =
40+
static constexpr std::array registry =
3841
{
3942
MessageEntry{
4043
"JobCancelled",
@@ -147,4 +150,9 @@ enum class Index
147150
jobStarted = 6,
148151
jobSuspended = 7,
149152
};
150-
} // namespace redfish::registries::job_event
153+
}; // struct job_event
154+
155+
[[gnu::constructor]] inline void registerJobEvent()
156+
{ registerRegistry<JobEvent>(); }
157+
158+
} // namespace redfish::registries

redfish-core/include/registries/license_message_registry.hpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@
1717

1818
// clang-format off
1919

20-
namespace redfish::registries::license
20+
namespace redfish::registries
2121
{
22-
const Header header = {
22+
struct License
23+
{
24+
static constexpr Header header = {
2325
"Copyright 2014-2023 DMTF. All rights reserved.",
2426
"#MessageRegistry.v1_6_2.MessageRegistry",
2527
1,
@@ -31,10 +33,11 @@ const Header header = {
3133
"License",
3234
"DMTF",
3335
};
34-
constexpr const char* url =
36+
37+
static constexpr const char* url =
3538
"https://redfish.dmtf.org/registries/License.1.0.3.json";
3639

37-
constexpr std::array registry =
40+
static constexpr std::array registry =
3841
{
3942
MessageEntry{
4043
"DaysBeforeExpiration",
@@ -142,4 +145,9 @@ enum class Index
142145
notApplicableToTarget = 6,
143146
targetsRequired = 7,
144147
};
145-
} // namespace redfish::registries::license
148+
}; // struct license
149+
150+
[[gnu::constructor]] inline void registerLicense()
151+
{ registerRegistry<License>(); }
152+
153+
} // namespace redfish::registries

redfish-core/include/registries/log_service_message_registry.hpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@
1717

1818
// clang-format off
1919

20-
namespace redfish::registries::log_service
20+
namespace redfish::registries
2121
{
22-
const Header header = {
22+
struct LogService
23+
{
24+
static constexpr Header header = {
2325
"Copyright 2020-2023 DMTF. All rights reserved.",
2426
"#MessageRegistry.v1_6_2.MessageRegistry",
2527
1,
@@ -31,10 +33,11 @@ const Header header = {
3133
"LogService",
3234
"DMTF",
3335
};
34-
constexpr const char* url =
36+
37+
static constexpr const char* url =
3538
"https://redfish.dmtf.org/registries/LogService.1.0.1.json";
3639

37-
constexpr std::array registry =
40+
static constexpr std::array registry =
3841
{
3942
MessageEntry{
4043
"DiagnosticDataCollected",
@@ -55,4 +58,9 @@ enum class Index
5558
{
5659
diagnosticDataCollected = 0,
5760
};
58-
} // namespace redfish::registries::log_service
61+
}; // struct log_service
62+
63+
[[gnu::constructor]] inline void registerLogService()
64+
{ registerRegistry<LogService>(); }
65+
66+
} // namespace redfish::registries

0 commit comments

Comments
 (0)