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}; 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 } 58 } 59 } 60 } 61 62 Service Objects::service(const Path& path, const Interface& interface) const 63 { 64 using Interfaces = std::vector<Interface>; 65 auto mapperCall = 66 bus.new_method_call(mapperService, mapperPath, mapperIntf, "GetObject"); 67 mapperCall.append(path); 68 mapperCall.append(Interfaces({interface})); 69 70 auto response = bus.call(mapperCall); 71 if (response.is_method_error()) 72 { 73 log<level::ERR>("Error in mapper GetObject"); 74 elog<InternalFailure>(); 75 } 76 77 std::map<Service, Interfaces> result; 78 response.read(result); 79 if (result.empty()) 80 { 81 log<level::ERR>("Invalid response from mapper"); 82 elog<InternalFailure>(); 83 } 84 85 return result.begin()->first; 86 } 87 88 } // namespace settings 89