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() 19 { 20 auto bus = sdbusplus::bus::new_default(); 21 std::vector<std::string> settingsIntfs = {timeOwnerIntf, timeSyncIntf, 22 hostStateIntf}; 23 auto depth = 0; 24 25 auto mapperCall = bus.new_method_call(mapperService, mapperPath, 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::vector< 39 std::pair<Path, std::vector<std::pair<Service, Interfaces>>>>; 40 MapperResponse result; 41 response.read(result); 42 if (result.empty()) 43 { 44 log<level::ERR>("Invalid response from mapper"); 45 elog<InternalFailure>(); 46 } 47 48 for (const auto& iter : result) 49 { 50 const Path& path = iter.first; 51 for (const auto& service_iter : iter.second) 52 { 53 for (const Interface& interface : service_iter.second) 54 { 55 if (timeOwnerIntf == interface) 56 { 57 timeOwner = path; 58 } 59 else if (timeSyncIntf == interface) 60 { 61 timeSyncMethod = path; 62 } 63 else if (hostStateIntf == interface) 64 { 65 hostState = path; 66 } 67 } 68 } 69 } 70 } 71 72 Service Objects::service(const Path& path, const Interface& interface) const 73 { 74 auto bus = sdbusplus::bus::new_default(); 75 using Interfaces = std::vector<Interface>; 76 auto mapperCall = 77 bus.new_method_call(mapperService, mapperPath, mapperIntf, "GetObject"); 78 mapperCall.append(path); 79 mapperCall.append(Interfaces({interface})); 80 81 auto response = bus.call(mapperCall); 82 if (response.is_method_error()) 83 { 84 log<level::ERR>("Error in mapper GetObject"); 85 elog<InternalFailure>(); 86 } 87 88 std::map<Service, Interfaces> result; 89 response.read(result); 90 if (result.empty()) 91 { 92 log<level::ERR>("Invalid response from mapper"); 93 elog<InternalFailure>(); 94 } 95 96 return result.begin()->first; 97 } 98 99 } // namespace settings 100