async changes to support 40749
https://gerrit.openbmc-project.xyz/c/openbmc/sdbusplus/+/40749
Is currently proposing changing these APIs to use C++ asio style
callbacks instead of the javascript callbacks. This was the only usage
of these callbacks that I found, so this patchset is to move to the new
type.
Requires 40749 to be merged before this will build.
Signed-off-by: Ed Tanous <edtanous@google.com>
Signed-off-by: Krzysztof Grobelny <krzysztof.grobelny@intel.com>
Change-Id: I1e950c096e36d2150a94c459e794bbac7303100d
diff --git a/tests/src/test_report.cpp b/tests/src/test_report.cpp
index 90043bd..ece4be8 100644
--- a/tests/src/test_report.cpp
+++ b/tests/src/test_report.cpp
@@ -87,15 +87,20 @@
template <class T>
static T getProperty(const std::string& path, const std::string& property)
{
- std::promise<T> propertyPromise;
+ auto propertyPromise = std::promise<T>();
+ auto propertyFuture = propertyPromise.get_future();
sdbusplus::asio::getProperty<T>(
*DbusEnvironment::getBus(), DbusEnvironment::serviceName(), path,
Report::reportIfaceName, property,
- [&propertyPromise](boost::system::error_code) {
- utils::setException(propertyPromise, "GetProperty failed");
- },
- [&propertyPromise](T t) { propertyPromise.set_value(t); });
- return DbusEnvironment::waitForFuture(propertyPromise.get_future());
+ [&propertyPromise](const boost::system::error_code& ec, T t) {
+ if (ec)
+ {
+ utils::setException(propertyPromise, "GetProperty failed");
+ return;
+ }
+ propertyPromise.set_value(t);
+ });
+ return DbusEnvironment::waitForFuture(std::move(propertyFuture));
}
boost::system::error_code call(const std::string& path,
@@ -121,17 +126,16 @@
const std::string& property,
const T& newValue)
{
- std::promise<boost::system::error_code> setPromise;
+ auto setPromise = std::promise<boost::system::error_code>();
+ auto future = setPromise.get_future();
sdbusplus::asio::setProperty(
*DbusEnvironment::getBus(), DbusEnvironment::serviceName(), path,
Report::reportIfaceName, property, std::move(newValue),
- [&setPromise](boost::system::error_code ec) {
+ [setPromise =
+ std::move(setPromise)](boost::system::error_code ec) mutable {
setPromise.set_value(ec);
- },
- [&setPromise]() {
- setPromise.set_value(boost::system::error_code{});
});
- return DbusEnvironment::waitForFuture(setPromise.get_future());
+ return DbusEnvironment::waitForFuture(std::move(future));
}
boost::system::error_code deleteReport(const std::string& path)