|
|
dc8eb2 |
From 84ec5f5a11908e636ff3b992aecfc5c8f8faddb5 Mon Sep 17 00:00:00 2001
|
|
|
dc8eb2 |
From: Bastien Nocera <hadess@hadess.net>
|
|
|
dc8eb2 |
Date: Wed, 20 Nov 2013 17:10:46 +0100
|
|
|
dc8eb2 |
Subject: [PATCH 2/3] lib: Fix cancellation handling
|
|
|
dc8eb2 |
|
|
|
dc8eb2 |
We weren't checking for cancellation properly, not passing
|
|
|
dc8eb2 |
cancellables to sub-routines, and not reporting cancelled calls
|
|
|
dc8eb2 |
correctly.
|
|
|
dc8eb2 |
---
|
|
|
dc8eb2 |
lib/bluetooth-client.c | 30 ++++++++++++++++++------------
|
|
|
dc8eb2 |
1 file changed, 18 insertions(+), 12 deletions(-)
|
|
|
dc8eb2 |
|
|
|
dc8eb2 |
diff --git a/lib/bluetooth-client.c b/lib/bluetooth-client.c
|
|
|
dc8eb2 |
index 1fe7e6d..e224033 100644
|
|
|
dc8eb2 |
--- a/lib/bluetooth-client.c
|
|
|
dc8eb2 |
+++ b/lib/bluetooth-client.c
|
|
|
dc8eb2 |
@@ -1661,23 +1661,20 @@ connect_callback (GDBusProxy *proxy,
|
|
|
dc8eb2 |
ConnectData *conndata)
|
|
|
dc8eb2 |
{
|
|
|
dc8eb2 |
GVariant *variant;
|
|
|
dc8eb2 |
- gboolean retval;
|
|
|
dc8eb2 |
GError *error = NULL;
|
|
|
dc8eb2 |
|
|
|
dc8eb2 |
variant = g_dbus_proxy_call_finish (proxy, res, &error);
|
|
|
dc8eb2 |
if (variant == NULL) {
|
|
|
dc8eb2 |
- retval = FALSE;
|
|
|
dc8eb2 |
g_debug ("Connect failed for %s: %s",
|
|
|
dc8eb2 |
g_dbus_proxy_get_object_path (proxy), error->message);
|
|
|
dc8eb2 |
- g_error_free (error);
|
|
|
dc8eb2 |
+ g_simple_async_result_take_error (conndata->simple, error);
|
|
|
dc8eb2 |
} else {
|
|
|
dc8eb2 |
g_debug ("Connect succeeded for %s",
|
|
|
dc8eb2 |
g_dbus_proxy_get_object_path (proxy));
|
|
|
dc8eb2 |
g_variant_unref (variant);
|
|
|
dc8eb2 |
- retval = TRUE;
|
|
|
dc8eb2 |
+ g_simple_async_result_set_op_res_gboolean (conndata->simple, TRUE);
|
|
|
dc8eb2 |
}
|
|
|
dc8eb2 |
|
|
|
dc8eb2 |
- g_simple_async_result_set_op_res_gboolean (conndata->simple, retval);
|
|
|
dc8eb2 |
g_simple_async_result_complete_in_idle (conndata->simple);
|
|
|
dc8eb2 |
|
|
|
dc8eb2 |
g_object_unref (conndata->simple);
|
|
|
dc8eb2 |
@@ -1699,10 +1696,11 @@ disconnect_callback (GDBusProxy *proxy,
|
|
|
dc8eb2 |
g_debug ("Disconnect failed for %s: %s",
|
|
|
dc8eb2 |
g_dbus_proxy_get_object_path (G_DBUS_PROXY (conndata->device)),
|
|
|
dc8eb2 |
error->message);
|
|
|
dc8eb2 |
- g_error_free (error);
|
|
|
dc8eb2 |
+ g_simple_async_result_take_error (conndata->simple, error);
|
|
|
dc8eb2 |
} else {
|
|
|
dc8eb2 |
g_debug ("Disconnect succeeded for %s",
|
|
|
dc8eb2 |
g_dbus_proxy_get_object_path (G_DBUS_PROXY (conndata->device)));
|
|
|
dc8eb2 |
+ g_simple_async_result_set_op_res_gboolean (conndata->simple, retval);
|
|
|
dc8eb2 |
}
|
|
|
dc8eb2 |
} else {
|
|
|
dc8eb2 |
GDBusProxy *service;
|
|
|
dc8eb2 |
@@ -1716,6 +1714,10 @@ disconnect_callback (GDBusProxy *proxy,
|
|
|
dc8eb2 |
g_dbus_proxy_get_object_path (proxy),
|
|
|
dc8eb2 |
g_dbus_proxy_get_interface_name (proxy),
|
|
|
dc8eb2 |
error->message);
|
|
|
dc8eb2 |
+ if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
|
|
|
dc8eb2 |
+ g_simple_async_result_take_error (conndata->simple, error);
|
|
|
dc8eb2 |
+ goto bail;
|
|
|
dc8eb2 |
+ }
|
|
|
dc8eb2 |
g_error_free (error);
|
|
|
dc8eb2 |
} else {
|
|
|
dc8eb2 |
g_debug ("Disconnect succeeded for %s on %s",
|
|
|
dc8eb2 |
@@ -1737,14 +1739,14 @@ disconnect_callback (GDBusProxy *proxy,
|
|
|
dc8eb2 |
g_variant_new ("()"),
|
|
|
dc8eb2 |
G_DBUS_CALL_FLAGS_NONE,
|
|
|
dc8eb2 |
-1,
|
|
|
dc8eb2 |
- NULL,
|
|
|
dc8eb2 |
+ g_object_get_data (G_OBJECT (conndata->simple), "cancellable"),
|
|
|
dc8eb2 |
(GAsyncReadyCallback) disconnect_callback,
|
|
|
dc8eb2 |
conndata);
|
|
|
dc8eb2 |
|
|
|
dc8eb2 |
return;
|
|
|
dc8eb2 |
}
|
|
|
dc8eb2 |
|
|
|
dc8eb2 |
- g_simple_async_result_set_op_res_gboolean (conndata->simple, retval);
|
|
|
dc8eb2 |
+bail:
|
|
|
dc8eb2 |
g_simple_async_result_complete_in_idle (conndata->simple);
|
|
|
dc8eb2 |
|
|
|
dc8eb2 |
g_object_unref (proxy);
|
|
|
dc8eb2 |
@@ -1836,6 +1838,7 @@ bluetooth_client_connect_service (BluetoothClient *client,
|
|
|
dc8eb2 |
g_object_set_data_full (G_OBJECT (simple), "device",
|
|
|
dc8eb2 |
g_strdup (device), g_free);
|
|
|
dc8eb2 |
}
|
|
|
dc8eb2 |
+ g_simple_async_result_set_check_cancellable (simple, cancellable);
|
|
|
dc8eb2 |
|
|
|
dc8eb2 |
gtk_tree_model_get (GTK_TREE_MODEL (priv->store), &iter,
|
|
|
dc8eb2 |
BLUETOOTH_COLUMN_PROXY, &proxy,
|
|
|
dc8eb2 |
@@ -1891,7 +1894,7 @@ bluetooth_client_connect_service (BluetoothClient *client,
|
|
|
dc8eb2 |
NULL,
|
|
|
dc8eb2 |
G_DBUS_CALL_FLAGS_NONE,
|
|
|
dc8eb2 |
-1,
|
|
|
dc8eb2 |
- NULL,
|
|
|
dc8eb2 |
+ cancellable,
|
|
|
dc8eb2 |
(GAsyncReadyCallback) connect_callback,
|
|
|
dc8eb2 |
conndata);
|
|
|
dc8eb2 |
} else if (table != NULL) {
|
|
|
dc8eb2 |
@@ -1914,14 +1917,14 @@ bluetooth_client_connect_service (BluetoothClient *client,
|
|
|
dc8eb2 |
NULL,
|
|
|
dc8eb2 |
G_DBUS_CALL_FLAGS_NONE,
|
|
|
dc8eb2 |
-1,
|
|
|
dc8eb2 |
- NULL,
|
|
|
dc8eb2 |
+ cancellable,
|
|
|
dc8eb2 |
(GAsyncReadyCallback) disconnect_callback,
|
|
|
dc8eb2 |
conndata);
|
|
|
dc8eb2 |
} else if (table == NULL) {
|
|
|
dc8eb2 |
g_debug ("Calling device_call_disconnect() for %s",
|
|
|
dc8eb2 |
g_dbus_proxy_get_object_path (proxy));
|
|
|
dc8eb2 |
device_call_disconnect (DEVICE (proxy),
|
|
|
dc8eb2 |
- NULL,
|
|
|
dc8eb2 |
+ cancellable,
|
|
|
dc8eb2 |
(GAsyncReadyCallback) disconnect_callback,
|
|
|
dc8eb2 |
conndata);
|
|
|
dc8eb2 |
g_object_unref (proxy);
|
|
|
dc8eb2 |
@@ -1956,7 +1959,10 @@ bluetooth_client_connect_service_finish (BluetoothClient *client,
|
|
|
dc8eb2 |
|
|
|
dc8eb2 |
g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == bluetooth_client_connect_service);
|
|
|
dc8eb2 |
|
|
|
dc8eb2 |
- return g_simple_async_result_get_op_res_gboolean (simple);
|
|
|
dc8eb2 |
+ if (g_simple_async_result_get_op_res_gboolean (simple))
|
|
|
dc8eb2 |
+ return TRUE;
|
|
|
dc8eb2 |
+ g_simple_async_result_propagate_error (simple, error);
|
|
|
dc8eb2 |
+ return FALSE;
|
|
|
dc8eb2 |
}
|
|
|
dc8eb2 |
|
|
|
dc8eb2 |
#define BOOL_STR(x) (x ? "True" : "False")
|
|
|
dc8eb2 |
--
|
|
|
dc8eb2 |
1.8.4.2
|
|
|
dc8eb2 |
|