Using AsyncResp everywhere
Get the core using AsyncResp everywhere, and not have each individual handler
creating its own object.We can call app.handle() without fear of the response
getting ended after the first tree is done populating.
Don't use res.end() anymore.
Tested:
1. Validator passed.
Signed-off-by: zhanghaicheng <zhanghch05@inspur.com>
Change-Id: I867367ce4a0caf8c4b3f4e07e06c11feed0782e8
diff --git a/redfish-core/lib/memory.hpp b/redfish-core/lib/memory.hpp
index f6be846..af619e0 100644
--- a/redfish-core/lib/memory.hpp
+++ b/redfish-core/lib/memory.hpp
@@ -136,7 +136,7 @@
return "";
}
-inline void dimmPropToHex(const std::shared_ptr<AsyncResp>& aResp,
+inline void dimmPropToHex(const std::shared_ptr<bmcweb::AsyncResp>& aResp,
const char* key,
const std::pair<std::string, DimmProperty>& property)
{
@@ -151,9 +151,9 @@
aResp->res.jsonValue[key] = (boost::format("0x%04x") % *value).str();
}
-inline void
- getPersistentMemoryProperties(const std::shared_ptr<AsyncResp>& aResp,
- const DimmProperties& properties)
+inline void getPersistentMemoryProperties(
+ const std::shared_ptr<bmcweb::AsyncResp>& aResp,
+ const DimmProperties& properties)
{
for (const auto& property : properties)
{
@@ -436,7 +436,7 @@
}
}
-inline void getDimmDataByService(std::shared_ptr<AsyncResp> aResp,
+inline void getDimmDataByService(std::shared_ptr<bmcweb::AsyncResp> aResp,
const std::string& dimmId,
const std::string& service,
const std::string& objPath)
@@ -716,7 +716,7 @@
service, objPath, "org.freedesktop.DBus.Properties", "GetAll", "");
}
-inline void getDimmPartitionData(std::shared_ptr<AsyncResp> aResp,
+inline void getDimmPartitionData(std::shared_ptr<bmcweb::AsyncResp> aResp,
const std::string& service,
const std::string& path)
{
@@ -800,7 +800,7 @@
"xyz.openbmc_project.Inventory.Item.PersistentMemory.Partition");
}
-inline void getDimmData(std::shared_ptr<AsyncResp> aResp,
+inline void getDimmData(std::shared_ptr<bmcweb::AsyncResp> aResp,
const std::string& dimmId)
{
BMCWEB_LOG_DEBUG << "Get available system dimm resources.";
@@ -886,13 +886,14 @@
/**
* Functions triggers appropriate requests on DBus
*/
- void doGet(crow::Response& res, const crow::Request&,
- const std::vector<std::string>&) override
+ void doGet(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
+ const crow::Request&, const std::vector<std::string>&) override
{
- res.jsonValue["@odata.type"] = "#MemoryCollection.MemoryCollection";
- res.jsonValue["Name"] = "Memory Module Collection";
- res.jsonValue["@odata.id"] = "/redfish/v1/Systems/system/Memory";
- auto asyncResp = std::make_shared<AsyncResp>(res);
+ asyncResp->res.jsonValue["@odata.type"] =
+ "#MemoryCollection.MemoryCollection";
+ asyncResp->res.jsonValue["Name"] = "Memory Module Collection";
+ asyncResp->res.jsonValue["@odata.id"] =
+ "/redfish/v1/Systems/system/Memory";
collection_util::getCollectionMembers(
asyncResp, "/redfish/v1/Systems/system/Memory",
@@ -922,23 +923,22 @@
/**
* Functions triggers appropriate requests on DBus
*/
- void doGet(crow::Response& res, const crow::Request&,
+ void doGet(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
+ const crow::Request&,
const std::vector<std::string>& params) override
{
// Check if there is required param, truly entering this shall be
// impossible
if (params.size() != 1)
{
- messages::internalError(res);
- res.end();
+ messages::internalError(asyncResp->res);
return;
}
const std::string& dimmId = params[0];
- res.jsonValue["@odata.type"] = "#Memory.v1_11_0.Memory";
- res.jsonValue["@odata.id"] =
+ asyncResp->res.jsonValue["@odata.type"] = "#Memory.v1_11_0.Memory";
+ asyncResp->res.jsonValue["@odata.id"] =
"/redfish/v1/Systems/system/Memory/" + dimmId;
- auto asyncResp = std::make_shared<AsyncResp>(res);
getDimmData(asyncResp, dimmId);
}