Add async_method_call to utility

Adding async_method_call in dbus utility gives us a place where we can
intercept method call requests from dbus to potentially add
logging/caching.

An example of logging is in the later commit:
https://gerrit.openbmc.org/c/openbmc/bmcweb/+/78265/

We already do this for setProperty, this moves the method calls to
follow a similar pattern.

Tested: Redfish service validator passes.

Change-Id: I6d2c96e2b6b6a023ed2138106a55faebca161592
Signed-off-by: Ed Tanous <etanous@nvidia.com>
diff --git a/include/async_resolve.hpp b/include/async_resolve.hpp
index 1a6f1b7..9dc41f7 100644
--- a/include/async_resolve.hpp
+++ b/include/async_resolve.hpp
@@ -1,7 +1,7 @@
 // SPDX-License-Identifier: Apache-2.0
 // SPDX-FileCopyrightText: Copyright OpenBMC Authors
 #pragma once
-#include "dbus_singleton.hpp"
+#include "dbus_utility.hpp"
 #include "logging.hpp"
 
 #include <sys/socket.h>
@@ -90,7 +90,7 @@
         }
 
         uint64_t flag = 0;
-        crow::connections::systemBus->async_method_call(
+        dbus::utility::async_method_call(
             [host{std::string(host)}, portNum,
              handler = std::forward<ResolveHandler>(handler)](
                 const boost::system::error_code& ec,
diff --git a/include/dbus_privileges.hpp b/include/dbus_privileges.hpp
index 9b12244..524ff1b 100644
--- a/include/dbus_privileges.hpp
+++ b/include/dbus_privileges.hpp
@@ -3,7 +3,6 @@
 #pragma once
 
 #include "async_resp.hpp"
-#include "dbus_singleton.hpp"
 #include "dbus_utility.hpp"
 #include "error_messages.hpp"
 #include "http_request.hpp"
@@ -139,7 +138,8 @@
     std::move_only_function<void(const dbus::utility::DBusPropertiesMap&)>&&
         callback)
 {
-    crow::connections::systemBus->async_method_call(
+    dbus::utility::async_method_call(
+        asyncResp,
         [asyncResp, callback = std::move(callback)](
             const boost::system::error_code& ec,
             const dbus::utility::DBusPropertiesMap& userInfoMap) mutable {
diff --git a/include/dbus_utility.hpp b/include/dbus_utility.hpp
index d1f4a84..4eedcbf 100644
--- a/include/dbus_utility.hpp
+++ b/include/dbus_utility.hpp
@@ -3,6 +3,7 @@
 // SPDX-FileCopyrightText: Copyright 2018 Intel Corporation
 #pragma once
 
+#include "async_resp.hpp"
 #include "boost_formatters.hpp"
 #include "dbus_singleton.hpp"
 
@@ -14,6 +15,7 @@
 #include <cstddef>
 #include <cstdint>
 #include <functional>
+#include <memory>
 #include <span>
 #include <string>
 #include <string_view>
@@ -99,6 +101,29 @@
                       std::function<void(const boost::system::error_code&,
                                          const DBusPropertiesMap&)>&& callback);
 
+template <typename MessageHandler, typename... InputArgs>
+// NOLINTNEXTLINE(readability-identifier-naming)
+void async_method_call(MessageHandler&& handler, const std::string& service,
+                       const std::string& objpath, const std::string& interf,
+                       const std::string& method, const InputArgs&... a)
+{
+    crow::connections::systemBus->async_method_call(
+        std::forward<MessageHandler>(handler), service, objpath, interf, method,
+        a...);
+}
+
+template <typename MessageHandler, typename... InputArgs>
+// NOLINTNEXTLINE(readability-identifier-naming)
+void async_method_call(const std::shared_ptr<bmcweb::AsyncResp>& /*asyncResp*/,
+                       MessageHandler&& handler, const std::string& service,
+                       const std::string& objpath, const std::string& interf,
+                       const std::string& method, const InputArgs&... a)
+{
+    crow::connections::systemBus->async_method_call(
+        std::forward<MessageHandler>(handler), service, objpath, interf, method,
+        a...);
+}
+
 template <typename PropertyType>
 void getProperty(const std::string& service, const std::string& objectPath,
                  const std::string& interface, const std::string& propertyName,
diff --git a/include/google/google_service_root.hpp b/include/google/google_service_root.hpp
index 8b0d36c..3d21af7 100644
--- a/include/google/google_service_root.hpp
+++ b/include/google/google_service_root.hpp
@@ -4,7 +4,6 @@
 
 #include "app.hpp"
 #include "async_resp.hpp"
-#include "dbus_singleton.hpp"
 #include "dbus_utility.hpp"
 #include "error_messages.hpp"
 #include "http_request.hpp"
@@ -188,7 +187,8 @@
         return;
     }
 
-    crow::connections::systemBus->async_method_call(
+    dbus::utility::async_method_call(
+        asyncResp,
         [asyncResp{asyncResp}](const boost::system::error_code& ec,
                                const std::vector<uint8_t>& responseBytes) {
             invocationCallback(asyncResp, ec, responseBytes);
diff --git a/include/hostname_monitor.hpp b/include/hostname_monitor.hpp
index 839faab..21cc88a 100644
--- a/include/hostname_monitor.hpp
+++ b/include/hostname_monitor.hpp
@@ -35,7 +35,7 @@
 
 inline void installCertificate(const std::filesystem::path& certPath)
 {
-    crow::connections::systemBus->async_method_call(
+    dbus::utility::async_method_call(
         [certPath](const boost::system::error_code& ec) {
             if (ec)
             {
diff --git a/include/obmc_console.hpp b/include/obmc_console.hpp
index e94b6a9..40b72fe 100644
--- a/include/obmc_console.hpp
+++ b/include/obmc_console.hpp
@@ -2,7 +2,6 @@
 // SPDX-FileCopyrightText: Copyright OpenBMC Authors
 #pragma once
 #include "app.hpp"
-#include "dbus_singleton.hpp"
 #include "dbus_utility.hpp"
 #include "io_context_singleton.hpp"
 #include "logging.hpp"
@@ -263,7 +262,7 @@
     BMCWEB_LOG_DEBUG("Looking up unixFD for Service {} Path {}", consoleService,
                      consoleObjPath);
     // Call Connect() method to get the unix FD
-    crow::connections::systemBus->async_method_call(
+    dbus::utility::async_method_call(
         [&conn](const boost::system::error_code& ec1,
                 const sdbusplus::message::unix_fd& unixfd) {
             connectConsoleSocket(conn, ec1, unixfd);
diff --git a/include/openbmc_dbus_rest.hpp b/include/openbmc_dbus_rest.hpp
index 967c934..f651c38 100644
--- a/include/openbmc_dbus_rest.hpp
+++ b/include/openbmc_dbus_rest.hpp
@@ -103,7 +103,7 @@
         transaction->res.jsonValue["objects"] = nlohmann::json::array();
     }
 
-    crow::connections::systemBus->async_method_call(
+    dbus::utility::async_method_call(
         [transaction, processName{std::string(processName)},
          objectPath{std::string(objectPath)}](
             const boost::system::error_code& ec,
@@ -335,7 +335,7 @@
 {
     BMCWEB_LOG_DEBUG("Finding objectmanager for path {} on connection:{}",
                      objectName, connectionName);
-    crow::connections::systemBus->async_method_call(
+    dbus::utility::async_method_call(
         [transaction, objectName, connectionName](
             const boost::system::error_code& ec,
             const dbus::utility::MapperGetAncestorsResponse& objects) {
@@ -1362,7 +1362,7 @@
     const std::string& connectionName)
 {
     BMCWEB_LOG_DEBUG("findActionOnInterface for connection {}", connectionName);
-    crow::connections::systemBus->async_method_call(
+    dbus::utility::async_method_call(
         [transaction, connectionName{std::string(connectionName)}](
             const boost::system::error_code& ec,
             const std::string& introspectXml) {
@@ -1896,7 +1896,7 @@
             {
                 const std::string& connectionName = connection.first;
 
-                crow::connections::systemBus->async_method_call(
+                dbus::utility::async_method_call(
                     [connectionName{std::string(connectionName)},
                      transaction](const boost::system::error_code& ec3,
                                   const std::string& introspectXml) {
@@ -2183,7 +2183,7 @@
     }
     if (interfaceName.empty())
     {
-        crow::connections::systemBus->async_method_call(
+        dbus::utility::async_method_call(
             [asyncResp, processName,
              objectPath](const boost::system::error_code& ec,
                          const std::string& introspectXml) {
@@ -2237,7 +2237,7 @@
     }
     else if (methodName.empty())
     {
-        crow::connections::systemBus->async_method_call(
+        dbus::utility::async_method_call(
             [asyncResp, processName, objectPath,
              interfaceName](const boost::system::error_code& ec,
                             const std::string& introspectXml) {
@@ -2504,7 +2504,7 @@
                         }
                     }
                 };
-                crow::connections::systemBus->async_method_call(
+                dbus::utility::async_method_call(
                     std::move(myCallback), "org.freedesktop.DBus", "/",
                     "org.freedesktop.DBus", "ListNames");
             });
diff --git a/include/vm_websocket.hpp b/include/vm_websocket.hpp
index 95cb982..b930b64 100644
--- a/include/vm_websocket.hpp
+++ b/include/vm_websocket.hpp
@@ -5,7 +5,6 @@
 #include "bmcweb_config.h"
 
 #include "app.hpp"
-#include "dbus_singleton.hpp"
 #include "dbus_utility.hpp"
 #include "io_context_singleton.hpp"
 #include "logging.hpp"
@@ -232,7 +231,7 @@
             BMCWEB_LOG_DEBUG("Failed to remove file, ignoring");
         }
 
-        crow::connections::systemBus->async_method_call(
+        dbus::utility::async_method_call(
             dbus::utility::logError, "xyz.openbmc_project.VirtualMedia", path,
             "xyz.openbmc_project.VirtualMedia.Proxy", "Unmount");
     }
@@ -290,7 +289,7 @@
         acceptor.async_accept(
             std::bind_front(&NbdProxyServer::afterAccept, weak_from_this()));
 
-        crow::connections::systemBus->async_method_call(
+        dbus::utility::async_method_call(
             [weak{weak_from_this()}](const boost::system::error_code& ec,
                                      bool isBinary) {
                 afterMount(weak, ec, isBinary);