diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/mm-broadband-modem.c | 125 | ||||
-rw-r--r-- | src/mm-iface-modem.c | 17 |
2 files changed, 72 insertions, 70 deletions
diff --git a/src/mm-broadband-modem.c b/src/mm-broadband-modem.c index a78278ea..3fe8d8b9 100644 --- a/src/mm-broadband-modem.c +++ b/src/mm-broadband-modem.c @@ -6824,6 +6824,7 @@ enabling_started (MMBroadbandModem *self, typedef enum { DISABLING_STEP_FIRST, + DISABLING_STEP_WAIT_FOR_FINAL_STATE, DISABLING_STEP_DISCONNECT_BEARERS, DISABLING_STEP_IFACE_SIMPLE, DISABLING_STEP_IFACE_FIRMWARE, @@ -6843,6 +6844,8 @@ typedef struct { GCancellable *cancellable; GSimpleAsyncResult *result; DisablingStep step; + MMModemState previous_state; + gboolean disabled; } DisablingContext; static void disabling_step (DisablingContext *ctx); @@ -6860,6 +6863,19 @@ disabling_context_complete_and_free (DisablingContext *ctx) g_error_free (error); } + if (ctx->disabled) + mm_iface_modem_update_state (MM_IFACE_MODEM (ctx->self), + MM_MODEM_STATE_DISABLED, + MM_MODEM_STATE_CHANGE_REASON_USER_REQUESTED); + else if (ctx->previous_state != MM_MODEM_STATE_DISABLED) { + /* Fallback to previous state */ + mm_info ("Falling back to previous state '%s'", + mm_modem_state_get_string (ctx->previous_state)); + mm_iface_modem_update_state (MM_IFACE_MODEM (ctx->self), + ctx->previous_state, + MM_MODEM_STATE_CHANGE_REASON_UNKNOWN); + } + g_object_unref (ctx->result); if (ctx->cancellable) g_object_unref (ctx->cancellable); @@ -6945,6 +6961,47 @@ bearer_list_disconnect_all_bearers_ready (MMBearerList *list, } static void +disabling_wait_for_final_state_ready (MMIfaceModem *self, + GAsyncResult *res, + DisablingContext *ctx) +{ + GError *error = NULL; + + ctx->previous_state = mm_iface_modem_wait_for_final_state_finish (self, res, &error); + if (error) { + g_simple_async_result_take_error (G_SIMPLE_ASYNC_RESULT (ctx->result), error); + disabling_context_complete_and_free (ctx); + return; + } + + switch (ctx->previous_state) { + case MM_MODEM_STATE_UNKNOWN: + case MM_MODEM_STATE_FAILED: + case MM_MODEM_STATE_LOCKED: + case MM_MODEM_STATE_DISABLED: + /* Just return success, don't relaunch disabling. + * Note that we do consider here UNKNOWN and FAILED status on purpose, + * as the MMManager will try to disable every modem before removing + * it. */ + mm_info ("Modem is already fully disabled..."); + g_simple_async_result_set_op_res_gboolean (ctx->result, TRUE); + disabling_context_complete_and_free (ctx); + return; + default: + break; + } + + /* We're in a final state now, go on */ + + mm_iface_modem_update_state (MM_IFACE_MODEM (ctx->self), + MM_MODEM_STATE_DISABLING, + MM_MODEM_STATE_CHANGE_REASON_USER_REQUESTED); + + ctx->step++; + disabling_step (ctx); +} + +static void disabling_step (DisablingContext *ctx) { /* Don't run new steps if we're cancelled */ @@ -6957,6 +7014,13 @@ disabling_step (DisablingContext *ctx) /* Fall down to next step */ ctx->step++; + case DISABLING_STEP_WAIT_FOR_FINAL_STATE: + mm_iface_modem_wait_for_final_state (MM_IFACE_MODEM (ctx->self), + MM_MODEM_STATE_UNKNOWN, /* just any */ + (GAsyncReadyCallback)disabling_wait_for_final_state_ready, + ctx); + return; + case DISABLING_STEP_DISCONNECT_BEARERS: if (ctx->self->priv->modem_bearer_list) { mm_bearer_list_disconnect_all_bearers ( @@ -7067,6 +7131,7 @@ disabling_step (DisablingContext *ctx) case DISABLING_STEP_LAST: mm_info ("Modem fully disabled..."); + ctx->disabled = TRUE; /* All disabled without errors! */ g_simple_async_result_set_op_res_gboolean (G_SIMPLE_ASYNC_RESULT (ctx->result), TRUE); disabling_context_complete_and_free (ctx); @@ -7082,61 +7147,15 @@ disable (MMBaseModem *self, GAsyncReadyCallback callback, gpointer user_data) { - GSimpleAsyncResult *result; + DisablingContext *ctx; - result = g_simple_async_result_new (G_OBJECT (self), callback, user_data, disable); - - /* Check state before launching modem disabling */ - switch (MM_BROADBAND_MODEM (self)->priv->modem_state) { - case MM_MODEM_STATE_UNKNOWN: - case MM_MODEM_STATE_FAILED: - case MM_MODEM_STATE_INITIALIZING: - case MM_MODEM_STATE_LOCKED: - case MM_MODEM_STATE_DISABLED: - /* Just return success, don't relaunch disabling. - * Note that we do consider here UNKNOWN and FAILED status on purpose, - * as the MMManager will try to disable every modem before removing - * it. */ - g_simple_async_result_set_op_res_gboolean (result, TRUE); - break; - - case MM_MODEM_STATE_DISABLING: - g_simple_async_result_set_error (result, - MM_CORE_ERROR, - MM_CORE_ERROR_WRONG_STATE, - "Cannot disable modem: " - "already being disabled"); - break; - - case MM_MODEM_STATE_ENABLING: - g_simple_async_result_set_error (result, - MM_CORE_ERROR, - MM_CORE_ERROR_WRONG_STATE, - "Cannot disable modem: " - "currently being enabled"); - break; - - case MM_MODEM_STATE_ENABLED: - case MM_MODEM_STATE_SEARCHING: - case MM_MODEM_STATE_REGISTERED: - case MM_MODEM_STATE_DISCONNECTING: - case MM_MODEM_STATE_CONNECTING: - case MM_MODEM_STATE_CONNECTED: { - DisablingContext *ctx; - - ctx = g_new0 (DisablingContext, 1); - ctx->self = g_object_ref (self); - ctx->result = result; - ctx->cancellable = (cancellable ? g_object_ref (cancellable) : NULL); - ctx->step = DISABLING_STEP_FIRST; - - disabling_step (ctx); - return; - } - } + ctx = g_new0 (DisablingContext, 1); + ctx->self = g_object_ref (self); + ctx->result = g_simple_async_result_new (G_OBJECT (self), callback, user_data, disable); + ctx->cancellable = (cancellable ? g_object_ref (cancellable) : NULL); + ctx->step = DISABLING_STEP_FIRST; - g_simple_async_result_complete_in_idle (result); - g_object_unref (result); + disabling_step (ctx); } /*****************************************************************************/ diff --git a/src/mm-iface-modem.c b/src/mm-iface-modem.c index caf8bfe7..55bad312 100644 --- a/src/mm-iface-modem.c +++ b/src/mm-iface-modem.c @@ -2594,7 +2594,6 @@ struct _DisablingContext { MMIfaceModem *self; DisablingStep step; MMModemState previous_state; - gboolean disabled; GSimpleAsyncResult *result; MmGdbusModem *skeleton; }; @@ -2603,17 +2602,6 @@ static void disabling_context_complete_and_free (DisablingContext *ctx) { g_simple_async_result_complete_in_idle (ctx->result); - - if (ctx->disabled) - mm_iface_modem_update_state (ctx->self, - MM_MODEM_STATE_DISABLED, - MM_MODEM_STATE_CHANGE_REASON_USER_REQUESTED); - else - /* Fallback to previous state */ - mm_iface_modem_update_state (ctx->self, - ctx->previous_state, - MM_MODEM_STATE_CHANGE_REASON_UNKNOWN); - g_object_unref (ctx->self); g_object_unref (ctx->result); if (ctx->skeleton) @@ -2693,7 +2681,6 @@ interface_disabling_step (DisablingContext *ctx) case DISABLING_STEP_LAST: /* We are done without errors! */ g_simple_async_result_set_op_res_gboolean (ctx->result, TRUE); - ctx->disabled = TRUE; disabling_context_complete_and_free (ctx); return; } @@ -2728,10 +2715,6 @@ mm_iface_modem_disable (MMIfaceModem *self, return; } - mm_iface_modem_update_state (ctx->self, - MM_MODEM_STATE_DISABLING, - MM_MODEM_STATE_CHANGE_REASON_USER_REQUESTED); - interface_disabling_step (ctx); } |