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> |
Patrick Williams | 6662be3 | 2024-02-22 13:35:46 -0600 | [diff] [blame] | 4 | #include <xyz/openbmc_project/ObjectMapper/client.hpp> |
Jagpal Singh Gill | 23f091e | 2023-12-10 15:23:19 -0800 | [diff] [blame] | 5 | |
| 6 | PHOSPHOR_LOG2_USING; |
| 7 | |
| 8 | namespace phosphor::health::utils |
| 9 | { |
| 10 | |
| 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 | |
Patrick Williams | 6662be3 | 2024-02-22 13:35:46 -0600 | [diff] [blame] | 24 | auto findPaths(sdbusplus::async::context& ctx, const std::string& iface, |
| 25 | const std::string& subpath) -> sdbusplus::async::task<paths_t> |
Jagpal Singh Gill | 81da137 | 2023-12-15 17:01:03 -0800 | [diff] [blame] | 26 | { |
Jagpal Singh Gill | 81da137 | 2023-12-15 17:01:03 -0800 | [diff] [blame] | 27 | try |
| 28 | { |
Patrick Williams | 6662be3 | 2024-02-22 13:35:46 -0600 | [diff] [blame] | 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); |
Jagpal Singh Gill | 81da137 | 2023-12-15 17:01:03 -0800 | [diff] [blame] | 38 | } |
| 39 | catch (std::exception& e) |
| 40 | { |
| 41 | error("Exception occurred for GetSubTreePaths for {PATH}: {ERROR}", |
Patrick Williams | 6662be3 | 2024-02-22 13:35:46 -0600 | [diff] [blame] | 42 | "PATH", subpath, "ERROR", e); |
Jagpal Singh Gill | 81da137 | 2023-12-15 17:01:03 -0800 | [diff] [blame] | 43 | } |
Patrick Williams | 6662be3 | 2024-02-22 13:35:46 -0600 | [diff] [blame] | 44 | co_return {}; |
Jagpal Singh Gill | 81da137 | 2023-12-15 17:01:03 -0800 | [diff] [blame] | 45 | } |
| 46 | |
Jagpal Singh Gill | 23f091e | 2023-12-10 15:23:19 -0800 | [diff] [blame] | 47 | } // namespace phosphor::health::utils |