bearer-qmi: common complete method for the connection attempt
Refactor the logic and setup a common complete_connect() method that helps us complete the GTask associated to the connection attempt.
This commit is contained in:
@@ -499,6 +499,21 @@ connect_finish (MMBaseBearer *self,
|
||||
return g_task_propagate_pointer (G_TASK (res), error);
|
||||
}
|
||||
|
||||
static void
|
||||
complete_connect (GTask *task,
|
||||
MMBearerConnectResult *result,
|
||||
GError *error)
|
||||
{
|
||||
g_assert (result || error);
|
||||
g_assert (!(result && error));
|
||||
|
||||
if (error)
|
||||
g_task_return_error (task, error);
|
||||
else
|
||||
g_task_return_pointer (task, result, (GDestroyNotify)mm_bearer_connect_result_unref);
|
||||
g_object_unref (task);
|
||||
}
|
||||
|
||||
static void connect_context_step (GTask *task);
|
||||
|
||||
static void
|
||||
@@ -1169,8 +1184,10 @@ qmi_port_allocate_client_ready (MMPortQmi *qmi,
|
||||
g_assert (!(ctx->running_ipv4 && ctx->running_ipv6));
|
||||
|
||||
if (!mm_port_qmi_allocate_client_finish (qmi, res, &error)) {
|
||||
g_task_return_error (task, error);
|
||||
g_object_unref (task);
|
||||
g_prefix_error (&error, "Couldn't allocate %s client in QMI port %s: ",
|
||||
ctx->running_ipv4 ? "IPv4" : "IPv6",
|
||||
mm_port_get_device (MM_PORT (qmi)));
|
||||
complete_connect (task, NULL, error);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1197,8 +1214,9 @@ qmi_port_open_ready (MMPortQmi *qmi,
|
||||
GError *error = NULL;
|
||||
|
||||
if (!mm_port_qmi_open_finish (qmi, res, &error)) {
|
||||
g_task_return_error (task, error);
|
||||
g_object_unref (task);
|
||||
g_prefix_error (&error, "Couldn't open QMI port %s: ",
|
||||
mm_port_get_device (MM_PORT (qmi)));
|
||||
complete_connect (task, NULL, error);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1216,14 +1234,18 @@ connect_context_step (GTask *task)
|
||||
ConnectContext *ctx;
|
||||
GCancellable *cancellable;
|
||||
|
||||
/* If cancelled, complete */
|
||||
if (g_task_return_error_if_cancelled (task)) {
|
||||
g_object_unref (task);
|
||||
cancellable = g_task_get_cancellable (task);
|
||||
|
||||
if (g_cancellable_is_cancelled (cancellable)) {
|
||||
complete_connect (task,
|
||||
NULL,
|
||||
g_error_new (G_IO_ERROR,
|
||||
G_IO_ERROR_CANCELLED,
|
||||
"operation cancelled"));
|
||||
return;
|
||||
}
|
||||
|
||||
ctx = g_task_get_task_data (task);
|
||||
cancellable = g_task_get_cancellable (task);
|
||||
|
||||
switch (ctx->step) {
|
||||
case CONNECT_STEP_FIRST:
|
||||
@@ -1467,7 +1489,22 @@ connect_context_step (GTask *task)
|
||||
|
||||
case CONNECT_STEP_LAST:
|
||||
/* If one of IPv4 or IPv6 succeeds, we're connected */
|
||||
if (ctx->packet_data_handle_ipv4 || ctx->packet_data_handle_ipv6) {
|
||||
if (!ctx->packet_data_handle_ipv4 && !ctx->packet_data_handle_ipv6) {
|
||||
GError *error;
|
||||
|
||||
/* No connection, set error. If both set, IPv4 error preferred */
|
||||
if (ctx->error_ipv4) {
|
||||
error = ctx->error_ipv4;
|
||||
ctx->error_ipv4 = NULL;
|
||||
} else {
|
||||
error = ctx->error_ipv6;
|
||||
ctx->error_ipv6 = NULL;
|
||||
}
|
||||
|
||||
complete_connect (task, NULL, error);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Port is connected; update the state */
|
||||
mm_port_set_connected (MM_PORT (ctx->data), TRUE);
|
||||
|
||||
@@ -1505,27 +1542,11 @@ connect_context_step (GTask *task)
|
||||
ctx->self->priv->client_ipv6 = g_object_ref (ctx->client_ipv6);
|
||||
}
|
||||
|
||||
/* Set operation result */
|
||||
g_task_return_pointer (
|
||||
task,
|
||||
mm_bearer_connect_result_new (ctx->data, ctx->ipv4_config, ctx->ipv6_config),
|
||||
(GDestroyNotify)mm_bearer_connect_result_unref);
|
||||
} else {
|
||||
GError *error;
|
||||
|
||||
/* No connection, set error. If both set, IPv4 error preferred */
|
||||
if (ctx->error_ipv4) {
|
||||
error = ctx->error_ipv4;
|
||||
ctx->error_ipv4 = NULL;
|
||||
} else {
|
||||
error = ctx->error_ipv6;
|
||||
ctx->error_ipv6 = NULL;
|
||||
}
|
||||
|
||||
g_task_return_error (task, error);
|
||||
}
|
||||
|
||||
g_object_unref (task);
|
||||
complete_connect (task,
|
||||
mm_bearer_connect_result_new (ctx->data,
|
||||
ctx->ipv4_config,
|
||||
ctx->ipv6_config),
|
||||
NULL);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user