Refactor getProcessorData
- Move list of interfaces to search for next to the result callback, so
that it's easier to catch mismatches. And add 1 missing interface to
GetSubTree request.
- Use vector instead of map for GetSubTree response
- Use structured bindings to make the loop variables easier to
understand.
- Reorganize logic to save an indent.
Tested: As part of child change Iab94b7fd49a9462cb0eca6f8ea0754f5fb241053
Signed-off-by: Jonathan Doman <jonathan.doman@intel.com>
Change-Id: Iccf76ca0ddf944b053ebcf904f872e7960f2b508
diff --git a/redfish-core/lib/processor.hpp b/redfish-core/lib/processor.hpp
index 2ba97e2..82c01f9 100644
--- a/redfish-core/lib/processor.hpp
+++ b/redfish-core/lib/processor.hpp
@@ -29,6 +29,10 @@
std::string,
boost::container::flat_map<std::string, dbus::utility::DbusVariantType>>;
+using MapperGetSubTreeResponse = std::vector<
+ std::pair<std::string,
+ std::vector<std::pair<std::string, std::vector<std::string>>>>>;
+
inline void
getCpuDataByInterface(const std::shared_ptr<AsyncResp>& aResp,
const InterfacesProperties& cpuInterfacesProperties)
@@ -377,63 +381,62 @@
}
inline void getProcessorData(std::shared_ptr<AsyncResp> aResp,
- const std::string& processorId,
- const std::vector<const char*>& inventoryItems)
+ const std::string& processorId)
{
BMCWEB_LOG_DEBUG << "Get available system processor resources.";
crow::connections::systemBus->async_method_call(
- [processorId, aResp{std::move(aResp)}](
- const boost::system::error_code ec,
- const boost::container::flat_map<
- std::string, boost::container::flat_map<
- std::string, std::vector<std::string>>>&
- subtree) {
+ [processorId,
+ aResp{std::move(aResp)}](const boost::system::error_code ec,
+ const MapperGetSubTreeResponse& subtree) {
if (ec)
{
BMCWEB_LOG_DEBUG << "DBUS response error";
messages::internalError(aResp->res);
return;
}
- for (const auto& object : subtree)
+ for (const auto& [objectPath, serviceMap] : subtree)
{
- if (boost::ends_with(object.first, processorId))
+ // Ignore any objects which don't end with our desired cpu name
+ if (!boost::ends_with(objectPath, processorId))
{
- for (const auto& service : object.second)
+ continue;
+ }
+
+ // Process the first object which does match our cpu name
+ // suffix, and potentially ignore any other matching objects.
+ // Assume all interfaces we want to process must be on the same
+ // object.
+
+ for (const auto& [serviceName, interfaceList] : serviceMap)
+ {
+ for (const auto& interface : interfaceList)
{
- for (const auto& inventory : service.second)
+ if (interface ==
+ "xyz.openbmc_project.Inventory.Decorator.Asset")
{
- if (inventory == "xyz.openbmc_project."
- "Inventory.Decorator.Asset")
- {
- getCpuAssetData(aResp, service.first,
- object.first);
- }
- else if (inventory ==
- "xyz.openbmc_project."
- "Inventory.Decorator.Revision")
- {
- getCpuRevisionData(aResp, service.first,
- object.first);
- }
- else if (inventory == "xyz.openbmc_project."
- "Inventory.Item.Cpu")
- {
- getCpuDataByService(aResp, processorId,
- service.first,
- object.first);
- }
- else if (inventory == "xyz.openbmc_project."
- "Inventory.Item.Accelerator")
- {
- getAcceleratorDataByService(aResp, processorId,
- service.first,
- object.first);
- }
+ getCpuAssetData(aResp, serviceName, objectPath);
+ }
+ else if (interface == "xyz.openbmc_project.Inventory."
+ "Decorator.Revision")
+ {
+ getCpuRevisionData(aResp, serviceName, objectPath);
+ }
+ else if (interface ==
+ "xyz.openbmc_project.Inventory.Item.Cpu")
+ {
+ getCpuDataByService(aResp, processorId, serviceName,
+ objectPath);
+ }
+ else if (interface == "xyz.openbmc_project.Inventory."
+ "Item.Accelerator")
+ {
+ getAcceleratorDataByService(
+ aResp, processorId, serviceName, objectPath);
}
}
- return;
}
+ return;
}
// Object not found
messages::resourceNotFound(aResp->res, "Processor", processorId);
@@ -442,7 +445,12 @@
"xyz.openbmc_project.ObjectMapper",
"/xyz/openbmc_project/object_mapper",
"xyz.openbmc_project.ObjectMapper", "GetSubTree",
- "/xyz/openbmc_project/inventory", 0, inventoryItems);
+ "/xyz/openbmc_project/inventory", 0,
+ std::array<const char*, 4>{
+ "xyz.openbmc_project.Inventory.Decorator.Asset",
+ "xyz.openbmc_project.Inventory.Decorator.Revision",
+ "xyz.openbmc_project.Inventory.Item.Cpu",
+ "xyz.openbmc_project.Inventory.Item.Accelerator"});
}
class ProcessorCollection : public Node
@@ -525,10 +533,7 @@
auto asyncResp = std::make_shared<AsyncResp>(res);
- getProcessorData(asyncResp, processorId,
- {"xyz.openbmc_project.Inventory.Item.Cpu",
- "xyz.openbmc_project.Inventory.Decorator.Asset",
- "xyz.openbmc_project.Inventory.Item.Accelerator"});
+ getProcessorData(asyncResp, processorId);
}
};