Enforce const correctness
For all async calls, we should be consistently capturing non trivial
objects by const reference. This corrects bmcweb to be consistent and
capture errors by const value, and objects by const reference.
Tested: Code compiles. Trivial changes.
This saves about 300 bytes on our compressed binary size.
Signed-off-by: Ed Tanous <edtanous@google.com>
Change-Id: Ib3e0b6edef9803a1c480701556949488406305d4
diff --git a/include/hostname_monitor.hpp b/include/hostname_monitor.hpp
index 17fbe51..65a5c1c 100644
--- a/include/hostname_monitor.hpp
+++ b/include/hostname_monitor.hpp
@@ -16,7 +16,7 @@
inline void installCertificate(const std::filesystem::path& certPath)
{
crow::connections::systemBus->async_method_call(
- [certPath](boost::system::error_code ec) {
+ [certPath](const boost::system::error_code ec) {
if (ec)
{
BMCWEB_LOG_ERROR << "Replace Certificate Fail..";
diff --git a/include/openbmc_dbus_rest.hpp b/include/openbmc_dbus_rest.hpp
index 78853a5..09bbd60 100644
--- a/include/openbmc_dbus_rest.hpp
+++ b/include/openbmc_dbus_rest.hpp
@@ -1611,7 +1611,7 @@
{
crow::connections::systemBus->async_method_call(
[asyncResp](const boost::system::error_code ec,
- std::vector<std::string>& objectPaths) {
+ const std::vector<std::string>& objectPaths) {
if (ec)
{
setErrorResponse(asyncResp->res,
@@ -1622,7 +1622,7 @@
{
asyncResp->res.jsonValue = {{"status", "ok"},
{"message", "200 OK"},
- {"data", std::move(objectPaths)}};
+ {"data", objectPaths}};
}
},
"xyz.openbmc_project.ObjectMapper",
@@ -1642,12 +1642,12 @@
crow::connections::systemBus->async_method_call(
[objectPath, asyncResp](const boost::system::error_code ec,
- GetSubTreeType& objectNames) {
+ const GetSubTreeType& objectNames) {
auto transaction = std::make_shared<InProgressEnumerateData>(
objectPath, asyncResp);
transaction->subtree =
- std::make_shared<GetSubTreeType>(std::move(objectNames));
+ std::make_shared<GetSubTreeType>(objectNames);
if (ec)
{
diff --git a/redfish-core/lib/certificate_service.hpp b/redfish-core/lib/certificate_service.hpp
index 89fad8c..fa9cc2f 100644
--- a/redfish-core/lib/certificate_service.hpp
+++ b/redfish-core/lib/certificate_service.hpp
@@ -468,7 +468,7 @@
}
});
crow::connections::systemBus->async_method_call(
- [asyncResp](const boost::system::error_code& ec,
+ [asyncResp](const boost::system::error_code ec,
const std::string&) {
if (ec)
{
diff --git a/redfish-core/lib/ethernet.hpp b/redfish-core/lib/ethernet.hpp
index 1097aec..049f9a6 100644
--- a/redfish-core/lib/ethernet.hpp
+++ b/redfish-core/lib/ethernet.hpp
@@ -1683,13 +1683,13 @@
crow::connections::systemBus->async_method_call(
[health](const boost::system::error_code ec,
- std::vector<std::string>& resp) {
+ const std::vector<std::string>& resp) {
if (ec)
{
return;
}
- health->inventory = std::move(resp);
+ health->inventory = resp;
},
"xyz.openbmc_project.ObjectMapper",
"/xyz/openbmc_project/object_mapper",
diff --git a/redfish-core/lib/health.hpp b/redfish-core/lib/health.hpp
index 71da99e..9a4cd6c 100644
--- a/redfish-core/lib/health.hpp
+++ b/redfish-core/lib/health.hpp
@@ -184,13 +184,13 @@
std::shared_ptr<HealthPopulate> self = shared_from_this();
crow::connections::systemBus->async_method_call(
[self](const boost::system::error_code ec,
- std::vector<std::string>& resp) {
+ const std::vector<std::string>& resp) {
if (ec || resp.size() != 1)
{
// no global item, or too many
return;
}
- self->globalInventoryPath = std::move(resp[0]);
+ self->globalInventoryPath = resp[0];
},
"xyz.openbmc_project.ObjectMapper",
"/xyz/openbmc_project/object_mapper",
@@ -204,11 +204,12 @@
std::shared_ptr<HealthPopulate> self = shared_from_this();
crow::connections::systemBus->async_method_call(
[self](const boost::system::error_code ec,
- dbus::utility::ManagedObjectType& resp) {
+ const dbus::utility::ManagedObjectType& resp) {
if (ec)
{
return;
}
+ dbus::utility::ManagedObjectType copy = resp;
for (auto it = resp.begin(); it != resp.end();)
{
if (boost::ends_with(it->first.str, "critical") ||
@@ -217,9 +218,9 @@
it++;
continue;
}
- it = resp.erase(it);
+ it = copy.erase(it);
}
- self->statuses = std::move(resp);
+ self->statuses = std::move(copy);
},
"xyz.openbmc_project.ObjectMapper", "/",
"org.freedesktop.DBus.ObjectManager", "GetManagedObjects");
diff --git a/redfish-core/lib/log_services.hpp b/redfish-core/lib/log_services.hpp
index 0bfd15e..ddd124b 100644
--- a/redfish-core/lib/log_services.hpp
+++ b/redfish-core/lib/log_services.hpp
@@ -1363,7 +1363,7 @@
// Make call to Logging Service to find all log entry objects
crow::connections::systemBus->async_method_call(
[asyncResp](const boost::system::error_code ec,
- dbus::utility::ManagedObjectType& resp) {
+ const dbus::utility::ManagedObjectType& resp) {
if (ec)
{
// TODO Handle for specific error code
@@ -1378,12 +1378,12 @@
entriesArray = nlohmann::json::array();
for (auto& objectPath : resp)
{
- uint32_t* id = nullptr;
+ const uint32_t* id = nullptr;
std::time_t timestamp{};
std::time_t updateTimestamp{};
- std::string* severity = nullptr;
- std::string* message = nullptr;
- std::string* filePath = nullptr;
+ const std::string* severity = nullptr;
+ const std::string* message = nullptr;
+ const std::string* filePath = nullptr;
bool resolved = false;
for (auto& interfaceMap : objectPath.second)
{
@@ -1434,8 +1434,9 @@
}
else if (propertyMap.first == "Resolved")
{
- bool* resolveptr = std::get_if<bool>(
- &propertyMap.second);
+ const bool* resolveptr =
+ std::get_if<bool>(
+ &propertyMap.second);
if (resolveptr == nullptr)
{
messages::internalError(
@@ -1528,7 +1529,7 @@
// Make call to Logging Service to find all log entry objects
crow::connections::systemBus->async_method_call(
[asyncResp, entryID](const boost::system::error_code ec,
- GetManagedPropertyType& resp) {
+ const GetManagedPropertyType& resp) {
if (ec.value() == EBADR)
{
messages::resourceNotFound(
@@ -1543,12 +1544,12 @@
messages::internalError(asyncResp->res);
return;
}
- uint32_t* id = nullptr;
+ const uint32_t* id = nullptr;
std::time_t timestamp{};
std::time_t updateTimestamp{};
- std::string* severity = nullptr;
- std::string* message = nullptr;
- std::string* filePath = nullptr;
+ const std::string* severity = nullptr;
+ const std::string* message = nullptr;
+ const std::string* filePath = nullptr;
bool resolved = false;
for (auto& propertyMap : resp)
@@ -1590,7 +1591,7 @@
}
else if (propertyMap.first == "Resolved")
{
- bool* resolveptr =
+ const bool* resolveptr =
std::get_if<bool>(&propertyMap.second);
if (resolveptr == nullptr)
{
diff --git a/redfish-core/lib/managers.hpp b/redfish-core/lib/managers.hpp
index 79ce368..a48fd77 100644
--- a/redfish-core/lib/managers.hpp
+++ b/redfish-core/lib/managers.hpp
@@ -1366,7 +1366,7 @@
// interface gets more traction
crow::connections::systemBus->async_method_call(
[self](const boost::system::error_code ec,
- dbus::utility::ManagedObjectType& mObj) {
+ const dbus::utility::ManagedObjectType& mObj) {
if (ec)
{
BMCWEB_LOG_ERROR << "Error communicating to Entity Manager";
@@ -1390,7 +1390,7 @@
}
}
}
- self->managedObj = std::move(mObj);
+ self->managedObj = mObj;
},
"xyz.openbmc_project.EntityManager", "/", objectManagerIface,
"GetManagedObjects");
diff --git a/redfish-core/lib/processor.hpp b/redfish-core/lib/processor.hpp
index cdeb4a0..1155000 100644
--- a/redfish-core/lib/processor.hpp
+++ b/redfish-core/lib/processor.hpp
@@ -832,7 +832,7 @@
const std::string& objPath)
{
crow::connections::systemBus->async_method_call(
- [aResp](boost::system::error_code ec,
+ [aResp](const boost::system::error_code ec,
const OperatingConfigProperties& properties) {
if (ec)
{
@@ -1053,8 +1053,8 @@
// Set the property, with handler to check error responses
crow::connections::systemBus->async_method_call(
- [resp, appliedConfigUri](boost::system::error_code ec,
- sdbusplus::message::message& msg) {
+ [resp, appliedConfigUri](const boost::system::error_code ec,
+ const sdbusplus::message::message& msg) {
handleAppliedConfigResponse(resp, appliedConfigUri, ec, msg);
},
*controlService, cpuObjectPath, "org.freedesktop.DBus.Properties",
diff --git a/redfish-core/lib/systems.hpp b/redfish-core/lib/systems.hpp
index e98e1e2..2605c3f 100644
--- a/redfish-core/lib/systems.hpp
+++ b/redfish-core/lib/systems.hpp
@@ -1135,7 +1135,7 @@
"xyz.openbmc_project.Control.Boot.RebootAttempts",
"AttemptsLeft",
[aResp](const boost::system::error_code ec2,
- uint32_t autoRebootAttemptsLeft) {
+ const uint32_t autoRebootAttemptsLeft) {
if (ec2)
{
BMCWEB_LOG_DEBUG << "D-BUS response error " << ec2;
@@ -2208,7 +2208,7 @@
BMCWEB_LOG_DEBUG << "Get host watchodg";
crow::connections::systemBus->async_method_call(
[aResp](const boost::system::error_code ec,
- PropertiesType& properties) {
+ const PropertiesType& properties) {
if (ec)
{
// watchdog service is stopped
@@ -2957,14 +2957,14 @@
auto health = std::make_shared<HealthPopulate>(asyncResp);
crow::connections::systemBus->async_method_call(
[health](const boost::system::error_code ec,
- std::vector<std::string>& resp) {
+ const std::vector<std::string>& resp) {
if (ec)
{
// no inventory
return;
}
- health->inventory = std::move(resp);
+ health->inventory = resp;
},
"xyz.openbmc_project.ObjectMapper",
"/xyz/openbmc_project/object_mapper",
diff --git a/redfish-core/lib/virtual_media.hpp b/redfish-core/lib/virtual_media.hpp
index 844b60d..a682486 100644
--- a/redfish-core/lib/virtual_media.hpp
+++ b/redfish-core/lib/virtual_media.hpp
@@ -223,8 +223,9 @@
BMCWEB_LOG_DEBUG << "Get Virtual Media resource data.";
crow::connections::systemBus->async_method_call(
- [resName, name, aResp](const boost::system::error_code ec,
- dbus::utility::ManagedObjectType& subtree) {
+ [resName, name,
+ aResp](const boost::system::error_code ec,
+ const dbus::utility::ManagedObjectType& subtree) {
if (ec)
{
BMCWEB_LOG_DEBUG << "DBUS response error";
@@ -232,7 +233,7 @@
return;
}
- for (auto& item : subtree)
+ for (const auto& item : subtree)
{
std::string thispath = item.first.filename();
if (thispath.empty())