summary refs log tree commit diff
path: root/src/devices/bluetooth/nm-bluez-device.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/devices/bluetooth/nm-bluez-device.c')
-rw-r--r--src/devices/bluetooth/nm-bluez-device.c73
1 files changed, 38 insertions, 35 deletions
diff --git a/src/devices/bluetooth/nm-bluez-device.c b/src/devices/bluetooth/nm-bluez-device.c
index b69b4320..d8e40d6f 100644
--- a/src/devices/bluetooth/nm-bluez-device.c
+++ b/src/devices/bluetooth/nm-bluez-device.c
@@ -94,7 +94,7 @@ typedef struct {
 	NMSettings *settings;
 	GSList *connections;
 
-	NMSettingsConnection *pan_connection;
+	NMConnection *pan_connection;
 	gboolean pan_connection_no_autocreate;
 } NMBluezDevicePrivate;
 
@@ -114,9 +114,8 @@ G_DEFINE_TYPE (NMBluezDevice, nm_bluez_device, G_TYPE_OBJECT)
 /*****************************************************************************/
 
 static void cp_connection_added (NMSettings *settings,
-                                 NMSettingsConnection *sett_conn,
-                                 NMBluezDevice *self);
-static gboolean connection_compatible (NMBluezDevice *self, NMSettingsConnection *sett_conn);
+                                 NMConnection *connection, NMBluezDevice *self);
+static gboolean connection_compatible (NMBluezDevice *self, NMConnection *connection);
 
 /*****************************************************************************/
 
@@ -182,10 +181,10 @@ nm_bluez_device_get_connected (NMBluezDevice *self)
 static void
 pan_connection_check_create (NMBluezDevice *self)
 {
-	gs_unref_object NMConnection *connection = NULL;
-	NMSettingsConnection *added;
+	NMConnection *connection;
+	NMConnection *added;
 	NMSetting *setting;
-	gs_free char *id = NULL;
+	char *id;
 	char uuid[37];
 	GError *error = NULL;
 	NMBluezDevicePrivate *priv = NM_BLUEZ_DEVICE_GET_PRIVATE (self);
@@ -247,14 +246,15 @@ pan_connection_check_create (NMBluezDevice *self)
 	 * which then already finds the suitable connection in priv->connections. This is confusing,
 	 * so block the signal. check_emit_usable will succeed after this function call returns. */
 	g_signal_handlers_block_by_func (priv->settings, cp_connection_added, self);
-	added = nm_settings_add_connection (priv->settings, connection, FALSE, &error);
+	added = NM_CONNECTION (nm_settings_add_connection (priv->settings, connection, FALSE, &error));
 	g_signal_handlers_unblock_by_func (priv->settings, cp_connection_added, self);
 
 	if (added) {
-		nm_assert (!g_slist_find (priv->connections, added));
-		nm_assert (connection_compatible (self, added));
+		g_assert (!g_slist_find (priv->connections, added));
+		g_assert (connection_compatible (self, added));
+		g_assert (nm_connection_compare (added, connection, NM_SETTING_COMPARE_FLAG_EXACT));
 
-		nm_settings_connection_set_flags (added, NM_SETTINGS_CONNECTION_INT_FLAGS_NM_GENERATED, TRUE);
+		nm_settings_connection_set_flags (NM_SETTINGS_CONNECTION (added), NM_SETTINGS_CONNECTION_INT_FLAGS_NM_GENERATED, TRUE);
 
 		priv->connections = g_slist_prepend (priv->connections, g_object_ref (added));
 		priv->pan_connection = added;
@@ -263,7 +263,11 @@ pan_connection_check_create (NMBluezDevice *self)
 		nm_log_warn (LOGD_BT, "bluez[%s] couldn't add new Bluetooth connection for NAP device: '%s' (%s): %s",
 		             priv->path, id, uuid, error->message);
 		g_clear_error (&error);
+
 	}
+	g_object_unref (connection);
+
+	g_free (id);
 }
 
 static gboolean
@@ -317,10 +321,9 @@ check_emit_usable_schedule (NMBluezDevice *self)
 /*****************************************************************************/
 
 static gboolean
-connection_compatible (NMBluezDevice *self, NMSettingsConnection *sett_conn)
+connection_compatible (NMBluezDevice *self, NMConnection *connection)
 {
 	NMBluezDevicePrivate *priv = NM_BLUEZ_DEVICE_GET_PRIVATE (self);
-	NMConnection *connection = nm_settings_connection_get_connection (sett_conn);
 	NMSettingBluetooth *s_bt;
 	const char *bt_type;
 	const char *bdaddr;
@@ -358,24 +361,22 @@ connection_compatible (NMBluezDevice *self, NMSettingsConnection *sett_conn)
 }
 
 static gboolean
