From 2b73119c57d054d1a0d67b376ae5651fccfae5ba Mon Sep 17 00:00:00 2001 From: George Liu Date: Wed, 11 Jan 2023 16:27:13 +0800 Subject: 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 Change-Id: If2af77294389b023b611987252ee6149906fcd25 --- include/openbmc_dbus_rest.hpp | 55 ++++++++++++++++--------------------------- 1 file changed, 20 insertions(+), 35 deletions(-) (limited to 'include/openbmc_dbus_rest.hpp') diff --git a/include/openbmc_dbus_rest.hpp b/include/openbmc_dbus_rest.hpp index 61eaa6e8c7..948bc367e5 100644 --- a/include/openbmc_dbus_rest.hpp +++ b/include/openbmc_dbus_rest.hpp @@ -406,8 +406,9 @@ inline void findObjectManagerPathForEnumerate( inline void getObjectAndEnumerate( const std::shared_ptr& transaction) { - crow::connections::systemBus->async_method_call( - [transaction](const boost::system::error_code ec, + dbus::utility::getDbusObject( + transaction->objectPath, {}, + [transaction](const boost::system::error_code& ec, const dbus::utility::MapperGetObject& objects) { if (ec) { @@ -466,11 +467,7 @@ inline void getObjectAndEnumerate( transaction->objectPath, connection.first, transaction); } } - }, - "xyz.openbmc_project.ObjectMapper", - "/xyz/openbmc_project/object_mapper", - "xyz.openbmc_project.ObjectMapper", "GetObject", - transaction->objectPath, std::array()); + }); } // Structure for storing data on an in progress action @@ -1571,9 +1568,10 @@ inline void handleAction(const crow::Request& req, transaction->path = objectPath; transaction->methodName = methodName; transaction->arguments = std::move(*data); - crow::connections::systemBus->async_method_call( + dbus::utility::getDbusObject( + objectPath, {}, [transaction]( - const boost::system::error_code ec, + const boost::system::error_code& ec, const std::vector>>& interfaceNames) { if (ec || interfaceNames.empty()) @@ -1593,11 +1591,7 @@ inline void handleAction(const crow::Request& req, { findActionOnInterface(transaction, object.first); } - }, - "xyz.openbmc_project.ObjectMapper", - "/xyz/openbmc_project/object_mapper", - "xyz.openbmc_project.ObjectMapper", "GetObject", objectPath, - std::array()); + }); } inline void handleDelete(const std::shared_ptr& asyncResp, @@ -1605,9 +1599,10 @@ inline void handleDelete(const std::shared_ptr& asyncResp, { BMCWEB_LOG_DEBUG << "handleDelete on path: " << objectPath; - crow::connections::systemBus->async_method_call( + dbus::utility::getDbusObject( + objectPath, {}, [asyncResp, objectPath]( - const boost::system::error_code ec, + const boost::system::error_code& ec, const std::vector>>& interfaceNames) { if (ec || interfaceNames.empty()) @@ -1630,11 +1625,7 @@ inline void handleDelete(const std::shared_ptr& asyncResp, { findActionOnInterface(transaction, object.first); } - }, - "xyz.openbmc_project.ObjectMapper", - "/xyz/openbmc_project/object_mapper", - "xyz.openbmc_project.ObjectMapper", "GetObject", objectPath, - std::array()); + }); } inline void handleList(const std::shared_ptr& asyncResp, @@ -1710,9 +1701,10 @@ inline void handleGet(const std::shared_ptr& asyncResp, std::shared_ptr path = std::make_shared(std::move(objectPath)); - crow::connections::systemBus->async_method_call( + dbus::utility::getDbusObject( + *path, {}, [asyncResp, path, - propertyName](const boost::system::error_code ec, + propertyName](const boost::system::error_code& ec, const dbus::utility::MapperGetObject& objectNames) { if (ec || objectNames.empty()) { @@ -1801,11 +1793,7 @@ inline void handleGet(const std::shared_ptr& asyncResp, }); } } - }, - "xyz.openbmc_project.ObjectMapper", - "/xyz/openbmc_project/object_mapper", - "xyz.openbmc_project.ObjectMapper", "GetObject", *path, - std::array()); + }); } struct AsyncPutRequest @@ -1878,8 +1866,9 @@ inline void handlePut(const crow::Request& req, transaction->propertyName = destProperty; transaction->propertyValue = propertySetValue; - crow::connections::systemBus->async_method_call( - [transaction](const boost::system::error_code ec2, + dbus::utility::getDbusObject( + transaction->objectPath, {}, + [transaction](const boost::system::error_code& ec2, const dbus::utility::MapperGetObject& objectNames) { if (!ec2 && objectNames.empty()) { @@ -2016,11 +2005,7 @@ inline void handlePut(const crow::Request& req, connectionName, transaction->objectPath, "org.freedesktop.DBus.Introspectable", "Introspect"); } - }, - "xyz.openbmc_project.ObjectMapper", - "/xyz/openbmc_project/object_mapper", - "xyz.openbmc_project.ObjectMapper", "GetObject", - transaction->objectPath, std::array()); + }); } inline void handleDBusUrl(const crow::Request& req, -- cgit v1.2.3