blob: 7f96419a52e89dc6d9246c70d57c4fc964e1ee6d [file] [log] [blame]
Patrick Williams32ffb032020-10-12 12:17:48 -05001#include <sdbusplus/bus.hpp>
2
Patrick Williamsfc0bb992024-10-11 09:42:07 -04003namespace sdbusplus::bus
Patrick Williams32ffb032020-10-12 12:17:48 -05004{
5
6void 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
14void 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 Williamsfc0bb992024-10-11 09:42:07 -040022/* Create a new default connection: system bus if root, session bus if user. */
23bus 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. */
31bus 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. */
39bus 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. */
47bus 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. */
57bus 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. */
67bus 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
76bus::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
90bus::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
105bus::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