blob: e0600dc357427044fd04412c80097e2dbe20e63c [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;
46 const Interface& interface = iter.second.begin()->second[0];
47
48 if (autoRebootIntf == interface)
49 {
50 autoReboot = path;
51 }
52 else if (powerRestoreIntf == interface)
53 {
54 powerRestorePolicy = path;
55 }
56 }
57}
58
59Service Objects::service(const Path& path, const Interface& interface) const
60{
61 using Interfaces = std::vector<Interface>;
Andrew Geissler58a18012018-01-19 19:36:05 -080062 auto mapperCall =
63 bus.new_method_call(mapperService, mapperPath, mapperIntf, "GetObject");
Deepak Kodihallia646edd2017-07-25 07:28:45 -050064 mapperCall.append(path);
65 mapperCall.append(Interfaces({interface}));
66
67 auto response = bus.call(mapperCall);
68 if (response.is_method_error())
69 {
70 log<level::ERR>("Error in mapper GetObject");
71 elog<InternalFailure>();
72 }
73
74 std::map<Service, Interfaces> result;
75 response.read(result);
76 if (result.empty())
77 {
78 log<level::ERR>("Invalid response from mapper");
79 elog<InternalFailure>();
80 }
81
82 return result.begin()->first;
83}
84
85} // namespace settings