Standardize the asio helper methods

As a general rule, std::networking/asio methods take a single callback
handler.  This is done intentionally, as it allows objects that cannot
be taken by reference to be taken directly by move.

The latest helper methods for properties seems to have taken a
javascript style approach, with "onSuccess" and "onError" handlers.
This works fine in js, where everything is reference counted, but
doesn't work in all cases in c++.

As an strawman.

std::unique_ptr<Thing> myThing;
setProperty(......
           [myThing{std::move(myThing)}](std::error_code){
               ... Use MyThing
           },
           [myThing{std::move(myThing)}](){
                ... Use mything
           });

The above code doesn't work, as you can't move out of myThing twice.
Sure, you could make myThing a shared_ptr, but that's wasteful, and
defeats c++es policy of "you don't pay for what you don't use".

This commit changes the new handlers to use more standard prototypes
that accept a single callback, and return error codes on failure.

I was able to find only one usage of these methods in the codebase,
inside telemetry, with a single getProperty call.  For that method, I
have left the old version of this method present, and marked it with the
c++17 [[deprecated]] flag, along with a note on what to do instead.
This is to avoid a hard binding between this patchset and
https://gerrit.openbmc-project.xyz/c/openbmc/telemetry/+/40878
which should allow them to be merged in whatever order we like.

Signed-off-by: Ed Tanous <edtanous@google.com>
Change-Id: Ia28e41fad5031656cef4d766c59baa948ea781e5
diff --git a/example/register-property.cpp b/example/register-property.cpp
index 6fd4c89..a95181c 100644
--- a/example/register-property.cpp
+++ b/example/register-property.cpp
@@ -39,20 +39,18 @@
         service_(service), path_(path), interface_(interface), name_(name)
     {}
 
-    template <class OnError, class OnSuccess>
-    void async_get(OnError&& onError, OnSuccess&& onSuccess)
+    template <class Handler>
+    void async_get(Handler&& handler)
     {
         sdbusplus::asio::getProperty<T>(bus_, service_, path_, interface_,
-                                        name_, std::forward<OnError>(onError),
-                                        std::forward<OnSuccess>(onSuccess));
+                                        name_, std::forward<Handler>(handler));
     }
 
-    template <class OnError, class OnSuccess>
-    void async_set(const T& value, OnError&& onError, OnSuccess&& onSuccess)
+    template <class Handler>
+    void async_set(const T& value, Handler&& handler)
     {
         sdbusplus::asio::setProperty(bus_, service_, path_, interface_, name_,
-                                     value, std::forward<OnError>(onError),
-                                     std::forward<OnSuccess>(onSuccess));
+                                     value, std::forward<Handler>(handler));
     }
 
   private:
@@ -112,12 +110,15 @@
             name::greetings};
 
         propertyWithWrongType.async_get(
-            [](boost::system::error_code error) {
-                std::cout
-                    << "As expected failed to getProperty with wrong type: "
-                    << error << "\n";
-            },
-            [this](uint32_t) {
+            [this](boost::system::error_code error, uint32_t) {
+                if (error)
+                {
+                    std::cout
+                        << "As expected failed to getProperty with wrong type: "
+                        << error << "\n";
+                    return;
+                }
+
                 std::cerr << "Error: it was expected to fail getProperty due "
                              "to wrong type\n";
                 ++fatalErrors_;
@@ -126,38 +127,55 @@
 
     void asyncReadProperties()
     {
-        propertyGreetings.async_get(getFailed(), [](std::string value) {
-            std::cout << "Greetings value is: " << value << "\n";
-        });
+        propertyGreetings.async_get(
+            [this](boost::system::error_code ec, std::string value) {
+                if (ec)
+                {
+                    getFailed();
+                    return;
+                }
+                std::cout << "Greetings value is: " << value << "\n";
+            });
 
-        propertyGoodbyes.async_get(getFailed(), [](std::string value) {
-            std::cout << "Goodbyes value is: " << value << "\n";
-        });
+        propertyGoodbyes.async_get(
+            [this](boost::system::error_code ec, std::string value) {
+                if (ec)
+                {
+                    getFailed();
+                    return;
+                }
+                std::cout << "Goodbyes value is: " << value << "\n";
+            });
     }
 
     void asyncChangeProperty()
     {
         propertyGreetings.async_set(
-            "Hi, hey, hello",
-            [](const boost::system::error_code& error) {
-                std::cout << "As expected, failed to set greetings property: "
-                          << error << "\n";
-            },
-            [this]() {
+            "Hi, hey, hello", [this](const boost::system::error_code& error) {
+                if (error)
+                {
+                    std::cout
+                        << "As expected, failed to set greetings property: "
+                        << error << "\n";
+                    return;
+                }
+
                 std::cout
                     << "Error: it was expected to fail to change greetings\n";
                 ++fatalErrors_;
             });
 
         propertyGoodbyes.async_set(
-            "Bye bye",
-            [this](const boost::system::error_code& error) {
-                std::cout << "Error: it supposed to be ok to change goodbyes "
-                             "property: "
-                          << error << "\n";
-                ++fatalErrors_;
-            },
-            [this]() {
+            "Bye bye", [this](const boost::system::error_code& error) {
+                if (error)
+                {
+                    std::cout
+                        << "Error: it supposed to be ok to change goodbyes "
+                           "property: "
+                        << error << "\n";
+                    ++fatalErrors_;
+                    return;
+                }
                 std::cout << "Changed goodbyes property as expected\n";
                 boost::asio::post(ioc_, [this] { asyncReadProperties(); });
             });