summaryrefslogtreecommitdiff
path: root/include/dbus_monitor.hpp
diff options
context:
space:
mode:
authorEd Tanous <edtanous@google.com>2022-03-15 20:44:42 +0300
committerEd Tanous <edtanous@google.com>2022-05-13 01:08:18 +0300
commit1476687deb1697d865b20458a0097c9ab5fd44e2 (patch)
tree6964ba82c382d03522f7a413a61ae1164b8e242e /include/dbus_monitor.hpp
parent1656b296313d75b172dcdbe5f37ff1d1b54800dc (diff)
downloadbmcweb-1476687deb1697d865b20458a0097c9ab5fd44e2.tar.xz
Remove brace initialization of json objects
Brace initialization of json objects, while quite interesting from an academic sense, are very difficult for people to grok, and lead to inconsistencies. This patchset aims to remove a majority of them in lieu of operator[]. Interestingly, this saves about 1% of the binary size of bmcweb. This also has an added benefit that as a design pattern, we're never constructing a new object, then moving it into place, we're always adding to the existing object, which in the future _could_ make things like OEM schemas or properties easier, as there's no case where we're completely replacing the response object. Tested: Ran redfish service validator. No new failures. Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: Iae409b0a40ddd3ae6112cb2d52c6f6ab388595fe
Diffstat (limited to 'include/dbus_monitor.hpp')
-rw-r--r--include/dbus_monitor.hpp13
1 files changed, 7 insertions, 6 deletions
diff --git a/include/dbus_monitor.hpp b/include/dbus_monitor.hpp
index 764d157985..977f3a3a3a 100644
--- a/include/dbus_monitor.hpp
+++ b/include/dbus_monitor.hpp
@@ -45,8 +45,9 @@ inline int onPropertyUpdate(sd_bus_message* m, void* userdata,
return 0;
}
sdbusplus::message::message message(m);
- nlohmann::json j{{"event", message.get_member()},
- {"path", message.get_path()}};
+ nlohmann::json json;
+ json["event"] = message.get_member();
+ json["path"] = message.get_path();
if (strcmp(message.get_member(), "PropertiesChanged") == 0)
{
nlohmann::json data;
@@ -63,8 +64,8 @@ inline int onPropertyUpdate(sd_bus_message* m, void* userdata,
}
// data is type sa{sv}as and is an array[3] of string, object, array
- j["interface"] = data[0];
- j["properties"] = data[1];
+ json["interface"] = data[0];
+ json["properties"] = data[1];
}
else if (strcmp(message.get_member(), "InterfacesAdded") == 0)
{
@@ -88,7 +89,7 @@ inline int onPropertyUpdate(sd_bus_message* m, void* userdata,
auto it = thisSession->second.interfaces.find(entry.key());
if (it != thisSession->second.interfaces.end())
{
- j["interfaces"][entry.key()] = entry.value();
+ json["interfaces"][entry.key()] = entry.value();
}
}
}
@@ -100,7 +101,7 @@ inline int onPropertyUpdate(sd_bus_message* m, void* userdata,
}
connection->sendText(
- j.dump(2, ' ', true, nlohmann::json::error_handler_t::replace));
+ json.dump(2, ' ', true, nlohmann::json::error_handler_t::replace));
return 0;
}