summaryrefslogtreecommitdiff
path: root/redfish-core/lib/pcie.hpp
diff options
context:
space:
mode:
authorKrzysztof Grobelny <krzysztof.grobelny@intel.com>2022-09-07 11:40:51 +0300
committerEd Tanous <ed@tanous.net>2022-09-09 06:20:53 +0300
commitd1bde9e590f165f28d948fda93e48d51b30bb463 (patch)
treeaabfdc5dc75090eeb1066d99a30402efa5bf7505 /redfish-core/lib/pcie.hpp
parentc6fecdabd58b4c380caf1b83801ad4eb54922fff (diff)
downloadbmcweb-d1bde9e590f165f28d948fda93e48d51b30bb463.tar.xz
used sdbusplus::unpackPropertiesNoThrow part 8
used sdbusplus::unpackPropertiesNoThrow in other places, also replaced all usages of "GetAll" with sdbusplus::asio::getAllProperties bmcweb size: 2697640 -> 2685336 (-12304) compressed size: 1129728 -> 1126078 (-3650) Tested: - Executed redfish service validator, no new errors detected Change-Id: I916e462e004fcbde67c209daef295de8f5fb68eb Signed-off-by: Krzysztof Grobelny <krzysztof.grobelny@intel.com>
Diffstat (limited to 'redfish-core/lib/pcie.hpp')
-rw-r--r--redfish-core/lib/pcie.hpp109
1 files changed, 55 insertions, 54 deletions
diff --git a/redfish-core/lib/pcie.hpp b/redfish-core/lib/pcie.hpp
index b4d64332b5..47c5c91bac 100644
--- a/redfish-core/lib/pcie.hpp
+++ b/redfish-core/lib/pcie.hpp
@@ -21,6 +21,9 @@
#include <dbus_utility.hpp>
#include <query.hpp>
#include <registries/privilege_registry.hpp>
+#include <sdbusplus/asio/property.hpp>
+#include <sdbusplus/unpack_properties.hpp>
+#include <utils/dbus_utils.hpp>
namespace redfish
{
@@ -174,6 +177,49 @@ inline void requestRoutesSystemPCIeDevice(App& app)
return;
}
+ const std::string* manufacturer = nullptr;
+ const std::string* deviceType = nullptr;
+ const std::string* generationInUse = nullptr;
+
+ const bool success = sdbusplus::unpackPropertiesNoThrow(
+ dbus_utils::UnpackErrorPrinter(), pcieDevProperties,
+ "Manufacturer", manufacturer, "DeviceType", deviceType,
+ "GenerationInUse", generationInUse);
+
+ if (!success)
+ {
+ messages::internalError(asyncResp->res);
+ return;
+ }
+
+ if (generationInUse != nullptr)
+ {
+ std::optional<std::string> redfishGenerationInUse =
+ redfishPcieGenerationFromDbus(*generationInUse);
+ if (!redfishGenerationInUse)
+ {
+ messages::internalError(asyncResp->res);
+ return;
+ }
+ if (redfishGenerationInUse->empty())
+ {
+ // unknown, no need to handle
+ return;
+ }
+ asyncResp->res.jsonValue["PCIeInterface"]["PCIeType"] =
+ *redfishGenerationInUse;
+ }
+
+ if (manufacturer != nullptr)
+ {
+ asyncResp->res.jsonValue["Manufacturer"] = *manufacturer;
+ }
+
+ if (deviceType != nullptr)
+ {
+ asyncResp->res.jsonValue["DeviceType"] = *deviceType;
+ }
+
asyncResp->res.jsonValue["@odata.type"] =
"#PCIeDevice.v1_4_0.PCIeDevice";
asyncResp->res.jsonValue["@odata.id"] =
@@ -184,57 +230,12 @@ inline void requestRoutesSystemPCIeDevice(App& app)
asyncResp->res.jsonValue["PCIeFunctions"]["@odata.id"] =
"/redfish/v1/Systems/system/PCIeDevices/" + device +
"/PCIeFunctions";
- for (const auto& property : pcieDevProperties)
- {
- const std::string* propertyString =
- std::get_if<std::string>(&property.second);
- if (property.first == "Manufacturer")
- {
- if (propertyString == nullptr)
- {
- messages::internalError(asyncResp->res);
- return;
- }
- asyncResp->res.jsonValue["Manufacturer"] = *propertyString;
- }
- if (property.first == "DeviceType")
- {
- if (propertyString == nullptr)
- {
- messages::internalError(asyncResp->res);
- return;
- }
- asyncResp->res.jsonValue["DeviceType"] = *propertyString;
- }
- if (property.first == "GenerationInUse")
- {
- if (propertyString == nullptr)
- {
- messages::internalError(asyncResp->res);
- return;
- }
- std::optional<std::string> generationInUse =
- redfishPcieGenerationFromDbus(*propertyString);
- if (!generationInUse)
- {
- messages::internalError(asyncResp->res);
- return;
- }
- if (generationInUse->empty())
- {
- // unknown, no need to handle
- return;
- }
- asyncResp->res.jsonValue["PCIeInterface"]["PCIeType"] =
- *generationInUse;
- }
- }
};
std::string escapedPath = std::string(pciePath) + "/" + device;
dbus::utility::escapePathForDbus(escapedPath);
- crow::connections::systemBus->async_method_call(
- std::move(getPCIeDeviceCallback), pcieService, escapedPath,
- "org.freedesktop.DBus.Properties", "GetAll", pcieDeviceInterface);
+ sdbusplus::asio::getAllProperties(
+ *crow::connections::systemBus, pcieService, escapedPath,
+ pcieDeviceInterface, std::move(getPCIeDeviceCallback));
});
}
@@ -320,9 +321,9 @@ inline void requestRoutesSystemPCIeFunctionCollection(App& app)
};
std::string escapedPath = std::string(pciePath) + "/" + device;
dbus::utility::escapePathForDbus(escapedPath);
- crow::connections::systemBus->async_method_call(
- std::move(getPCIeDeviceCallback), pcieService, escapedPath,
- "org.freedesktop.DBus.Properties", "GetAll", pcieDeviceInterface);
+ sdbusplus::asio::getAllProperties(
+ *crow::connections::systemBus, pcieService, escapedPath,
+ pcieDeviceInterface, std::move(getPCIeDeviceCallback));
});
}
@@ -435,9 +436,9 @@ inline void requestRoutesSystemPCIeFunction(App& app)
};
std::string escapedPath = std::string(pciePath) + "/" + device;
dbus::utility::escapePathForDbus(escapedPath);
- crow::connections::systemBus->async_method_call(
- std::move(getPCIeDeviceCallback), pcieService, escapedPath,
- "org.freedesktop.DBus.Properties", "GetAll", pcieDeviceInterface);
+ sdbusplus::asio::getAllProperties(
+ *crow::connections::systemBus, pcieService, escapedPath,
+ pcieDeviceInterface, std::move(getPCIeDeviceCallback));
});
}