Add the GetObject method to dbus_utility
There are currently many files that use the GetObject method.
Since they are a general method, they are defined in the
dbus_utility.hpp file and refactors them.
Tested: Built bmcweb successfully and Validator passes.
Signed-off-by: George Liu <liuxiwei@inspur.com>
Change-Id: If2af77294389b023b611987252ee6149906fcd25
diff --git a/redfish-core/lib/virtual_media.hpp b/redfish-core/lib/virtual_media.hpp
index 7c53f7e..45f384b 100644
--- a/redfish-core/lib/virtual_media.hpp
+++ b/redfish-core/lib/virtual_media.hpp
@@ -17,6 +17,7 @@
#include "account_service.hpp"
#include "app.hpp"
+#include "dbus_utility.hpp"
#include "query.hpp"
#include "registries/privilege_registry.hpp"
#include "utils/json_utils.hpp"
@@ -25,6 +26,9 @@
#include <boost/type_traits/has_dereference.hpp>
#include <boost/url/url_view.hpp>
+#include <array>
+#include <string_view>
+
namespace redfish
{
/**
@@ -797,9 +801,10 @@
return;
}
- crow::connections::systemBus->async_method_call(
+ dbus::utility::getDbusObject(
+ "/xyz/openbmc_project/VirtualMedia", {},
[asyncResp, actionParams,
- resName](const boost::system::error_code ec,
+ resName](const boost::system::error_code& ec,
const dbus::utility::MapperGetObject& getObjectType) mutable {
if (ec)
{
@@ -873,11 +878,7 @@
},
service, "/xyz/openbmc_project/VirtualMedia",
"org.freedesktop.DBus.ObjectManager", "GetManagedObjects");
- },
- "xyz.openbmc_project.ObjectMapper",
- "/xyz/openbmc_project/object_mapper",
- "xyz.openbmc_project.ObjectMapper", "GetObject",
- "/xyz/openbmc_project/VirtualMedia", std::array<const char*, 0>());
+ });
}
inline void handleManagersVirtualMediaActionEject(
@@ -897,9 +898,10 @@
return;
}
- crow::connections::systemBus->async_method_call(
+ dbus::utility::getDbusObject(
+ "/xyz/openbmc_project/VirtualMedia", {},
[asyncResp,
- resName](const boost::system::error_code ec2,
+ resName](const boost::system::error_code& ec2,
const dbus::utility::MapperGetObject& getObjectType) {
if (ec2)
{
@@ -960,11 +962,7 @@
},
service, "/xyz/openbmc_project/VirtualMedia",
"org.freedesktop.DBus.ObjectManager", "GetManagedObjects");
- },
- "xyz.openbmc_project.ObjectMapper",
- "/xyz/openbmc_project/object_mapper",
- "xyz.openbmc_project.ObjectMapper", "GetObject",
- "/xyz/openbmc_project/VirtualMedia", std::array<const char*, 0>());
+ });
}
inline void handleManagersVirtualMediaCollectionGet(
@@ -989,8 +987,9 @@
asyncResp->res.jsonValue["@odata.id"] = crow::utility::urlFromPieces(
"redfish", "v1", "Managers", name, "VirtualMedia");
- crow::connections::systemBus->async_method_call(
- [asyncResp, name](const boost::system::error_code ec,
+ dbus::utility::getDbusObject(
+ "/xyz/openbmc_project/VirtualMedia", {},
+ [asyncResp, name](const boost::system::error_code& ec,
const dbus::utility::MapperGetObject& getObjectType) {
if (ec)
{
@@ -1003,11 +1002,7 @@
BMCWEB_LOG_DEBUG << "GetObjectType: " << service;
getVmResourceList(asyncResp, service, name);
- },
- "xyz.openbmc_project.ObjectMapper",
- "/xyz/openbmc_project/object_mapper",
- "xyz.openbmc_project.ObjectMapper", "GetObject",
- "/xyz/openbmc_project/VirtualMedia", std::array<const char*, 0>());
+ });
}
inline void
@@ -1026,9 +1021,10 @@
return;
}
- crow::connections::systemBus->async_method_call(
+ dbus::utility::getDbusObject(
+ "/xyz/openbmc_project/VirtualMedia", {},
[asyncResp, name,
- resName](const boost::system::error_code ec,
+ resName](const boost::system::error_code& ec,
const dbus::utility::MapperGetObject& getObjectType) {
if (ec)
{
@@ -1041,11 +1037,7 @@
BMCWEB_LOG_DEBUG << "GetObjectType: " << service;
getVmData(asyncResp, service, name, resName);
- },
- "xyz.openbmc_project.ObjectMapper",
- "/xyz/openbmc_project/object_mapper",
- "xyz.openbmc_project.ObjectMapper", "GetObject",
- "/xyz/openbmc_project/VirtualMedia", std::array<const char*, 0>());
+ });
}
inline void requestNBDVirtualMediaRoutes(App& app)