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 {
operator ()redfish::dbus_utils::UnpackErrorPrinter23351053f2SKrzysztof 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 {
37d02aad39SEd Tanous void afterSetProperty(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
38d02aad39SEd Tanous const std::string& redfishPropertyName,
39d02aad39SEd Tanous const nlohmann::json& propertyValue,
40d02aad39SEd Tanous const boost::system::error_code& ec,
41d02aad39SEd Tanous const sdbusplus::message_t& msg);
421827b4f1SAsmitha Karunanithi
431827b4f1SAsmitha Karunanithi void afterSetPropertyAction(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
441827b4f1SAsmitha Karunanithi const std::string& redfishActionName,
451827b4f1SAsmitha Karunanithi const std::string& redfishActionParameterName,
461827b4f1SAsmitha Karunanithi const boost::system::error_code& ec,
471827b4f1SAsmitha Karunanithi const sdbusplus::message_t& msg);
481827b4f1SAsmitha Karunanithi } // namespace details
49d02aad39SEd Tanous
50d02aad39SEd Tanous template <typename PropertyType>
setDbusProperty(const std::shared_ptr<bmcweb::AsyncResp> & asyncResp,std::string_view redfishPropertyName,std::string_view processName,const sdbusplus::message::object_path & path,std::string_view interface,std::string_view dbusProperty,const PropertyType & prop)51d02aad39SEd Tanous void setDbusProperty(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
52*e93abac6SGinu George std::string_view redfishPropertyName,
53d02aad39SEd Tanous std::string_view processName,
54d02aad39SEd Tanous const sdbusplus::message::object_path& path,
55d02aad39SEd Tanous std::string_view interface, std::string_view dbusProperty,
56d02aad39SEd Tanous const PropertyType& prop)
57d02aad39SEd Tanous {
58d02aad39SEd Tanous std::string processNameStr(processName);
59d02aad39SEd Tanous std::string interfaceStr(interface);
60d02aad39SEd Tanous std::string dbusPropertyStr(dbusProperty);
61d02aad39SEd Tanous
62d02aad39SEd Tanous sdbusplus::asio::setProperty(
63d02aad39SEd Tanous *crow::connections::systemBus, processNameStr, path.str, interfaceStr,
64d02aad39SEd Tanous dbusPropertyStr, prop,
65d02aad39SEd Tanous [asyncResp, redfishPropertyNameStr = std::string{redfishPropertyName},
66d02aad39SEd Tanous jsonProp = nlohmann::json(prop)](const boost::system::error_code& ec,
67d02aad39SEd Tanous const sdbusplus::message_t& msg) {
68d02aad39SEd Tanous details::afterSetProperty(asyncResp, redfishPropertyNameStr, jsonProp,
69d02aad39SEd Tanous ec, msg);
70d02aad39SEd Tanous });
71d02aad39SEd Tanous }
72d02aad39SEd Tanous
731827b4f1SAsmitha Karunanithi template <typename DbusPropertyType>
setDbusPropertyAction(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 redfishActionParameterName,std::string_view redfishActionName,const DbusPropertyType & prop)741827b4f1SAsmitha Karunanithi void setDbusPropertyAction(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
751827b4f1SAsmitha Karunanithi std::string_view processName,
761827b4f1SAsmitha Karunanithi const sdbusplus::message::object_path& path,
771827b4f1SAsmitha Karunanithi std::string_view interface,
781827b4f1SAsmitha Karunanithi std::string_view dbusProperty,
791827b4f1SAsmitha Karunanithi std::string_view redfishActionParameterName,
801827b4f1SAsmitha Karunanithi std::string_view redfishActionName,
811827b4f1SAsmitha Karunanithi const DbusPropertyType& prop)
821827b4f1SAsmitha Karunanithi {
831827b4f1SAsmitha Karunanithi std::string processNameStr(processName);
841827b4f1SAsmitha Karunanithi std::string interfaceStr(interface);
851827b4f1SAsmitha Karunanithi std::string dbusPropertyStr(dbusProperty);
861827b4f1SAsmitha Karunanithi
871827b4f1SAsmitha Karunanithi sdbusplus::asio::setProperty(
881827b4f1SAsmitha Karunanithi *crow::connections::systemBus, processNameStr, path.str, interfaceStr,
891827b4f1SAsmitha Karunanithi dbusPropertyStr, prop,
901827b4f1SAsmitha Karunanithi [asyncResp,
911827b4f1SAsmitha Karunanithi redfishActionParameterName = std::string{redfishActionParameterName},
921827b4f1SAsmitha Karunanithi jsonProp = nlohmann::json(prop),
931827b4f1SAsmitha Karunanithi redfishActionNameStr = std::string{redfishActionName}](
941827b4f1SAsmitha Karunanithi const boost::system::error_code& ec,
951827b4f1SAsmitha Karunanithi const sdbusplus::message_t& msg) {
961827b4f1SAsmitha Karunanithi details::afterSetPropertyAction(asyncResp, redfishActionNameStr,
971827b4f1SAsmitha Karunanithi redfishActionParameterName, ec, msg);
981827b4f1SAsmitha Karunanithi });
991827b4f1SAsmitha Karunanithi }
1001827b4f1SAsmitha Karunanithi
101351053f2SKrzysztof Grobelny } // namespace redfish
102