summaryrefslogtreecommitdiff
path: root/redfish-core/lib/processor.hpp
diff options
context:
space:
mode:
authorJonathan Doman <jonathan.doman@intel.com>2020-12-03 02:27:40 +0300
committerEd Tanous <ed@tanous.net>2020-12-04 03:07:40 +0300
commit2bab9831767c180bedd005dfcbeb65af8798f088 (patch)
tree8db929656437e8fefb5b57eb44a5968f997c344a /redfish-core/lib/processor.hpp
parentdea43dd4bc9c6edcf8a89d91ee57e019fc5e645d (diff)
downloadbmcweb-2bab9831767c180bedd005dfcbeb65af8798f088.tar.xz
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
Diffstat (limited to 'redfish-core/lib/processor.hpp')
-rw-r--r--redfish-core/lib/processor.hpp95
1 files changed, 50 insertions, 45 deletions
diff --git a/redfish-core/lib/processor.hpp b/redfish-core/lib/processor.hpp
index 2ba97e281f..82c01f949e 100644
--- a/redfish-core/lib/processor.hpp
+++ b/redfish-core/lib/processor.hpp
@@ -29,6 +29,10 @@ using InterfacesProperties = boost::container::flat_map<
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 getAcceleratorDataByService(std::shared_ptr<AsyncResp> aResp,
}
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))
+ {
+ 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& service : object.second)
+ 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 @@ inline void getProcessorData(std::shared_ptr<AsyncResp> aResp,
"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 @@ class Processor : public Node
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);
}
};