Jagpal Singh Gill | 23f091e | 2023-12-10 15:23:19 -0800 | [diff] [blame] | 1 | #include "health_utils.hpp" |
| 2 | |
| 3 | #include <phosphor-logging/lg2.hpp> |
| 4 | |
| 5 | PHOSPHOR_LOG2_USING; |
| 6 | |
| 7 | namespace phosphor::health::utils |
| 8 | { |
| 9 | |
| 10 | void 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 Gill | 81da137 | 2023-12-15 17:01:03 -0800 | [diff] [blame^] | 23 | auto 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 Gill | 23f091e | 2023-12-10 15:23:19 -0800 | [diff] [blame] | 48 | } // namespace phosphor::health::utils |