diff options
author | Aleksander Morgado <aleksander@aleksander.es> | 2020-01-22 12:24:30 +0100 |
---|---|---|
committer | Aleksander Morgado <aleksander@aleksander.es> | 2020-01-22 13:15:08 +0100 |
commit | de8b6dd01956cc7af74cbe4cbab9a903f610557c (patch) | |
tree | a74f8d2db408fc4aff7f9525973dd380287b8a68 /src/mm-port-mbim.c | |
parent | 31c94a883b4b7b2157f402a53399003c563bacfa (diff) |
port-mbim: use qmi_device_close_async()
The qmi_device_close() synchronous operation is deprecated.
Diffstat (limited to 'src/mm-port-mbim.c')
-rw-r--r-- | src/mm-port-mbim.c | 102 |
1 files changed, 77 insertions, 25 deletions
diff --git a/src/mm-port-mbim.c b/src/mm-port-mbim.c index 143f8299..1778e783 100644 --- a/src/mm-port-mbim.c +++ b/src/mm-port-mbim.c @@ -441,40 +441,91 @@ mm_port_mbim_is_open (MMPortMbim *self) /*****************************************************************************/ +typedef struct { + MbimDevice *mbim_device; +#if defined WITH_QMI && QMI_MBIM_QMUX_SUPPORTED + QmiDevice *qmi_device; +#endif +} PortMbimCloseContext; + +static void +port_mbim_close_context_free (PortMbimCloseContext *ctx) +{ + g_clear_object (&ctx->mbim_device); +#if defined WITH_QMI && QMI_MBIM_QMUX_SUPPORTED + g_clear_object (&ctx->qmi_device); +#endif + g_slice_free (PortMbimCloseContext, ctx); +} + gboolean -mm_port_mbim_close_finish (MMPortMbim *self, - GAsyncResult *res, - GError **error) +mm_port_mbim_close_finish (MMPortMbim *self, + GAsyncResult *res, + GError **error) { return g_task_propagate_boolean (G_TASK (res), error); } static void -mbim_device_close_ready (MbimDevice *device, +mbim_device_close_ready (MbimDevice *mbim_device, GAsyncResult *res, - GTask *task) + GTask *task) { - GError *error = NULL; + GError *error = NULL; MMPortMbim *self; self = g_task_get_source_object (task); + + g_assert (!self->priv->mbim_device); self->priv->in_progress = FALSE; - g_clear_object (&self->priv->mbim_device); - if (!mbim_device_close_finish (device, res, &error)) + if (!mbim_device_close_finish (mbim_device, res, &error)) g_task_return_error (task, error); else g_task_return_boolean (task, TRUE); - g_object_unref (task); } +static void +port_mbim_device_close (GTask *task) +{ + PortMbimCloseContext *ctx; + + ctx = g_task_get_task_data (task); + g_assert (ctx->mbim_device); + mbim_device_close (ctx->mbim_device, + 5, + NULL, + (GAsyncReadyCallback)mbim_device_close_ready, + task); +} + +#if defined WITH_QMI && QMI_MBIM_QMUX_SUPPORTED + +static void +qmi_device_close_ready (QmiDevice *qmi_device, + GAsyncResult *res, + GTask *task) +{ + GError *error = NULL; + + if (!qmi_device_close_finish (qmi_device, res, &error)) { + mm_warn ("Couldn't properly close QMI device: %s", error->message); + g_error_free (error); + } + + port_mbim_device_close (task); +} + +#endif + void -mm_port_mbim_close (MMPortMbim *self, - GAsyncReadyCallback callback, - gpointer user_data) +mm_port_mbim_close (MMPortMbim *self, + GAsyncReadyCallback callback, + gpointer user_data) { - GTask *task; + PortMbimCloseContext *ctx; + GTask *task; g_return_if_fail (MM_IS_PORT_MBIM (self)); @@ -497,9 +548,13 @@ mm_port_mbim_close (MMPortMbim *self, self->priv->in_progress = TRUE; + /* Store device(s) to close in the context */ + ctx = g_slice_new0 (PortMbimCloseContext); + ctx->mbim_device = g_steal_pointer (&self->priv->mbim_device); + g_task_set_task_data (task, ctx, (GDestroyNotify)port_mbim_close_context_free); + #if defined WITH_QMI && QMI_MBIM_QMUX_SUPPORTED if (self->priv->qmi_device) { - GError *error = NULL; GList *l; /* Release all allocated clients */ @@ -515,20 +570,17 @@ mm_port_mbim_close (MMPortMbim *self, g_list_free_full (self->priv->qmi_clients, g_object_unref); self->priv->qmi_clients = NULL; - if (!qmi_device_close (self->priv->qmi_device, &error)) { - mm_warn ("Couldn't properly close QMI device: %s", error->message); - g_error_free (error); - } - g_clear_object (&self->priv->qmi_device); + ctx->qmi_device = g_steal_pointer (&self->priv->qmi_device); + qmi_device_close_async (ctx->qmi_device, + 5, + NULL, + (GAsyncReadyCallback)qmi_device_close_ready, + task); + return; } #endif - mbim_device_close (self->priv->mbim_device, - 5, - NULL, - (GAsyncReadyCallback)mbim_device_close_ready, - task); - g_clear_object (&self->priv->mbim_device); + port_mbim_device_close (task); } /*****************************************************************************/ |