blob: 65df0ea9fd4360057a4bb851b8a9515aafb30fdb [file] [log] [blame]
Gunnar Millsab4cc6a2018-09-14 14:42:39 -05001#include "settings.hpp"
2
3#include "xyz/openbmc_project/Common/error.hpp"
4
Deepak Kodihalli20ed79e2017-07-25 05:48:58 -05005#include <phosphor-logging/elog-errors.hpp>
6#include <phosphor-logging/log.hpp>
Deepak Kodihalli20ed79e2017-07-25 05:48:58 -05007
8namespace settings
9{
10
11using namespace phosphor::logging;
12using namespace sdbusplus::xyz::openbmc_project::Common::Error;
13
14constexpr auto mapperService = "xyz.openbmc_project.ObjectMapper";
15constexpr auto mapperPath = "/xyz/openbmc_project/object_mapper";
16constexpr auto mapperIntf = "xyz.openbmc_project.ObjectMapper";
17
Brad Bishop4e845392018-12-18 18:13:12 -050018Objects::Objects(sdbusplus::bus::bus& bus) : bus(bus)
Deepak Kodihalli20ed79e2017-07-25 05:48:58 -050019{
George Liu0a704522020-04-13 14:51:40 +080020 std::vector<std::string> settingsIntfs = {timeSyncIntf};
Deepak Kodihalli20ed79e2017-07-25 05:48:58 -050021 auto depth = 0;
22
Gunnar Millsab4cc6a2018-09-14 14:42:39 -050023 auto mapperCall = bus.new_method_call(mapperService, mapperPath, mapperIntf,
Deepak Kodihalli20ed79e2017-07-25 05:48:58 -050024 "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>;
Ed Tanous7aa715b2018-05-09 17:28:05 -070036 using MapperResponse = std::vector<
37 std::pair<Path, std::vector<std::pair<Service, Interfaces>>>>;
Deepak Kodihalli20ed79e2017-07-25 05:48:58 -050038 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;
Gunnar Millsab4cc6a2018-09-14 14:42:39 -050049 for (const auto& service_iter : iter.second)
Deepak Kodihalli20ed79e2017-07-25 05:48:58 -050050 {
Gunnar Millsab4cc6a2018-09-14 14:42:39 -050051 for (const Interface& interface : service_iter.second)
Ed Tanous7aa715b2018-05-09 17:28:05 -070052 {
George Liu3c2f4492020-04-12 11:35:57 +080053 if (timeSyncIntf == interface)
Ed Tanous7aa715b2018-05-09 17:28:05 -070054 {
55 timeSyncMethod = path;
56 }
Ed Tanous7aa715b2018-05-09 17:28:05 -070057 }
Lei YUdebe1d82017-10-13 13:21:37 +080058 }
Deepak Kodihalli20ed79e2017-07-25 05:48:58 -050059 }
60}
61
62Service Objects::service(const Path& path, const Interface& interface) const
63{
Deepak Kodihalli20ed79e2017-07-25 05:48:58 -050064 using Interfaces = std::vector<Interface>;
Gunnar Millsab4cc6a2018-09-14 14:42:39 -050065 auto mapperCall =
66 bus.new_method_call(mapperService, mapperPath, mapperIntf, "GetObject");
Deepak Kodihalli20ed79e2017-07-25 05:48:58 -050067 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