1 #include "settings.hpp" 2 3 #include "xyz/openbmc_project/Common/error.hpp" 4 5 #include <phosphor-logging/elog-errors.hpp> 6 #include <phosphor-logging/log.hpp> 7 8 namespace settings 9 { 10 11 using namespace phosphor::logging; 12 using namespace sdbusplus::xyz::openbmc_project::Common::Error; 13 14 constexpr auto mapperService = "xyz.openbmc_project.ObjectMapper"; 15 constexpr auto mapperPath = "/xyz/openbmc_project/object_mapper"; 16 constexpr auto mapperIntf = "xyz.openbmc_project.ObjectMapper"; 17 18 Objects::Objects(sdbusplus::bus::bus& bus) : bus(bus) 19 { 20 std::vector<std::string> settingsIntfs = {timeSyncIntf, hostStateIntf}; 21 auto depth = 0; 22 23 auto mapperCall = bus.new_method_call(mapperService, mapperPath, mapperIntf, 24 "GetSubTree"); 25 mapperCall.append(root); 26 mapperCall.append(depth); 27 mapperCall.append(settingsIntfs); 28 auto response = bus.call(mapperCall); 29 if (response.is_method_error()) 30 { 31 log<level::ERR>("Error in mapper GetSubTree"); 32 elog<InternalFailure>(); 33 } 34 35 using Interfaces = std::vector<Interface>; 36 using MapperResponse = std::vector< 37 std::pair<Path, std::vector<std::pair<Service, Interfaces>>>>; 38 MapperResponse result; 39 response.read(result); 40 if (result.empty()) 41 { 42 log<level::ERR>("Invalid response from mapper"); 43 elog<InternalFailure>(); 44 } 45 46 for (const auto& iter : result) 47 { 48 const Path& path = iter.first; 49 for (const auto& service_iter : iter.second) 50 { 51 for (const Interface& interface : service_iter.second) 52 { 53 if (timeSyncIntf == interface) 54 { 55 timeSyncMethod = path; 56 } 57 else if (hostStateIntf == interface) 58 { 59 hostState = path; 60 } 61 } 62 } 63 } 64 } 65 66 Service Objects::service(const Path& path, const Interface& interface) const 67 { 68 using Interfaces = std::vector<Interface>; 69 auto mapperCall = 70 bus.new_method_call(mapperService, mapperPath, mapperIntf, "GetObject"); 71 mapperCall.append(path); 72 mapperCall.append(Interfaces({interface})); 73 74 auto response = bus.call(mapperCall); 75 if (response.is_method_error()) 76 { 77 log<level::ERR>("Error in mapper GetObject"); 78 elog<InternalFailure>(); 79 } 80 81 std::map<Service, Interfaces> result; 82 response.read(result); 83 if (result.empty()) 84 { 85 log<level::ERR>("Invalid response from mapper"); 86 elog<InternalFailure>(); 87 } 88 89 return result.begin()->first; 90 } 91 92 } // namespace settings 93