1351053f2SKrzysztof Grobelny #pragma once 2351053f2SKrzysztof Grobelny 3d02aad39SEd Tanous #include "async_resp.hpp" 4d02aad39SEd Tanous #include "dbus_singleton.hpp" 5d02aad39SEd Tanous #include "error_messages.hpp" 6351053f2SKrzysztof Grobelny #include "logging.hpp" 7351053f2SKrzysztof Grobelny 8d02aad39SEd Tanous #include <nlohmann/json.hpp> 9d02aad39SEd Tanous #include <sdbusplus/asio/property.hpp> 10d02aad39SEd Tanous #include <sdbusplus/message.hpp> 11351053f2SKrzysztof Grobelny #include <sdbusplus/unpack_properties.hpp> 12351053f2SKrzysztof Grobelny 13d02aad39SEd Tanous #include <memory> 14d02aad39SEd Tanous #include <string_view> 15d02aad39SEd 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 34d02aad39SEd Tanous 35d02aad39SEd Tanous namespace details 36d02aad39SEd Tanous { 37*bd79bce8SPatrick Williams void afterSetProperty( 38*bd79bce8SPatrick Williams const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 39*bd79bce8SPatrick Williams const std::string& redfishPropertyName, const nlohmann::json& propertyValue, 40*bd79bce8SPatrick Williams const boost::system::error_code& ec, const sdbusplus::message_t& msg); 411827b4f1SAsmitha Karunanithi 421827b4f1SAsmitha Karunanithi void afterSetPropertyAction(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 431827b4f1SAsmitha Karunanithi const std::string& redfishActionName, 441827b4f1SAsmitha Karunanithi const std::string& redfishActionParameterName, 451827b4f1SAsmitha Karunanithi const boost::system::error_code& ec, 461827b4f1SAsmitha Karunanithi const sdbusplus::message_t& msg); 471827b4f1SAsmitha Karunanithi } // namespace details 48d02aad39SEd Tanous 49d02aad39SEd Tanous template <typename PropertyType> 50*bd79bce8SPatrick Williams void setDbusProperty( 51*bd79bce8SPatrick Williams const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 52*bd79bce8SPatrick Williams std::string_view redfishPropertyName, std::string_view processName, 53*bd79bce8SPatrick Williams const sdbusplus::message::object_path& path, std::string_view interface, 54*bd79bce8SPatrick Williams std::string_view dbusProperty, const PropertyType& prop) 55d02aad39SEd Tanous { 56d02aad39SEd Tanous std::string processNameStr(processName); 57d02aad39SEd Tanous std::string interfaceStr(interface); 58d02aad39SEd Tanous std::string dbusPropertyStr(dbusProperty); 59d02aad39SEd Tanous 60d02aad39SEd Tanous sdbusplus::asio::setProperty( 61d02aad39SEd Tanous *crow::connections::systemBus, processNameStr, path.str, interfaceStr, 62d02aad39SEd Tanous dbusPropertyStr, prop, 63d02aad39SEd Tanous [asyncResp, redfishPropertyNameStr = std::string{redfishPropertyName}, 64d02aad39SEd Tanous jsonProp = nlohmann::json(prop)](const boost::system::error_code& ec, 65d02aad39SEd Tanous const sdbusplus::message_t& msg) { 66*bd79bce8SPatrick Williams details::afterSetProperty(asyncResp, redfishPropertyNameStr, 67*bd79bce8SPatrick Williams jsonProp, ec, msg); 68d02aad39SEd Tanous }); 69d02aad39SEd Tanous } 70d02aad39SEd Tanous 711827b4f1SAsmitha Karunanithi template <typename DbusPropertyType> 72*bd79bce8SPatrick Williams void setDbusPropertyAction( 73*bd79bce8SPatrick Williams const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 74*bd79bce8SPatrick Williams std::string_view processName, const sdbusplus::message::object_path& path, 75*bd79bce8SPatrick Williams std::string_view interface, std::string_view dbusProperty, 761827b4f1SAsmitha Karunanithi std::string_view redfishActionParameterName, 77*bd79bce8SPatrick Williams std::string_view redfishActionName, const DbusPropertyType& prop) 781827b4f1SAsmitha Karunanithi { 791827b4f1SAsmitha Karunanithi std::string processNameStr(processName); 801827b4f1SAsmitha Karunanithi std::string interfaceStr(interface); 811827b4f1SAsmitha Karunanithi std::string dbusPropertyStr(dbusProperty); 821827b4f1SAsmitha Karunanithi 831827b4f1SAsmitha Karunanithi sdbusplus::asio::setProperty( 841827b4f1SAsmitha Karunanithi *crow::connections::systemBus, processNameStr, path.str, interfaceStr, 851827b4f1SAsmitha Karunanithi dbusPropertyStr, prop, 861827b4f1SAsmitha Karunanithi [asyncResp, 871827b4f1SAsmitha Karunanithi redfishActionParameterName = std::string{redfishActionParameterName}, 881827b4f1SAsmitha Karunanithi jsonProp = nlohmann::json(prop), 891827b4f1SAsmitha Karunanithi redfishActionNameStr = std::string{redfishActionName}]( 901827b4f1SAsmitha Karunanithi const boost::system::error_code& ec, 911827b4f1SAsmitha Karunanithi const sdbusplus::message_t& msg) { 921827b4f1SAsmitha Karunanithi details::afterSetPropertyAction(asyncResp, redfishActionNameStr, 93*bd79bce8SPatrick Williams redfishActionParameterName, ec, 94*bd79bce8SPatrick Williams msg); 951827b4f1SAsmitha Karunanithi }); 961827b4f1SAsmitha Karunanithi } 971827b4f1SAsmitha Karunanithi 98351053f2SKrzysztof Grobelny } // namespace redfish 99