#include #include #include #include "xyz/openbmc_project/Common/error.hpp" #include "settings.hpp" namespace settings { using namespace phosphor::logging; using namespace sdbusplus::xyz::openbmc_project::Common::Error; using sdbusplus::exception::SdBusError; constexpr auto mapperService = "xyz.openbmc_project.ObjectMapper"; constexpr auto mapperPath = "/xyz/openbmc_project/object_mapper"; constexpr auto mapperIntf = "xyz.openbmc_project.ObjectMapper"; Objects::Objects(sdbusplus::bus::bus& bus) : bus(bus) { std::vector settingsIntfs = {autoRebootIntf, powerRestoreIntf}; auto depth = 0; auto mapperCall = bus.new_method_call(mapperService, mapperPath, mapperIntf, "GetSubTree"); mapperCall.append(root); mapperCall.append(depth); mapperCall.append(settingsIntfs); using Interfaces = std::vector; using MapperResponse = std::map>; MapperResponse result; try { auto response = bus.call(mapperCall); response.read(result); if (result.empty()) { log("Invalid response from mapper"); elog(); } } catch (const SdBusError& e) { log("Error in mapper GetSubTree", entry("ERROR=%s", e.what())); elog(); } for (const auto& iter : result) { const Path& path = iter.first; for (const auto& serviceIter : iter.second) { for (const auto& interface : serviceIter.second) { if (autoRebootIntf == interface) { autoReboot = path; } else if (powerRestoreIntf == interface) { powerRestorePolicy = path; } } } } } Service Objects::service(const Path& path, const Interface& interface) const { using Interfaces = std::vector; auto mapperCall = bus.new_method_call(mapperService, mapperPath, mapperIntf, "GetObject"); mapperCall.append(path); mapperCall.append(Interfaces({interface})); std::map result; try { auto response = bus.call(mapperCall); response.read(result); } catch (const SdBusError& e) { log("Error in mapper GetObject", entry("ERROR=%s", e.what())); elog(); } if (result.empty()) { log("Invalid response from mapper"); elog(); } return result.begin()->first; } } // namespace settings