diff options
author | Ed Tanous <edtanous@google.com> | 2022-07-09 21:17:36 +0300 |
---|---|---|
committer | Ed Tanous <ed@tanous.net> | 2022-09-12 19:42:37 +0300 |
commit | 613dabea03cd2f5cb999be37aaf539280c63ea7a (patch) | |
tree | fbf586118f079918883c97caec8b1b8fd43967f1 /redfish-core/include/event_service_manager.hpp | |
parent | 188cb6294105a045a445619415d01843de8c3732 (diff) | |
download | bmcweb-613dabea03cd2f5cb999be37aaf539280c63ea7a.tar.xz |
Remove nlohmann brace initialization
There's a few last places (outside of tests) where we still use
nlohmann brace initialization. Per the transforms we've been doing,
move these to constructing the objects explicitly, using operator[],
nlohmann::object_t and nlohmann::array_t. Theses were found by manual
inspection grepping for all uses of nlohmann::json.
This is done to reduce binary size and reduce the number of intermediate
objects being constructed. This commit saves a trivial amount of size
(~4KB, Half a percent of total) and in addition but makes our
construction consistent.
Tested:
Redfish service validator passes.
Signed-off-by: Ed Tanous <edtanous@google.com>
Change-Id: I7478479a9fdc41b254eef325002d413c1fb411a0
Diffstat (limited to 'redfish-core/include/event_service_manager.hpp')
-rw-r--r-- | redfish-core/include/event_service_manager.hpp | 68 |
1 files changed, 31 insertions, 37 deletions
diff --git a/redfish-core/include/event_service_manager.hpp b/redfish-core/include/event_service_manager.hpp index b20946a6a1..e102b7b294 100644 --- a/redfish-core/include/event_service_manager.hpp +++ b/redfish-core/include/event_service_manager.hpp @@ -416,15 +416,15 @@ class Subscription : public persistent_data::UserSubscription logEntryArray.push_back({}); nlohmann::json& logEntryJson = logEntryArray.back(); - logEntryJson = {{"EventId", "TestID"}, - {"EventType", "Event"}, - {"Severity", "OK"}, - {"Message", "Generated test event"}, - {"MessageId", "OpenBMC.0.2.TestEventLog"}, - {"MessageArgs", nlohmann::json::array()}, - {"EventTimestamp", - redfish::time_utils::getDateTimeOffsetNow().first}, - {"Context", customText}}; + logEntryJson["EventId"] = "TestID"; + logEntryJson["EventType"] = "Event"; + logEntryJson["Severity"] = "OK"; + logEntryJson["Message"] = "Generated test event"; + logEntryJson["MessageId"] = "OpenBMC.0.2.TestEventLog"; + logEntryJson["MessageArgs"] = nlohmann::json::array(); + logEntryJson["EventTimestamp"] = + redfish::time_utils::getDateTimeOffsetNow().first; + logEntryJson["Context"] = customText; nlohmann::json msg; msg["@odata.type"] = "#Event.v1_4_0.Event"; @@ -1011,8 +1011,8 @@ class EventServiceManager return true; } - void sendEvent(const nlohmann::json& eventMessageIn, - const std::string& origin, const std::string& resType) + void sendEvent(nlohmann::json eventMessage, const std::string& origin, + const std::string& resType) { if (!serviceEnabled || (noOfEventLogSubscribers == 0U)) { @@ -1020,22 +1020,15 @@ class EventServiceManager return; } nlohmann::json eventRecord = nlohmann::json::array(); - nlohmann::json eventMessage = eventMessageIn; + + eventMessage["EventId"] = eventId; // MemberId is 0 : since we are sending one event record. - uint64_t memberId = 0; - - nlohmann::json event = { - {"EventId", eventId}, - {"MemberId", memberId}, - {"EventTimestamp", - redfish::time_utils::getDateTimeOffsetNow().first}, - {"OriginOfCondition", origin}}; - for (nlohmann::json::iterator it = event.begin(); it != event.end(); - ++it) - { - eventMessage[it.key()] = it.value(); - } - eventRecord.push_back(eventMessage); + eventMessage["MemberId"] = 0; + eventMessage["EventTimestamp"] = + redfish::time_utils::getDateTimeOffsetNow().first; + eventMessage["OriginOfCondition"] = origin; + + eventRecord.emplace_back(std::move(eventMessage)); for (const auto& it : this->subscriptionsMap) { @@ -1063,11 +1056,12 @@ class EventServiceManager } if (isSubscribed) { - nlohmann::json msgJson = { - {"@odata.type", "#Event.v1_4_0.Event"}, - {"Name", "Event Log"}, - {"Id", eventId}, - {"Events", eventRecord}}; + nlohmann::json msgJson; + + msgJson["@odata.type"] = "#Event.v1_4_0.Event"; + msgJson["Name"] = "Event Log"; + msgJson["Id"] = eventId; + msgJson["Events"] = eventRecord; std::string strMsg = msgJson.dump( 2, ' ', true, nlohmann::json::error_handler_t::replace); @@ -1085,12 +1079,12 @@ class EventServiceManager for (const auto& it : this->subscriptionsMap) { std::shared_ptr<Subscription> entry = it.second; - nlohmann::json msgJson = { - {"Timestamp", - redfish::time_utils::getDateTimeOffsetNow().first}, - {"OriginOfCondition", "/ibm/v1/HMC/BroadcastService"}, - {"Name", "Broadcast Message"}, - {"Message", broadcastMsg}}; + nlohmann::json msgJson; + msgJson["Timestamp"] = + redfish::time_utils::getDateTimeOffsetNow().first; + msgJson["OriginOfCondition"] = "/ibm/v1/HMC/BroadcastService"; + msgJson["Name"] = "Broadcast Message"; + msgJson["Message"] = broadcastMsg; std::string strMsg = msgJson.dump( 2, ' ', true, nlohmann::json::error_handler_t::replace); |