blob: 70bf04e46c9098f532b019a1868e017e638e31fa [file] [log] [blame]
Deepak Kodihallia646edd2017-07-25 07:28:45 -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
Andrew Geissler58a18012018-01-19 19:36:05 -080016Objects::Objects(sdbusplus::bus::bus& bus) : bus(bus)
Deepak Kodihallia646edd2017-07-25 07:28:45 -050017{
Andrew Geissler58a18012018-01-19 19:36:05 -080018 std::vector<std::string> settingsIntfs = {autoRebootIntf, powerRestoreIntf};
Deepak Kodihallia646edd2017-07-25 07:28:45 -050019 auto depth = 0;
20
Andrew Geissler58a18012018-01-19 19:36:05 -080021 auto mapperCall = bus.new_method_call(mapperService, mapperPath, mapperIntf,
Deepak Kodihallia646edd2017-07-25 07:28:45 -050022 "GetSubTree");
23 mapperCall.append(root);
24 mapperCall.append(depth);
25 mapperCall.append(settingsIntfs);
26 auto response = bus.call(mapperCall);
27 if (response.is_method_error())
28 {
29 log<level::ERR>("Error in mapper GetSubTree");
30 elog<InternalFailure>();
31 }
32
33 using Interfaces = std::vector<Interface>;
34 using MapperResponse = std::map<Path, std::map<Service, Interfaces>>;
35 MapperResponse result;
36 response.read(result);
37 if (result.empty())
38 {
39 log<level::ERR>("Invalid response from mapper");
40 elog<InternalFailure>();
41 }
42
43 for (const auto& iter : result)
44 {
45 const Path& path = iter.first;
Deepak Kodihallia646edd2017-07-25 07:28:45 -050046
Matt Spinler14e14cd2018-09-07 15:04:16 -050047 for (const auto& serviceIter : iter.second)
Deepak Kodihallia646edd2017-07-25 07:28:45 -050048 {
Matt Spinler14e14cd2018-09-07 15:04:16 -050049 for (const auto& interface : serviceIter.second)
50 {
51 if (autoRebootIntf == interface)
52 {
53 autoReboot = path;
54 }
55 else if (powerRestoreIntf == interface)
56 {
57 powerRestorePolicy = path;
58 }
59 }
Deepak Kodihallia646edd2017-07-25 07:28:45 -050060 }
61 }
62}
63
64Service Objects::service(const Path& path, const Interface& interface) const
65{
66 using Interfaces = std::vector<Interface>;
Andrew Geissler58a18012018-01-19 19:36:05 -080067 auto mapperCall =
68 bus.new_method_call(mapperService, mapperPath, mapperIntf, "GetObject");
Deepak Kodihallia646edd2017-07-25 07:28:45 -050069 mapperCall.append(path);
70 mapperCall.append(Interfaces({interface}));
71
72 auto response = bus.call(mapperCall);
73 if (response.is_method_error())
74 {
75 log<level::ERR>("Error in mapper GetObject");
76 elog<InternalFailure>();
77 }
78
79 std::map<Service, Interfaces> result;
80 response.read(result);
81 if (result.empty())
82 {
83 log<level::ERR>("Invalid response from mapper");
84 elog<InternalFailure>();
85 }
86
87 return result.begin()->first;
88}
89
90} // namespace settings