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/src/sensor.cpp b/src/sensor.cpp
index 8b4fe01..26cadb7 100644
--- a/src/sensor.cpp
+++ b/src/sensor.cpp
@@ -35,14 +35,16 @@
     sdbusplus::asio::getProperty<double>(
         *bus, sensorId.service, sensorId.path,
         "xyz.openbmc_project.Sensor.Value", "Value",
-        [lock, id = sensorId,
-         weakSelf = weak_from_this()](boost::system::error_code ec) {
-            phosphor::logging::log<phosphor::logging::level::WARNING>(
-                "DBus 'GetProperty' call failed on Sensor Value",
-                phosphor::logging::entry("SENSOR_PATH=%s", id.path.c_str()),
-                phosphor::logging::entry("ERROR_CODE=%d", ec.value()));
-        },
-        [lock, weakSelf = weak_from_this()](double newValue) {
+        [lock, id = sensorId, weakSelf = weak_from_this()](
+            boost::system::error_code ec, double newValue) {
+            if (ec)
+            {
+                phosphor::logging::log<phosphor::logging::level::WARNING>(
+                    "DBus 'GetProperty' call failed on Sensor Value",
+                    phosphor::logging::entry("SENSOR_PATH=%s", id.path.c_str()),
+                    phosphor::logging::entry("ERROR_CODE=%d", ec.value()));
+                return;
+            }
             if (auto self = weakSelf.lock())
             {
                 self->updateValue(newValue);
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)
diff --git a/tests/src/test_report_manager.cpp b/tests/src/test_report_manager.cpp
index 19760fe..d9ea4af 100644
--- a/tests/src/test_report_manager.cpp
+++ b/tests/src/test_report_manager.cpp
@@ -6,6 +6,7 @@
 #include "report.hpp"
 #include "report_manager.hpp"
 #include "utils/conversion.hpp"
+#include "utils/set_exception.hpp"
 #include "utils/transform.hpp"
 
 using namespace testing;
@@ -67,17 +68,21 @@
     template <class T>
     static T getProperty(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(),
             ReportManager::reportManagerPath,
             ReportManager::reportManagerIfaceName, property,
-            [&propertyPromise](boost::system::error_code ec) {
-                EXPECT_THAT(static_cast<bool>(ec), ::testing::Eq(false));
-                propertyPromise.set_value(T{});
-            },
-            [&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, "Get property failed");
+                    return;
+                }
+                propertyPromise.set_value(t);
+            });
+        return DbusEnvironment::waitForFuture(std::move(propertyFuture));
     }
 };
 
diff --git a/tests/src/test_trigger.cpp b/tests/src/test_trigger.cpp
index 2b2b0fb..b2b259c 100644
--- a/tests/src/test_trigger.cpp
+++ b/tests/src/test_trigger.cpp
@@ -32,15 +32,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,
             Trigger::triggerIfaceName, 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 deleteTrigger(const std::string& path)