core: prefer g_task_return_error_if_cancelled() than custom errors
When the GCancellable is added to the GTask, we can use a single method call to check for the task being cancelled, and complete it right away if so. This patch also clears up the logic in the Novatel plugin, where the code was trying to return "TRUE" when the task was cancelled, but wouldn't work as the check-cancellable flag in the GTask is TRUE by default (i.e. when completing the GTask, if it was cancelled, a G_IO_ERROR_CANCELLED would be returned by default, regardless of any other return value set). This patch also introduces a small variation of the logic in the Cinterion plugin: instead of running SWWAN=0 before completing the async action, the command is now sent just after completion of the async action. This shouldn't be an issue, as the SWWAN result itself is ignored.
This commit is contained in:
@@ -343,10 +343,6 @@ handle_cancel_dial (GTask *task)
|
||||
NULL,
|
||||
NULL);
|
||||
g_free (command);
|
||||
|
||||
g_task_return_new_error (task, MM_CORE_ERROR, MM_CORE_ERROR_CANCELLED,
|
||||
"Connection operation has been cancelled");
|
||||
g_object_unref (task);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -357,8 +353,9 @@ dial_3gpp_context_step (GTask *task)
|
||||
ctx = (Dial3gppContext *) g_task_get_task_data (task);
|
||||
|
||||
/* Check for cancellation */
|
||||
if (g_cancellable_is_cancelled (g_task_get_cancellable (task))) {
|
||||
if (g_task_return_error_if_cancelled (task)) {
|
||||
handle_cancel_dial (task);
|
||||
g_object_unref (task);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@@ -87,10 +87,9 @@ custom_init_step (GTask *task)
|
||||
ctx = g_task_get_task_data (task);
|
||||
|
||||
/* If cancelled, end */
|
||||
if (g_cancellable_is_cancelled (g_task_get_cancellable (task))) {
|
||||
if (g_task_return_error_if_cancelled (task)) {
|
||||
mm_dbg ("(Novatel) no need to keep on running custom init in (%s)",
|
||||
mm_port_get_device (MM_PORT (ctx->port)));
|
||||
g_task_return_boolean (task, TRUE);
|
||||
g_object_unref (task);
|
||||
return;
|
||||
}
|
||||
|
@@ -72,11 +72,7 @@ check_authorization_ready (PolkitAuthority *authority,
|
||||
GError *error = NULL;
|
||||
AuthorizeContext *ctx;
|
||||
|
||||
if (g_cancellable_is_cancelled (g_task_get_cancellable (task))) {
|
||||
g_task_return_new_error (task,
|
||||
MM_CORE_ERROR,
|
||||
MM_CORE_ERROR_CANCELLED,
|
||||
"PolicyKit authorization attempt cancelled");
|
||||
if (g_task_return_error_if_cancelled (task)) {
|
||||
g_object_unref (task);
|
||||
return;
|
||||
}
|
||||
|
@@ -418,11 +418,7 @@ interface_initialization_step (GTask *task)
|
||||
InitializationContext *ctx;
|
||||
|
||||
/* Don't run new steps if we're cancelled */
|
||||
if (g_cancellable_is_cancelled (g_task_get_cancellable (task))) {
|
||||
g_task_return_new_error (task,
|
||||
MM_CORE_ERROR,
|
||||
MM_CORE_ERROR_CANCELLED,
|
||||
"Interface initialization cancelled");
|
||||
if (g_task_return_error_if_cancelled (task)) {
|
||||
g_object_unref (task);
|
||||
return;
|
||||
}
|
||||
|
Reference in New Issue
Block a user