update service: extract get version callback
Extract getSoftwareVersionCallback from inline lambda for readability
reasons.
Tested: Next patches in series.
Change-Id: I5b89bcfb47b55336bbbe70063bb68f94f2513a21
Signed-off-by: Alexander Hansen <alexander.hansen@9elements.com>
diff --git a/redfish-core/lib/update_service.hpp b/redfish-core/lib/update_service.hpp
index bfa9443..28dd77c 100644
--- a/redfish-core/lib/update_service.hpp
+++ b/redfish-core/lib/update_service.hpp
@@ -1225,6 +1225,61 @@
}
}
+inline void getSoftwareVersionCallback(
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
+ const std::string& swId, const boost::system::error_code& ec,
+ const dbus::utility::DBusPropertiesMap& propertiesList)
+{
+ if (ec)
+ {
+ messages::internalError(asyncResp->res);
+ return;
+ }
+ const std::string* swInvPurpose = nullptr;
+ const std::string* version = nullptr;
+ const bool success = sdbusplus::unpackPropertiesNoThrow(
+ dbus_utils::UnpackErrorPrinter(), propertiesList, "Purpose",
+ swInvPurpose, "Version", version);
+ if (!success)
+ {
+ messages::internalError(asyncResp->res);
+ return;
+ }
+ if (swInvPurpose == nullptr)
+ {
+ BMCWEB_LOG_DEBUG("Can't find property \"Purpose\"!");
+ messages::internalError(asyncResp->res);
+ return;
+ }
+ BMCWEB_LOG_DEBUG("swInvPurpose = {}", *swInvPurpose);
+ if (version == nullptr)
+ {
+ BMCWEB_LOG_DEBUG("Can't find property \"Version\"!");
+ messages::internalError(asyncResp->res);
+ return;
+ }
+ asyncResp->res.jsonValue["Version"] = *version;
+ asyncResp->res.jsonValue["Id"] = swId;
+ // swInvPurpose is of format:
+ // xyz.openbmc_project.Software.Version.VersionPurpose.ABC
+ // Translate this to "ABC image"
+ size_t endDesc = swInvPurpose->rfind('.');
+ if (endDesc == std::string::npos)
+ {
+ messages::internalError(asyncResp->res);
+ return;
+ }
+ endDesc++;
+ if (endDesc >= swInvPurpose->size())
+ {
+ messages::internalError(asyncResp->res);
+ return;
+ }
+ std::string formatDesc = swInvPurpose->substr(endDesc);
+ asyncResp->res.jsonValue["Description"] = formatDesc + " image";
+ getRelatedItems(asyncResp, *swInvPurpose);
+}
+
inline void getSoftwareVersion(
const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
const std::string& service, const std::string& path,
@@ -1232,68 +1287,7 @@
{
dbus::utility::getAllProperties(
service, path, "xyz.openbmc_project.Software.Version",
- [asyncResp,
- swId](const boost::system::error_code& ec,
- const dbus::utility::DBusPropertiesMap& propertiesList) {
- if (ec)
- {
- messages::internalError(asyncResp->res);
- return;
- }
-
- const std::string* swInvPurpose = nullptr;
- const std::string* version = nullptr;
-
- const bool success = sdbusplus::unpackPropertiesNoThrow(
- dbus_utils::UnpackErrorPrinter(), propertiesList, "Purpose",
- swInvPurpose, "Version", version);
-
- if (!success)
- {
- messages::internalError(asyncResp->res);
- return;
- }
-
- if (swInvPurpose == nullptr)
- {
- BMCWEB_LOG_DEBUG("Can't find property \"Purpose\"!");
- messages::internalError(asyncResp->res);
- return;
- }
-
- BMCWEB_LOG_DEBUG("swInvPurpose = {}", *swInvPurpose);
-
- if (version == nullptr)
- {
- BMCWEB_LOG_DEBUG("Can't find property \"Version\"!");
-
- messages::internalError(asyncResp->res);
-
- return;
- }
- asyncResp->res.jsonValue["Version"] = *version;
- asyncResp->res.jsonValue["Id"] = swId;
-
- // swInvPurpose is of format:
- // xyz.openbmc_project.Software.Version.VersionPurpose.ABC
- // Translate this to "ABC image"
- size_t endDesc = swInvPurpose->rfind('.');
- if (endDesc == std::string::npos)
- {
- messages::internalError(asyncResp->res);
- return;
- }
- endDesc++;
- if (endDesc >= swInvPurpose->size())
- {
- messages::internalError(asyncResp->res);
- return;
- }
-
- std::string formatDesc = swInvPurpose->substr(endDesc);
- asyncResp->res.jsonValue["Description"] = formatDesc + " image";
- getRelatedItems(asyncResp, *swInvPurpose);
- });
+ std::bind_front(getSoftwareVersionCallback, asyncResp, swId));
}
inline void handleUpdateServiceFirmwareInventoryGetCallback(