diff options
Diffstat (limited to 'src/mm-iface-modem-3gpp.c')
-rw-r--r-- | src/mm-iface-modem-3gpp.c | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/src/mm-iface-modem-3gpp.c b/src/mm-iface-modem-3gpp.c index 16ddce6d..222d8836 100644 --- a/src/mm-iface-modem-3gpp.c +++ b/src/mm-iface-modem-3gpp.c @@ -1163,11 +1163,13 @@ struct _EnablingContext { MMIfaceModem3gpp *self; EnablingStep step; GSimpleAsyncResult *result; + GCancellable *cancellable; MmGdbusModem3gpp *skeleton; }; static EnablingContext * enabling_context_new (MMIfaceModem3gpp *self, + GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) { @@ -1175,6 +1177,7 @@ enabling_context_new (MMIfaceModem3gpp *self, ctx = g_new0 (EnablingContext, 1); ctx->self = g_object_ref (self); + ctx->cancellable = g_object_ref (cancellable); ctx->result = g_simple_async_result_new (G_OBJECT (self), callback, user_data, @@ -1194,10 +1197,25 @@ enabling_context_complete_and_free (EnablingContext *ctx) g_simple_async_result_complete_in_idle (ctx->result); g_object_unref (ctx->self); g_object_unref (ctx->result); + g_object_unref (ctx->cancellable); g_object_unref (ctx->skeleton); g_free (ctx); } +static gboolean +enabling_context_complete_and_free_if_cancelled (EnablingContext *ctx) +{ + if (!g_cancellable_is_cancelled (ctx->cancellable)) + return FALSE; + + g_simple_async_result_set_error (ctx->result, + MM_CORE_ERROR, + MM_CORE_ERROR_CANCELLED, + "Interface enabling cancelled"); + enabling_context_complete_and_free (ctx); + return TRUE; +} + gboolean mm_iface_modem_3gpp_enable_finish (MMIfaceModem3gpp *self, GAsyncResult *res, @@ -1394,6 +1412,10 @@ setup_unsolicited_registration_ready (MMIfaceModem3gpp *self, static void interface_enabling_step (EnablingContext *ctx) { + /* Don't run new steps if we're cancelled */ + if (enabling_context_complete_and_free_if_cancelled (ctx)) + return; + switch (ctx->step) { case ENABLING_STEP_FIRST: /* Setup quarks if we didn't do it before */ @@ -1531,10 +1553,12 @@ interface_enabling_step (EnablingContext *ctx) void mm_iface_modem_3gpp_enable (MMIfaceModem3gpp *self, + GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) { interface_enabling_step (enabling_context_new (self, + cancellable, callback, user_data)); } @@ -1555,11 +1579,13 @@ struct _InitializationContext { MMIfaceModem3gpp *self; MmGdbusModem3gpp *skeleton; GSimpleAsyncResult *result; + GCancellable *cancellable; InitializationStep step; }; static InitializationContext * initialization_context_new (MMIfaceModem3gpp *self, + GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) { @@ -1567,6 +1593,7 @@ initialization_context_new (MMIfaceModem3gpp *self, ctx = g_new0 (InitializationContext, 1); ctx->self = g_object_ref (self); + ctx->cancellable = g_object_ref (cancellable); ctx->result = g_simple_async_result_new (G_OBJECT (self), callback, user_data, @@ -1585,10 +1612,25 @@ initialization_context_complete_and_free (InitializationContext *ctx) g_simple_async_result_complete_in_idle (ctx->result); g_object_unref (ctx->self); g_object_unref (ctx->result); + g_object_unref (ctx->cancellable); g_object_unref (ctx->skeleton); g_free (ctx); } +static gboolean +initialization_context_complete_and_free_if_cancelled (InitializationContext *ctx) +{ + if (!g_cancellable_is_cancelled (ctx->cancellable)) + return FALSE; + + g_simple_async_result_set_error (ctx->result, + MM_CORE_ERROR, + MM_CORE_ERROR_CANCELLED, + "Interface initialization cancelled"); + initialization_context_complete_and_free (ctx); + return TRUE; +} + static void sim_pin_lock_enabled_cb (MMSim *self, gboolean enabled, @@ -1666,6 +1708,10 @@ load_imei_ready (MMIfaceModem3gpp *self, static void interface_initialization_step (InitializationContext *ctx) { + /* Don't run new steps if we're cancelled */ + if (initialization_context_complete_and_free_if_cancelled (ctx)) + return; + switch (ctx->step) { case INITIALIZATION_STEP_FIRST: /* Fall down to next step */ @@ -1738,6 +1784,7 @@ mm_iface_modem_3gpp_initialize_finish (MMIfaceModem3gpp *self, void mm_iface_modem_3gpp_initialize (MMIfaceModem3gpp *self, + GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) { @@ -1779,6 +1826,7 @@ mm_iface_modem_3gpp_initialize (MMIfaceModem3gpp *self, /* Perform async initialization here */ interface_initialization_step (initialization_context_new (self, + cancellable, callback, user_data)); g_object_unref (skeleton); |