Move getProperty calls to utility
Having all dbus calls run through the same utility reduces the amount of
generated code, and more importantly, gives us a place where we can log
the requests and responses to help with debugging.
Tested: Redfish service validator passes.
Change-Id: Ic1bf45130b5069cd57f7af26e12c8d3159c87c67
Signed-off-by: Ed Tanous <etanous@nvidia.com>
diff --git a/include/dbus_utility.hpp b/include/dbus_utility.hpp
index efeb2a0..68b3930 100644
--- a/include/dbus_utility.hpp
+++ b/include/dbus_utility.hpp
@@ -140,13 +140,57 @@
return count >= index;
}
+inline void
+ getAllProperties(const std::string& service, const std::string& objectPath,
+ const std::string& interface,
+ std::function<void(const boost::system::error_code&,
+ const DBusPropertiesMap&)>&& callback)
+{
+ sdbusplus::asio::getAllProperties(*crow::connections::systemBus, service,
+ objectPath, interface,
+ std::move(callback));
+}
+
+template <typename PropertyType>
+inline void getProperty(
+ const std::string& service, const std::string& objectPath,
+ const std::string& interface, const std::string& propertyName,
+ std::function<void(const boost::system::error_code&, const PropertyType&)>&&
+ callback)
+{
+ sdbusplus::asio::getProperty<PropertyType>(
+ *crow::connections::systemBus, service, objectPath, interface,
+ propertyName, std::move(callback));
+}
+
+template <typename PropertyType>
+inline void getProperty(
+ sdbusplus::asio::connection& /*conn*/, const std::string& service,
+ const std::string& objectPath, const std::string& interface,
+ const std::string& propertyName,
+ std::function<void(const boost::system::error_code&, const PropertyType&)>&&
+ callback)
+{
+ getProperty(service, objectPath, interface, propertyName,
+ std::move(callback));
+}
+
+inline void getAllProperties(
+ sdbusplus::asio::connection& /*conn*/, const std::string& service,
+ const std::string& objectPath, const std::string& interface,
+ std::function<void(const boost::system::error_code&,
+ const DBusPropertiesMap&)>&& callback)
+{
+ getAllProperties(service, objectPath, interface, std::move(callback));
+}
+
template <typename Callback>
inline void checkDbusPathExists(const std::string& path, Callback&& callback)
{
crow::connections::systemBus->async_method_call(
[callback = std::forward<Callback>(callback)](
const boost::system::error_code& ec,
- const dbus::utility::MapperGetObject& objectNames) {
+ const MapperGetObject& objectNames) {
callback(!ec && !objectNames.empty());
},
"xyz.openbmc_project.ObjectMapper",
@@ -283,9 +327,9 @@
std::function<void(const boost::system::error_code&,
const MapperEndPoints&)>&& callback)
{
- sdbusplus::asio::getProperty<MapperEndPoints>(
- *crow::connections::systemBus, "xyz.openbmc_project.ObjectMapper", path,
- "xyz.openbmc_project.Association", "endpoints", std::move(callback));
+ getProperty<MapperEndPoints>("xyz.openbmc_project.ObjectMapper", path,
+ "xyz.openbmc_project.Association", "endpoints",
+ std::move(callback));
}
inline void getManagedObjects(
diff --git a/include/openbmc_dbus_rest.hpp b/include/openbmc_dbus_rest.hpp
index fc074d6..8a6830e 100644
--- a/include/openbmc_dbus_rest.hpp
+++ b/include/openbmc_dbus_rest.hpp
@@ -181,8 +181,8 @@
BMCWEB_LOG_DEBUG("getPropertiesForEnumerate {} {} {}", objectPath, service,
interface);
- sdbusplus::asio::getAllProperties(
- *crow::connections::systemBus, service, objectPath, interface,
+ dbus::utility::getAllProperties(
+ service, objectPath, interface,
[asyncResp, objectPath, service,
interface](const boost::system::error_code& ec,
const dbus::utility::DBusPropertiesMap& propertiesList) {
diff --git a/include/vm_websocket.hpp b/include/vm_websocket.hpp
index 1e56cd9..5d92f5f 100644
--- a/include/vm_websocket.hpp
+++ b/include/vm_websocket.hpp
@@ -474,8 +474,8 @@
std::string path =
std::format("/xyz/openbmc_project/VirtualMedia/Proxy/Slot_{}", index);
- sdbusplus::asio::getAllProperties(
- *crow::connections::systemBus, "xyz.openbmc_project.VirtualMedia", path,
+ dbus::utility::getAllProperties(
+ "xyz.openbmc_project.VirtualMedia", path,
"xyz.openbmc_project.VirtualMedia.MountPoint",
[&conn, path](const boost::system::error_code& ec,
const dbus::utility::DBusPropertiesMap& propertiesList) {