From bacb216228c45ca715163f4c81717b1af39889ab Mon Sep 17 00:00:00 2001 From: Nan Zhou Date: Wed, 6 Apr 2022 11:28:32 -0700 Subject: sensors: move callback from lambda to inline functions with bind_front bind_front + function is more readable than local lambdas. Tested: Tested sensor collection, works as expected. Signed-off-by: Nan Zhou Change-Id: Ib3bd6d4249df97c4be5afcd1393477ed424f5de8 --- redfish-core/lib/sensors.hpp | 73 ++++++++++++++++++++++---------------------- 1 file changed, 36 insertions(+), 37 deletions(-) (limited to 'redfish-core/lib/sensors.hpp') diff --git a/redfish-core/lib/sensors.hpp b/redfish-core/lib/sensors.hpp index 25ac5e0448..2e314aca98 100644 --- a/redfish-core/lib/sensors.hpp +++ b/redfish-core/lib/sensors.hpp @@ -2921,6 +2921,39 @@ inline void retrieveUriToDbusMap(const std::string& chassis, getChassisData(resp); } +namespace sensors +{ +inline void getChassisCallback( + const std::shared_ptr& asyncResp, + const std::shared_ptr>& sensorNames) +{ + BMCWEB_LOG_DEBUG << "getChassisCallback enter"; + + nlohmann::json& entriesArray = + asyncResp->asyncResp->res.jsonValue["Members"]; + for (auto& sensor : *sensorNames) + { + BMCWEB_LOG_DEBUG << "Adding sensor: " << sensor; + + sdbusplus::message::object_path path(sensor); + std::string sensorName = path.filename(); + if (sensorName.empty()) + { + BMCWEB_LOG_ERROR << "Invalid sensor path: " << sensor; + messages::internalError(asyncResp->asyncResp->res); + return; + } + entriesArray.push_back( + {{"@odata.id", "/redfish/v1/Chassis/" + asyncResp->chassisId + "/" + + asyncResp->chassisSubNode + "/" + sensorName}}); + } + + asyncResp->asyncResp->res.jsonValue["Members@odata.count"] = + entriesArray.size(); + BMCWEB_LOG_DEBUG << "getChassisCallback exit"; +} +} // namespace sensors + inline void requestRoutesSensorCollection(App& app) { BMCWEB_ROUTE(app, "/redfish/v1/Chassis//Sensors/") @@ -2941,44 +2974,10 @@ inline void requestRoutesSensorCollection(App& app) aResp, chassisId, sensors::dbus::paths.at(sensors::node::sensors), sensors::node::sensors); - - auto getChassisCb = - [asyncResp](const std::shared_ptr< - boost::container::flat_set>& - sensorNames) { - BMCWEB_LOG_DEBUG << "getChassisCb enter"; - - nlohmann::json& entriesArray = - asyncResp->asyncResp->res.jsonValue["Members"]; - for (auto& sensor : *sensorNames) - { - BMCWEB_LOG_DEBUG << "Adding sensor: " << sensor; - - sdbusplus::message::object_path path(sensor); - std::string sensorName = path.filename(); - if (sensorName.empty()) - { - BMCWEB_LOG_ERROR << "Invalid sensor path: " - << sensor; - messages::internalError( - asyncResp->asyncResp->res); - return; - } - entriesArray.push_back( - {{"@odata.id", "/redfish/v1/Chassis/" + - asyncResp->chassisId + "/" + - asyncResp->chassisSubNode + - "/" + sensorName}}); - } - - asyncResp->asyncResp->res - .jsonValue["Members@odata.count"] = - entriesArray.size(); - BMCWEB_LOG_DEBUG << "getChassisCb exit"; - }; - // Get set of sensors in chassis - getChassis(asyncResp, std::move(getChassisCb)); + getChassis( + asyncResp, + std::bind_front(sensors::getChassisCallback, asyncResp)); BMCWEB_LOG_DEBUG << "SensorCollection doGet exit"; }); } -- cgit v1.2.3