Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1 | #include "settings.hpp" |
| 2 | |
Vernon Mauery | 6a98fe7 | 2019-03-11 15:57:48 -0700 | [diff] [blame] | 3 | #include <ipmid/utils.hpp> |
Deepak Kodihalli | 18aa044 | 2017-07-21 07:07:09 -0500 | [diff] [blame] | 4 | #include <phosphor-logging/elog-errors.hpp> |
| 5 | #include <phosphor-logging/log.hpp> |
William A. Kennington III | 4c00802 | 2018-10-12 17:18:14 -0700 | [diff] [blame] | 6 | #include <sdbusplus/message/types.hpp> |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 7 | #include <xyz/openbmc_project/Common/error.hpp> |
Deepak Kodihalli | 18aa044 | 2017-07-21 07:07:09 -0500 | [diff] [blame] | 8 | |
| 9 | namespace settings |
| 10 | { |
| 11 | |
| 12 | using namespace phosphor::logging; |
Willy Tu | 523e2d1 | 2023-09-05 11:36:48 -0700 | [diff] [blame] | 13 | using namespace sdbusplus::error::xyz::openbmc_project::common; |
Deepak Kodihalli | 18aa044 | 2017-07-21 07:07:09 -0500 | [diff] [blame] | 14 | |
| 15 | constexpr auto mapperService = "xyz.openbmc_project.ObjectMapper"; |
| 16 | constexpr auto mapperPath = "/xyz/openbmc_project/object_mapper"; |
| 17 | constexpr auto mapperIntf = "xyz.openbmc_project.ObjectMapper"; |
| 18 | |
Patrick Williams | 5d82f47 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 19 | Objects::Objects(sdbusplus::bus_t& bus, const std::vector<Interface>& filter) : |
Deepak Kodihalli | 18aa044 | 2017-07-21 07:07:09 -0500 | [diff] [blame] | 20 | bus(bus) |
| 21 | { |
George Liu | c1c7eac | 2024-02-04 17:24:19 +0800 | [diff] [blame] | 22 | ipmi::ObjectTree objectTree; |
George Liu | 3e3cc35 | 2023-07-26 15:59:31 +0800 | [diff] [blame] | 23 | try |
Deepak Kodihalli | 18aa044 | 2017-07-21 07:07:09 -0500 | [diff] [blame] | 24 | { |
George Liu | c1c7eac | 2024-02-04 17:24:19 +0800 | [diff] [blame] | 25 | objectTree = ipmi::getSubTree(bus, filter); |
George Liu | 3e3cc35 | 2023-07-26 15:59:31 +0800 | [diff] [blame] | 26 | } |
| 27 | catch (const std::exception& e) |
| 28 | { |
George Liu | c1c7eac | 2024-02-04 17:24:19 +0800 | [diff] [blame] | 29 | log<level::ERR>("Failed to call the getSubTree method.", |
George Liu | 3e3cc35 | 2023-07-26 15:59:31 +0800 | [diff] [blame] | 30 | entry("ERROR=%s", e.what())); |
Deepak Kodihalli | 18aa044 | 2017-07-21 07:07:09 -0500 | [diff] [blame] | 31 | elog<InternalFailure>(); |
| 32 | } |
| 33 | |
George Liu | c1c7eac | 2024-02-04 17:24:19 +0800 | [diff] [blame] | 34 | for (auto& iter : objectTree) |
Deepak Kodihalli | 18aa044 | 2017-07-21 07:07:09 -0500 | [diff] [blame] | 35 | { |
| 36 | const auto& path = iter.first; |
Deepak Kodihalli | e602709 | 2017-08-27 08:13:37 -0500 | [diff] [blame] | 37 | 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 Kodihalli | 18aa044 | 2017-07-21 07:07:09 -0500 | [diff] [blame] | 50 | } |
| 51 | } |
| 52 | |
| 53 | Service Objects::service(const Path& path, const Interface& interface) const |
| 54 | { |
| 55 | using Interfaces = std::vector<Interface>; |
Patrick Williams | fbc6c9d | 2023-05-10 07:50:16 -0500 | [diff] [blame] | 56 | auto mapperCall = bus.new_method_call(mapperService, mapperPath, mapperIntf, |
| 57 | "GetObject"); |
Deepak Kodihalli | 18aa044 | 2017-07-21 07:07:09 -0500 | [diff] [blame] | 58 | mapperCall.append(path); |
| 59 | mapperCall.append(Interfaces({interface})); |
| 60 | |
Deepak Kodihalli | 18aa044 | 2017-07-21 07:07:09 -0500 | [diff] [blame] | 61 | std::map<Service, Interfaces> result; |
George Liu | 3e3cc35 | 2023-07-26 15:59:31 +0800 | [diff] [blame] | 62 | try |
Deepak Kodihalli | 18aa044 | 2017-07-21 07:07:09 -0500 | [diff] [blame] | 63 | { |
George Liu | 3e3cc35 | 2023-07-26 15:59:31 +0800 | [diff] [blame] | 64 | 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 Kodihalli | 18aa044 | 2017-07-21 07:07:09 -0500 | [diff] [blame] | 72 | elog<InternalFailure>(); |
| 73 | } |
Deepak Kodihalli | 18aa044 | 2017-07-21 07:07:09 -0500 | [diff] [blame] | 74 | } |
| 75 | |
Deepak Kodihalli | 18aa044 | 2017-07-21 07:07:09 -0500 | [diff] [blame] | 76 | } // namespace settings |