Refactor setProperty method
SetProperty is a method we should use more, and use consistently in the
codebase, this commit makes it consistently used from the utility
namespace.
Tested: Refactor. Code compiles.
Signed-off-by: George Liu <liuxiwei@inspur.com>
Change-Id: I5939317d23483e16bd98a8298f53e75604ef374d
diff --git a/redfish-core/lib/managers.hpp b/redfish-core/lib/managers.hpp
index a3f060b..c97ba02 100644
--- a/redfish-core/lib/managers.hpp
+++ b/redfish-core/lib/managers.hpp
@@ -61,9 +61,9 @@
const char* destProperty = "RequestedBMCTransition";
// Create the D-Bus variant for D-Bus call.
- dbus::utility::DbusVariantType dbusPropertyValue(propertyValue);
-
- crow::connections::systemBus->async_method_call(
+ sdbusplus::asio::setProperty(
+ *crow::connections::systemBus, processName, objectPath, interfaceName,
+ destProperty, propertyValue,
[asyncResp](const boost::system::error_code& ec) {
// Use "Set" method to set the property value.
if (ec)
@@ -74,9 +74,7 @@
}
messages::success(asyncResp->res);
- },
- processName, objectPath, "org.freedesktop.DBus.Properties", "Set",
- interfaceName, destProperty, dbusPropertyValue);
+ });
}
inline void
@@ -90,9 +88,9 @@
const char* destProperty = "RequestedBMCTransition";
// Create the D-Bus variant for D-Bus call.
- dbus::utility::DbusVariantType dbusPropertyValue(propertyValue);
-
- crow::connections::systemBus->async_method_call(
+ sdbusplus::asio::setProperty(
+ *crow::connections::systemBus, processName, objectPath, interfaceName,
+ destProperty, propertyValue,
[asyncResp](const boost::system::error_code& ec) {
// Use "Set" method to set the property value.
if (ec)
@@ -103,9 +101,7 @@
}
messages::success(asyncResp->res);
- },
- processName, objectPath, "org.freedesktop.DBus.Properties", "Set",
- interfaceName, destProperty, dbusPropertyValue);
+ });
}
/**
@@ -1466,17 +1462,16 @@
return;
}
currentProfile = *profile;
- crow::connections::systemBus->async_method_call(
+ sdbusplus::asio::setProperty(
+ *crow::connections::systemBus, profileConnection, profilePath,
+ thermalModeIface, "Current", *profile,
[response](const boost::system::error_code& ec) {
if (ec)
{
BMCWEB_LOG_ERROR << "Error patching profile" << ec;
messages::internalError(response->res);
}
- },
- profileConnection, profilePath,
- "org.freedesktop.DBus.Properties", "Set", thermalModeIface,
- "Current", dbus::utility::DbusVariantType(*profile));
+ });
}
for (auto& containerPair : configuration)
@@ -1600,7 +1595,10 @@
{
for (const auto& property : output)
{
- crow::connections::systemBus->async_method_call(
+ sdbusplus::asio::setProperty(
+ *crow::connections::systemBus,
+ "xyz.openbmc_project.EntityManager", path, iface,
+ property.first, property.second,
[response,
propertyName{std::string(property.first)}](
const boost::system::error_code& ec) {
@@ -1612,10 +1610,7 @@
return;
}
messages::success(response->res);
- },
- "xyz.openbmc_project.EntityManager", path,
- "org.freedesktop.DBus.Properties", "Set", iface,
- property.first, property.second);
+ });
}
}
else
@@ -1839,7 +1834,12 @@
// Only support Immediate
// An addition could be a Redfish Setting like
// ActiveSoftwareImageApplyTime and support OnReset
- crow::connections::systemBus->async_method_call(
+ sdbusplus::asio::setProperty(
+ *crow::connections::systemBus,
+ "xyz.openbmc_project.Software.BMC.Updater",
+ "/xyz/openbmc_project/software/" + firmwareId,
+ "xyz.openbmc_project.Software.RedundancyPriority", "Priority",
+ static_cast<uint8_t>(0),
[asyncResp](const boost::system::error_code& ec2) {
if (ec2)
{
@@ -1848,13 +1848,7 @@
return;
}
doBMCGracefulRestart(asyncResp);
- },
-
- "xyz.openbmc_project.Software.BMC.Updater",
- "/xyz/openbmc_project/software/" + firmwareId,
- "org.freedesktop.DBus.Properties", "Set",
- "xyz.openbmc_project.Software.RedundancyPriority", "Priority",
- dbus::utility::DbusVariantType(static_cast<uint8_t>(0)));
+ });
});
}
@@ -1871,7 +1865,10 @@
"DateTime");
return;
}
- crow::connections::systemBus->async_method_call(
+ sdbusplus::asio::setProperty(
+ *crow::connections::systemBus, "xyz.openbmc_project.Time.Manager",
+ "/xyz/openbmc_project/time/bmc", "xyz.openbmc_project.Time.EpochTime",
+ "Elapsed", us->count(),
[asyncResp{std::move(asyncResp)},
datetime{std::move(datetime)}](const boost::system::error_code& ec) {
if (ec)
@@ -1883,11 +1880,7 @@
return;
}
asyncResp->res.jsonValue["DateTime"] = datetime;
- },
- "xyz.openbmc_project.Time.Manager", "/xyz/openbmc_project/time/bmc",
- "org.freedesktop.DBus.Properties", "Set",
- "xyz.openbmc_project.Time.EpochTime", "Elapsed",
- dbus::utility::DbusVariantType(us->count()));
+ });
}
inline void