diff options
author | Nan Zhou <nanzhoumails@gmail.com> | 2022-06-01 07:47:45 +0300 |
---|---|---|
committer | Nan Zhou <nanzhoumails@gmail.com> | 2022-06-01 22:03:31 +0300 |
commit | de167a6f30c0f32683480e06c6e81cfc9d4eb37b (patch) | |
tree | 37dc92f208f41951691d86afc0db1ab9c39fce7d | |
parent | e6bd846d38bf7bb565b3f6a9aa8236543feb59f4 (diff) | |
download | bmcweb-de167a6f30c0f32683480e06c6e81cfc9d4eb37b.tar.xz |
SensorCollection: use inline functions+bind_front
This commit changes the `/redfish/v1/Chassis/<str>/Sensors/` route
to take std::bind_front instead of lambdas. We can clearly see the
indent levels decrease. It increases the readability.
Tested:
1. trivial change; code compiles.
2. tested on my local mock environment;
URL:/redfish/v1/Chassis/fake_chassis/Sensors/
Response:
{
"@odata.id": "/redfish/v1/Chassis/fake_chassis/Sensors",
"@odata.type": "#SensorCollection.SensorCollection",
"Description": "Collection of Sensors for this Chassis",
"Members": [
{
"@odata.id": "/redfish/v1/Chassis/fake_chassis/Sensors/sensor0"
},
{
"@odata.id": "/redfish/v1/Chassis/fake_chassis/Sensors/sensor1"
},
{
"@odata.id": "/redfish/v1/Chassis/fake_chassis/Sensors/sensor5"
},
{
"@odata.id": "/redfish/v1/Chassis/fake_chassis/Sensors/sensor6"
}
],
"Members@odata.count": 4,
"Name": "Sensors"
}
3. Service Validator Passes
*** /redfish/v1/Chassis/fake_chassis/Sensors
Type (SensorCollection.SensorCollection), GET SUCCESS (time: 0:00:00.002345)
Attempt 1 of /redfish/v1/Chassis/fake_chassis/Sensors/sensor0
Response Time for GET to /redfish/v1/Chassis/fake_chassis/Sensors/sensor0: 0.006815780187025666 seconds.
Attempt 1 of /redfish/v1/Chassis/fake_chassis/Sensors/sensor1
Response Time for GET to /redfish/v1/Chassis/fake_chassis/Sensors/sensor1: 0.004200570052489638 seconds.
Attempt 1 of /redfish/v1/Chassis/fake_chassis/Sensors/sensor5
Response Time for GET to /redfish/v1/Chassis/fake_chassis/Sensors/sensor5: 0.004602659028023481 seconds.
Attempt 1 of /redfish/v1/Chassis/fake_chassis/Sensors/sensor6
Response Time for GET to /redfish/v1/Chassis/fake_chassis/Sensors/sensor6: 0.00432420102879405 seconds.
PASS
Signed-off-by: Nan Zhou <nanzhoumails@gmail.com>
Change-Id: Ibdebd9b5427db5b42d5047367ae8548fa981ddea
-rw-r--r-- | redfish-core/lib/sensors.hpp | 81 |
1 files changed, 42 insertions, 39 deletions
diff --git a/redfish-core/lib/sensors.hpp b/redfish-core/lib/sensors.hpp index e1e25d576e..b09b582cb0 100644 --- a/redfish-core/lib/sensors.hpp +++ b/redfish-core/lib/sensors.hpp @@ -2992,6 +2992,47 @@ inline void getChassisCallback( BMCWEB_LOG_DEBUG << "getChassisCallback exit"; } +inline void + handleSensorCollectionGet(App& app, const crow::Request& req, + const std::shared_ptr<bmcweb::AsyncResp>& aResp, + const std::string& chassisId) +{ + query_param::QueryCapabilities capabilities = { + .canDelegateExpandLevel = 1, + }; + query_param::Query delegatedQuery; + if (!redfish::setUpRedfishRouteWithDelegation(app, req, aResp->res, + delegatedQuery, capabilities)) + { + return; + } + + if (delegatedQuery.expandType != query_param::ExpandType::None) + { + // we perform efficient expand. + auto asyncResp = std::make_shared<SensorsAsyncResp>( + aResp, chassisId, sensors::dbus::sensorPaths, + sensors::node::sensors, + /*efficientExpand=*/true); + getChassisData(asyncResp); + + BMCWEB_LOG_DEBUG + << "SensorCollection doGet exit via efficient expand handler"; + return; + }; + + // if there's no efficient expand available, we use the default + // Query Parameters route + auto asyncResp = std::make_shared<SensorsAsyncResp>( + aResp, chassisId, sensors::dbus::sensorPaths, sensors::node::sensors); + + // We get all sensors as hyperlinkes in the chassis (this + // implies we reply on the default query parameters handler) + getChassis(asyncResp, + std::bind_front(sensors::getChassisCallback, asyncResp)); + BMCWEB_LOG_DEBUG << "SensorCollection doGet exit"; +} + inline void handleSensorGet(App& app, const crow::Request& req, const std::shared_ptr<bmcweb::AsyncResp>& aResp, const std::string& chassisId, @@ -3077,45 +3118,7 @@ inline void requestRoutesSensorCollection(App& app) BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/Sensors/") .privileges(redfish::privileges::getSensorCollection) .methods(boost::beast::http::verb::get)( - [&app](const crow::Request& req, - const std::shared_ptr<bmcweb::AsyncResp>& aResp, - const std::string& chassisId) { - query_param::QueryCapabilities capabilities = { - .canDelegateExpandLevel = 1, - }; - query_param::Query delegatedQuery; - if (!redfish::setUpRedfishRouteWithDelegation( - app, req, aResp->res, delegatedQuery, capabilities)) - { - return; - } - - if (delegatedQuery.expandType != query_param::ExpandType::None) - { - // we perform efficient expand. - auto asyncResp = std::make_shared<SensorsAsyncResp>( - aResp, chassisId, sensors::dbus::sensorPaths, - sensors::node::sensors, - /*efficientExpand=*/true); - getChassisData(asyncResp); - - BMCWEB_LOG_DEBUG - << "SensorCollection doGet exit via efficient expand handler"; - return; - }; - - // if there's no efficient expand available, we use the default - // Query Parameters route - auto asyncResp = std::make_shared<SensorsAsyncResp>( - aResp, chassisId, sensors::dbus::sensorPaths, - sensors::node::sensors); - - // We get all sensors as hyperlinkes in the chassis (this - // implies we reply on the default query parameters handler) - getChassis(asyncResp, - std::bind_front(sensors::getChassisCallback, asyncResp)); - BMCWEB_LOG_DEBUG << "SensorCollection doGet exit"; - }); + std::bind_front(sensors::handleSensorCollectionGet, std::ref(app))); } inline void requestRoutesSensor(App& app) |