bluetooth: pass GDBusConnection to NMBluezDevice

No need to let NMBluezDevice ask for glib's G_BUS_TYPE_SYSTEM
connection. We already have the right D-Bus connection at hand,
just use it.
This commit is contained in:
Thomas Haller
2019-08-10 14:02:02 +02:00
parent 3c9b646524
commit a76e906dca
3 changed files with 18 additions and 34 deletions

View File

@@ -61,6 +61,7 @@ static guint signals[LAST_SIGNAL] = { 0 };
typedef struct {
char *path;
GDBusConnection *dbus_connection;
GDBusProxy *proxy;
@@ -961,24 +962,6 @@ on_proxy_acquired (GObject *object, GAsyncResult *res, NMBluezDevice *self)
g_object_unref (self);
}
static void
on_bus_acquired (GObject *object, GAsyncResult *res, NMBluezDevice *self)
{
NMBluezDevicePrivate *priv = NM_BLUEZ_DEVICE_GET_PRIVATE (self);
GError *error = NULL;
priv->dbus_connection = g_bus_get_finish (res, &error);
if (!priv->dbus_connection) {
nm_log_warn (LOGD_BT, "bluez[%s] failed to acquire bus connection: %s.", priv->path, error->message);
g_clear_error (&error);
g_signal_emit (self, signals[INITIALIZED], 0, FALSE);
} else
check_emit_usable (self);
g_object_unref (self);
}
/*****************************************************************************/
static void
@@ -1037,7 +1020,8 @@ nm_bluez_device_init (NMBluezDevice *self)
}
NMBluezDevice *
nm_bluez_device_new (const char *path,
nm_bluez_device_new (GDBusConnection *dbus_connection,
const char *path,
NMSettings *settings)
{
NMBluezDevice *self;
@@ -1045,6 +1029,7 @@ nm_bluez_device_new (const char *path,
g_return_val_if_fail (path != NULL, NULL);
g_return_val_if_fail (NM_IS_SETTINGS (settings), NULL);
g_return_val_if_fail (G_IS_DBUS_CONNECTION (dbus_connection), NULL);
self = (NMBluezDevice *) g_object_new (NM_TYPE_BLUEZ_DEVICE,
NM_BLUEZ_DEVICE_PATH, path,
@@ -1062,12 +1047,9 @@ nm_bluez_device_new (const char *path,
g_signal_connect (priv->settings, NM_SETTINGS_SIGNAL_CONNECTION_REMOVED, G_CALLBACK (cp_connection_removed), self);
g_signal_connect (priv->settings, NM_SETTINGS_SIGNAL_CONNECTION_UPDATED, G_CALLBACK (cp_connection_updated), self);
g_bus_get (G_BUS_TYPE_SYSTEM,
NULL,
(GAsyncReadyCallback) on_bus_acquired,
g_object_ref (self));
priv->dbus_connection = g_object_ref (dbus_connection);
g_dbus_proxy_new_for_bus (G_BUS_TYPE_SYSTEM,
g_dbus_proxy_new (priv->dbus_connection,
G_DBUS_PROXY_FLAGS_NONE,
NULL,
NM_BLUEZ_SERVICE,
@@ -1076,6 +1058,7 @@ nm_bluez_device_new (const char *path,
NULL,
(GAsyncReadyCallback) on_proxy_acquired,
g_object_ref (self));
return self;
}

View File

@@ -46,7 +46,8 @@ typedef struct _NMBluezDeviceClass NMBluezDeviceClass;
GType nm_bluez_device_get_type (void);
NMBluezDevice *nm_bluez_device_new (const char *path,
NMBluezDevice *nm_bluez_device_new (GDBusConnection *dbus_connection,
const char *path,
NMSettings *settings);
const char *nm_bluez_device_get_path (NMBluezDevice *self);

View File

@@ -346,7 +346,7 @@ device_added (GDBusProxy *proxy, const char *path, NMBluez5Manager *self)
NMBluez5ManagerPrivate *priv = NM_BLUEZ5_MANAGER_GET_PRIVATE (self);
NMBluezDevice *device;
device = nm_bluez_device_new (path, priv->settings);
device = nm_bluez_device_new (g_dbus_proxy_get_connection (proxy), path, priv->settings);
g_signal_connect (device, NM_BLUEZ_DEVICE_INITIALIZED, G_CALLBACK (device_initialized), self);
g_signal_connect (device, "notify::" NM_BLUEZ_DEVICE_USABLE, G_CALLBACK (device_usable), self);
g_hash_table_insert (priv->devices, (gpointer) nm_bluez_device_get_path (device), device);