blob: a60db8b4ddda5c90c5432130ea04838ae7120c62 [file] [log] [blame]
Jagpal Singh Gill23f091e2023-12-10 15:23:19 -08001#include "health_utils.hpp"
2
3#include <phosphor-logging/lg2.hpp>
4
5PHOSPHOR_LOG2_USING;
6
7namespace phosphor::health::utils
8{
9
10void startUnit(sdbusplus::bus_t& bus, const std::string& sysdUnit)
11{
12 if (sysdUnit.empty())
13 {
14 return;
15 }
16 sdbusplus::message_t msg = bus.new_method_call(
17 "org.freedesktop.systemd1", "/org/freedesktop/systemd1",
18 "org.freedesktop.systemd1.Manager", "StartUnit");
19 msg.append(sysdUnit, "replace");
20 bus.call_noreply(msg);
21}
22
Jagpal Singh Gill81da1372023-12-15 17:01:03 -080023auto findPaths(sdbusplus::bus_t& bus, const std::string& iface) -> paths_t
24{
25 sdbusplus::message_t msg = bus.new_method_call(
26 "xyz.openbmc_project.ObjectMapper",
27 "/xyz/openbmc_project/object_mapper",
28 "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths");
29 const char* inventoryPath = "/xyz/openbmc_project/inventory";
30
31 msg.append("/", 0, std::vector<std::string>{iface});
32
33 try
34 {
35 auto paths = bus.call(msg, int32_t(0)).unpack<paths_t>();
36 debug("Found {COUNT} paths for {IFACE}", "COUNT", paths.size(), "IFACE",
37 iface);
38 return paths;
39 }
40 catch (std::exception& e)
41 {
42 error("Exception occurred for GetSubTreePaths for {PATH}: {ERROR}",
43 "PATH", inventoryPath, "ERROR", e);
44 }
45 return {};
46}
47
Jagpal Singh Gill23f091e2023-12-10 15:23:19 -080048} // namespace phosphor::health::utils