1 #include "settings.hpp"
2 
3 #include <ipmid/utils.hpp>
4 #include <phosphor-logging/elog-errors.hpp>
5 #include <phosphor-logging/log.hpp>
6 #include <sdbusplus/message/types.hpp>
7 #include <xyz/openbmc_project/Common/error.hpp>
8 
9 namespace settings
10 {
11 
12 using namespace phosphor::logging;
13 using namespace sdbusplus::error::xyz::openbmc_project::common;
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 
19 Objects::Objects(sdbusplus::bus_t& bus, const std::vector<Interface>& filter) :
20     bus(bus)
21 {
22     ipmi::ObjectTree objectTree;
23     try
24     {
25         objectTree = ipmi::getSubTree(bus, filter);
26     }
27     catch (const std::exception& e)
28     {
29         log<level::ERR>("Failed to call the getSubTree method.",
30                         entry("ERROR=%s", e.what()));
31         elog<InternalFailure>();
32     }
33 
34     for (auto& iter : objectTree)
35     {
36         const auto& path = iter.first;
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         }
50     }
51 }
52 
53 Service Objects::service(const Path& path, const Interface& interface) const
54 {
55     using Interfaces = std::vector<Interface>;
56     auto mapperCall = bus.new_method_call(mapperService, mapperPath, mapperIntf,
57                                           "GetObject");
58     mapperCall.append(path);
59     mapperCall.append(Interfaces({interface}));
60 
61     std::map<Service, Interfaces> result;
62     try
63     {
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()));
72         elog<InternalFailure>();
73     }
74 }
75 
76 } // namespace settings
77