connection: add createDefaultBusConnection()

This internally calls sd_bus_open(), which automatically selects the
system or session bus connection based on the presence and 
content of a DBUS_STARTER_BUS_TYPE environment variable and
whether the calling process has root privileges.

This option is very helpful when creating services and clients that will use the system bus in production, but connect to a session
for testing.

Additional changes:
* Removed assertions null-checking make_unique() return values.
  make_unique() calls new, and new is expected to throw or abort
  on failure, making the assertions unhelpful.
* Corrected a typo in the ClosesAndUnrefsBusWhenDestructed
  unit test for the system bus (tested the wrong function).
This commit is contained in:
David Leeds authored and Stanislav Angelovič committed 2021-06-21 15:55:23 +02:00
1 parent d74365c535
commit 75ea127374
8 files changed
+87 -6

No files matched your search

+2
View File
@@ -48,10 +48,12 @@ namespace sdbus::internal {
{
public:
// Bus type tags
struct default_bus_t{};
struct system_bus_t{};
struct session_bus_t{};
struct remote_system_bus_t{};
Connection(std::unique_ptr<ISdBus>&& interface, default_bus_t);
Connection(std::unique_ptr<ISdBus>&& interface, system_bus_t);
Connection(std::unique_ptr<ISdBus>&& interface, session_bus_t);
Connection(std::unique_ptr<ISdBus>&& interface, remote_system_bus_t, const std::string& host);