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>
diff --git a/http/app.hpp b/http/app.hpp
index 1a7af83..eeb331e 100644
--- a/http/app.hpp
+++ b/http/app.hpp
@@ -63,7 +63,7 @@
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 0ed4777..49a9cba 100644
--- a/http/logging.hpp
+++ b/http/logging.hpp
@@ -182,7 +182,7 @@
}
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 921bfe8..7872b76 100644
--- a/http/routing.hpp
+++ b/http/routing.hpp
@@ -605,7 +605,7 @@
// 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 2ef8412..4262c70 100644
--- a/http/websocket.hpp
+++ b/http/websocket.hpp
@@ -36,11 +36,9 @@
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 @@
});
}
- 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 @@
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 805fbad..798c3e8 100644
--- a/include/async_resolve.hpp
+++ b/include/async_resolve.hpp
@@ -83,7 +83,7 @@
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 b2bb1e3..a58f9be 100644
--- a/include/dbus_privileges.hpp
+++ b/include/dbus_privileges.hpp
@@ -109,7 +109,7 @@
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 @@
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 933d733..c06ba9e 100644
--- a/include/dbus_utility.hpp
+++ b/include/dbus_utility.hpp
@@ -147,7 +147,7 @@
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 9dd2405..00c5e36 100644
--- a/include/google/google_service_root.hpp
+++ b/include/google/google_service_root.hpp
@@ -104,8 +104,7 @@
"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 6d1f8d1..410a289 100644
--- a/redfish-core/include/utils/chassis_utils.hpp
+++ b/redfish-core/include/utils/chassis_utils.hpp
@@ -29,7 +29,7 @@
// 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 3a1869f..47fb58d 100644
--- a/redfish-core/lib/account_service.hpp
+++ b/redfish-core/lib/account_service.hpp
@@ -513,7 +513,7 @@
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 2d538d7..876bc2e 100644
--- a/redfish-core/lib/ethernet.hpp
+++ b/redfish-core/lib/ethernet.hpp
@@ -1111,7 +1111,7 @@
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 @@
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 1a3d6cb..2b3714b 100644
--- a/redfish-core/lib/hypervisor_system.hpp
+++ b/redfish-core/lib/hypervisor_system.hpp
@@ -315,7 +315,7 @@
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 6ea165d..f27785d 100644
--- a/redfish-core/lib/log_services.hpp
+++ b/redfish-core/lib/log_services.hpp
@@ -960,7 +960,7 @@
}
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 31fc5af..d864e22 100644
--- a/redfish-core/lib/network_protocol.hpp
+++ b/redfish-core/lib/network_protocol.hpp
@@ -101,7 +101,7 @@
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 e8da219..9392916 100644
--- a/redfish-core/lib/pcie.hpp
+++ b/redfish-core/lib/pcie.hpp
@@ -221,7 +221,7 @@
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 7a96481..5d8c0e6 100644
--- a/redfish-core/lib/redfish_util.hpp
+++ b/redfish-core/lib/redfish_util.hpp
@@ -69,7 +69,7 @@
"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 @@
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 @@
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 8506185..75eaa7c 100644
--- a/redfish-core/lib/sensors.hpp
+++ b/redfish-core/lib/sensors.hpp
@@ -361,7 +361,7 @@
// 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 @@
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 @@
// 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 @@
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 @@
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 @@
// 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 @@
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 @@
// 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 @@
// 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 @@
// 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 @@
// 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 @@
{
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 @@
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 9784d37..b03f323 100644
--- a/redfish-core/lib/virtual_media.hpp
+++ b/redfish-core/lib/virtual_media.hpp
@@ -98,9 +98,9 @@
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");