| 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> |
| George Liu | 81eb6b3 | 2024-07-19 09:11:42 +0800 | [diff] [blame] | 5 | #include <phosphor-logging/lg2.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> |
| Alexander Hansen | 93aa983 | 2025-11-07 15:29:49 +0100 | [diff] [blame^] | 8 | #include <xyz/openbmc_project/ObjectMapper/common.hpp> |
| 9 | |
| 10 | using ObjectMapper = sdbusplus::common::xyz::openbmc_project::ObjectMapper; |
| Deepak Kodihalli | 18aa044 | 2017-07-21 07:07:09 -0500 | [diff] [blame] | 11 | |
| 12 | namespace settings |
| 13 | { |
| 14 | |
| 15 | using namespace phosphor::logging; |
| Willy Tu | 523e2d1 | 2023-09-05 11:36:48 -0700 | [diff] [blame] | 16 | using namespace sdbusplus::error::xyz::openbmc_project::common; |
| Deepak Kodihalli | 18aa044 | 2017-07-21 07:07:09 -0500 | [diff] [blame] | 17 | |
| Patrick Williams | 5d82f47 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 18 | Objects::Objects(sdbusplus::bus_t& bus, const std::vector<Interface>& filter) : |
| Deepak Kodihalli | 18aa044 | 2017-07-21 07:07:09 -0500 | [diff] [blame] | 19 | bus(bus) |
| 20 | { |
| George Liu | c1c7eac | 2024-02-04 17:24:19 +0800 | [diff] [blame] | 21 | ipmi::ObjectTree objectTree; |
| George Liu | 3e3cc35 | 2023-07-26 15:59:31 +0800 | [diff] [blame] | 22 | try |
| Deepak Kodihalli | 18aa044 | 2017-07-21 07:07:09 -0500 | [diff] [blame] | 23 | { |
| George Liu | c1c7eac | 2024-02-04 17:24:19 +0800 | [diff] [blame] | 24 | objectTree = ipmi::getSubTree(bus, filter); |
| George Liu | 3e3cc35 | 2023-07-26 15:59:31 +0800 | [diff] [blame] | 25 | } |
| 26 | catch (const std::exception& e) |
| 27 | { |
| George Liu | 81eb6b3 | 2024-07-19 09:11:42 +0800 | [diff] [blame] | 28 | lg2::error("Failed to call the getSubTree method: {ERROR}", "ERROR", e); |
| Deepak Kodihalli | 18aa044 | 2017-07-21 07:07:09 -0500 | [diff] [blame] | 29 | elog<InternalFailure>(); |
| 30 | } |
| 31 | |
| George Liu | c1c7eac | 2024-02-04 17:24:19 +0800 | [diff] [blame] | 32 | for (auto& iter : objectTree) |
| Deepak Kodihalli | 18aa044 | 2017-07-21 07:07:09 -0500 | [diff] [blame] | 33 | { |
| 34 | const auto& path = iter.first; |
| Deepak Kodihalli | e602709 | 2017-08-27 08:13:37 -0500 | [diff] [blame] | 35 | for (auto& interface : iter.second.begin()->second) |
| 36 | { |
| 37 | auto found = map.find(interface); |
| 38 | if (map.end() != found) |
| 39 | { |
| 40 | auto& paths = found->second; |
| 41 | paths.push_back(path); |
| 42 | } |
| 43 | else |
| 44 | { |
| 45 | map.emplace(std::move(interface), std::vector<Path>({path})); |
| 46 | } |
| 47 | } |
| Deepak Kodihalli | 18aa044 | 2017-07-21 07:07:09 -0500 | [diff] [blame] | 48 | } |
| 49 | } |
| 50 | |
| 51 | Service Objects::service(const Path& path, const Interface& interface) const |
| 52 | { |
| 53 | using Interfaces = std::vector<Interface>; |
| Alexander Hansen | 93aa983 | 2025-11-07 15:29:49 +0100 | [diff] [blame^] | 54 | auto mapperCall = bus.new_method_call( |
| 55 | ObjectMapper::default_service, ObjectMapper::instance_path, |
| 56 | ObjectMapper::interface, "GetObject"); |
| Deepak Kodihalli | 18aa044 | 2017-07-21 07:07:09 -0500 | [diff] [blame] | 57 | mapperCall.append(path); |
| 58 | mapperCall.append(Interfaces({interface})); |
| 59 | |
| Deepak Kodihalli | 18aa044 | 2017-07-21 07:07:09 -0500 | [diff] [blame] | 60 | std::map<Service, Interfaces> result; |
| George Liu | 3e3cc35 | 2023-07-26 15:59:31 +0800 | [diff] [blame] | 61 | try |
| Deepak Kodihalli | 18aa044 | 2017-07-21 07:07:09 -0500 | [diff] [blame] | 62 | { |
| George Liu | 3e3cc35 | 2023-07-26 15:59:31 +0800 | [diff] [blame] | 63 | auto response = bus.call(mapperCall); |
| 64 | response.read(result); |
| 65 | return result.begin()->first; |
| 66 | } |
| 67 | catch (const std::exception& e) |
| 68 | { |
| George Liu | 81eb6b3 | 2024-07-19 09:11:42 +0800 | [diff] [blame] | 69 | lg2::error("Invalid response from mapper: {ERROR}", "ERROR", e); |
| Deepak Kodihalli | 18aa044 | 2017-07-21 07:07:09 -0500 | [diff] [blame] | 70 | elog<InternalFailure>(); |
| 71 | } |
| Deepak Kodihalli | 18aa044 | 2017-07-21 07:07:09 -0500 | [diff] [blame] | 72 | } |
| 73 | |
| Deepak Kodihalli | 18aa044 | 2017-07-21 07:07:09 -0500 | [diff] [blame] | 74 | } // namespace settings |