summaryrefslogtreecommitdiff
path: root/redfish-core/lib/sensors.hpp
diff options
context:
space:
mode:
authorNan Zhou <nanzhoumails@gmail.com>2022-04-06 21:28:32 +0300
committerEd Tanous <ed@tanous.net>2022-04-08 20:40:54 +0300
commitbacb216228c45ca715163f4c81717b1af39889ab (patch)
tree441999807fa9c9eedd916ab78ea98408d97c0d3b /redfish-core/lib/sensors.hpp
parent0e2d06918f100d962763d19a08361f20adec4a5f (diff)
downloadbmcweb-bacb216228c45ca715163f4c81717b1af39889ab.tar.xz
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 <nanzhoumails@gmail.com> Change-Id: Ib3bd6d4249df97c4be5afcd1393477ed424f5de8
Diffstat (limited to 'redfish-core/lib/sensors.hpp')
-rw-r--r--redfish-core/lib/sensors.hpp73
1 files changed, 36 insertions, 37 deletions
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<SensorsAsyncResp>& asyncResp,
+ const std::shared_ptr<boost::container::flat_set<std::string>>& 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/<str>/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<std::string>>&
- 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";
});
}