diff options
author | Thomas Haller <thaller@redhat.com> | 2019-08-10 14:02:02 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2019-08-12 16:07:12 +0200 |
commit | a76e906dca14b01452169fcb5436df40385a41e3 (patch) | |
tree | f75ea73f4bae1d3ca5b538dfb2ebe04734b27143 | |
parent | 3c9b64652459581adc0bafbc6834fa533f42a13a (diff) | |
download | NetworkManager-a76e906dca14b01452169fcb5436df40385a41e3.tar.gz |
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.
-rw-r--r-- | src/devices/bluetooth/nm-bluez-device.c | 47 | ||||
-rw-r--r-- | src/devices/bluetooth/nm-bluez-device.h | 3 | ||||
-rw-r--r-- | src/devices/bluetooth/nm-bluez5-manager.c | 2 |
3 files changed, 18 insertions, 34 deletions
diff --git a/src/devices/bluetooth/nm-bluez-device.c b/src/devices/bluetooth/nm-bluez-device.c index 657f521ee5..7246ef03cf 100644 --- a/src/devices/bluetooth/nm-bluez-device.c +++ b/src/devices/bluetooth/nm-bluez-device.c @@ -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,20 +1047,18 @@ 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 (priv->dbus_connection, + G_DBUS_PROXY_FLAGS_NONE, + NULL, + NM_BLUEZ_SERVICE, + priv->path, + NM_BLUEZ5_DEVICE_INTERFACE, + NULL, + (GAsyncReadyCallback) on_proxy_acquired, + g_object_ref (self)); - g_dbus_proxy_new_for_bus (G_BUS_TYPE_SYSTEM, - G_DBUS_PROXY_FLAGS_NONE, - NULL, - NM_BLUEZ_SERVICE, - priv->path, - NM_BLUEZ5_DEVICE_INTERFACE, - NULL, - (GAsyncReadyCallback) on_proxy_acquired, - g_object_ref (self)); return self; } diff --git a/src/devices/bluetooth/nm-bluez-device.h b/src/devices/bluetooth/nm-bluez-device.h index 93a228cac2..cef13f4682 100644 --- a/src/devices/bluetooth/nm-bluez-device.h +++ b/src/devices/bluetooth/nm-bluez-device.h @@ -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); diff --git a/src/devices/bluetooth/nm-bluez5-manager.c b/src/devices/bluetooth/nm-bluez5-manager.c index 9d8d9a28cf..d5e58bc650 100644 --- a/src/devices/bluetooth/nm-bluez5-manager.c +++ b/src/devices/bluetooth/nm-bluez5-manager.c @@ -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); |