iface-modem: let initialization and enabling sequences get cancelled
This commit is contained in:
@@ -6225,6 +6225,7 @@ enabling_step (EnablingContext *ctx)
|
|||||||
g_assert (ctx->self->priv->modem_dbus_skeleton != NULL);
|
g_assert (ctx->self->priv->modem_dbus_skeleton != NULL);
|
||||||
/* Enabling the Modem interface */
|
/* Enabling the Modem interface */
|
||||||
mm_iface_modem_enable (MM_IFACE_MODEM (ctx->self),
|
mm_iface_modem_enable (MM_IFACE_MODEM (ctx->self),
|
||||||
|
ctx->cancellable,
|
||||||
(GAsyncReadyCallback)iface_modem_enable_ready,
|
(GAsyncReadyCallback)iface_modem_enable_ready,
|
||||||
ctx);
|
ctx);
|
||||||
return;
|
return;
|
||||||
@@ -6582,6 +6583,7 @@ initialize_step (InitializeContext *ctx)
|
|||||||
case INITIALIZE_STEP_IFACE_MODEM:
|
case INITIALIZE_STEP_IFACE_MODEM:
|
||||||
/* Initialize the Modem interface */
|
/* Initialize the Modem interface */
|
||||||
mm_iface_modem_initialize (MM_IFACE_MODEM (ctx->self),
|
mm_iface_modem_initialize (MM_IFACE_MODEM (ctx->self),
|
||||||
|
ctx->cancellable,
|
||||||
(GAsyncReadyCallback)iface_modem_initialize_ready,
|
(GAsyncReadyCallback)iface_modem_initialize_ready,
|
||||||
ctx);
|
ctx);
|
||||||
return;
|
return;
|
||||||
|
@@ -2492,11 +2492,13 @@ struct _EnablingContext {
|
|||||||
const MMModemCharset *current_charset;
|
const MMModemCharset *current_charset;
|
||||||
gboolean enabled;
|
gboolean enabled;
|
||||||
GSimpleAsyncResult *result;
|
GSimpleAsyncResult *result;
|
||||||
|
GCancellable *cancellable;
|
||||||
MmGdbusModem *skeleton;
|
MmGdbusModem *skeleton;
|
||||||
};
|
};
|
||||||
|
|
||||||
static EnablingContext *
|
static EnablingContext *
|
||||||
enabling_context_new (MMIfaceModem *self,
|
enabling_context_new (MMIfaceModem *self,
|
||||||
|
GCancellable *cancellable,
|
||||||
GAsyncReadyCallback callback,
|
GAsyncReadyCallback callback,
|
||||||
gpointer user_data)
|
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->primary = mm_base_modem_get_port_primary (MM_BASE_MODEM (self));
|
||||||
ctx->secondary = mm_base_modem_get_port_secondary (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->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),
|
ctx->result = g_simple_async_result_new (G_OBJECT (self),
|
||||||
callback,
|
callback,
|
||||||
user_data,
|
user_data,
|
||||||
@@ -2558,10 +2561,25 @@ enabling_context_complete_and_free (EnablingContext *ctx)
|
|||||||
if (ctx->qcdm)
|
if (ctx->qcdm)
|
||||||
g_object_unref (ctx->qcdm);
|
g_object_unref (ctx->qcdm);
|
||||||
g_object_unref (ctx->result);
|
g_object_unref (ctx->result);
|
||||||
|
g_object_unref (ctx->cancellable);
|
||||||
g_object_unref (ctx->skeleton);
|
g_object_unref (ctx->skeleton);
|
||||||
g_free (ctx);
|
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
|
gboolean
|
||||||
mm_iface_modem_enable_finish (MMIfaceModem *self,
|
mm_iface_modem_enable_finish (MMIfaceModem *self,
|
||||||
GAsyncResult *res,
|
GAsyncResult *res,
|
||||||
@@ -2726,6 +2744,10 @@ static const MMModemCharset best_charsets[] = {
|
|||||||
static void
|
static void
|
||||||
interface_enabling_step (EnablingContext *ctx)
|
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) {
|
switch (ctx->step) {
|
||||||
case ENABLING_STEP_FIRST:
|
case ENABLING_STEP_FIRST:
|
||||||
/* Fall down to next step */
|
/* Fall down to next step */
|
||||||
@@ -2929,10 +2951,12 @@ interface_enabling_step (EnablingContext *ctx)
|
|||||||
|
|
||||||
void
|
void
|
||||||
mm_iface_modem_enable (MMIfaceModem *self,
|
mm_iface_modem_enable (MMIfaceModem *self,
|
||||||
|
GCancellable *cancellable,
|
||||||
GAsyncReadyCallback callback,
|
GAsyncReadyCallback callback,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
interface_enabling_step (enabling_context_new (self,
|
interface_enabling_step (enabling_context_new (self,
|
||||||
|
cancellable,
|
||||||
callback,
|
callback,
|
||||||
user_data));
|
user_data));
|
||||||
}
|
}
|
||||||
@@ -2966,11 +2990,13 @@ struct _InitializationContext {
|
|||||||
MMIfaceModem *self;
|
MMIfaceModem *self;
|
||||||
InitializationStep step;
|
InitializationStep step;
|
||||||
GSimpleAsyncResult *result;
|
GSimpleAsyncResult *result;
|
||||||
|
GCancellable *cancellable;
|
||||||
MmGdbusModem *skeleton;
|
MmGdbusModem *skeleton;
|
||||||
};
|
};
|
||||||
|
|
||||||
static InitializationContext *
|
static InitializationContext *
|
||||||
initialization_context_new (MMIfaceModem *self,
|
initialization_context_new (MMIfaceModem *self,
|
||||||
|
GCancellable *cancellable,
|
||||||
GAsyncReadyCallback callback,
|
GAsyncReadyCallback callback,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
@@ -2978,6 +3004,7 @@ initialization_context_new (MMIfaceModem *self,
|
|||||||
|
|
||||||
ctx = g_new0 (InitializationContext, 1);
|
ctx = g_new0 (InitializationContext, 1);
|
||||||
ctx->self = g_object_ref (self);
|
ctx->self = g_object_ref (self);
|
||||||
|
ctx->cancellable = g_object_ref (cancellable);
|
||||||
ctx->result = g_simple_async_result_new (G_OBJECT (self),
|
ctx->result = g_simple_async_result_new (G_OBJECT (self),
|
||||||
callback,
|
callback,
|
||||||
user_data,
|
user_data,
|
||||||
@@ -2994,12 +3021,27 @@ static void
|
|||||||
initialization_context_complete_and_free (InitializationContext *ctx)
|
initialization_context_complete_and_free (InitializationContext *ctx)
|
||||||
{
|
{
|
||||||
g_simple_async_result_complete_in_idle (ctx->result);
|
g_simple_async_result_complete_in_idle (ctx->result);
|
||||||
|
g_object_unref (ctx->cancellable);
|
||||||
g_object_unref (ctx->self);
|
g_object_unref (ctx->self);
|
||||||
g_object_unref (ctx->result);
|
g_object_unref (ctx->result);
|
||||||
g_object_unref (ctx->skeleton);
|
g_object_unref (ctx->skeleton);
|
||||||
g_free (ctx);
|
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
|
#undef STR_REPLY_READY_FN
|
||||||
#define STR_REPLY_READY_FN(NAME,DISPLAY) \
|
#define STR_REPLY_READY_FN(NAME,DISPLAY) \
|
||||||
static void \
|
static void \
|
||||||
@@ -3248,6 +3290,10 @@ sim_reinit_ready (MMSim *sim,
|
|||||||
static void
|
static void
|
||||||
interface_initialization_step (InitializationContext *ctx)
|
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) {
|
switch (ctx->step) {
|
||||||
case INITIALIZATION_STEP_FIRST:
|
case INITIALIZATION_STEP_FIRST:
|
||||||
/* Load device if not done before */
|
/* Load device if not done before */
|
||||||
@@ -3609,6 +3655,7 @@ mm_iface_modem_initialize_finish (MMIfaceModem *self,
|
|||||||
|
|
||||||
void
|
void
|
||||||
mm_iface_modem_initialize (MMIfaceModem *self,
|
mm_iface_modem_initialize (MMIfaceModem *self,
|
||||||
|
GCancellable *cancellable,
|
||||||
GAsyncReadyCallback callback,
|
GAsyncReadyCallback callback,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
@@ -3663,6 +3710,7 @@ mm_iface_modem_initialize (MMIfaceModem *self,
|
|||||||
|
|
||||||
/* Perform async initialization here */
|
/* Perform async initialization here */
|
||||||
interface_initialization_step (initialization_context_new (self,
|
interface_initialization_step (initialization_context_new (self,
|
||||||
|
cancellable,
|
||||||
callback,
|
callback,
|
||||||
user_data));
|
user_data));
|
||||||
g_object_unref (skeleton);
|
g_object_unref (skeleton);
|
||||||
|
@@ -310,6 +310,7 @@ gboolean mm_iface_modem_is_cdma_only (MMIfaceModem *self);
|
|||||||
|
|
||||||
/* Initialize Modem interface (async) */
|
/* Initialize Modem interface (async) */
|
||||||
void mm_iface_modem_initialize (MMIfaceModem *self,
|
void mm_iface_modem_initialize (MMIfaceModem *self,
|
||||||
|
GCancellable *cancellable,
|
||||||
GAsyncReadyCallback callback,
|
GAsyncReadyCallback callback,
|
||||||
gpointer user_data);
|
gpointer user_data);
|
||||||
gboolean mm_iface_modem_initialize_finish (MMIfaceModem *self,
|
gboolean mm_iface_modem_initialize_finish (MMIfaceModem *self,
|
||||||
@@ -318,6 +319,7 @@ gboolean mm_iface_modem_initialize_finish (MMIfaceModem *self,
|
|||||||
|
|
||||||
/* Enable Modem interface (async) */
|
/* Enable Modem interface (async) */
|
||||||
void mm_iface_modem_enable (MMIfaceModem *self,
|
void mm_iface_modem_enable (MMIfaceModem *self,
|
||||||
|
GCancellable *cancellable,
|
||||||
GAsyncReadyCallback callback,
|
GAsyncReadyCallback callback,
|
||||||
gpointer user_data);
|
gpointer user_data);
|
||||||
gboolean mm_iface_modem_enable_finish (MMIfaceModem *self,
|
gboolean mm_iface_modem_enable_finish (MMIfaceModem *self,
|
||||||
|
Reference in New Issue
Block a user