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