diff options
author | Ed Tanous <ed@tanous.net> | 2024-03-28 02:31:46 +0300 |
---|---|---|
committer | Ed Tanous <ed@tanous.net> | 2024-04-07 21:09:42 +0300 |
commit | 8cb2c024c4625e2fe2f0b107a865faffcd4bb770 (patch) | |
tree | 252d85214747ab3b9ae784b08b0f07ec31ea0c13 | |
parent | dce4d230c52978fc258ee3bc31117389d9c25388 (diff) | |
download | bmcweb-8cb2c024c4625e2fe2f0b107a865faffcd4bb770.tar.xz |
Fix moves/forward
Clang has new checks for std::move/std::forward correctness, which
catches quite a few "wrong" things where we were making copies of
callback handlers.
Unfortunately, the lambda syntax of
callback{std::forward<Callback>(callback)}
in a capture confuses it, so change usages to
callback = std::forward<Callback>(callback)
to be consistent.
Tested: Redfish service validator passes.
Change-Id: I7a111ec00cf78ecb7d5f5b102c786c1c14d74384
Signed-off-by: Ed Tanous <ed@tanous.net>
-rw-r--r-- | http/app.hpp | 2 | ||||
-rw-r--r-- | http/logging.hpp | 2 | ||||
-rw-r--r-- | http/routing.hpp | 2 | ||||
-rw-r--r-- | http/websocket.hpp | 18 | ||||
-rw-r--r-- | include/async_resolve.hpp | 2 | ||||
-rw-r--r-- | include/dbus_privileges.hpp | 4 | ||||
-rw-r--r-- | include/dbus_utility.hpp | 2 | ||||
-rw-r--r-- | include/google/google_service_root.hpp | 3 | ||||
-rw-r--r-- | redfish-core/include/utils/chassis_utils.hpp | 2 | ||||
-rw-r--r-- | redfish-core/lib/account_service.hpp | 2 | ||||
-rw-r--r-- | redfish-core/lib/ethernet.hpp | 4 | ||||
-rw-r--r-- | redfish-core/lib/hypervisor_system.hpp | 2 | ||||
-rw-r--r-- | redfish-core/lib/log_services.hpp | 2 | ||||
-rw-r--r-- | redfish-core/lib/network_protocol.hpp | 2 | ||||
-rw-r--r-- | redfish-core/lib/pcie.hpp | 2 | ||||
-rw-r--r-- | redfish-core/lib/redfish_util.hpp | 6 | ||||
-rw-r--r-- | redfish-core/lib/sensors.hpp | 33 | ||||
-rw-r--r-- | redfish-core/lib/virtual_media.hpp | 6 |
18 files changed, 39 insertions, 57 deletions
diff --git a/http/app.hpp b/http/app.hpp index 1a7af83241..eeb331ea96 100644 --- a/http/app.hpp +++ b/http/app.hpp @@ -63,7 +63,7 @@ class App router.handle(req, asyncResp); } - DynamicRule& routeDynamic(std::string&& rule) + DynamicRule& routeDynamic(const std::string& rule) { return router.newRuleDynamic(rule); } diff --git a/http/logging.hpp b/http/logging.hpp index 0ed47771c4..49a9cbaaf0 100644 --- a/http/logging.hpp +++ b/http/logging.hpp @@ -182,7 +182,7 @@ const void* logPtr(T p) } template <LogLevel level> -inline void vlog(const FormatString& format, std::format_args&& args) +inline void vlog(const FormatString& format, const std::format_args& args) { if constexpr (bmcwebCurrentLoggingLevel < level) { diff --git a/http/routing.hpp b/http/routing.hpp index 921bfe8dc0..7872b76cb5 100644 --- a/http/routing.hpp +++ b/http/routing.hpp @@ -605,7 +605,7 @@ class Router // appear to work with the std::move on adaptor. validatePrivilege( req, asyncResp, rule, - [&rule, asyncResp, adaptor(std::forward<Adaptor>(adaptor))]( + [&rule, asyncResp, adaptor = std::forward<Adaptor>(adaptor)]( Request& thisReq) mutable { rule.handleUpgrade(thisReq, asyncResp, std::move(adaptor)); }); diff --git a/http/websocket.hpp b/http/websocket.hpp index 2ef8412886..4262c70a5c 100644 --- a/http/websocket.hpp +++ b/http/websocket.hpp @@ -36,11 +36,9 @@ struct Connection : std::enable_shared_from_this<Connection> Connection& operator=(const Connection&&) = delete; virtual void sendBinary(std::string_view msg) = 0; - virtual void sendBinary(std::string&& msg) = 0; virtual void sendEx(MessageType type, std::string_view msg, std::function<void()>&& onDone) = 0; virtual void sendText(std::string_view msg) = 0; - virtual void sendText(std::string&& msg) = 0; virtual void close(std::string_view msg = "quit") = 0; virtual void deferRead() = 0; virtual void resumeRead() = 0; @@ -181,14 +179,6 @@ class ConnectionImpl : public Connection }); } - void sendBinary(std::string&& msg) override - { - ws.binary(true); - outBuffer.commit(boost::asio::buffer_copy(outBuffer.prepare(msg.size()), - boost::asio::buffer(msg))); - doWrite(); - } - void sendText(std::string_view msg) override { ws.text(true); @@ -197,14 +187,6 @@ class ConnectionImpl : public Connection doWrite(); } - void sendText(std::string&& msg) override - { - ws.text(true); - outBuffer.commit(boost::asio::buffer_copy(outBuffer.prepare(msg.size()), - boost::asio::buffer(msg))); - doWrite(); - } - void close(std::string_view msg) override { ws.async_close( diff --git a/include/async_resolve.hpp b/include/async_resolve.hpp index 805fbad124..798c3e8964 100644 --- a/include/async_resolve.hpp +++ b/include/async_resolve.hpp @@ -83,7 +83,7 @@ class Resolver uint64_t flag = 0; crow::connections::systemBus->async_method_call( [host{std::string(host)}, portNum, - handler{std::forward<ResolveHandler>(handler)}]( + handler = std::forward<ResolveHandler>(handler)]( const boost::system::error_code& ec, const std::vector< std::tuple<int32_t, int32_t, std::vector<uint8_t>>>& resp, diff --git a/include/dbus_privileges.hpp b/include/dbus_privileges.hpp index b2bb1e3b70..a58f9bebd0 100644 --- a/include/dbus_privileges.hpp +++ b/include/dbus_privileges.hpp @@ -109,7 +109,7 @@ inline bool template <typename CallbackFn> void afterGetUserInfo(Request& req, const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, - BaseRule& rule, CallbackFn&& callback, + BaseRule& rule, CallbackFn callback, const boost::system::error_code& ec, const dbus::utility::DBusPropertiesMap& userInfoMap) { @@ -151,7 +151,7 @@ void validatePrivilege(Request& req, std::string username = req.session->username; crow::connections::systemBus->async_method_call( [req{std::move(req)}, asyncResp, &rule, - callback(std::forward<CallbackFn>(callback))]( + callback = std::forward<CallbackFn>(callback)]( const boost::system::error_code& ec, const dbus::utility::DBusPropertiesMap& userInfoMap) mutable { afterGetUserInfo(req, asyncResp, rule, diff --git a/include/dbus_utility.hpp b/include/dbus_utility.hpp index 933d733f96..c06ba9eae6 100644 --- a/include/dbus_utility.hpp +++ b/include/dbus_utility.hpp @@ -147,7 +147,7 @@ template <typename Callback> inline void checkDbusPathExists(const std::string& path, Callback&& callback) { crow::connections::systemBus->async_method_call( - [callback{std::forward<Callback>(callback)}]( + [callback = std::forward<Callback>(callback)]( const boost::system::error_code& ec, const dbus::utility::MapperGetObject& objectNames) { callback(!ec && !objectNames.empty()); diff --git a/include/google/google_service_root.hpp b/include/google/google_service_root.hpp index 9dd2405738..00c5e36736 100644 --- a/include/google/google_service_root.hpp +++ b/include/google/google_service_root.hpp @@ -104,8 +104,7 @@ inline void resolveRoT(const std::string& command, "xyz.openbmc_project.Control.Hoth"}; dbus::utility::getSubTree( "/xyz/openbmc_project", 0, hothIfaces, - [command, asyncResp, rotId, - entityHandler{std::forward<ResolvedEntityHandler>(entityHandler)}]( + [command, asyncResp, rotId, entityHandler{std::move(entityHandler)}]( const boost::system::error_code& ec, const dbus::utility::MapperGetSubTreeResponse& subtree) { hothGetSubtreeCallback(command, asyncResp, rotId, entityHandler, ec, diff --git a/redfish-core/include/utils/chassis_utils.hpp b/redfish-core/include/utils/chassis_utils.hpp index 6d1f8d1572..410a28990d 100644 --- a/redfish-core/include/utils/chassis_utils.hpp +++ b/redfish-core/include/utils/chassis_utils.hpp @@ -29,7 +29,7 @@ void getValidChassisPath(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, // Get the Chassis Collection dbus::utility::getSubTreePaths( "/xyz/openbmc_project/inventory", 0, interfaces, - [callback{std::forward<Callback>(callback)}, asyncResp, + [callback = std::forward<Callback>(callback), asyncResp, chassisId](const boost::system::error_code& ec, const dbus::utility::MapperGetSubTreePathsResponse& chassisPaths) mutable { diff --git a/redfish-core/lib/account_service.hpp b/redfish-core/lib/account_service.hpp index 3a1869f095..47fb58d902 100644 --- a/redfish-core/lib/account_service.hpp +++ b/redfish-core/lib/account_service.hpp @@ -513,7 +513,7 @@ inline void getLDAPConfigData(const std::string& ldapType, dbus::utility::getDbusObject( ldapConfigObjectName, interfaces, - [callback, + [callback = std::forward<CallbackFunc>(callback), ldapType](const boost::system::error_code& ec, const dbus::utility::MapperGetObject& resp) mutable { if (ec || resp.empty()) diff --git a/redfish-core/lib/ethernet.hpp b/redfish-core/lib/ethernet.hpp index 2d538d7f1f..876bc2edb4 100644 --- a/redfish-core/lib/ethernet.hpp +++ b/redfish-core/lib/ethernet.hpp @@ -1111,7 +1111,7 @@ void getEthernetIfaceData(const std::string& ethifaceId, dbus::utility::getManagedObjects( "xyz.openbmc_project.Network", path, [ethifaceId{std::string{ethifaceId}}, - callback{std::forward<CallbackFunc>(callback)}]( + callback = std::forward<CallbackFunc>(callback)]( const boost::system::error_code& ec, const dbus::utility::ManagedObjectType& resp) mutable { EthernetInterfaceData ethData{}; @@ -1166,7 +1166,7 @@ void getEthernetIfaceList(CallbackFunc&& callback) sdbusplus::message::object_path path("/xyz/openbmc_project/network"); dbus::utility::getManagedObjects( "xyz.openbmc_project.Network", path, - [callback{std::forward<CallbackFunc>(callback)}]( + [callback = std::forward<CallbackFunc>(callback)]( const boost::system::error_code& ec, const dbus::utility::ManagedObjectType& resp) { // Callback requires vector<string> to retrieve all available diff --git a/redfish-core/lib/hypervisor_system.hpp b/redfish-core/lib/hypervisor_system.hpp index 1a3d6cbb54..2b3714bae4 100644 --- a/redfish-core/lib/hypervisor_system.hpp +++ b/redfish-core/lib/hypervisor_system.hpp @@ -315,7 +315,7 @@ void getHypervisorIfaceData(const std::string& ethIfaceId, dbus::utility::getManagedObjects( "xyz.openbmc_project.Settings", path, [ethIfaceId{std::string{ethIfaceId}}, - callback{std::forward<CallbackFunc>(callback)}]( + callback = std::forward<CallbackFunc>(callback)]( const boost::system::error_code& ec, const dbus::utility::ManagedObjectType& resp) mutable { EthernetInterfaceData ethData{}; diff --git a/redfish-core/lib/log_services.hpp b/redfish-core/lib/log_services.hpp index 6ea165d799..f27785d78f 100644 --- a/redfish-core/lib/log_services.hpp +++ b/redfish-core/lib/log_services.hpp @@ -960,7 +960,7 @@ inline void createDumpTaskCallback( } crow::connections::systemBus->async_method_call( - [asyncResp, payload, createdObjPath, + [asyncResp, payload = std::move(payload), createdObjPath, dumpEntryPath{std::move(dumpEntryPath)}, dumpId](const boost::system::error_code& ec, const std::string& introspectXml) { diff --git a/redfish-core/lib/network_protocol.hpp b/redfish-core/lib/network_protocol.hpp index 31fc5afc04..d864e222d6 100644 --- a/redfish-core/lib/network_protocol.hpp +++ b/redfish-core/lib/network_protocol.hpp @@ -101,7 +101,7 @@ void getEthernetIfaceData(CallbackFunc&& callback) sdbusplus::message::object_path path("/xyz/openbmc_project/network"); dbus::utility::getManagedObjects( "xyz.openbmc_project.Network", path, - [callback{std::forward<CallbackFunc>(callback)}]( + [callback = std::forward<CallbackFunc>(callback)]( const boost::system::error_code& ec, const dbus::utility::ManagedObjectType& dbusData) { std::vector<std::string> ntpServers; diff --git a/redfish-core/lib/pcie.hpp b/redfish-core/lib/pcie.hpp index e8da2195a8..9392916c47 100644 --- a/redfish-core/lib/pcie.hpp +++ b/redfish-core/lib/pcie.hpp @@ -221,7 +221,7 @@ inline void getPCIeDeviceSlotPath( dbus::utility::getAssociatedSubTreePaths( associationPath, sdbusplus::message::object_path(inventoryPath), 0, pcieSlotInterface, - [callback, asyncResp, pcieDevicePath]( + [callback = std::move(callback), asyncResp, pcieDevicePath]( const boost::system::error_code& ec, const dbus::utility::MapperGetSubTreePathsResponse& endpoints) { if (ec) diff --git a/redfish-core/lib/redfish_util.hpp b/redfish-core/lib/redfish_util.hpp index 7a96481782..5d8c0e6670 100644 --- a/redfish-core/lib/redfish_util.hpp +++ b/redfish-core/lib/redfish_util.hpp @@ -69,7 +69,7 @@ void getMainChassisId(std::shared_ptr<bmcweb::AsyncResp> asyncResp, "xyz.openbmc_project.Inventory.Item.Chassis"}; dbus::utility::getSubTree( "/xyz/openbmc_project/inventory", 0, interfaces, - [callback, + [callback = std::forward<CallbackFunc>(callback), asyncResp](const boost::system::error_code& ec, const dbus::utility::MapperGetSubTreeResponse& subtree) { if (ec) @@ -104,7 +104,7 @@ void getPortStatusAndPath( CallbackFunc&& callback) { crow::connections::systemBus->async_method_call( - [protocolToDBus, callback{std::forward<CallbackFunc>(callback)}]( + [protocolToDBus, callback = std::forward<CallbackFunc>(callback)]( const boost::system::error_code& ec, const std::vector<UnitStruct>& r) { std::vector<std::tuple<std::string, std::string, bool>> socketData; @@ -211,7 +211,7 @@ void getPortNumber(const std::string& socketPath, CallbackFunc&& callback) std::vector<std::tuple<std::string, std::string>>>( *crow::connections::systemBus, "org.freedesktop.systemd1", socketPath, "org.freedesktop.systemd1.Socket", "Listen", - [callback{std::forward<CallbackFunc>(callback)}]( + [callback = std::forward<CallbackFunc>(callback)]( const boost::system::error_code& ec, const std::vector<std::tuple<std::string, std::string>>& resp) { if (ec) diff --git a/redfish-core/lib/sensors.hpp b/redfish-core/lib/sensors.hpp index 8506185e8d..75eaa7cde1 100644 --- a/redfish-core/lib/sensors.hpp +++ b/redfish-core/lib/sensors.hpp @@ -361,7 +361,7 @@ void getObjectsWithConnection( // Make call to ObjectMapper to find all sensors objects dbus::utility::getSubTree( path, 2, interfaces, - [callback{std::forward<Callback>(callback)}, sensorsAsyncResp, + [callback = std::forward<Callback>(callback), sensorsAsyncResp, sensorNames](const boost::system::error_code& ec, const dbus::utility::MapperGetSubTreeResponse& subtree) { // Response handler for parsing objects subtree @@ -423,9 +423,10 @@ void getConnections(std::shared_ptr<SensorsAsyncResp> sensorsAsyncResp, Callback&& callback) { auto objectsWithConnectionCb = - [callback](const std::set<std::string>& connections, - const std::set<std::pair<std::string, std::string>>& - /*objectsWithConnection*/) { callback(connections); }; + [callback = std::forward<Callback>(callback)]( + const std::set<std::string>& connections, + const std::set<std::pair<std::string, std::string>>& + /*objectsWithConnection*/) { callback(connections); }; getObjectsWithConnection(sensorsAsyncResp, sensorNames, std::move(objectsWithConnectionCb)); } @@ -524,7 +525,7 @@ void getChassis(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, // Get the Chassis Collection dbus::utility::getSubTreePaths( "/xyz/openbmc_project/inventory", 0, interfaces, - [callback{std::forward<Callback>(callback)}, asyncResp, + [callback = std::forward<Callback>(callback), asyncResp, chassisIdStr{std::string(chassisId)}, chassisSubNode{std::string(chassisSubNode)}, sensorTypes]( const boost::system::error_code& ec, @@ -567,7 +568,7 @@ void getChassis(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, dbus::utility::getAssociationEndPoints( sensorPath, [asyncResp, chassisSubNode, sensorTypes, - callback{std::forward<const Callback>(callback)}]( + callback = std::forward<const Callback>(callback)]( const boost::system::error_code& ec2, const dbus::utility::MapperEndPoints& nodeSensorList) { if (ec2) @@ -1474,7 +1475,7 @@ static void getInventoryItemsData( dbus::utility::getManagedObjects( invConnection, path, [sensorsAsyncResp, inventoryItems, invConnections, - callback{std::forward<Callback>(callback)}, invConnectionsIndex]( + callback = std::forward<Callback>(callback), invConnectionsIndex]( const boost::system::error_code& ec, const dbus::utility::ManagedObjectType& resp) { BMCWEB_LOG_DEBUG("getInventoryItemsData respHandler enter"); @@ -1550,7 +1551,7 @@ static void getInventoryItemsConnections( // Make call to ObjectMapper to find all inventory items dbus::utility::getSubTree( path, 0, interfaces, - [callback{std::forward<Callback>(callback)}, sensorsAsyncResp, + [callback = std::forward<Callback>(callback), sensorsAsyncResp, inventoryItems]( const boost::system::error_code& ec, const dbus::utility::MapperGetSubTreeResponse& subtree) { @@ -1626,7 +1627,7 @@ static void getInventoryItemAssociations( sdbusplus::message::object_path path("/"); dbus::utility::getManagedObjects( "xyz.openbmc_project.ObjectMapper", path, - [callback{std::forward<Callback>(callback)}, sensorsAsyncResp, + [callback = std::forward<Callback>(callback), sensorsAsyncResp, sensorNames](const boost::system::error_code& ec, const dbus::utility::ManagedObjectType& resp) { BMCWEB_LOG_DEBUG("getInventoryItemAssociations respHandler enter"); @@ -1795,7 +1796,7 @@ void getInventoryLedData( // Response handler for Get State property auto respHandler = [sensorsAsyncResp, inventoryItems, ledConnections, ledPath, - callback{std::forward<Callback>(callback)}, ledConnectionsIndex]( + callback = std::forward<Callback>(callback), ledConnectionsIndex]( const boost::system::error_code& ec, const std::string& state) { BMCWEB_LOG_DEBUG("getInventoryLedData respHandler enter"); if (ec) @@ -1886,7 +1887,7 @@ void getInventoryLeds( // Make call to ObjectMapper to find all inventory items dbus::utility::getSubTree( path, 0, interfaces, - [callback{std::forward<Callback>(callback)}, sensorsAsyncResp, + [callback = std::forward<Callback>(callback), sensorsAsyncResp, inventoryItems]( const boost::system::error_code& ec, const dbus::utility::MapperGetSubTreeResponse& subtree) { @@ -1976,7 +1977,7 @@ void getPowerSupplyAttributesData( // Response handler for Get DeratingFactor property auto respHandler = [sensorsAsyncResp, inventoryItems, - callback{std::forward<Callback>(callback)}]( + callback = std::forward<Callback>(callback)]( const boost::system::error_code& ec, const uint32_t value) { BMCWEB_LOG_DEBUG("getPowerSupplyAttributesData respHandler enter"); @@ -2058,7 +2059,7 @@ void getPowerSupplyAttributes( // Make call to ObjectMapper to find the PowerSupplyAttributes service dbus::utility::getSubTree( "/xyz/openbmc_project", 0, interfaces, - [callback{std::forward<Callback>(callback)}, sensorsAsyncResp, + [callback = std::forward<Callback>(callback), sensorsAsyncResp, inventoryItems]( const boost::system::error_code& ec, const dbus::utility::MapperGetSubTreeResponse& subtree) { @@ -2142,12 +2143,12 @@ static void { BMCWEB_LOG_DEBUG("getInventoryItems enter"); auto getInventoryItemAssociationsCb = - [sensorsAsyncResp, callback{std::forward<Callback>(callback)}]( + [sensorsAsyncResp, callback = std::forward<Callback>(callback)]( std::shared_ptr<std::vector<InventoryItem>> inventoryItems) { BMCWEB_LOG_DEBUG("getInventoryItemAssociationsCb enter"); auto getInventoryItemsConnectionsCb = [sensorsAsyncResp, inventoryItems, - callback{std::forward<const Callback>(callback)}]( + callback = std::forward<const Callback>(callback)]( std::shared_ptr<std::set<std::string>> invConnections) { BMCWEB_LOG_DEBUG("getInventoryItemsConnectionsCb enter"); auto getInventoryItemsDataCb = [sensorsAsyncResp, inventoryItems, @@ -2778,7 +2779,7 @@ inline void retrieveUriToDbusMap(const std::string& chassis, auto asyncResp = std::make_shared<bmcweb::AsyncResp>(); auto callback = [asyncResp, - mapCompleteCb{std::forward<Callback>(mapComplete)}]( + mapCompleteCb = std::forward<Callback>(mapComplete)]( const boost::beast::http::status status, const std::map<std::string, std::string>& uriToDbus) { mapCompleteCb(status, uriToDbus); diff --git a/redfish-core/lib/virtual_media.hpp b/redfish-core/lib/virtual_media.hpp index 9784d37724..b03f323620 100644 --- a/redfish-core/lib/virtual_media.hpp +++ b/redfish-core/lib/virtual_media.hpp @@ -98,9 +98,9 @@ inline void sdbusplus::message::object_path path("/xyz/openbmc_project/VirtualMedia"); dbus::utility::getManagedObjects( service, path, - [service, resName, asyncResp, - handler](const boost::system::error_code& ec, - const dbus::utility::ManagedObjectType& subtree) { + [service, resName, asyncResp, handler = std::move(handler)]( + const boost::system::error_code& ec, + const dbus::utility::ManagedObjectType& subtree) { if (ec) { BMCWEB_LOG_DEBUG("DBUS response error"); |