diff options
author | Ed Tanous <edtanous@google.com> | 2022-01-07 22:38:34 +0300 |
---|---|---|
committer | Ed Tanous <ed@tanous.net> | 2022-01-10 20:36:54 +0300 |
commit | 914e2d5d5dbeddca9f48504256f7089efe86fc65 (patch) | |
tree | b9e60be35e5a15989b5d2d70038e9085dbd6e2bb | |
parent | 711ac7a931dd3f151fc4064063b5ea90404b9054 (diff) | |
download | bmcweb-914e2d5d5dbeddca9f48504256f7089efe86fc65.tar.xz |
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
-rw-r--r-- | include/hostname_monitor.hpp | 2 | ||||
-rw-r--r-- | include/openbmc_dbus_rest.hpp | 8 | ||||
-rw-r--r-- | redfish-core/lib/certificate_service.hpp | 2 | ||||
-rw-r--r-- | redfish-core/lib/ethernet.hpp | 4 | ||||
-rw-r--r-- | redfish-core/lib/health.hpp | 11 | ||||
-rw-r--r-- | redfish-core/lib/log_services.hpp | 27 | ||||
-rw-r--r-- | redfish-core/lib/managers.hpp | 4 | ||||
-rw-r--r-- | redfish-core/lib/processor.hpp | 6 | ||||
-rw-r--r-- | redfish-core/lib/systems.hpp | 8 | ||||
-rw-r--r-- | redfish-core/lib/virtual_media.hpp | 7 |
10 files changed, 41 insertions, 38 deletions
diff --git a/include/hostname_monitor.hpp b/include/hostname_monitor.hpp index 17fbe510c4..65a5c1c34a 100644 --- a/include/hostname_monitor.hpp +++ b/include/hostname_monitor.hpp @@ -16,7 +16,7 @@ static std::unique_ptr<sdbusplus::bus::match::match> hostnameSignalMonitor; 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 78853a5101..09bbd601a1 100644 --- a/include/openbmc_dbus_rest.hpp +++ b/include/openbmc_dbus_rest.hpp @@ -1611,7 +1611,7 @@ inline void handleList(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, { 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 @@ inline void handleList(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, { asyncResp->res.jsonValue = {{"status", "ok"}, {"message", "200 OK"}, - {"data", std::move(objectPaths)}}; + {"data", objectPaths}}; } }, "xyz.openbmc_project.ObjectMapper", @@ -1642,12 +1642,12 @@ inline void handleEnumerate(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 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 89fad8c174..fa9cc2fda8 100644 --- a/redfish-core/lib/certificate_service.hpp +++ b/redfish-core/lib/certificate_service.hpp @@ -468,7 +468,7 @@ inline void requestRoutesCertificateActionGenerateCSR(App& app) } }); 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 1097aec750..049f9a6d53 100644 --- a/redfish-core/lib/ethernet.hpp +++ b/redfish-core/lib/ethernet.hpp @@ -1683,13 +1683,13 @@ inline void parseInterfaceData( 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 71da99ec01..9a4cd6c815 100644 --- a/redfish-core/lib/health.hpp +++ b/redfish-core/lib/health.hpp @@ -184,13 +184,13 @@ struct HealthPopulate : std::enable_shared_from_this<HealthPopulate> 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 @@ struct HealthPopulate : std::enable_shared_from_this<HealthPopulate> 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 @@ struct HealthPopulate : std::enable_shared_from_this<HealthPopulate> 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 0bfd15e8e6..ddd124bb49 100644 --- a/redfish-core/lib/log_services.hpp +++ b/redfish-core/lib/log_services.hpp @@ -1363,7 +1363,7 @@ inline void requestRoutesDBusEventLogEntryCollection(App& app) // 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 @@ inline void requestRoutesDBusEventLogEntryCollection(App& app) 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 @@ inline void requestRoutesDBusEventLogEntryCollection(App& app) } 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 @@ inline void requestRoutesDBusEventLogEntry(App& app) // 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 @@ inline void requestRoutesDBusEventLogEntry(App& app) 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 @@ inline void requestRoutesDBusEventLogEntry(App& app) } 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 79ce368868..a48fd7715c 100644 --- a/redfish-core/lib/managers.hpp +++ b/redfish-core/lib/managers.hpp @@ -1366,7 +1366,7 @@ struct SetPIDValues : std::enable_shared_from_this<SetPIDValues> // 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 @@ struct SetPIDValues : std::enable_shared_from_this<SetPIDValues> } } } - 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 cdeb4a05b4..11550000a6 100644 --- a/redfish-core/lib/processor.hpp +++ b/redfish-core/lib/processor.hpp @@ -832,7 +832,7 @@ inline void 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 @@ inline void patchAppliedOperatingConfig( // 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 e98e1e2f20..2605c3f811 100644 --- a/redfish-core/lib/systems.hpp +++ b/redfish-core/lib/systems.hpp @@ -1135,7 +1135,7 @@ inline void getAutomaticRetry(const std::shared_ptr<bmcweb::AsyncResp>& aResp) "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 @@ inline void 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 @@ inline void requestRoutesSystems(App& app) 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 844b60d862..a682486a70 100644 --- a/redfish-core/lib/virtual_media.hpp +++ b/redfish-core/lib/virtual_media.hpp @@ -223,8 +223,9 @@ inline void getVmData(const std::shared_ptr<bmcweb::AsyncResp>& aResp, 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 @@ inline void getVmData(const std::shared_ptr<bmcweb::AsyncResp>& aResp, return; } - for (auto& item : subtree) + for (const auto& item : subtree) { std::string thispath = item.first.filename(); if (thispath.empty()) |