Commit d58d65eb authored by Max Kellermann's avatar Max Kellermann

lib/dbus/Glue: use private connection

Avoid interfering with libraries also using the shared connection.
parent adf2d3af
...@@ -43,6 +43,15 @@ ODBus::Connection::GetSystem() ...@@ -43,6 +43,15 @@ ODBus::Connection::GetSystem()
} }
ODBus::Connection 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) ODBus::Connection::Open(const char *address)
{ {
ODBus::Error error; ODBus::Error error;
......
...@@ -69,6 +69,7 @@ public: ...@@ -69,6 +69,7 @@ public:
} }
static Connection GetSystem(); static Connection GetSystem();
static Connection GetSystemPrivate();
static Connection Open(const char *address); static Connection Open(const char *address);
operator DBusConnection *() noexcept { operator DBusConnection *() noexcept {
...@@ -78,6 +79,10 @@ public: ...@@ -78,6 +79,10 @@ public:
operator bool() const noexcept { operator bool() const noexcept {
return c != nullptr; return c != nullptr;
} }
void Close() noexcept {
dbus_connection_close(c);
}
}; };
} /* namespace ODBus */ } /* namespace ODBus */
......
...@@ -25,7 +25,7 @@ namespace ODBus { ...@@ -25,7 +25,7 @@ namespace ODBus {
void void
Glue::Connect() Glue::Connect()
{ {
watch.SetConnection(Connection::GetSystem()); watch.SetConnection(Connection::GetSystemPrivate());
dbus_connection_set_exit_on_disconnect(GetConnection(), false); dbus_connection_set_exit_on_disconnect(GetConnection(), false);
} }
...@@ -33,6 +33,8 @@ Glue::Connect() ...@@ -33,6 +33,8 @@ Glue::Connect()
void void
Glue::Disconnect() Glue::Disconnect()
{ {
GetConnection().Close();
watch.SetConnection(Connection()); watch.SetConnection(Connection());
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment