blob: 704905ace37358355a23759ccb3c210892333fdb [file] [log] [blame]
Deepak Kodihalli20ed79e2017-07-25 05:48:58 -05001#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
6namespace settings
7{
8
9using namespace phosphor::logging;
10using namespace sdbusplus::xyz::openbmc_project::Common::Error;
11
12constexpr auto mapperService = "xyz.openbmc_project.ObjectMapper";
13constexpr auto mapperPath = "/xyz/openbmc_project/object_mapper";
14constexpr auto mapperIntf = "xyz.openbmc_project.ObjectMapper";
15
16Objects::Objects()
17{
18 auto bus = sdbusplus::bus::new_default();
19 std::vector<std::string> settingsIntfs =
Lei YUdebe1d82017-10-13 13:21:37 +080020 {timeOwnerIntf, timeSyncIntf, hostStateIntf};
Deepak Kodihalli20ed79e2017-07-25 05:48:58 -050021 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>;
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;
Ed Tanous7aa715b2018-05-09 17:28:05 -070051 for (const auto& service_iter: iter.second)
Deepak Kodihalli20ed79e2017-07-25 05:48:58 -050052 {
Ed Tanous7aa715b2018-05-09 17:28:05 -070053 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 }
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>;
76 auto mapperCall = bus.new_method_call(mapperService,
77 mapperPath,
78 mapperIntf,
79 "GetObject");
80 mapperCall.append(path);
81 mapperCall.append(Interfaces({interface}));
82
83 auto response = bus.call(mapperCall);
84 if (response.is_method_error())
85 {
86 log<level::ERR>("Error in mapper GetObject");
87 elog<InternalFailure>();
88 }
89
90 std::map<Service, Interfaces> result;
91 response.read(result);
92 if (result.empty())
93 {
94 log<level::ERR>("Invalid response from mapper");
95 elog<InternalFailure>();
96 }
97
98 return result.begin()->first;
99}
100
101} // namespace settings