#pragma once #include "configuration.hpp" #include #include #include #include #include #include namespace dbus_interface { void tryIfaceInitialize( std::shared_ptr& iface); std::shared_ptr createInterface( sdbusplus::asio::object_server& objServer, const std::string& path, const std::string& interface, const std::string& parent, bool checkNull = false); template void addArrayToDbus(const std::string& name, const nlohmann::json& array, sdbusplus::asio::dbus_interface* iface, sdbusplus::asio::PropertyPermission permission, nlohmann::json& systemConfiguration, const std::string& jsonPointerString) { std::vector values; for (const auto& property : array) { auto ptr = property.get_ptr(); if (ptr != nullptr) { values.emplace_back(*ptr); } } if (permission == sdbusplus::asio::PropertyPermission::readOnly) { iface->register_property(name, values); } else { iface->register_property( name, values, [&systemConfiguration, jsonPointerString{std::string(jsonPointerString)}]( const std::vector& newVal, std::vector& val) { val = newVal; if (!configuration::setJsonFromPointer(jsonPointerString, val, systemConfiguration)) { std::cerr << "error setting json field\n"; return -1; } if (!configuration::writeJsonFiles(systemConfiguration)) { std::cerr << "error setting json file\n"; return -1; } return 1; }); } } template void addProperty(const std::string& name, const PropertyType& value, sdbusplus::asio::dbus_interface* iface, nlohmann::json& systemConfiguration, const std::string& jsonPointerString, sdbusplus::asio::PropertyPermission permission) { if (permission == sdbusplus::asio::PropertyPermission::readOnly) { iface->register_property(name, value); return; } iface->register_property( name, value, [&systemConfiguration, jsonPointerString{std::string(jsonPointerString)}]( const PropertyType& newVal, PropertyType& val) { val = newVal; if (!configuration::setJsonFromPointer(jsonPointerString, val, systemConfiguration)) { std::cerr << "error setting json field\n"; return -1; } if (!configuration::writeJsonFiles(systemConfiguration)) { std::cerr << "error setting json file\n"; return -1; } return 1; }); } void createDeleteObjectMethod( const std::string& jsonPointerPath, const std::shared_ptr& iface, sdbusplus::asio::object_server& objServer, nlohmann::json& systemConfiguration); void populateInterfaceFromJson( nlohmann::json& systemConfiguration, const std::string& jsonPointerPath, std::shared_ptr& iface, nlohmann::json& dict, sdbusplus::asio::object_server& objServer, sdbusplus::asio::PropertyPermission permission = sdbusplus::asio::PropertyPermission::readOnly); void createAddObjectMethod( const std::string& jsonPointerPath, const std::string& path, nlohmann::json& systemConfiguration, sdbusplus::asio::object_server& objServer, const std::string& board); std::vector>& getDeviceInterfaces(const nlohmann::json& device); } // namespace dbus_interface