lib/dbus/Glue: use private connection

Avoid interfering with libraries also using the shared connection.
This commit is contained in:
Max Kellermann 2018-06-03 10:36:12 +02:00
parent adf2d3aff2
commit d58d65ebf0
3 changed files with 17 additions and 1 deletions

View File

@ -42,6 +42,15 @@ ODBus::Connection::GetSystem()
return Connection(c);
}
ODBus::Connection
ODBus::Connection::GetSystemPrivate()
{
ODBus::Error error;
auto *c = dbus_bus_get_private(DBUS_BUS_SYSTEM, error);
error.CheckThrow("DBus connection error");
return Connection(c);
}
ODBus::Connection
ODBus::Connection::Open(const char *address)
{

View File

@ -69,6 +69,7 @@ public:
}
static Connection GetSystem();
static Connection GetSystemPrivate();
static Connection Open(const char *address);
operator DBusConnection *() noexcept {
@ -78,6 +79,10 @@ public:
operator bool() const noexcept {
return c != nullptr;
}
void Close() noexcept {
dbus_connection_close(c);
}
};
} /* namespace ODBus */

View File

@ -25,7 +25,7 @@ namespace ODBus {
void
Glue::Connect()
{
watch.SetConnection(Connection::GetSystem());
watch.SetConnection(Connection::GetSystemPrivate());
dbus_connection_set_exit_on_disconnect(GetConnection(), false);
}
@ -33,6 +33,8 @@ Glue::Connect()
void
Glue::Disconnect()
{
GetConnection().Close();
watch.SetConnection(Connection());
}