blob: 9add59d996a71092005fe65384d01c9ee374f72b [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{
Gunnar Millsab4cc6a2018-09-14 14:42:39 -050020 std::vector<std::string> settingsIntfs = {timeOwnerIntf, timeSyncIntf,
21 hostStateIntf};
Deepak Kodihalli20ed79e2017-07-25 05:48:58 -050022 auto depth = 0;
23
Gunnar Millsab4cc6a2018-09-14 14:42:39 -050024 auto mapperCall = bus.new_method_call(mapperService, mapperPath, mapperIntf,
Deepak Kodihalli20ed79e2017-07-25 05:48:58 -050025 "GetSubTree");
26 mapperCall.append(root);
27 mapperCall.append(depth);
28 mapperCall.append(settingsIntfs);
29 auto response = bus.call(mapperCall);
30 if (response.is_method_error())
31 {
32 log<level::ERR>("Error in mapper GetSubTree");
33 elog<InternalFailure>();
34 }
35
36 using Interfaces = std::vector<Interface>;
Ed Tanous7aa715b2018-05-09 17:28:05 -070037 using MapperResponse = std::vector<
38 std::pair<Path, std::vector<std::pair<Service, Interfaces>>>>;
Deepak Kodihalli20ed79e2017-07-25 05:48:58 -050039 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;
Gunnar Millsab4cc6a2018-09-14 14:42:39 -050050 for (const auto& service_iter : iter.second)
Deepak Kodihalli20ed79e2017-07-25 05:48:58 -050051 {
Gunnar Millsab4cc6a2018-09-14 14:42:39 -050052 for (const Interface& interface : service_iter.second)
Ed Tanous7aa715b2018-05-09 17:28:05 -070053 {
54 if (timeOwnerIntf == interface)
55 {
56 timeOwner = path;
57 }
58 else if (timeSyncIntf == interface)
59 {
60 timeSyncMethod = path;
61 }
62 else if (hostStateIntf == interface)
63 {
64 hostState = path;
65 }
66 }
Lei YUdebe1d82017-10-13 13:21:37 +080067 }
Deepak Kodihalli20ed79e2017-07-25 05:48:58 -050068 }
69}
70
71Service Objects::service(const Path& path, const Interface& interface) const
72{
Deepak Kodihalli20ed79e2017-07-25 05:48:58 -050073 using Interfaces = std::vector<Interface>;
Gunnar Millsab4cc6a2018-09-14 14:42:39 -050074 auto mapperCall =
75 bus.new_method_call(mapperService, mapperPath, mapperIntf, "GetObject");
Deepak Kodihalli20ed79e2017-07-25 05:48:58 -050076 mapperCall.append(path);
77 mapperCall.append(Interfaces({interface}));
78
79 auto response = bus.call(mapperCall);
80 if (response.is_method_error())
81 {
82 log<level::ERR>("Error in mapper GetObject");
83 elog<InternalFailure>();
84 }
85
86 std::map<Service, Interfaces> result;
87 response.read(result);
88 if (result.empty())
89 {
90 log<level::ERR>("Invalid response from mapper");
91 elog<InternalFailure>();
92 }
93
94 return result.begin()->first;
95}
96
97} // namespace settings