-_internal_track_connection (NMBluezDevice *self,
-                            NMSettingsConnection *sett_conn,
-                            gboolean tracked)
+_internal_track_connection (NMBluezDevice *self, NMConnection *connection, gboolean tracked)
 {
 	NMBluezDevicePrivate *priv = NM_BLUEZ_DEVICE_GET_PRIVATE (self);
 	gboolean was_tracked;
 
-	was_tracked = !!g_slist_find (priv->connections, sett_conn);
+	was_tracked = !!g_slist_find (priv->connections, connection);
 	if (was_tracked == !!tracked)
 		return FALSE;
 
 	if (tracked)
-		priv->connections = g_slist_prepend (priv->connections, g_object_ref (sett_conn));
+		priv->connections = g_slist_prepend (priv->connections, g_object_ref (connection));
 	else {
-		priv->connections = g_slist_remove (priv->connections, sett_conn);
-		if (priv->pan_connection == sett_conn)
+		priv->connections = g_slist_remove (priv->connections, connection);
+		if (priv->pan_connection == connection)
 			priv->pan_connection = NULL;
-		g_object_unref (sett_conn);
+		g_object_unref (connection);
 	}
 
 	return TRUE;
@@ -383,32 +384,32 @@ _internal_track_connection (NMBluezDevice *self,
 
 static void
 cp_connection_added (NMSettings *settings,
-                     NMSettingsConnection *sett_conn,
+                     NMConnection *connection,
                      NMBluezDevice *self)
 {
-	if (connection_compatible (self, sett_conn)) {
-		if (_internal_track_connection (self, sett_conn, TRUE))
+	if (connection_compatible (self, connection)) {
+		if (_internal_track_connection (self, connection, TRUE))
 			check_emit_usable (self);
 	}
 }
 
 static void
 cp_connection_removed (NMSettings *settings,
-                       NMSettingsConnection *sett_conn,
+                       NMConnection *connection,
                        NMBluezDevice *self)
 {
-	if (_internal_track_connection (self, sett_conn, FALSE))
+	if (_internal_track_connection (self, connection, FALSE))
 		check_emit_usable (self);
 }
 
 static void
 cp_connection_updated (NMSettings *settings,
-                       NMSettingsConnection *sett_conn,
+                       NMConnection *connection,
                        gboolean by_user,
                        NMBluezDevice *self)
 {
-	if (_internal_track_connection (self, sett_conn,
-	                                connection_compatible (self, sett_conn)))
+	if (_internal_track_connection (self, connection,
+	                                connection_compatible (self, connection)))
 		check_emit_usable_schedule (self);
 }
 
@@ -422,8 +423,10 @@ load_connections (NMBluezDevice *self)
 
 	connections = nm_settings_get_connections (priv->settings, NULL);
 	for (i = 0; connections[i]; i++) {
-		if (connection_compatible (self, connections[i]))
-			changed |= _internal_track_connection (self, connections[i], TRUE);
+		NMConnection *connection = (NMConnection *) connections[i];
+
+		if (connection_compatible (self, connection))
+			changed |= _internal_track_connection (self, connection, TRUE);
 	}
 	if (changed)
 		check_emit_usable (self);
@@ -1175,14 +1178,14 @@ dispose (GObject *object)
 {
 	NMBluezDevice *self = NM_BLUEZ_DEVICE (object);
 	NMBluezDevicePrivate *priv = NM_BLUEZ_DEVICE_GET_PRIVATE (self);
-	NMSettingsConnection *to_delete = NULL;
+	NMConnection *to_delete = NULL;
 
 	nm_clear_g_source (&priv->check_emit_usable_id);
 
 	if (priv->pan_connection) {
 		/* Check whether we want to remove the created connection. If so, we take a reference
 		 * and delete it at the end of dispose(). */
-		if (NM_FLAGS_HAS (nm_settings_connection_get_flags (priv->pan_connection),
+		if (NM_FLAGS_HAS (nm_settings_connection_get_flags (NM_SETTINGS_CONNECTION (priv->pan_connection)),
 		                  NM_SETTINGS_CONNECTION_INT_FLAGS_NM_GENERATED))
 			to_delete = g_object_ref (priv->pan_connection);
 
@@ -1216,8 +1219,8 @@ dispose (GObject *object)
 
 	if (to_delete) {
 		nm_log_dbg (LOGD_BT, "bluez[%s] removing Bluetooth connection for NAP device: '%s' (%s)", priv->path,
-		            nm_settings_connection_get_id (to_delete), nm_settings_connection_get_uuid (to_delete));
-		nm_settings_connection_delete (to_delete, NULL);
+		            nm_connection_get_id (to_delete), nm_connection_get_uuid (to_delete));
+		nm_settings_connection_delete (NM_SETTINGS_CONNECTION (to_delete), NULL);
 		g_object_unref (to_delete);
 	}