globalhandler: switch to asynchronous dbus calls

Use the latest asynchronous D-Bus method calls instead of synchronous
methods.

Change-Id: I1afd8a526f8dbed6359d93ec4a1a4e0853f205de
Signed-off-by: George Liu <liuxiwei@ieisystem.com>
diff --git a/globalhandler.cpp b/globalhandler.cpp
index 31f1781..7b64d42 100644
--- a/globalhandler.cpp
+++ b/globalhandler.cpp
@@ -14,33 +14,29 @@
 
 void registerNetFnGlobalFunctions() __attribute__((constructor));
 
-void resetBMC()
-{
-    sdbusplus::bus_t bus{ipmid_get_sd_bus_connection()};
-
-    auto bmcStateObj =
-        ipmi::getDbusObject(bus, bmcStateIntf, bmcStateRoot, match);
-
-    auto service = ipmi::getService(bus, bmcStateIntf, bmcStateObj.first);
-
-    ipmi::setDbusProperty(bus, service, bmcStateObj.first, bmcStateIntf,
-                          reqTransition,
-                          convertForMessage(BMC::Transition::Reboot));
-}
-
 /** @brief implements cold and warm reset commands
  *  @param - None
  *  @returns IPMI completion code.
  */
-ipmi::RspType<> ipmiGlobalReset()
+ipmi::RspType<> ipmiGlobalReset(ipmi::Context::ptr ctx)
 {
-    try
+    ipmi::DbusObjectInfo bmcStateObj;
+    boost::system::error_code ec = ipmi::getDbusObject(
+        ctx, bmcStateIntf, bmcStateRoot, match, bmcStateObj);
+    if (!ec)
     {
-        resetBMC();
+        std::string service;
+        ec = ipmi::getService(ctx, bmcStateIntf, bmcStateObj.first, service);
+        if (!ec)
+        {
+            ec = ipmi::setDbusProperty(
+                ctx, service, bmcStateObj.first, bmcStateIntf, reqTransition,
+                convertForMessage(BMC::Transition::Reboot));
+        }
     }
-    catch (const std::exception& e)
+    if (ec)
     {
-        lg2::error("Exception in Global Reset: {ERROR}", "ERROR", e);
+        lg2::error("Exception in Global Reset: {ERROR}", "ERROR", ec.message());
         return ipmi::responseUnspecifiedError();
     }