blob: c136c22cf88a1b9c6fe24e3e65008a10582f29c1 [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{
George Liu0a704522020-04-13 14:51:40 +080020 std::vector<std::string> settingsIntfs = {timeSyncIntf};
Deepak Kodihalli20ed79e2017-07-25 05:48:58 -050021 auto depth = 0;
22
Gunnar Millsab4cc6a2018-09-14 14:42:39 -050023 auto mapperCall = bus.new_method_call(mapperService, mapperPath, mapperIntf,
Deepak Kodihalli20ed79e2017-07-25 05:48:58 -050024 "GetSubTree");
25 mapperCall.append(root);
26 mapperCall.append(depth);
27 mapperCall.append(settingsIntfs);
Deepak Kodihalli20ed79e2017-07-25 05:48:58 -050028
29 using Interfaces = std::vector<Interface>;
Ed Tanous7aa715b2018-05-09 17:28:05 -070030 using MapperResponse = std::vector<
31 std::pair<Path, std::vector<std::pair<Service, Interfaces>>>>;
Deepak Kodihalli20ed79e2017-07-25 05:48:58 -050032 MapperResponse result;
George Liuf344f842022-07-01 16:09:41 +080033
34 try
35 {
36 auto response = bus.call(mapperCall);
37 response.read(result);
38 }
39 catch (const sdbusplus::exception::exception& ex)
40 {
41 log<level::ERR>("Failed to invoke GetSubTree method");
42 }
43
Deepak Kodihalli20ed79e2017-07-25 05:48:58 -050044 if (result.empty())
45 {
46 log<level::ERR>("Invalid response from mapper");
47 elog<InternalFailure>();
48 }
49
50 for (const auto& iter : result)
51 {
52 const Path& path = iter.first;
Gunnar Millsab4cc6a2018-09-14 14:42:39 -050053 for (const auto& service_iter : iter.second)
Deepak Kodihalli20ed79e2017-07-25 05:48:58 -050054 {
Gunnar Millsab4cc6a2018-09-14 14:42:39 -050055 for (const Interface& interface : service_iter.second)
Ed Tanous7aa715b2018-05-09 17:28:05 -070056 {
George Liu3c2f4492020-04-12 11:35:57 +080057 if (timeSyncIntf == interface)
Ed Tanous7aa715b2018-05-09 17:28:05 -070058 {
59 timeSyncMethod = path;
60 }
Ed Tanous7aa715b2018-05-09 17:28:05 -070061 }
Lei YUdebe1d82017-10-13 13:21:37 +080062 }
Deepak Kodihalli20ed79e2017-07-25 05:48:58 -050063 }
64}
65
66Service Objects::service(const Path& path, const Interface& interface) const
67{
Deepak Kodihalli20ed79e2017-07-25 05:48:58 -050068 using Interfaces = std::vector<Interface>;
Gunnar Millsab4cc6a2018-09-14 14:42:39 -050069 auto mapperCall =
70 bus.new_method_call(mapperService, mapperPath, mapperIntf, "GetObject");
Deepak Kodihalli20ed79e2017-07-25 05:48:58 -050071 mapperCall.append(path);
72 mapperCall.append(Interfaces({interface}));
73
George Liuf344f842022-07-01 16:09:41 +080074 std::map<Service, Interfaces> result;
75 try
76 {
77 auto response = bus.call(mapperCall);
78 response.read(result);
79 }
80 catch (const sdbusplus::exception::exception& ex)
Deepak Kodihalli20ed79e2017-07-25 05:48:58 -050081 {
82 log<level::ERR>("Error in mapper GetObject");
Deepak Kodihalli20ed79e2017-07-25 05:48:58 -050083 }
84
Deepak Kodihalli20ed79e2017-07-25 05:48:58 -050085 if (result.empty())
86 {
87 log<level::ERR>("Invalid response from mapper");
88 elog<InternalFailure>();
89 }
90
91 return result.begin()->first;
92}
93
94} // namespace settings