1 #include "health_utils.hpp"
2
3 #include <phosphor-logging/lg2.hpp>
4 #include <xyz/openbmc_project/ObjectMapper/client.hpp>
5
6 PHOSPHOR_LOG2_USING;
7
8 namespace phosphor::health::utils
9 {
10
startUnit(sdbusplus::bus_t & bus,const std::string & sysdUnit)11 void startUnit(sdbusplus::bus_t& bus, const std::string& sysdUnit)
12 {
13 if (sysdUnit.empty())
14 {
15 return;
16 }
17 sdbusplus::message_t msg = bus.new_method_call(
18 "org.freedesktop.systemd1", "/org/freedesktop/systemd1",
19 "org.freedesktop.systemd1.Manager", "StartUnit");
20 msg.append(sysdUnit, "replace");
21 bus.call_noreply(msg);
22 }
23
findPaths(sdbusplus::async::context & ctx,const std::string & iface,const std::string & subpath)24 auto findPaths(sdbusplus::async::context& ctx, const std::string& iface,
25 const std::string& subpath) -> sdbusplus::async::task<paths_t>
26 {
27 try
28 {
29 using ObjectMapper =
30 sdbusplus::client::xyz::openbmc_project::ObjectMapper<>;
31
32 auto mapper = ObjectMapper(ctx)
33 .service(ObjectMapper::default_service)
34 .path(ObjectMapper::instance_path);
35
36 std::vector<std::string> ifaces = {iface};
37 co_return co_await mapper.get_sub_tree_paths(subpath, 0, ifaces);
38 }
39 catch (std::exception& e)
40 {
41 error("Exception occurred for GetSubTreePaths for {PATH}: {ERROR}",
42 "PATH", subpath, "ERROR", e);
43 }
44 co_return {};
45 }
46
47 } // namespace phosphor::health::utils
48