blob: cac44c64658883014356e0c115848242ab526fa0 [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>
George Liu81eb6b32024-07-19 09:11:42 +08005#include <phosphor-logging/lg2.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>
Alexander Hansen93aa9832025-11-07 15:29:49 +01008#include <xyz/openbmc_project/ObjectMapper/common.hpp>
9
10using ObjectMapper = sdbusplus::common::xyz::openbmc_project::ObjectMapper;
Deepak Kodihalli18aa0442017-07-21 07:07:09 -050011
12namespace settings
13{
14
15using namespace phosphor::logging;
Willy Tu523e2d12023-09-05 11:36:48 -070016using namespace sdbusplus::error::xyz::openbmc_project::common;
Deepak Kodihalli18aa0442017-07-21 07:07:09 -050017
Patrick Williams5d82f472022-07-22 19:26:53 -050018Objects::Objects(sdbusplus::bus_t& bus, const std::vector<Interface>& filter) :
Deepak Kodihalli18aa0442017-07-21 07:07:09 -050019 bus(bus)
20{
George Liuc1c7eac2024-02-04 17:24:19 +080021 ipmi::ObjectTree objectTree;
George Liu3e3cc352023-07-26 15:59:31 +080022 try
Deepak Kodihalli18aa0442017-07-21 07:07:09 -050023 {
George Liuc1c7eac2024-02-04 17:24:19 +080024 objectTree = ipmi::getSubTree(bus, filter);
George Liu3e3cc352023-07-26 15:59:31 +080025 }
26 catch (const std::exception& e)
27 {
George Liu81eb6b32024-07-19 09:11:42 +080028 lg2::error("Failed to call the getSubTree method: {ERROR}", "ERROR", e);
Deepak Kodihalli18aa0442017-07-21 07:07:09 -050029 elog<InternalFailure>();
30 }
31
George Liuc1c7eac2024-02-04 17:24:19 +080032 for (auto& iter : objectTree)
Deepak Kodihalli18aa0442017-07-21 07:07:09 -050033 {
34 const auto& path = iter.first;
Deepak Kodihallie6027092017-08-27 08:13:37 -050035 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 Kodihalli18aa0442017-07-21 07:07:09 -050048 }
49}
50
51Service Objects::service(const Path& path, const Interface& interface) const
52{
53 using Interfaces = std::vector<Interface>;
Alexander Hansen93aa9832025-11-07 15:29:49 +010054 auto mapperCall = bus.new_method_call(
55 ObjectMapper::default_service, ObjectMapper::instance_path,
56 ObjectMapper::interface, "GetObject");
Deepak Kodihalli18aa0442017-07-21 07:07:09 -050057 mapperCall.append(path);
58 mapperCall.append(Interfaces({interface}));
59
Deepak Kodihalli18aa0442017-07-21 07:07:09 -050060 std::map<Service, Interfaces> result;
George Liu3e3cc352023-07-26 15:59:31 +080061 try
Deepak Kodihalli18aa0442017-07-21 07:07:09 -050062 {
George Liu3e3cc352023-07-26 15:59:31 +080063 auto response = bus.call(mapperCall);
64 response.read(result);
65 return result.begin()->first;
66 }
67 catch (const std::exception& e)
68 {
George Liu81eb6b32024-07-19 09:11:42 +080069 lg2::error("Invalid response from mapper: {ERROR}", "ERROR", e);
Deepak Kodihalli18aa0442017-07-21 07:07:09 -050070 elog<InternalFailure>();
71 }
Deepak Kodihalli18aa0442017-07-21 07:07:09 -050072}
73
Deepak Kodihalli18aa0442017-07-21 07:07:09 -050074} // namespace settings