Generate indexes for message registries
Being able to index into the message registry constexpr arrays will be
useful in the future, so update the parse_registries script to generate
an Index enum class, that allows directly indexing into the constexpr
table when necessary.
These indexes are used in the patchset here:
https://gerrit.openbmc-project.xyz/c/openbmc/bmcweb/+/50950
to avoid a binary search lookup for each entry.
Tested: No-op change, code inspection only.
Signed-off-by: Ed Tanous <edtanous@google.com>
Change-Id: I345cc26a2b17b5bcd8cfb0055642f4ae443caad4
diff --git a/redfish-core/include/registries/base_message_registry.hpp b/redfish-core/include/registries/base_message_registry.hpp
index 9508221..cfba904 100644
--- a/redfish-core/include/registries/base_message_registry.hpp
+++ b/redfish-core/include/registries/base_message_registry.hpp
@@ -1191,4 +1191,101 @@
"Correct the request body and resubmit the request if it failed.",
}},
};
-} // namespace redfish::message_registries::base
+
+enum class Index
+{
+ accessDenied = 0,
+ accountForSessionNoLongerExists = 1,
+ accountModified = 2,
+ accountNotModified = 3,
+ accountRemoved = 4,
+ actionDeprecated = 5,
+ actionNotSupported = 6,
+ actionParameterDuplicate = 7,
+ actionParameterMissing = 8,
+ actionParameterNotSupported = 9,
+ actionParameterUnknown = 10,
+ actionParameterValueError = 11,
+ actionParameterValueFormatError = 12,
+ actionParameterValueNotInList = 13,
+ actionParameterValueTypeError = 14,
+ chassisPowerStateOffRequired = 15,
+ chassisPowerStateOnRequired = 16,
+ conditionInRelatedResource = 17,
+ couldNotEstablishConnection = 18,
+ createFailedMissingReqProperties = 19,
+ createLimitReachedForResource = 20,
+ created = 21,
+ emptyJSON = 22,
+ eventSubscriptionLimitExceeded = 23,
+ generalError = 24,
+ insufficientPrivilege = 25,
+ internalError = 26,
+ invalidIndex = 27,
+ invalidJSON = 28,
+ invalidObject = 29,
+ invalidURI = 30,
+ malformedJSON = 31,
+ maximumErrorsExceeded = 32,
+ networkNameResolutionNotConfigured = 33,
+ networkNameResolutionNotSupported = 34,
+ noOperation = 35,
+ noValidSession = 36,
+ operationFailed = 37,
+ operationTimeout = 38,
+ passwordChangeRequired = 39,
+ preconditionFailed = 40,
+ preconditionRequired = 41,
+ propertyDeprecated = 42,
+ propertyDuplicate = 43,
+ propertyMissing = 44,
+ propertyNotWritable = 45,
+ propertyUnknown = 46,
+ propertyValueConflict = 47,
+ propertyValueDeprecated = 48,
+ propertyValueError = 49,
+ propertyValueExternalConflict = 50,
+ propertyValueFormatError = 51,
+ propertyValueIncorrect = 52,
+ propertyValueModified = 53,
+ propertyValueNotInList = 54,
+ propertyValueResourceConflict = 55,
+ propertyValueTypeError = 56,
+ queryCombinationInvalid = 57,
+ queryNotSupported = 58,
+ queryNotSupportedOnOperation = 59,
+ queryNotSupportedOnResource = 60,
+ queryParameterOutOfRange = 61,
+ queryParameterValueError = 62,
+ queryParameterValueFormatError = 63,
+ queryParameterValueTypeError = 64,
+ resetRequired = 65,
+ resourceAlreadyExists = 66,
+ resourceAtUriInUnknownFormat = 67,
+ resourceAtUriUnauthorized = 68,
+ resourceCannotBeDeleted = 69,
+ resourceCreationConflict = 70,
+ resourceDeprecated = 71,
+ resourceExhaustion = 72,
+ resourceInStandby = 73,
+ resourceInUse = 74,
+ resourceMissingAtURI = 75,
+ resourceNotFound = 76,
+ resourceTypeIncompatible = 77,
+ restrictedPrivilege = 78,
+ restrictedRole = 79,
+ serviceDisabled = 80,
+ serviceInUnknownState = 81,
+ serviceShuttingDown = 82,
+ serviceTemporarilyUnavailable = 83,
+ sessionLimitExceeded = 84,
+ sessionTerminated = 85,
+ sourceDoesNotSupportProtocol = 86,
+ strictAccountTypes = 87,
+ stringValueTooLong = 88,
+ subscriptionTerminated = 89,
+ success = 90,
+ undeterminedFault = 91,
+ unrecognizedRequestBody = 92,
+};
+} // namespace redfish::message_registries::base
\ No newline at end of file
diff --git a/redfish-core/include/registries/resource_event_message_registry.hpp b/redfish-core/include/registries/resource_event_message_registry.hpp
index eab44ab..e02aece 100644
--- a/redfish-core/include/registries/resource_event_message_registry.hpp
+++ b/redfish-core/include/registries/resource_event_message_registry.hpp
@@ -272,4 +272,27 @@
"None.",
}},
};
-} // namespace redfish::message_registries::resource_event
+
+enum class Index
+{
+ licenseAdded = 0,
+ licenseChanged = 1,
+ licenseExpired = 2,
+ resourceChanged = 3,
+ resourceCreated = 4,
+ resourceErrorThresholdCleared = 5,
+ resourceErrorThresholdExceeded = 6,
+ resourceErrorsCorrected = 7,
+ resourceErrorsDetected = 8,
+ resourceRemoved = 9,
+ resourceSelfTestCompleted = 10,
+ resourceSelfTestFailed = 11,
+ resourceStatusChangedCritical = 12,
+ resourceStatusChangedOK = 13,
+ resourceStatusChangedWarning = 14,
+ resourceVersionIncompatible = 15,
+ resourceWarningThresholdCleared = 16,
+ resourceWarningThresholdExceeded = 17,
+ uRIForResourceChanged = 18,
+};
+} // namespace redfish::message_registries::resource_event
\ No newline at end of file
diff --git a/redfish-core/include/registries/task_event_message_registry.hpp b/redfish-core/include/registries/task_event_message_registry.hpp
index 6c83dc1..421bc35 100644
--- a/redfish-core/include/registries/task_event_message_registry.hpp
+++ b/redfish-core/include/registries/task_event_message_registry.hpp
@@ -135,4 +135,17 @@
"None.",
}},
};
-} // namespace redfish::message_registries::task_event
+
+enum class Index
+{
+ taskAborted = 0,
+ taskCancelled = 1,
+ taskCompletedOK = 2,
+ taskCompletedWarning = 3,
+ taskPaused = 4,
+ taskProgressChanged = 5,
+ taskRemoved = 6,
+ taskResumed = 7,
+ taskStarted = 8,
+};
+} // namespace redfish::message_registries::task_event
\ No newline at end of file
diff --git a/scripts/parse_registries.py b/scripts/parse_registries.py
index d64e540..8334eae 100755
--- a/scripts/parse_registries.py
+++ b/scripts/parse_registries.py
@@ -91,7 +91,9 @@
registry.write(
"constexpr std::array<MessageEntry, {}> registry = {{".format(
len(json_dict["Messages"])))
- for messageId, message in sorted(json_dict["Messages"].items()):
+
+ messages_sorted = sorted(json_dict["Messages"].items())
+ for messageId, message in messages_sorted:
registry.write("MessageEntry{")
registry.write("\"{}\",".format(messageId))
registry.write("{")
@@ -108,7 +110,17 @@
registry.write("},")
registry.write("\"{}\",".format(message["Resolution"]))
registry.write("}},")
- registry.write("};}\n")
+
+ registry.write("\n};")
+
+ registry.write("\n\nenum class Index {\n")
+ for index, (messageId, message) in enumerate(messages_sorted):
+ messageId = messageId[0].lower() + messageId[1:]
+ registry.write(
+ "{} = {},\n".format(messageId, index))
+ registry.write("};")
+ registry.write("}")
+
clang_format(file)