summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/dbus_utility.hpp16
-rw-r--r--include/openbmc_dbus_rest.hpp55
-rw-r--r--redfish-core/lib/account_service.hpp15
-rw-r--r--redfish-core/lib/hypervisor_system.hpp28
-rw-r--r--redfish-core/lib/sensors.hpp13
-rw-r--r--redfish-core/lib/update_service.hpp17
-rw-r--r--redfish-core/lib/virtual_media.hpp48
7 files changed, 90 insertions, 102 deletions
diff --git a/include/dbus_utility.hpp b/include/dbus_utility.hpp
index c7fda6d33b..c9143de21d 100644
--- a/include/dbus_utility.hpp
+++ b/include/dbus_utility.hpp
@@ -175,5 +175,21 @@ inline void getSubTreePaths(
interfaces);
}
+inline void
+ getDbusObject(const std::string& path,
+ std::span<const std::string_view> interfaces,
+ std::function<void(const boost::system::error_code&,
+ const MapperGetObject&)>&& callback)
+{
+ crow::connections::systemBus->async_method_call(
+ [callback{std::move(callback)}](const boost::system::error_code& ec,
+ const MapperGetObject& object) {
+ callback(ec, object);
+ },
+ "xyz.openbmc_project.ObjectMapper",
+ "/xyz/openbmc_project/object_mapper",
+ "xyz.openbmc_project.ObjectMapper", "GetObject", path, interfaces);
+}
+
} // namespace utility
} // namespace dbus
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<InProgressEnumerateData>& 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<const char*, 0>());
+ });
}
// 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<std::pair<std::string, std::vector<std::string>>>&
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<std::string, 0>());
+ });
}
inline void handleDelete(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
@@ -1605,9 +1599,10 @@ inline void handleDelete(const std::shared_ptr<bmcweb::AsyncResp>& 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<std::pair<std::string, std::vector<std::string>>>&
interfaceNames) {
if (ec || interfaceNames.empty())
@@ -1630,11 +1625,7 @@ inline void handleDelete(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
{
findActionOnInterface(transaction, object.first);
}
- },
- "xyz.openbmc_project.ObjectMapper",
- "/xyz/openbmc_project/object_mapper",
- "xyz.openbmc_project.ObjectMapper", "GetObject", objectPath,
- std::array<const char*, 0>());
+ });
}
inline void handleList(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
@@ -1710,9 +1701,10 @@ inline void handleGet(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
std::shared_ptr<std::string> path =
std::make_shared<std::string>(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<bmcweb::AsyncResp>& asyncResp,
});
}
}
- },
- "xyz.openbmc_project.ObjectMapper",
- "/xyz/openbmc_project/object_mapper",
- "xyz.openbmc_project.ObjectMapper", "GetObject", *path,
- std::array<std::string, 0>());
+ });
}
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<std::string, 0>());
+ });
}
inline void handleDBusUrl(const crow::Request& req,
diff --git a/redfish-core/lib/account_service.hpp b/redfish-core/lib/account_service.hpp
index abf255eb00..9f99d184ab 100644
--- a/redfish-core/lib/account_service.hpp
+++ b/redfish-core/lib/account_service.hpp
@@ -29,8 +29,10 @@
#include <sdbusplus/asio/property.hpp>
#include <sdbusplus/unpack_properties.hpp>
+#include <array>
#include <optional>
#include <string>
+#include <string_view>
#include <vector>
namespace redfish
@@ -425,11 +427,12 @@ inline void getLDAPConfigData(const std::string& ldapType,
CallbackFunc&& callback)
{
- const std::array<const char*, 2> interfaces = {ldapEnableInterface,
- ldapConfigInterface};
+ constexpr std::array<std::string_view, 2> interfaces = {
+ ldapEnableInterface, ldapConfigInterface};
- crow::connections::systemBus->async_method_call(
- [callback, ldapType](const boost::system::error_code ec,
+ dbus::utility::getDbusObject(
+ ldapConfigObjectName, interfaces,
+ [callback, ldapType](const boost::system::error_code& ec,
const dbus::utility::MapperGetObject& resp) {
if (ec || resp.empty())
{
@@ -580,9 +583,7 @@ inline void getLDAPConfigData(const std::string& ldapType,
callback(true, confData, ldapType);
},
service, ldapRootObject, dbusObjManagerIntf, "GetManagedObjects");
- },
- mapperBusName, mapperObjectPath, mapperIntf, "GetObject",
- ldapConfigObjectName, interfaces);
+ });
}
/**
diff --git a/redfish-core/lib/hypervisor_system.hpp b/redfish-core/lib/hypervisor_system.hpp
index c675be35b8..b558030fed 100644
--- a/redfish-core/lib/hypervisor_system.hpp
+++ b/redfish-core/lib/hypervisor_system.hpp
@@ -111,9 +111,12 @@ inline void
getHypervisorActions(const std::shared_ptr<bmcweb::AsyncResp>& aResp)
{
BMCWEB_LOG_DEBUG << "Get hypervisor actions.";
- crow::connections::systemBus->async_method_call(
+ constexpr std::array<std::string_view, 1> interfaces = {
+ "xyz.openbmc_project.State.Host"};
+ dbus::utility::getDbusObject(
+ "/xyz/openbmc_project/state/hypervisor0", interfaces,
[aResp](
- const boost::system::error_code ec,
+ const boost::system::error_code& ec,
const std::vector<std::pair<std::string, std::vector<std::string>>>&
objInfo) {
if (ec)
@@ -146,12 +149,7 @@ inline void
"/redfish/v1/Systems/hypervisor/Actions/ComputerSystem.Reset";
reset["@Redfish.ActionInfo"] =
"/redfish/v1/Systems/hypervisor/ResetActionInfo";
- },
- "xyz.openbmc_project.ObjectMapper",
- "/xyz/openbmc_project/object_mapper",
- "xyz.openbmc_project.ObjectMapper", "GetObject",
- "/xyz/openbmc_project/state/hypervisor0",
- std::array<const char*, 1>{"xyz.openbmc_project.State.Host"});
+ });
}
inline bool extractHypervisorInterfaceData(
@@ -993,8 +991,11 @@ inline void requestRoutesHypervisorSystems(App& app)
return;
}
// Only return action info if hypervisor D-Bus object present
- crow::connections::systemBus->async_method_call(
- [asyncResp](const boost::system::error_code ec,
+ constexpr std::array<std::string_view, 1> interfaces = {
+ "xyz.openbmc_project.State.Host"};
+ dbus::utility::getDbusObject(
+ "/xyz/openbmc_project/state/hypervisor0", interfaces,
+ [asyncResp](const boost::system::error_code& ec,
const std::vector<std::pair<
std::string, std::vector<std::string>>>& objInfo) {
if (ec)
@@ -1040,12 +1041,7 @@ inline void requestRoutesHypervisorSystems(App& app)
parameter["AllowableValues"] = std::move(allowed);
parameters.push_back(std::move(parameter));
asyncResp->res.jsonValue["Parameters"] = std::move(parameters);
- },
- "xyz.openbmc_project.ObjectMapper",
- "/xyz/openbmc_project/object_mapper",
- "xyz.openbmc_project.ObjectMapper", "GetObject",
- "/xyz/openbmc_project/state/hypervisor0",
- std::array<const char*, 1>{"xyz.openbmc_project.State.Host"});
+ });
});
BMCWEB_ROUTE(app,
diff --git a/redfish-core/lib/sensors.hpp b/redfish-core/lib/sensors.hpp
index 1aaeaf1d0a..315398ee3d 100644
--- a/redfish-core/lib/sensors.hpp
+++ b/redfish-core/lib/sensors.hpp
@@ -2910,15 +2910,16 @@ inline void handleSensorGet(App& app, const crow::Request& req,
BMCWEB_LOG_DEBUG << "Sensor doGet enter";
- const std::array<const char*, 1> interfaces = {
+ constexpr std::array<std::string_view, 1> interfaces = {
"xyz.openbmc_project.Sensor.Value"};
std::string sensorPath = "/xyz/openbmc_project/sensors/" + nameType.first +
'/' + nameType.second;
// Get a list of all of the sensors that implement Sensor.Value
// and get the path and service name associated with the sensor
- crow::connections::systemBus->async_method_call(
+ ::dbus::utility::getDbusObject(
+ sensorPath, interfaces,
[asyncResp,
- sensorPath](const boost::system::error_code ec,
+ sensorPath](const boost::system::error_code& ec,
const ::dbus::utility::MapperGetObject& subtree) {
BMCWEB_LOG_DEBUG << "respHandler1 enter";
if (ec)
@@ -2930,11 +2931,7 @@ inline void handleSensorGet(App& app, const crow::Request& req,
}
getSensorFromDbus(asyncResp, sensorPath, subtree);
BMCWEB_LOG_DEBUG << "respHandler1 exit";
- },
- "xyz.openbmc_project.ObjectMapper",
- "/xyz/openbmc_project/object_mapper",
- "xyz.openbmc_project.ObjectMapper", "GetObject", sensorPath,
- interfaces);
+ });
}
} // namespace sensors
diff --git a/redfish-core/lib/update_service.hpp b/redfish-core/lib/update_service.hpp
index a9174a1e9e..a8f0a6caa4 100644
--- a/redfish-core/lib/update_service.hpp
+++ b/redfish-core/lib/update_service.hpp
@@ -28,6 +28,9 @@
#include <sdbusplus/bus/match.hpp>
#include <sdbusplus/unpack_properties.hpp>
+#include <array>
+#include <string_view>
+
namespace redfish
{
@@ -87,9 +90,12 @@ static void
if (interface.first == "xyz.openbmc_project.Software.Activation")
{
// Retrieve service and activate
- crow::connections::systemBus->async_method_call(
+ constexpr std::array<std::string_view, 1> interfaces = {
+ "xyz.openbmc_project.Software.Activation"};
+ dbus::utility::getDbusObject(
+ objPath.str, interfaces,
[objPath, asyncResp, payload(std::move(payload))](
- const boost::system::error_code errorCode,
+ const boost::system::error_code& errorCode,
const std::vector<
std::pair<std::string, std::vector<std::string>>>&
objInfo) mutable {
@@ -246,12 +252,7 @@ static void
task->payload.emplace(std::move(payload));
}
fwUpdateInProgress = false;
- },
- "xyz.openbmc_project.ObjectMapper",
- "/xyz/openbmc_project/object_mapper",
- "xyz.openbmc_project.ObjectMapper", "GetObject", objPath.str,
- std::array<const char*, 1>{
- "xyz.openbmc_project.Software.Activation"});
+ });
break;
}
diff --git a/redfish-core/lib/virtual_media.hpp b/redfish-core/lib/virtual_media.hpp
index 7c53f7e5f9..45f384be34 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 @@ inline void handleManagersVirtualMediaActionInsertPost(
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 @@ inline void handleManagersVirtualMediaActionInsertPost(
},
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 @@ inline void handleManagersVirtualMediaActionEject(
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 @@ inline void handleManagersVirtualMediaActionEject(
},
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 @@ inline void handleManagersVirtualMediaCollectionGet(
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 @@ inline void handleManagersVirtualMediaCollectionGet(
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 @@ inline void
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 @@ inline void
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)