blob: 93eb09468abd5bb6b23d1c9972abc573c05cf461 [file] [log] [blame]
Patrick Venture0b02be92018-08-31 11:55:55 -07001#include "settings.hpp"
2
Vernon Mauery6a98fe72019-03-11 15:57:48 -07003#include <ipmid/utils.hpp>
Deepak Kodihalli18aa0442017-07-21 07:07:09 -05004#include <phosphor-logging/elog-errors.hpp>
5#include <phosphor-logging/log.hpp>
William A. Kennington III4c008022018-10-12 17:18:14 -07006#include <sdbusplus/message/types.hpp>
Patrick Venture0b02be92018-08-31 11:55:55 -07007#include <xyz/openbmc_project/Common/error.hpp>
Deepak Kodihalli18aa0442017-07-21 07:07:09 -05008
9namespace settings
10{
11
12using namespace phosphor::logging;
Willy Tu523e2d12023-09-05 11:36:48 -070013using namespace sdbusplus::error::xyz::openbmc_project::common;
Deepak Kodihalli18aa0442017-07-21 07:07:09 -050014
15constexpr auto mapperService = "xyz.openbmc_project.ObjectMapper";
16constexpr auto mapperPath = "/xyz/openbmc_project/object_mapper";
17constexpr auto mapperIntf = "xyz.openbmc_project.ObjectMapper";
18
Patrick Williams5d82f472022-07-22 19:26:53 -050019Objects::Objects(sdbusplus::bus_t& bus, const std::vector<Interface>& filter) :
Deepak Kodihalli18aa0442017-07-21 07:07:09 -050020 bus(bus)
21{
George Liuc1c7eac2024-02-04 17:24:19 +080022 ipmi::ObjectTree objectTree;
George Liu3e3cc352023-07-26 15:59:31 +080023 try
Deepak Kodihalli18aa0442017-07-21 07:07:09 -050024 {
George Liuc1c7eac2024-02-04 17:24:19 +080025 objectTree = ipmi::getSubTree(bus, filter);
George Liu3e3cc352023-07-26 15:59:31 +080026 }
27 catch (const std::exception& e)
28 {
George Liuc1c7eac2024-02-04 17:24:19 +080029 log<level::ERR>("Failed to call the getSubTree method.",
George Liu3e3cc352023-07-26 15:59:31 +080030 entry("ERROR=%s", e.what()));
Deepak Kodihalli18aa0442017-07-21 07:07:09 -050031 elog<InternalFailure>();
32 }
33
George Liuc1c7eac2024-02-04 17:24:19 +080034 for (auto& iter : objectTree)
Deepak Kodihalli18aa0442017-07-21 07:07:09 -050035 {
36 const auto& path = iter.first;
Deepak Kodihallie6027092017-08-27 08:13:37 -050037 for (auto& interface : iter.second.begin()->second)
38 {
39 auto found = map.find(interface);
40 if (map.end() != found)
41 {
42 auto& paths = found->second;
43 paths.push_back(path);
44 }
45 else
46 {
47 map.emplace(std::move(interface), std::vector<Path>({path}));
48 }
49 }
Deepak Kodihalli18aa0442017-07-21 07:07:09 -050050 }
51}
52
53Service Objects::service(const Path& path, const Interface& interface) const
54{
55 using Interfaces = std::vector<Interface>;
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -050056 auto mapperCall = bus.new_method_call(mapperService, mapperPath, mapperIntf,
57 "GetObject");
Deepak Kodihalli18aa0442017-07-21 07:07:09 -050058 mapperCall.append(path);
59 mapperCall.append(Interfaces({interface}));
60
Deepak Kodihalli18aa0442017-07-21 07:07:09 -050061 std::map<Service, Interfaces> result;
George Liu3e3cc352023-07-26 15:59:31 +080062 try
Deepak Kodihalli18aa0442017-07-21 07:07:09 -050063 {
George Liu3e3cc352023-07-26 15:59:31 +080064 auto response = bus.call(mapperCall);
65 response.read(result);
66 return result.begin()->first;
67 }
68 catch (const std::exception& e)
69 {
70 log<level::ERR>("Invalid response from mapper",
71 entry("ERROR=%s", e.what()));
Deepak Kodihalli18aa0442017-07-21 07:07:09 -050072 elog<InternalFailure>();
73 }
Deepak Kodihalli18aa0442017-07-21 07:07:09 -050074}
75
Deepak Kodihalli18aa0442017-07-21 07:07:09 -050076} // namespace settings