blob: d5fdd69237f4b17794904023f3c3140c1c2c0e7c [file] [log] [blame]
Matt Spinlerbc997492018-03-27 11:24:45 -05001/**
2 * Copyright © 2018 IBM Corporation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Matt Spinlerbc997492018-03-27 11:24:45 -050016#include "dbus.hpp"
17
Matt Spinler66e07072018-09-12 10:36:14 -050018#include <phosphor-logging/log.hpp>
19
Matt Spinlerbc997492018-03-27 11:24:45 -050020namespace ibm
21{
22namespace logging
23{
24
Matt Spinlerd82a6dd2018-05-23 11:31:22 -050025constexpr auto MAPPER_BUSNAME = "xyz.openbmc_project.ObjectMapper";
26constexpr auto MAPPER_PATH = "/xyz/openbmc_project/object_mapper";
27constexpr auto MAPPER_IFACE = "xyz.openbmc_project.ObjectMapper";
28constexpr auto PROPERTY_IFACE = "org.freedesktop.DBus.Properties";
29
30using namespace phosphor::logging;
31
Patrick Williams8123a712022-07-22 19:26:53 -050032ObjectValueTree getManagedObjects(sdbusplus::bus_t& bus,
Matt Spinler259e7272018-03-29 10:57:17 -050033 const std::string& service,
34 const std::string& objPath)
Matt Spinlerbc997492018-03-27 11:24:45 -050035{
36 ObjectValueTree interfaces;
37
Matt Spinler259e7272018-03-29 10:57:17 -050038 auto method = bus.new_method_call(service.c_str(), objPath.c_str(),
39 "org.freedesktop.DBus.ObjectManager",
40 "GetManagedObjects");
Matt Spinlerbc997492018-03-27 11:24:45 -050041
42 auto reply = bus.call(method);
43
Matt Spinler93516652018-10-23 10:49:47 -050044 reply.read(interfaces);
Matt Spinlerbc997492018-03-27 11:24:45 -050045
46 return interfaces;
47}
Matt Spinlerd82a6dd2018-05-23 11:31:22 -050048
Patrick Williams8123a712022-07-22 19:26:53 -050049DbusPropertyMap getAllProperties(sdbusplus::bus_t& bus,
Matt Spinlerd82a6dd2018-05-23 11:31:22 -050050 const std::string& service,
51 const std::string& objPath,
52 const std::string& interface)
53{
54 DbusPropertyMap properties;
55
56 auto method = bus.new_method_call(service.c_str(), objPath.c_str(),
57 PROPERTY_IFACE, "GetAll");
58 method.append(interface);
59 auto reply = bus.call(method);
60
Matt Spinler93516652018-10-23 10:49:47 -050061 reply.read(properties);
Matt Spinlerd82a6dd2018-05-23 11:31:22 -050062
63 return properties;
64}
65
Patrick Williams8123a712022-07-22 19:26:53 -050066DbusSubtree getSubtree(sdbusplus::bus_t& bus, const std::string& root,
Matt Spinler7766e252018-09-12 10:37:56 -050067 int depth, const std::string& interface)
Matt Spinlerd82a6dd2018-05-23 11:31:22 -050068{
69 DbusSubtree tree;
70
71 auto method = bus.new_method_call(MAPPER_BUSNAME, MAPPER_PATH, MAPPER_IFACE,
72 "GetSubTree");
73 method.append(root);
74 method.append(depth);
75 method.append(std::vector<std::string>({interface}));
76 auto reply = bus.call(method);
77
Matt Spinler93516652018-10-23 10:49:47 -050078 reply.read(tree);
Matt Spinlerd82a6dd2018-05-23 11:31:22 -050079
80 return tree;
81}
82
83DbusService getService(const std::string& objPath, const std::string& interface,
84 const DbusSubtree& tree)
85{
86 DbusService service;
87
88 auto services = tree.find(objPath);
89 if (services != tree.end())
90 {
91 auto s = std::find_if(services->second.begin(), services->second.end(),
92 [&interface](const auto& entry) {
Patrick Williams6a2b8952023-05-10 07:50:35 -050093 auto i = std::find(entry.second.begin(), entry.second.end(),
94 interface);
95 return i != entry.second.end();
96 });
Matt Spinlerd82a6dd2018-05-23 11:31:22 -050097 if (s != services->second.end())
98 {
99 service = s->first;
100 }
101 }
102
103 return service;
104}
Matt Spinler66e07072018-09-12 10:36:14 -0500105} // namespace logging
106} // namespace ibm