Blame SOURCES/rh1054212-bluetooth.patch

49336e
From 958a2612a550c8433537a73c253c9951f7015049 Mon Sep 17 00:00:00 2001
49336e
From: Dan Winship <danw@gnome.org>
49336e
Date: Wed, 26 Mar 2014 12:08:34 -0400
49336e
Subject: [PATCH] bluetooth: fix ModemManager1 code
49336e
49336e
The ModemManager1 code was assuming that the modem object would not be
49336e
created until after the Bluez Connect call returned, but that's only
49336e
true if this is the first time you tried to use it in the session. Fix
49336e
it.
49336e
49336e
NOTE: The MM 0.7 code is presumably also broken in the same way, but
49336e
is not fixed by the patch.
49336e
---
49336e
 src/gnome-bluetooth/nma-bt-device.c | 94 ++++++++++++++++++++-----------------
49336e
 1 file changed, 52 insertions(+), 42 deletions(-)
49336e
49336e
diff --git a/src/gnome-bluetooth/nma-bt-device.c b/src/gnome-bluetooth/nma-bt-device.c
49336e
index 8426242..3a33dce 100644
49336e
--- a/src/gnome-bluetooth/nma-bt-device.c
49336e
+++ b/src/gnome-bluetooth/nma-bt-device.c
49336e
@@ -641,10 +641,9 @@ modem_removed (DBusGProxy *proxy, const char *path, gpointer user_data)
49336e
 
49336e
 #if WITH_MODEM_MANAGER_1
49336e
 
