diff options
author | Krzysztof Grobelny <krzysztof.grobelny@intel.com> | 2022-09-07 11:40:51 +0300 |
---|---|---|
committer | Ed Tanous <ed@tanous.net> | 2022-09-09 06:20:53 +0300 |
commit | d1bde9e590f165f28d948fda93e48d51b30bb463 (patch) | |
tree | aabfdc5dc75090eeb1066d99a30402efa5bf7505 /redfish-core/lib | |
parent | c6fecdabd58b4c380caf1b83801ad4eb54922fff (diff) | |
download | bmcweb-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')
-rw-r--r-- | redfish-core/lib/account_service.hpp | 70 | ||||
-rw-r--r-- | redfish-core/lib/log_services.hpp | 134 | ||||
-rw-r--r-- | redfish-core/lib/pcie.hpp | 109 | ||||
-rw-r--r-- | redfish-core/lib/pcie_slots.hpp | 107 | ||||
-rw-r--r-- | redfish-core/lib/power.hpp | 9 | ||||
-rw-r--r-- | redfish-core/lib/storage.hpp | 133 | ||||
-rw-r--r-- | redfish-core/lib/update_service.hpp | 28 |
7 files changed, 298 insertions, 292 deletions
diff --git a/redfish-core/lib/account_service.hpp b/redfish-core/lib/account_service.hpp index b6316ef915..5d8bb15f6c 100644 --- a/redfish-core/lib/account_service.hpp +++ b/redfish-core/lib/account_service.hpp @@ -23,6 +23,8 @@ #include <query.hpp> #include <registries/privilege_registry.hpp> #include <sdbusplus/asio/property.hpp> +#include <sdbusplus/unpack_properties.hpp> +#include <utils/dbus_utils.hpp> #include <utils/json_utils.hpp> namespace redfish @@ -1291,7 +1293,9 @@ inline void asyncResp->res.jsonValue["LDAP"]["Certificates"]["@odata.id"] = "/redfish/v1/AccountService/LDAP/Certificates"; } - crow::connections::systemBus->async_method_call( + sdbusplus::asio::getAllProperties( + *crow::connections::systemBus, "xyz.openbmc_project.User.Manager", + "/xyz/openbmc_project/user", "xyz.openbmc_project.User.AccountPolicy", [asyncResp](const boost::system::error_code ec, const dbus::utility::DBusPropertiesMap& propertiesList) { if (ec) @@ -1299,41 +1303,43 @@ inline void messages::internalError(asyncResp->res); return; } + BMCWEB_LOG_DEBUG << "Got " << propertiesList.size() << "properties for AccountService"; - for (const std::pair<std::string, dbus::utility::DbusVariantType>& - property : propertiesList) + + const uint8_t* minPasswordLength = nullptr; + const uint32_t* accountUnlockTimeout = nullptr; + const uint16_t* maxLoginAttemptBeforeLockout = nullptr; + + const bool success = sdbusplus::unpackPropertiesNoThrow( + dbus_utils::UnpackErrorPrinter(), propertiesList, + "MinPasswordLength", minPasswordLength, "AccountUnlockTimeout", + accountUnlockTimeout, "MaxLoginAttemptBeforeLockout", + maxLoginAttemptBeforeLockout); + + if (!success) { - if (property.first == "MinPasswordLength") - { - const uint8_t* value = std::get_if<uint8_t>(&property.second); - if (value != nullptr) - { - asyncResp->res.jsonValue["MinPasswordLength"] = *value; - } - } - if (property.first == "AccountUnlockTimeout") - { - const uint32_t* value = std::get_if<uint32_t>(&property.second); - if (value != nullptr) - { - asyncResp->res.jsonValue["AccountLockoutDuration"] = *value; - } - } - if (property.first == "MaxLoginAttemptBeforeLockout") - { - const uint16_t* value = std::get_if<uint16_t>(&property.second); - if (value != nullptr) - { - asyncResp->res.jsonValue["AccountLockoutThreshold"] = - *value; - } - } + messages::internalError(asyncResp->res); + return; } - }, - "xyz.openbmc_project.User.Manager", "/xyz/openbmc_project/user", - "org.freedesktop.DBus.Properties", "GetAll", - "xyz.openbmc_project.User.AccountPolicy"); + + if (minPasswordLength != nullptr) + { + asyncResp->res.jsonValue["MinPasswordLength"] = *minPasswordLength; + } + + if (accountUnlockTimeout != nullptr) + { + asyncResp->res.jsonValue["AccountLockoutDuration"] = + *accountUnlockTimeout; + } + + if (maxLoginAttemptBeforeLockout != nullptr) + { + asyncResp->res.jsonValue["AccountLockoutThreshold"] = + *maxLoginAttemptBeforeLockout; + } + }); auto callback = [asyncResp](bool success, const LDAPConfigData& confData, const std::string& ldapType) { diff --git a/redfish-core/lib/log_services.hpp b/redfish-core/lib/log_services.hpp index 533c15e8c5..faa295adc1 100644 --- a/redfish-core/lib/log_services.hpp +++ b/redfish-core/lib/log_services.hpp @@ -38,6 +38,9 @@ #include <error_messages.hpp> #include <query.hpp> #include <registries/privilege_registry.hpp> +#include <sdbusplus/asio/property.hpp> +#include <sdbusplus/unpack_properties.hpp> +#include <utils/dbus_utils.hpp> #include <utils/time_utils.hpp> #include <charconv> @@ -579,7 +582,8 @@ inline void { // Dump status is not Complete // return not found until status is changed to Completed - messages::resourceNotFound(asyncResp->res, "LogEntry", entryID); + messages::resourceNotFound(asyncResp->res, dumpType + " dump", + entryID); return; } @@ -871,35 +875,32 @@ inline static void std::string& filename, std::string& timestamp, std::string& logfile) { - for (auto property : params) + const std::string* filenamePtr = nullptr; + const std::string* timestampPtr = nullptr; + const std::string* logfilePtr = nullptr; + + const bool success = sdbusplus::unpackPropertiesNoThrow( + dbus_utils::UnpackErrorPrinter(), params, "Timestamp", timestampPtr, + "Filename", filenamePtr, "Log", logfilePtr); + + if (!success) { - if (property.first == "Timestamp") - { - const std::string* value = - std::get_if<std::string>(&property.second); - if (value != nullptr) - { - timestamp = *value; - } - } - else if (property.first == "Filename") - { - const std::string* value = - std::get_if<std::string>(&property.second); - if (value != nullptr) - { - filename = *value; - } - } - else if (property.first == "Log") - { - const std::string* value = - std::get_if<std::string>(&property.second); - if (value != nullptr) - { - logfile = *value; - } - } + return; + } + + if (filenamePtr != nullptr) + { + filename = *filenamePtr; + } + + if (timestampPtr != nullptr) + { + timestamp = *timestampPtr; + } + + if (logfilePtr != nullptr) + { + logfile = *logfilePtr; } } @@ -1500,12 +1501,15 @@ inline void requestRoutesDBusEventLogEntry(App& app) // DBus implementation of EventLog/Entries // Make call to Logging Service to find all log entry objects - crow::connections::systemBus->async_method_call( + sdbusplus::asio::getAllProperties( + *crow::connections::systemBus, "xyz.openbmc_project.Logging", + "/xyz/openbmc_project/logging/entry/" + entryID, "", [asyncResp, entryID](const boost::system::error_code ec, const dbus::utility::DBusPropertiesMap& resp) { if (ec.value() == EBADR) { - messages::resourceNotFound(asyncResp->res, "LogEntry", entryID); + messages::resourceNotFound(asyncResp->res, "EventLogEntry", + entryID); return; } if (ec) @@ -1523,45 +1527,18 @@ inline void requestRoutesDBusEventLogEntry(App& app) const std::string* filePath = nullptr; bool resolved = false; - for (const auto& propertyMap : resp) + const bool success = sdbusplus::unpackPropertiesNoThrow( + dbus_utils::UnpackErrorPrinter(), resp, "Id", id, "Timestamp", + timestamp, "UpdateTimestamp", updateTimestamp, "Severity", + severity, "Message", message, "Resolved", resolved, "Path", + filePath); + + if (!success) { - if (propertyMap.first == "Id") - { - id = std::get_if<uint32_t>(&propertyMap.second); - } - else if (propertyMap.first == "Timestamp") - { - timestamp = std::get_if<uint64_t>(&propertyMap.second); - } - else if (propertyMap.first == "UpdateTimestamp") - { - updateTimestamp = - std::get_if<uint64_t>(&propertyMap.second); - } - else if (propertyMap.first == "Severity") - { - severity = std::get_if<std::string>(&propertyMap.second); - } - else if (propertyMap.first == "Message") - { - message = std::get_if<std::string>(&propertyMap.second); - } - else if (propertyMap.first == "Resolved") - { - const bool* resolveptr = - std::get_if<bool>(&propertyMap.second); - if (resolveptr == nullptr) - { - messages::internalError(asyncResp->res); - return; - } - resolved = *resolveptr; - } - else if (propertyMap.first == "Path") - { - filePath = std::get_if<std::string>(&propertyMap.second); - } + messages::internalError(asyncResp->res); + return; } + if (id == nullptr || message == nullptr || severity == nullptr || timestamp == nullptr || updateTimestamp == nullptr) { @@ -1590,10 +1567,7 @@ inline void requestRoutesDBusEventLogEntry(App& app) "/redfish/v1/Systems/system/LogServices/EventLog/Entries/" + std::to_string(*id) + "/attachment"; } - }, - "xyz.openbmc_project.Logging", - "/xyz/openbmc_project/logging/entry/" + entryID, - "org.freedesktop.DBus.Properties", "GetAll", ""); + }); }); BMCWEB_ROUTE( @@ -2834,10 +2808,10 @@ static void logEntryJson.update(logEntry); } }; - crow::connections::systemBus->async_method_call( - std::move(getStoredLogCallback), crashdumpObject, - crashdumpPath + std::string("/") + logID, - "org.freedesktop.DBus.Properties", "GetAll", crashdumpInterface); + sdbusplus::asio::getAllProperties( + *crow::connections::systemBus, crashdumpObject, + crashdumpPath + std::string("/") + logID, crashdumpInterface, + std::move(getStoredLogCallback)); } inline void requestRoutesCrashdumpEntryCollection(App& app) @@ -2989,10 +2963,10 @@ inline void requestRoutesCrashdumpFile(App& app) asyncResp->res.addHeader( boost::beast::http::field::content_disposition, "attachment"); }; - crow::connections::systemBus->async_method_call( - std::move(getStoredLogCallback), crashdumpObject, - crashdumpPath + std::string("/") + logID, - "org.freedesktop.DBus.Properties", "GetAll", crashdumpInterface); + sdbusplus::asio::getAllProperties( + *crow::connections::systemBus, crashdumpObject, + crashdumpPath + std::string("/") + logID, crashdumpInterface, + std::move(getStoredLogCallback)); }); } 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)); }); } diff --git a/redfish-core/lib/pcie_slots.hpp b/redfish-core/lib/pcie_slots.hpp index cff1e27ec1..778768f092 100644 --- a/redfish-core/lib/pcie_slots.hpp +++ b/redfish-core/lib/pcie_slots.hpp @@ -6,6 +6,9 @@ #include <app.hpp> #include <pcie.hpp> #include <registries/privilege_registry.hpp> +#include <sdbusplus/asio/property.hpp> +#include <sdbusplus/unpack_properties.hpp> +#include <utils/dbus_utils.hpp> #include <utils/json_utils.hpp> namespace redfish @@ -85,66 +88,56 @@ inline void nlohmann::json::object_t slot; - for (const auto& property : propertiesList) + const std::string* generation = nullptr; + const size_t* lanes = nullptr; + const std::string* slotType = nullptr; + const bool* hotPluggable = nullptr; + + const bool success = sdbusplus::unpackPropertiesNoThrow( + dbus_utils::UnpackErrorPrinter(), propertiesList, "Generation", + generation, "Lanes", lanes, "SlotType", slotType, "HotPluggable", + hotPluggable); + + if (!success) { - const std::string& propertyName = property.first; + messages::internalError(asyncResp->res); + return; + } - if (propertyName == "Generation") - { - const std::string* value = - std::get_if<std::string>(&property.second); - if (value == nullptr) - { - messages::internalError(asyncResp->res); - return; - } - std::optional<std::string> pcieType = - redfishPcieGenerationFromDbus(*value); - if (!pcieType) - { - messages::internalError(asyncResp->res); - return; - } - slot["PCIeType"] = !pcieType; - } - else if (propertyName == "Lanes") - { - const size_t* value = std::get_if<size_t>(&property.second); - if (value == nullptr) - { - messages::internalError(asyncResp->res); - return; - } - slot["Lanes"] = *value; - } - else if (propertyName == "SlotType") + if (generation != nullptr) + { + std::optional<std::string> pcieType = + redfishPcieGenerationFromDbus(*generation); + if (!pcieType) { - const std::string* value = - std::get_if<std::string>(&property.second); - if (value == nullptr) - { - messages::internalError(asyncResp->res); - return; - } - std::string slotType = dbusSlotTypeToRf(*value); - if (!slotType.empty()) - { - messages::internalError(asyncResp->res); - return; - } - slot["SlotType"] = slotType; + messages::internalError(asyncResp->res); + return; } - else if (propertyName == "HotPluggable") + slot["PCIeType"] = !pcieType; + } + + if (lanes != nullptr) + { + + slot["Lanes"] = *lanes; + } + + if (slotType != nullptr) + { + std::string redfishSlotType = dbusSlotTypeToRf(*slotType); + if (!slotType.empty()) { - const bool* value = std::get_if<bool>(&property.second); - if (value == nullptr) - { - messages::internalError(asyncResp->res); - return; - } - slot["HotPluggable"] = *value; + messages::internalError(asyncResp->res); + return; } + slot["SlotType"] = redfishSlotType; } + + if (hotPluggable != nullptr) + { + slot["HotPluggable"] = *hotPluggable; + } + slots.emplace_back(std::move(slot)); } @@ -191,13 +184,13 @@ inline void onMapperAssociationDone( return; } - crow::connections::systemBus->async_method_call( + sdbusplus::asio::getAllProperties( + *crow::connections::systemBus, connectionName, pcieSlotPath, + "xyz.openbmc_project.Inventory.Item.PCIeSlot", [asyncResp](const boost::system::error_code ec, const dbus::utility::DBusPropertiesMap& propertiesList) { onPcieSlotGetAllDone(asyncResp, ec, propertiesList); - }, - connectionName, pcieSlotPath, "org.freedesktop.DBus.Properties", - "GetAll", "xyz.openbmc_project.Inventory.Item.PCIeSlot"); + }); } inline void diff --git a/redfish-core/lib/power.hpp b/redfish-core/lib/power.hpp index cecaeab4bb..47f0c5d24f 100644 --- a/redfish-core/lib/power.hpp +++ b/redfish-core/lib/power.hpp @@ -23,6 +23,7 @@ #include <dbus_utility.hpp> #include <query.hpp> #include <registries/privilege_registry.hpp> +#include <sdbusplus/asio/property.hpp> namespace redfish { @@ -288,11 +289,11 @@ inline void requestRoutesPower(App& app) } }; - crow::connections::systemBus->async_method_call( - std::move(valueHandler), "xyz.openbmc_project.Settings", + sdbusplus::asio::getAllProperties( + *crow::connections::systemBus, "xyz.openbmc_project.Settings", "/xyz/openbmc_project/control/host0/power_cap", - "org.freedesktop.DBus.Properties", "GetAll", - "xyz.openbmc_project.Control.Power.Cap"); + "xyz.openbmc_project.Control.Power.Cap", + std::move(valueHandler)); }; crow::connections::systemBus->async_method_call( diff --git a/redfish-core/lib/storage.hpp b/redfish-core/lib/storage.hpp index 30b679deea..cf1b441d0b 100644 --- a/redfish-core/lib/storage.hpp +++ b/redfish-core/lib/storage.hpp @@ -23,6 +23,8 @@ #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 { @@ -165,7 +167,9 @@ inline void } }); - crow::connections::systemBus->async_method_call( + sdbusplus::asio::getAllProperties( + *crow::connections::systemBus, connectionName, path, + "xyz.openbmc_project.Inventory.Decorator.Asset", [asyncResp, index]( const boost::system::error_code ec2, const std::vector< @@ -176,35 +180,46 @@ inline void // this interface isn't necessary return; } - for (const std::pair<std::string, - dbus::utility::DbusVariantType>& property : - propertiesList) + + const std::string* partNumber = nullptr; + const std::string* serialNumber = nullptr; + const std::string* manufacturer = nullptr; + const std::string* model = nullptr; + + const bool success = sdbusplus::unpackPropertiesNoThrow( + dbus_utils::UnpackErrorPrinter(), propertiesList, + "PartNumber", partNumber, "SerialNumber", serialNumber, + "Manufacturer", manufacturer, "Model", model); + + if (!success) + { + messages::internalError(asyncResp->res); + return; + } + + nlohmann::json& controller = + asyncResp->res.jsonValue["StorageControllers"][index]; + + if (partNumber != nullptr) + { + controller["PartNumber"] = *partNumber; + } + + if (serialNumber != nullptr) + { + controller["SerialNumber"] = *serialNumber; + } + + if (manufacturer != nullptr) { - // Store DBus properties that are also - // Redfish properties with same name and a - // string value - const std::string& propertyName = property.first; - nlohmann::json& controller = - asyncResp->res.jsonValue["StorageControllers"][index]; - if ((propertyName == "PartNumber") || - (propertyName == "SerialNumber") || - (propertyName == "Manufacturer") || - (propertyName == "Model")) - { - const std::string* value = - std::get_if<std::string>(&property.second); - if (value == nullptr) - { - // illegal property - messages::internalError(asyncResp->res); - return; - } - controller[propertyName] = *value; - } + controller["Manufacturer"] = *manufacturer; } - }, - connectionName, path, "org.freedesktop.DBus.Properties", - "GetAll", "xyz.openbmc_project.Inventory.Decorator.Asset"); + + if (model != nullptr) + { + controller["Model"] = *model; + } + }); } // this is done after we know the json array will no longer @@ -262,7 +277,9 @@ inline void getDriveAsset(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, const std::string& connectionName, const std::string& path) { - crow::connections::systemBus->async_method_call( + sdbusplus::asio::getAllProperties( + *crow::connections::systemBus, connectionName, path, + "xyz.openbmc_project.Inventory.Decorator.Asset", [asyncResp](const boost::system::error_code ec, const std::vector< std::pair<std::string, dbus::utility::DbusVariantType>>& @@ -272,31 +289,43 @@ inline void getDriveAsset(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, // this interface isn't necessary return; } - for (const std::pair<std::string, dbus::utility::DbusVariantType>& - property : propertiesList) + + const std::string* partNumber = nullptr; + const std::string* serialNumber = nullptr; + const std::string* manufacturer = nullptr; + const std::string* model = nullptr; + + const bool success = sdbusplus::unpackPropertiesNoThrow( + dbus_utils::UnpackErrorPrinter(), propertiesList, "PartNumber", + partNumber, "SerialNumber", serialNumber, "Manufacturer", + manufacturer, "Model", model); + + if (!success) { - // Store DBus properties that are also - // Redfish properties with same name and a - // string value - const std::string& propertyName = property.first; - if ((propertyName == "PartNumber") || - (propertyName == "SerialNumber") || - (propertyName == "Manufacturer") || (propertyName == "Model")) - { - const std::string* value = - std::get_if<std::string>(&property.second); - if (value == nullptr) - { - // illegal property - messages::internalError(asyncResp->res); - return; - } - asyncResp->res.jsonValue[propertyName] = *value; - } + messages::internalError(asyncResp->res); + return; } - }, - connectionName, path, "org.freedesktop.DBus.Properties", "GetAll", - "xyz.openbmc_project.Inventory.Decorator.Asset"); + + if (partNumber != nullptr) + { + asyncResp->res.jsonValue["PartNumber"] = *partNumber; + } + + if (serialNumber != nullptr) + { + asyncResp->res.jsonValue["SerialNumber"] = *serialNumber; + } + + if (manufacturer != nullptr) + { + asyncResp->res.jsonValue["Manufacturer"] = *manufacturer; + } + + if (model != nullptr) + { + asyncResp->res.jsonValue["Model"] = *model; + } + }); } inline void getDrivePresent(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, diff --git a/redfish-core/lib/update_service.hpp b/redfish-core/lib/update_service.hpp index fd4f53fa68..9acf5689c6 100644 --- a/redfish-core/lib/update_service.hpp +++ b/redfish-core/lib/update_service.hpp @@ -22,6 +22,8 @@ #include <query.hpp> #include <registries/privilege_registry.hpp> #include <sdbusplus/asio/property.hpp> +#include <sdbusplus/unpack_properties.hpp> +#include <utils/dbus_utils.hpp> #include <utils/sw_utils.hpp> namespace redfish @@ -818,7 +820,9 @@ inline void const std::string& service, const std::string& path, const std::string& swId) { - crow::connections::systemBus->async_method_call( + sdbusplus::asio::getAllProperties( + *crow::connections::systemBus, service, path, + "xyz.openbmc_project.Software.Version", [asyncResp, swId](const boost::system::error_code errorCode, const dbus::utility::DBusPropertiesMap& propertiesList) { @@ -827,18 +831,18 @@ inline void messages::internalError(asyncResp->res); return; } + const std::string* swInvPurpose = nullptr; const std::string* version = nullptr; - for (const auto& property : propertiesList) + + const bool success = sdbusplus::unpackPropertiesNoThrow( + dbus_utils::UnpackErrorPrinter(), propertiesList, "Purpose", + swInvPurpose, "Version", version); + + if (!success) { - if (property.first == "Purpose") - { - swInvPurpose = std::get_if<std::string>(&property.second); - } - else if (property.first == "Version") - { - version = std::get_if<std::string>(&property.second); - } + messages::internalError(asyncResp->res); + return; } if (swInvPurpose == nullptr) @@ -880,9 +884,7 @@ inline void std::string formatDesc = swInvPurpose->substr(endDesc); asyncResp->res.jsonValue["Description"] = formatDesc + " image"; getRelatedItems(asyncResp, *swInvPurpose); - }, - service, path, "org.freedesktop.DBus.Properties", "GetAll", - "xyz.openbmc_project.Software.Version"); + }); } inline void requestRoutesSoftwareInventory(App& app) |