|
20 | 20 | #include "node.hpp"
|
21 | 21 |
|
22 | 22 | #include <boost/container/flat_map.hpp>
|
| 23 | +#include <utils/collection.hpp> |
23 | 24 |
|
24 | 25 | #include <variant>
|
25 | 26 |
|
@@ -182,49 +183,12 @@ class ChassisCollection : public Node
|
182 | 183 | res.jsonValue["@odata.id"] = "/redfish/v1/Chassis";
|
183 | 184 | res.jsonValue["Name"] = "Chassis Collection";
|
184 | 185 |
|
185 |
| - const std::array<const char*, 2> interfaces = { |
186 |
| - "xyz.openbmc_project.Inventory.Item.Board", |
187 |
| - "xyz.openbmc_project.Inventory.Item.Chassis"}; |
188 |
| - |
189 | 186 | auto asyncResp = std::make_shared<AsyncResp>(res);
|
190 |
| - crow::connections::systemBus->async_method_call( |
191 |
| - [asyncResp](const boost::system::error_code ec, |
192 |
| - const std::vector<std::string>& chassisList) { |
193 |
| - if (ec) |
194 |
| - { |
195 |
| - messages::internalError(asyncResp->res); |
196 |
| - return; |
197 |
| - } |
198 |
| - nlohmann::json& chassisArray = |
199 |
| - asyncResp->res.jsonValue["Members"]; |
200 |
| - chassisArray = nlohmann::json::array(); |
201 |
| - for (const std::string& objpath : chassisList) |
202 |
| - { |
203 |
| - std::size_t lastPos = objpath.rfind("/"); |
204 |
| - if (lastPos == std::string::npos) |
205 |
| - { |
206 |
| - BMCWEB_LOG_ERROR << "Failed to find '/' in " << objpath; |
207 |
| - messages::internalError(asyncResp->res); |
208 |
| - return; |
209 |
| - } |
210 |
| - if ((lastPos + 1) >= objpath.size()) |
211 |
| - { |
212 |
| - BMCWEB_LOG_ERROR << "Failed to parse path " << objpath; |
213 |
| - messages::internalError(asyncResp->res); |
214 |
| - return; |
215 |
| - } |
216 |
| - chassisArray.push_back( |
217 |
| - {{"@odata.id", "/redfish/v1/Chassis/" + |
218 |
| - objpath.substr(lastPos + 1)}}); |
219 |
| - } |
220 | 187 |
|
221 |
| - asyncResp-> res. jsonValue[ "[email protected]"] = |
222 |
| - chassisArray.size(); |
223 |
| - }, |
224 |
| - "xyz.openbmc_project.ObjectMapper", |
225 |
| - "/xyz/openbmc_project/object_mapper", |
226 |
| - "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths", |
227 |
| - "/xyz/openbmc_project/inventory", 0, interfaces); |
| 188 | + collection_util::getCollectionMembers( |
| 189 | + asyncResp, "/redfish/v1/Chassis", |
| 190 | + {"xyz.openbmc_project.Inventory.Item.Board", |
| 191 | + "xyz.openbmc_project.Inventory.Item.Chassis"}); |
228 | 192 | }
|
229 | 193 | };
|
230 | 194 |
|
|
0 commit comments