49336e
-static void
49336e
-modem_object_added (MMManager *modem_manager,
49336e
-                    MMObject  *modem_object,
49336e
-                    NmaBtDevice *self)
49336e
+static gboolean
49336e
+check_modem (NmaBtDevice *self,
49336e
+             MMObject *modem_object)
49336e
 {
49336e
 	NmaBtDevicePrivate *priv = NMA_BT_DEVICE_GET_PRIVATE (self);
49336e
 	NMDeviceType devtype = NM_DEVICE_TYPE_UNKNOWN;
49336e
@@ -659,11 +658,11 @@ modem_object_added (MMManager *modem_manager,
49336e
 
49336e
 	/* Ensure we have the 'Modem' interface at least */
49336e
 	modem_iface = mm_object_peek_modem (modem_object);
49336e
-	g_return_if_fail (modem_iface != NULL);
49336e
+	g_return_val_if_fail (modem_iface != NULL, FALSE);
49336e
 
49336e
 	/* Get modem's primary port */
49336e
 	primary_port = mm_modem_get_primary_port (modem_iface);
49336e
-	g_return_if_fail (primary_port != NULL);
49336e
+	g_return_val_if_fail (primary_port != NULL, FALSE);
49336e
 
49336e
 	/* Get rfcomm iface name */
49336e
 	iface_basename = g_path_get_basename (priv->rfcomm_iface);
49336e
@@ -672,7 +671,7 @@ modem_object_added (MMManager *modem_manager,
49336e
 	if (!g_str_equal (primary_port, iface_basename)) {
49336e
 		g_message ("%s: (%s) (%s) not the modem we're looking for (%s)",
49336e
 		           __func__, path, primary_port, iface_basename);
49336e
-		return;
49336e
+		return FALSE;
49336e
 	}
49336e
 
49336e
 	/* This is the modem we were waiting for, so keep on */
49336e
@@ -691,14 +690,16 @@ modem_object_added (MMManager *modem_manager,
49336e
 
49336e
 	/* Launch wizard! */
49336e
 	start_wizard (self, path, devtype);
49336e
+
49336e
+	return TRUE;
49336e
 }
49336e
 
49336e
 static void
49336e
-modem_object_removed (MMManager *manager,
49336e
-                      MMObject  *modem_object,
49336e
-                      NmaBtDevice *self)
49336e
+modem_object_added (MMManager *modem_manager,
49336e
+                    MMObject  *modem_object,
49336e
+                    NmaBtDevice *self)
49336e
 {
49336e
-	g_message ("%s: (%s) modem removed", __func__, mm_object_get_path (modem_object));
49336e
+	check_modem (self, modem_object);
49336e
 }
49336e
 
49336e
 #endif /* WITH_MODEM_MANAGER_1 */
49336e
@@ -712,6 +713,10 @@ dun_connect_cb (DBusGProxy *proxy,
49336e
 	NmaBtDevicePrivate *priv = NMA_BT_DEVICE_GET_PRIVATE (self);
49336e
 	GError *error = NULL;
49336e
 	char *device;
49336e
+#if WITH_MODEM_MANAGER_1
49336e
+	GList *modems, *iter;
49336e
+	gboolean matched = FALSE;
49336e
+#endif
49336e
 
49336e
 	g_message ("%s: processing Connect reply", __func__);
49336e
 
49336e
@@ -733,6 +738,42 @@ dun_connect_cb (DBusGProxy *proxy,
49336e
 	priv->rfcomm_iface = device;
49336e
 	g_message ("%s: new rfcomm interface '%s'", __func__, device);
49336e
 
49336e
+#if WITH_MODEM_MANAGER_1
49336e
+	/* ModemManager1 stuff */
49336e
+	priv->dbus_connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error);
49336e
+	if (!priv->dbus_connection) {
49336e
+		dun_error (self, __func__, error, _("error getting bus connection"));
49336e
+		g_error_free (error);
49336e
+		goto out;
49336e
+	}
49336e
+
49336e
+	priv->modem_manager_1 = mm_manager_new_sync (priv->dbus_connection,
49336e
+	                                             G_DBUS_OBJECT_MANAGER_CLIENT_FLAGS_NONE,
49336e
+	                                             NULL,
49336e
+	                                             &error);
49336e
+	if (!priv->modem_manager_1) {
49336e
+		dun_error (self, __func__, error, "error creating modem manager");
49336e
+		g_error_free (error);
49336e
+		goto out;
49336e
+	}
49336e
+
49336e
+	modems = g_dbus_object_manager_get_objects (G_DBUS_OBJECT_MANAGER (priv->modem_manager_1));
49336e
+	for (iter = modems; iter; iter = iter->next) {
49336e
+		if (check_modem (self, iter->data)) {
49336e
+			matched = TRUE;
49336e
+			break;
49336e
+		}
49336e
+	}
49336e
+	g_list_free_full (modems, g_object_unref);
49336e
+
49336e
+	if (!matched) {
49336e
+		g_signal_connect (priv->modem_manager_1,
49336e
+		                  "object-added",
49336e
+		                  G_CALLBACK (modem_object_added),
49336e
+		                  self);
49336e
+	}
49336e
+#endif
49336e
+
49336e
 out:
49336e
 	g_message ("%s: finished", __func__);
49336e
 }
49336e
@@ -801,37 +842,6 @@ dun_start (NmaBtDevice *self)
49336e
 								 G_CALLBACK (modem_removed), self,
49336e
 								 NULL);
49336e
 
49336e
-#if WITH_MODEM_MANAGER_1
49336e
-	/* ModemManager1 stuff */
49336e
-	{
49336e
-		GError *error = NULL;
49336e
-
49336e
-		priv->dbus_connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error);
49336e
-		if (!priv->dbus_connection) {
49336e
-			dun_error (self, __func__, error, _("error getting bus connection"));
49336e
-			g_error_free (error);
49336e
-		} else {
49336e
-			priv->modem_manager_1 = mm_manager_new_sync (priv->dbus_connection,
49336e
-			                                             G_DBUS_OBJECT_MANAGER_CLIENT_FLAGS_NONE,
49336e
-			                                             NULL,
49336e
-			                                             &error);
49336e
-			if (!priv->modem_manager_1) {
49336e
-				dun_error (self, __func__, error, "error creating modem manager");
49336e
-				g_error_free (error);
49336e
-			} else {
49336e
-				g_signal_connect (priv->modem_manager_1,
49336e
-				                  "object-added",
49336e
-				                  G_CALLBACK (modem_object_added),
49336e
-				                  self);
49336e
-				g_signal_connect (priv->modem_manager_1,
49336e
-				                  "object-removed",
49336e
-				                  G_CALLBACK (modem_object_removed),
49336e
-				                  self);
49336e
-			}
49336e
-		}
49336e
-	}
49336e
-#endif
49336e
-
49336e
 	/* Bluez */
49336e
 	priv->dun_proxy = dbus_g_proxy_new_for_name (priv->bus,
49336e
 	                                             BLUEZ_SERVICE,
49336e
-- 
49336e
1.8.5.3
49336e