diff options
author | Aleksander Morgado <aleksander@lanedo.com> | 2012-03-13 11:52:20 +0100 |
---|---|---|
committer | Aleksander Morgado <aleksander@lanedo.com> | 2012-03-16 14:53:24 +0100 |
commit | e140ff3c5f1dda2e1310b79b81e73fada5b6d312 (patch) | |
tree | 7bb6f1959001cc1a13b26bf0eeee63b903b99909 /src | |
parent | d27e40ae9aea1166831920a92d4eba4f3f51605d (diff) | |
download | ModemManager-e140ff3c5f1dda2e1310b79b81e73fada5b6d312.tar.gz |
iface-modem: let initialization and enabling sequences get cancelled
Diffstat (limited to 'src')
-rw-r--r-- | src/mm-broadband-modem.c | 2 | ||||
-rw-r--r-- | src/mm-iface-modem.c | 48 | ||||
-rw-r--r-- | src/mm-iface-modem.h | 2 |
3 files changed, 52 insertions, 0 deletions
diff --git a/src/mm-broadband-modem.c b/src/mm-broadband-modem.c index 7473d231b..68c712f40 100644 --- a/src/mm-broadband-modem.c +++ b/src/mm-broadband-modem.c @@ -6225,6 +6225,7 @@ enabling_step (EnablingContext *ctx) g_assert (ctx->self->priv->modem_dbus_skeleton != NULL); /* Enabling the Modem interface */ mm_iface_modem_enable (MM_IFACE_MODEM (ctx->self), + ctx->cancellable, (GAsyncReadyCallback)iface_modem_enable_ready, ctx); return; @@ -6582,6 +6583,7 @@ initialize_step (InitializeContext *ctx) case INITIALIZE_STEP_IFACE_MODEM: /* Initialize the Modem interface */ mm_iface_modem_initialize (MM_IFACE_MODEM (ctx->self), + ctx->cancellable, (GAsyncReadyCallback)iface_modem_initialize_ready, ctx); return; diff --git a/src/mm-iface-modem.c b/src/mm-iface-modem.c index 506184966..f031a1ecf 100644 --- a/src/mm-iface-modem.c +++ b/src/mm-iface-modem.c @@ -2492,11 +2492,13 @@ struct _EnablingContext { const MMModemCharset *current_charset; gboolean enabled; GSimpleAsyncResult *result; + GCancellable *cancellable; MmGdbusModem *skeleton; }; static EnablingContext * enabling_context_new (MMIfaceModem *self, + GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) { @@ -2507,6 +2509,7 @@ enabling_context_new (MMIfaceModem *self, ctx->primary = mm_base_modem_get_port_primary (MM_BASE_MODEM (self)); ctx->secondary = mm_base_modem_get_port_secondary (MM_BASE_MODEM (self)); ctx->qcdm = mm_base_modem_get_port_qcdm (MM_BASE_MODEM (self)); + ctx->cancellable = g_object_ref (cancellable); ctx->result = g_simple_async_result_new (G_OBJECT (self), callback, user_data, @@ -2558,10 +2561,25 @@ enabling_context_complete_and_free (EnablingContext *ctx) if (ctx->qcdm) g_object_unref (ctx->qcdm); 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_enable_finish (MMIfaceModem *self, GAsyncResult *res, @@ -2726,6 +2744,10 @@ static const MMModemCharset best_charsets[] = { 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: /* Fall down to next step */ @@ -2929,10 +2951,12 @@ interface_enabling_step (EnablingContext *ctx) void mm_iface_modem_enable (MMIfaceModem *self, + GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) { interface_enabling_step (enabling_context_new (self, + cancellable, callback, user_data)); } @@ -2966,11 +2990,13 @@ struct _InitializationContext { MMIfaceModem *self; InitializationStep step; GSimpleAsyncResult *result; + GCancellable *cancellable; MmGdbusModem *skeleton; }; static InitializationContext * initialization_context_new (MMIfaceModem *self, + GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) { @@ -2978,6 +3004,7 @@ initialization_context_new (MMIfaceModem *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, @@ -2994,12 +3021,27 @@ static void initialization_context_complete_and_free (InitializationContext *ctx) { g_simple_async_result_complete_in_idle (ctx->result); + g_object_unref (ctx->cancellable); g_object_unref (ctx->self); g_object_unref (ctx->result); 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; +} + #undef STR_REPLY_READY_FN #define STR_REPLY_READY_FN(NAME,DISPLAY) \ static void \ @@ -3248,6 +3290,10 @@ sim_reinit_ready (MMSim *sim, 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: /* Load device if not done before */ @@ -3609,6 +3655,7 @@ mm_iface_modem_initialize_finish (MMIfaceModem *self, void mm_iface_modem_initialize (MMIfaceModem *self, + GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) { @@ -3663,6 +3710,7 @@ mm_iface_modem_initialize (MMIfaceModem *self, /* Perform async initialization here */ interface_initialization_step (initialization_context_new (self, + cancellable, callback, user_data)); g_object_unref (skeleton); diff --git a/src/mm-iface-modem.h b/src/mm-iface-modem.h index fe4eeb03d..a9e54bb21 100644 --- a/src/mm-iface-modem.h +++ b/src/mm-iface-modem.h @@ -310,6 +310,7 @@ gboolean mm_iface_modem_is_cdma_only (MMIfaceModem *self); /* Initialize Modem interface (async) */ void mm_iface_modem_initialize (MMIfaceModem *self, + GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); gboolean mm_iface_modem_initialize_finish (MMIfaceModem *self, @@ -318,6 +319,7 @@ gboolean mm_iface_modem_initialize_finish (MMIfaceModem *self, /* Enable Modem interface (async) */ void mm_iface_modem_enable (MMIfaceModem *self, + GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); gboolean mm_iface_modem_enable_finish (MMIfaceModem *self, |