diff options
Diffstat (limited to 'redfish-core/include')
-rw-r--r-- | redfish-core/include/utils/dbus_utils.hpp | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/redfish-core/include/utils/dbus_utils.hpp b/redfish-core/include/utils/dbus_utils.hpp index 298a56b6ec..cd7e0e2ca2 100644 --- a/redfish-core/include/utils/dbus_utils.hpp +++ b/redfish-core/include/utils/dbus_utils.hpp @@ -1,9 +1,18 @@ #pragma once +#include "async_resp.hpp" +#include "dbus_singleton.hpp" +#include "error_messages.hpp" #include "logging.hpp" +#include <nlohmann/json.hpp> +#include <sdbusplus/asio/property.hpp> +#include <sdbusplus/message.hpp> #include <sdbusplus/unpack_properties.hpp> +#include <memory> +#include <string_view> + namespace redfish { namespace dbus_utils @@ -22,4 +31,37 @@ struct UnpackErrorPrinter }; } // namespace dbus_utils + +namespace details +{ +void afterSetProperty(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, + const std::string& redfishPropertyName, + const nlohmann::json& propertyValue, + const boost::system::error_code& ec, + const sdbusplus::message_t& msg); +} + +template <typename PropertyType> +void setDbusProperty(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, + std::string_view processName, + const sdbusplus::message::object_path& path, + std::string_view interface, std::string_view dbusProperty, + std::string_view redfishPropertyName, + const PropertyType& prop) +{ + std::string processNameStr(processName); + std::string interfaceStr(interface); + std::string dbusPropertyStr(dbusProperty); + + sdbusplus::asio::setProperty( + *crow::connections::systemBus, processNameStr, path.str, interfaceStr, + dbusPropertyStr, prop, + [asyncResp, redfishPropertyNameStr = std::string{redfishPropertyName}, + jsonProp = nlohmann::json(prop)](const boost::system::error_code& ec, + const sdbusplus::message_t& msg) { + details::afterSetProperty(asyncResp, redfishPropertyNameStr, jsonProp, + ec, msg); + }); +} + } // namespace redfish |