blob: aeefe642e3808a5d3e18c5ffc14e06cbc990c8f7 [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
18Objects::Objects()
19{
20 auto bus = sdbusplus::bus::new_default();
Gunnar Millsab4cc6a2018-09-14 14:42:39 -050021 std::vector<std::string> settingsIntfs = {timeOwnerIntf, timeSyncIntf,
22 hostStateIntf};
Deepak Kodihalli20ed79e2017-07-25 05:48:58 -050023 auto depth = 0;
24
Gunnar Millsab4cc6a2018-09-14 14:42:39 -050025 auto mapperCall = bus.new_method_call(mapperService, mapperPath, mapperIntf,
Deepak Kodihalli20ed79e2017-07-25 05:48:58 -050026 "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>;
Ed Tanous7aa715b2018-05-09 17:28:05 -070038 using MapperResponse = std::vector<
39 std::pair<Path, std::vector<std::pair<Service, Interfaces>>>>;
Deepak Kodihalli20ed79e2017-07-25 05:48:58 -050040 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;
Gunnar Millsab4cc6a2018-09-14 14:42:39 -050051 for (const auto& service_iter : iter.second)
Deepak Kodihalli20ed79e2017-07-25 05:48:58 -050052 {
Gunnar Millsab4cc6a2018-09-14 14:42:39 -050053 for (const Interface& interface : service_iter.second)
Ed Tanous7aa715b2018-05-09 17:28:05 -070054 {
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 }
Lei YUdebe1d82017-10-13 13:21:37 +080068 }
Deepak Kodihalli20ed79e2017-07-25 05:48:58 -050069 }
70}
71
72Service Objects::service(const Path& path, const Interface& interface) const
73{
74 auto bus = sdbusplus::bus::new_default();
75 using Interfaces = std::vector<Interface>;
Gunnar Millsab4cc6a2018-09-14 14:42:39 -050076 auto mapperCall =
77 bus.new_method_call(mapperService, mapperPath, mapperIntf, "GetObject");
Deepak Kodihalli20ed79e2017-07-25 05:48:58 -050078 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