diff options
author | Ben Chan <benchan@chromium.org> | 2017-07-10 17:07:32 -0700 |
---|---|---|
committer | Ben Chan <benchan@chromium.org> | 2017-07-11 10:30:39 -0700 |
commit | 20b3675adf373c6f2463c4ecf25400fddd560452 (patch) | |
tree | d1bb49164488dd865c08254ad6cc0257557a2d57 /src | |
parent | e8ffefaf6ff483fb3724faaaa1cae99f87ca64c8 (diff) |
broadband-modem-mbim: port initialization_started to use GTask
Diffstat (limited to 'src')
-rw-r--r-- | src/mm-broadband-modem-mbim.c | 63 |
1 files changed, 30 insertions, 33 deletions
diff --git a/src/mm-broadband-modem-mbim.c b/src/mm-broadband-modem-mbim.c index f89a122f..613e2425 100644 --- a/src/mm-broadband-modem-mbim.c +++ b/src/mm-broadband-modem-mbim.c @@ -1524,19 +1524,14 @@ enabling_started (MMBroadbandModem *self, /* First initialization step */ typedef struct { - MMBroadbandModem *self; - GSimpleAsyncResult *result; MMPortMbim *mbim; } InitializationStartedContext; static void -initialization_started_context_complete_and_free (InitializationStartedContext *ctx) +initialization_started_context_free (InitializationStartedContext *ctx) { - g_simple_async_result_complete_in_idle (ctx->result); if (ctx->mbim) g_object_unref (ctx->mbim); - g_object_unref (ctx->result); - g_object_unref (ctx->self); g_slice_free (InitializationStartedContext, ctx); } @@ -1545,21 +1540,19 @@ initialization_started_finish (MMBroadbandModem *self, GAsyncResult *res, GError **error) { - if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error)) - return NULL; - - /* Just parent's pointer passed here */ - return g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (res)); + return g_task_propagate_pointer (G_TASK (res), error); } static void parent_initialization_started_ready (MMBroadbandModem *self, GAsyncResult *res, - InitializationStartedContext *ctx) + GTask *task) { + InitializationStartedContext *ctx; gpointer parent_ctx; GError *error = NULL; + ctx = g_task_get_task_data (task); parent_ctx = MM_BROADBAND_MODEM_CLASS (mm_broadband_modem_mbim_parent_class)->initialization_started_finish ( self, res, @@ -1571,34 +1564,39 @@ parent_initialization_started_ready (MMBroadbandModem *self, g_error_free (error); } - g_simple_async_result_set_op_res_gpointer (ctx->result, parent_ctx, NULL); - initialization_started_context_complete_and_free (ctx); + /* Just parent's pointer passed here */ + g_task_return_pointer (task, parent_ctx, NULL); + g_object_unref (task); } static void -parent_initialization_started (InitializationStartedContext *ctx) +parent_initialization_started (GTask *task) { + MMBroadbandModem *self; + + self = g_task_get_source_object (task); MM_BROADBAND_MODEM_CLASS (mm_broadband_modem_mbim_parent_class)->initialization_started ( - ctx->self, + self, (GAsyncReadyCallback)parent_initialization_started_ready, - ctx); + task); } static void mbim_port_open_ready (MMPortMbim *mbim, GAsyncResult *res, - InitializationStartedContext *ctx) + GTask *task) { + InitializationStartedContext *ctx; GError *error = NULL; if (!mm_port_mbim_open_finish (mbim, res, &error)) { - g_simple_async_result_take_error (ctx->result, error); - initialization_started_context_complete_and_free (ctx); + g_task_return_error (task, error); + g_object_unref (task); return; } /* Done we are, launch parent's callback */ - parent_initialization_started (ctx); + parent_initialization_started (task); } static void @@ -1607,28 +1605,27 @@ initialization_started (MMBroadbandModem *self, gpointer user_data) { InitializationStartedContext *ctx; + GTask *task; ctx = g_slice_new0 (InitializationStartedContext); - ctx->self = g_object_ref (self); - ctx->result = g_simple_async_result_new (G_OBJECT (self), - callback, - user_data, - initialization_started); ctx->mbim = mm_base_modem_get_port_mbim (MM_BASE_MODEM (self)); + task = g_task_new (self, NULL, callback, user_data); + g_task_set_task_data (task, ctx, (GDestroyNotify)initialization_started_context_free); + /* This may happen if we unplug the modem unexpectedly */ if (!ctx->mbim) { - g_simple_async_result_set_error (ctx->result, - MM_CORE_ERROR, - MM_CORE_ERROR_FAILED, - "Cannot initialize: MBIM port went missing"); - initialization_started_context_complete_and_free (ctx); + g_task_return_new_error (task, + MM_CORE_ERROR, + MM_CORE_ERROR_FAILED, + "Cannot initialize: MBIM port went missing"); + g_object_unref (task); return; } if (mm_port_mbim_is_open (ctx->mbim)) { /* Nothing to be done, just launch parent's callback */ - parent_initialization_started (ctx); + parent_initialization_started (task); return; } @@ -1636,7 +1633,7 @@ initialization_started (MMBroadbandModem *self, mm_port_mbim_open (ctx->mbim, NULL, (GAsyncReadyCallback)mbim_port_open_ready, - ctx); + task); } /*****************************************************************************/ |