common: break out fetching common configuration
Since SoftwareConfig is holding the common configuration, create a
static function on that class to fetch it from dbus.
This helps to keep that logic contained and decouple it from iterating
over the response returned by the mapper.
The code is only moved and unchanged otherwise.
Tested: Unit Tests Pass
Change-Id: Ic0786e3bb1be4f139321dc2515218c40f13e9597
Signed-off-by: Alexander Hansen <alexander.hansen@9elements.com>
diff --git a/common/src/software_manager.cpp b/common/src/software_manager.cpp
index 77ee0b1..c3cf718 100644
--- a/common/src/software_manager.cpp
+++ b/common/src/software_manager.cpp
@@ -33,6 +33,64 @@
}
// NOLINTBEGIN(readability-static-accessed-through-instance)
+static sdbusplus::async::task<std::optional<SoftwareConfig>> getConfig(
+ sdbusplus::async::context& ctx, const std::string& service,
+ const std::string& objectPath, const std::string& interfacePrefix)
+// NOLINTEND(readability-static-accessed-through-instance)
+{
+ auto client = sdbusplus::async::proxy()
+ .service(service)
+ .path(objectPath)
+ .interface("org.freedesktop.DBus.Properties");
+
+ uint64_t vendorIANA = 0;
+ std::string compatible{};
+ std::string configType{};
+ std::string configName{};
+
+ const std::string interfaceName = interfacePrefix + ".FirmwareInfo";
+
+ try
+ {
+ {
+ auto propVendorIANA = co_await client.call<std::variant<uint64_t>>(
+ ctx, "Get", interfaceName, "VendorIANA");
+
+ vendorIANA = std::get<uint64_t>(propVendorIANA);
+ }
+ {
+ auto propCompatible =
+ co_await client.call<std::variant<std::string>>(
+ ctx, "Get", interfaceName, "CompatibleHardware");
+
+ compatible = std::get<std::string>(propCompatible);
+ }
+ {
+ auto propConfigType =
+ co_await client.call<std::variant<std::string>>(
+ ctx, "Get", interfacePrefix, "Type");
+
+ configType = std::get<std::string>(propConfigType);
+ }
+ {
+ auto propConfigName =
+ co_await client.call<std::variant<std::string>>(
+ ctx, "Get", interfacePrefix, "Name");
+
+ configName = std::get<std::string>(propConfigName);
+ }
+ }
+ catch (std::exception& e)
+ {
+ error("Failed to get config with {ERROR}", "ERROR", e);
+ co_return std::nullopt;
+ }
+
+ co_return SoftwareConfig(objectPath, vendorIANA, compatible, configType,
+ configName);
+}
+
+// NOLINTBEGIN(readability-static-accessed-through-instance)
sdbusplus::async::task<> SoftwareManager::initDevices(
const std::vector<std::string>& configurationInterfaces)
// NOLINTEND(readability-static-accessed-through-instance)
@@ -75,60 +133,18 @@
"[config] found configuration interface at {SERVICE}, {OBJPATH}",
"SERVICE", service, "OBJPATH", path);
- auto client =
- sdbusplus::async::proxy().service(service).path(path).interface(
- "org.freedesktop.DBus.Properties");
-
- uint64_t vendorIANA = 0;
- std::string compatible{};
- std::string emConfigType{};
- std::string emConfigName{};
-
- const std::string ifaceFwInfoDef = interfaceFound + ".FirmwareInfo";
-
- try
+ auto optConfig =
+ co_await getConfig(ctx, service, path, interfaceFound);
+ if (!optConfig.has_value())
{
- {
- auto propVendorIANA =
- co_await client.call<std::variant<uint64_t>>(
- ctx, "Get", ifaceFwInfoDef, "VendorIANA");
-
- vendorIANA = std::get<uint64_t>(propVendorIANA);
- }
- {
- auto propCompatible =
- co_await client.call<std::variant<std::string>>(
- ctx, "Get", ifaceFwInfoDef, "CompatibleHardware");
-
- compatible = std::get<std::string>(propCompatible);
- }
- {
- auto propEMConfigType =
- co_await client.call<std::variant<std::string>>(
- ctx, "Get", interfaceFound, "Type");
-
- emConfigType = std::get<std::string>(propEMConfigType);
- }
- {
- auto propEMConfigName =
- co_await client.call<std::variant<std::string>>(
- ctx, "Get", interfaceFound, "Name");
-
- emConfigName = std::get<std::string>(propEMConfigName);
- }
- }
- catch (std::exception& e)
- {
- error(e.what());
+ error("Error fetching common configuration from {PATH}", "PATH",
+ path);
continue;
}
- SoftwareConfig config(path, vendorIANA, compatible, emConfigType,
- emConfigName);
-
- co_await initDevice(service, path, config);
+ co_await initDevice(service, path, optConfig.value());
}
}
- debug("[config] done with initial configuration");
+ debug("Done with initial configuration");
}