1351053f2SKrzysztof Grobelny #pragma once 2351053f2SKrzysztof Grobelny 3*d02aad39SEd Tanous #include "async_resp.hpp" 4*d02aad39SEd Tanous #include "dbus_singleton.hpp" 5*d02aad39SEd Tanous #include "error_messages.hpp" 6351053f2SKrzysztof Grobelny #include "logging.hpp" 7351053f2SKrzysztof Grobelny 8*d02aad39SEd Tanous #include <nlohmann/json.hpp> 9*d02aad39SEd Tanous #include <sdbusplus/asio/property.hpp> 10*d02aad39SEd Tanous #include <sdbusplus/message.hpp> 11351053f2SKrzysztof Grobelny #include <sdbusplus/unpack_properties.hpp> 12351053f2SKrzysztof Grobelny 13*d02aad39SEd Tanous #include <memory> 14*d02aad39SEd Tanous #include <string_view> 15*d02aad39SEd Tanous 16351053f2SKrzysztof Grobelny namespace redfish 17351053f2SKrzysztof Grobelny { 18351053f2SKrzysztof Grobelny namespace dbus_utils 19351053f2SKrzysztof Grobelny { 20351053f2SKrzysztof Grobelny 21351053f2SKrzysztof Grobelny struct UnpackErrorPrinter 22351053f2SKrzysztof Grobelny { 23351053f2SKrzysztof Grobelny void operator()(const sdbusplus::UnpackErrorReason reason, 24351053f2SKrzysztof Grobelny const std::string& property) const noexcept 25351053f2SKrzysztof Grobelny { 2662598e31SEd Tanous BMCWEB_LOG_ERROR( 2762598e31SEd Tanous "DBUS property error in property: {}, reason: {}", property, 2862598e31SEd Tanous static_cast<std::underlying_type_t<sdbusplus::UnpackErrorReason>>( 2962598e31SEd Tanous reason)); 30351053f2SKrzysztof Grobelny } 31351053f2SKrzysztof Grobelny }; 32351053f2SKrzysztof Grobelny 33351053f2SKrzysztof Grobelny } // namespace dbus_utils 34*d02aad39SEd Tanous 35*d02aad39SEd Tanous namespace details 36*d02aad39SEd Tanous { 37*d02aad39SEd Tanous void afterSetProperty(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 38*d02aad39SEd Tanous const std::string& redfishPropertyName, 39*d02aad39SEd Tanous const nlohmann::json& propertyValue, 40*d02aad39SEd Tanous const boost::system::error_code& ec, 41*d02aad39SEd Tanous const sdbusplus::message_t& msg); 42*d02aad39SEd Tanous } 43*d02aad39SEd Tanous 44*d02aad39SEd Tanous template <typename PropertyType> 45*d02aad39SEd Tanous void setDbusProperty(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 46*d02aad39SEd Tanous std::string_view processName, 47*d02aad39SEd Tanous const sdbusplus::message::object_path& path, 48*d02aad39SEd Tanous std::string_view interface, std::string_view dbusProperty, 49*d02aad39SEd Tanous std::string_view redfishPropertyName, 50*d02aad39SEd Tanous const PropertyType& prop) 51*d02aad39SEd Tanous { 52*d02aad39SEd Tanous std::string processNameStr(processName); 53*d02aad39SEd Tanous std::string interfaceStr(interface); 54*d02aad39SEd Tanous std::string dbusPropertyStr(dbusProperty); 55*d02aad39SEd Tanous 56*d02aad39SEd Tanous sdbusplus::asio::setProperty( 57*d02aad39SEd Tanous *crow::connections::systemBus, processNameStr, path.str, interfaceStr, 58*d02aad39SEd Tanous dbusPropertyStr, prop, 59*d02aad39SEd Tanous [asyncResp, redfishPropertyNameStr = std::string{redfishPropertyName}, 60*d02aad39SEd Tanous jsonProp = nlohmann::json(prop)](const boost::system::error_code& ec, 61*d02aad39SEd Tanous const sdbusplus::message_t& msg) { 62*d02aad39SEd Tanous details::afterSetProperty(asyncResp, redfishPropertyNameStr, jsonProp, 63*d02aad39SEd Tanous ec, msg); 64*d02aad39SEd Tanous }); 65*d02aad39SEd Tanous } 66*d02aad39SEd Tanous 67351053f2SKrzysztof Grobelny } // namespace redfish 68