iface-modem,broadband-modem: update 'enabling->enabled transition logic
It is not the Modem interface the one notifying about the 'enabling->enabled' transition, it's the BroadbandModem directly doing it, covering all the enabling sequences of all the interfaces.
This commit is contained in:
+75
-18
@@ -7162,6 +7162,7 @@ disable (MMBaseModem *self,
|
||||
|
||||
typedef enum {
|
||||
ENABLING_STEP_FIRST,
|
||||
ENABLING_STEP_WAIT_FOR_FINAL_STATE,
|
||||
ENABLING_STEP_STARTED,
|
||||
ENABLING_STEP_IFACE_MODEM,
|
||||
ENABLING_STEP_IFACE_3GPP,
|
||||
@@ -7181,6 +7182,8 @@ typedef struct {
|
||||
GCancellable *cancellable;
|
||||
GSimpleAsyncResult *result;
|
||||
EnablingStep step;
|
||||
MMModemState previous_state;
|
||||
gboolean enabled;
|
||||
} EnablingContext;
|
||||
|
||||
static void enabling_step (EnablingContext *ctx);
|
||||
@@ -7190,6 +7193,20 @@ enabling_context_complete_and_free (EnablingContext *ctx)
|
||||
{
|
||||
g_simple_async_result_complete_in_idle (ctx->result);
|
||||
g_object_unref (ctx->result);
|
||||
|
||||
if (ctx->enabled)
|
||||
mm_iface_modem_update_state (MM_IFACE_MODEM (ctx->self),
|
||||
MM_MODEM_STATE_ENABLED,
|
||||
MM_MODEM_STATE_CHANGE_REASON_USER_REQUESTED);
|
||||
else if (ctx->previous_state != MM_MODEM_STATE_ENABLED) {
|
||||
/* 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->cancellable);
|
||||
g_object_unref (ctx->self);
|
||||
g_free (ctx);
|
||||
@@ -7220,24 +7237,6 @@ enable_finish (MMBaseModem *self,
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
enabling_started_ready (MMBroadbandModem *self,
|
||||
GAsyncResult *result,
|
||||
EnablingContext *ctx)
|
||||
{
|
||||
GError *error = NULL;
|
||||
|
||||
if (!MM_BROADBAND_MODEM_GET_CLASS (self)->enabling_started_finish (self, result, &error)) {
|
||||
g_simple_async_result_take_error (G_SIMPLE_ASYNC_RESULT (ctx->result), error);
|
||||
enabling_context_complete_and_free (ctx);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Go on to next step */
|
||||
ctx->step++;
|
||||
enabling_step (ctx);
|
||||
}
|
||||
|
||||
#undef INTERFACE_ENABLE_READY_FN
|
||||
#define INTERFACE_ENABLE_READY_FN(NAME,TYPE,FATAL_ERRORS) \
|
||||
static void \
|
||||
@@ -7274,6 +7273,56 @@ INTERFACE_ENABLE_READY_FN (iface_modem_location, MM_IFACE_MODEM_LOCATION, FALS
|
||||
INTERFACE_ENABLE_READY_FN (iface_modem_messaging, MM_IFACE_MODEM_MESSAGING, FALSE)
|
||||
INTERFACE_ENABLE_READY_FN (iface_modem_time, MM_IFACE_MODEM_TIME, FALSE)
|
||||
|
||||
static void
|
||||
enabling_started_ready (MMBroadbandModem *self,
|
||||
GAsyncResult *result,
|
||||
EnablingContext *ctx)
|
||||
{
|
||||
GError *error = NULL;
|
||||
|
||||
if (!MM_BROADBAND_MODEM_GET_CLASS (self)->enabling_started_finish (self, result, &error)) {
|
||||
g_simple_async_result_take_error (G_SIMPLE_ASYNC_RESULT (ctx->result), error);
|
||||
enabling_context_complete_and_free (ctx);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Go on to next step */
|
||||
ctx->step++;
|
||||
enabling_step (ctx);
|
||||
}
|
||||
|
||||
static void
|
||||
enabling_wait_for_final_state_ready (MMIfaceModem *self,
|
||||
GAsyncResult *res,
|
||||
EnablingContext *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);
|
||||
enabling_context_complete_and_free (ctx);
|
||||
return;
|
||||
}
|
||||
|
||||
if (ctx->previous_state >= MM_MODEM_STATE_ENABLED) {
|
||||
/* Just return success, don't relaunch enabling */
|
||||
mm_info ("Modem is already fully enabled...");
|
||||
g_simple_async_result_set_op_res_gboolean (ctx->result, TRUE);
|
||||
enabling_context_complete_and_free (ctx);
|
||||
return;
|
||||
}
|
||||
|
||||
/* We're in a final state now, go on */
|
||||
|
||||
mm_iface_modem_update_state (MM_IFACE_MODEM (ctx->self),
|
||||
MM_MODEM_STATE_ENABLING,
|
||||
MM_MODEM_STATE_CHANGE_REASON_USER_REQUESTED);
|
||||
|
||||
ctx->step++;
|
||||
enabling_step (ctx);
|
||||
}
|
||||
|
||||
static void
|
||||
enabling_step (EnablingContext *ctx)
|
||||
{
|
||||
@@ -7287,6 +7336,13 @@ enabling_step (EnablingContext *ctx)
|
||||
/* Fall down to next step */
|
||||
ctx->step++;
|
||||
|
||||
case ENABLING_STEP_WAIT_FOR_FINAL_STATE:
|
||||
mm_iface_modem_wait_for_final_state (MM_IFACE_MODEM (ctx->self),
|
||||
MM_MODEM_STATE_UNKNOWN, /* just any */
|
||||
(GAsyncReadyCallback)enabling_wait_for_final_state_ready,
|
||||
ctx);
|
||||
return;
|
||||
|
||||
case ENABLING_STEP_STARTED:
|
||||
if (MM_BROADBAND_MODEM_GET_CLASS (ctx->self)->enabling_started &&
|
||||
MM_BROADBAND_MODEM_GET_CLASS (ctx->self)->enabling_started_finish) {
|
||||
@@ -7397,6 +7453,7 @@ enabling_step (EnablingContext *ctx)
|
||||
|
||||
case ENABLING_STEP_LAST:
|
||||
mm_info ("Modem fully enabled...");
|
||||
ctx->enabled = TRUE;
|
||||
/* All enabled without errors! */
|
||||
g_simple_async_result_set_op_res_gboolean (G_SIMPLE_ASYNC_RESULT (ctx->result), TRUE);
|
||||
enabling_context_complete_and_free (ctx);
|
||||
|
||||
@@ -2742,7 +2742,6 @@ struct _EnablingContext {
|
||||
EnablingStep step;
|
||||
MMModemCharset supported_charsets;
|
||||
const MMModemCharset *current_charset;
|
||||
gboolean enabled;
|
||||
GSimpleAsyncResult *result;
|
||||
GCancellable *cancellable;
|
||||
MmGdbusModem *skeleton;
|
||||
@@ -2752,26 +2751,6 @@ static void
|
||||
enabling_context_complete_and_free (EnablingContext *ctx)
|
||||
{
|
||||
g_simple_async_result_complete_in_idle (ctx->result);
|
||||
|
||||
if (ctx->enabled)
|
||||
mm_iface_modem_update_state (ctx->self,
|
||||
MM_MODEM_STATE_ENABLED,
|
||||
MM_MODEM_STATE_CHANGE_REASON_USER_REQUESTED);
|
||||
else if (ctx->skeleton) {
|
||||
MMModemLock lock;
|
||||
|
||||
/* Fallback to DISABLED/LOCKED */
|
||||
lock = mm_gdbus_modem_get_unlock_required (ctx->skeleton);
|
||||
mm_iface_modem_update_state (
|
||||
ctx->self,
|
||||
((lock == MM_MODEM_LOCK_NONE ||
|
||||
lock == MM_MODEM_LOCK_SIM_PIN2 ||
|
||||
lock == MM_MODEM_LOCK_SIM_PUK2) ?
|
||||
MM_MODEM_STATE_DISABLED :
|
||||
MM_MODEM_STATE_LOCKED),
|
||||
MM_MODEM_STATE_CHANGE_REASON_UNKNOWN);
|
||||
}
|
||||
|
||||
g_object_unref (ctx->self);
|
||||
g_object_unref (ctx->result);
|
||||
g_object_unref (ctx->cancellable);
|
||||
@@ -3094,7 +3073,6 @@ interface_enabling_step (EnablingContext *ctx)
|
||||
case ENABLING_STEP_LAST:
|
||||
/* We are done without errors! */
|
||||
g_simple_async_result_set_op_res_gboolean (ctx->result, TRUE);
|
||||
ctx->enabled = TRUE;
|
||||
enabling_context_complete_and_free (ctx);
|
||||
return;
|
||||
}
|
||||
@@ -3130,10 +3108,6 @@ mm_iface_modem_enable (MMIfaceModem *self,
|
||||
return;
|
||||
}
|
||||
|
||||
mm_iface_modem_update_state (ctx->self,
|
||||
MM_MODEM_STATE_ENABLING,
|
||||
MM_MODEM_STATE_CHANGE_REASON_USER_REQUESTED);
|
||||
|
||||
interface_enabling_step (ctx);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user