Patrick Williams | 32ffb03 | 2020-10-12 12:17:48 -0500 | [diff] [blame] | 1 | #include <sdbusplus/bus.hpp> |
| 2 | |
Patrick Williams | fc0bb99 | 2024-10-11 09:42:07 -0400 | [diff] [blame^] | 3 | namespace sdbusplus::bus |
Patrick Williams | 32ffb03 | 2020-10-12 12:17:48 -0500 | [diff] [blame] | 4 | { |
| 5 | |
| 6 | void bus::emit_interfaces_added(const char* path, |
| 7 | const std::vector<std::string>& ifaces) |
| 8 | { |
| 9 | details::Strv s{ifaces}; |
| 10 | _intf->sd_bus_emit_interfaces_added_strv(_bus.get(), path, |
| 11 | static_cast<char**>(s)); |
| 12 | } |
| 13 | |
| 14 | void bus::emit_interfaces_removed(const char* path, |
| 15 | const std::vector<std::string>& ifaces) |
| 16 | { |
| 17 | details::Strv s{ifaces}; |
| 18 | _intf->sd_bus_emit_interfaces_removed_strv(_bus.get(), path, |
| 19 | static_cast<char**>(s)); |
| 20 | } |
| 21 | |
Patrick Williams | fc0bb99 | 2024-10-11 09:42:07 -0400 | [diff] [blame^] | 22 | /* Create a new default connection: system bus if root, session bus if user. */ |
| 23 | bus new_default() |
| 24 | { |
| 25 | sd_bus* b = nullptr; |
| 26 | sd_bus_default(&b); |
| 27 | return bus(b, std::false_type()); |
| 28 | } |
| 29 | |
| 30 | /* Create a new default connection to the session bus. */ |
| 31 | bus new_default_user() |
| 32 | { |
| 33 | sd_bus* b = nullptr; |
| 34 | sd_bus_default_user(&b); |
| 35 | return bus(b, std::false_type()); |
| 36 | } |
| 37 | |
| 38 | /* Create a new default connection to the system bus. */ |
| 39 | bus new_default_system() |
| 40 | { |
| 41 | sd_bus* b = nullptr; |
| 42 | sd_bus_default_system(&b); |
| 43 | return bus(b, std::false_type()); |
| 44 | } |
| 45 | |
| 46 | /* Create a new connection: system bus if root, session bus if user. */ |
| 47 | bus new_bus() |
| 48 | { |
| 49 | sd_bus* b = nullptr; |
| 50 | sd_bus_open(&b); |
| 51 | bus bus(b, std::false_type()); |
| 52 | bus.set_should_close(true); |
| 53 | return bus; |
| 54 | } |
| 55 | |
| 56 | /* Create a new connection to the session bus. */ |
| 57 | bus new_user() |
| 58 | { |
| 59 | sd_bus* b = nullptr; |
| 60 | sd_bus_open_user(&b); |
| 61 | bus bus(b, std::false_type()); |
| 62 | bus.set_should_close(true); |
| 63 | return bus; |
| 64 | } |
| 65 | |
| 66 | /* Create a new connection to the system bus. */ |
| 67 | bus new_system() |
| 68 | { |
| 69 | sd_bus* b = nullptr; |
| 70 | sd_bus_open_system(&b); |
| 71 | bus bus(b, std::false_type()); |
| 72 | bus.set_should_close(true); |
| 73 | return bus; |
| 74 | } |
| 75 | |
| 76 | bus::bus(busp_t b, sdbusplus::SdBusInterface* intf) : |
| 77 | _intf(intf), _bus(_intf->sd_bus_ref(b), details::BusDeleter(intf)) |
| 78 | { |
| 79 | // Emitting object added causes a message to get the properties |
| 80 | // which can trigger a 'transaction' in the server bindings. If |
| 81 | // the bus isn't up far enough, this causes an assert deep in |
| 82 | // sd-bus code. Get the 'unique_name' to ensure the bus is up far |
| 83 | // enough to avoid the assert. |
| 84 | if (b != nullptr) |
| 85 | { |
| 86 | get_unique_name(); |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | bus::bus(busp_t b) : |
| 91 | _intf(&sdbus_impl), |
| 92 | _bus(_intf->sd_bus_ref(b), details::BusDeleter(&sdbus_impl)) |
| 93 | { |
| 94 | // Emitting object added causes a message to get the properties |
| 95 | // which can trigger a 'transaction' in the server bindings. If |
| 96 | // the bus isn't up far enough, this causes an assert deep in |
| 97 | // sd-bus code. Get the 'unique_name' to ensure the bus is up far |
| 98 | // enough to avoid the assert. |
| 99 | if (b != nullptr) |
| 100 | { |
| 101 | get_unique_name(); |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | bus::bus(busp_t b, std::false_type) : |
| 106 | _intf(&sdbus_impl), _bus(b, details::BusDeleter(&sdbus_impl)) |
| 107 | { |
| 108 | // Emitting object added causes a message to get the properties |
| 109 | // which can trigger a 'transaction' in the server bindings. If |
| 110 | // the bus isn't up far enough, this causes an assert deep in |
| 111 | // sd-bus code. Get the 'unique_name' to ensure the bus is up far |
| 112 | // enough to avoid the assert. |
| 113 | if (b != nullptr) |
| 114 | { |
| 115 | get_unique_name(); |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | } // namespace sdbusplus::bus |