iface-modem-cdma: let initialization and enabling sequences get cancelled

This commit is contained in:
Aleksander Morgado
2012-03-13 12:07:03 +01:00
parent 0d4b644572
commit fea2ef0e5c
3 changed files with 52 additions and 0 deletions

View File

@@ -6259,6 +6259,7 @@ enabling_step (EnablingContext *ctx)
mm_dbg ("Modem has CDMA capabilities, enabling the Modem CDMA interface..."); mm_dbg ("Modem has CDMA capabilities, enabling the Modem CDMA interface...");
/* Enabling the Modem CDMA interface */ /* Enabling the Modem CDMA interface */
mm_iface_modem_cdma_enable (MM_IFACE_MODEM_CDMA (ctx->self), mm_iface_modem_cdma_enable (MM_IFACE_MODEM_CDMA (ctx->self),
ctx->cancellable,
(GAsyncReadyCallback)iface_modem_cdma_enable_ready, (GAsyncReadyCallback)iface_modem_cdma_enable_ready,
ctx); ctx);
return; return;
@@ -6633,6 +6634,7 @@ initialize_step (InitializeContext *ctx)
if (mm_iface_modem_is_cdma (MM_IFACE_MODEM (ctx->self))) { if (mm_iface_modem_is_cdma (MM_IFACE_MODEM (ctx->self))) {
/* Initialize the CDMA interface */ /* Initialize the CDMA interface */
mm_iface_modem_cdma_initialize (MM_IFACE_MODEM_CDMA (ctx->self), mm_iface_modem_cdma_initialize (MM_IFACE_MODEM_CDMA (ctx->self),
ctx->cancellable,
(GAsyncReadyCallback)iface_modem_cdma_initialize_ready, (GAsyncReadyCallback)iface_modem_cdma_initialize_ready,
ctx); ctx);
return; return;

View File

@@ -1209,11 +1209,13 @@ struct _EnablingContext {
MMIfaceModemCdma *self; MMIfaceModemCdma *self;
EnablingStep step; EnablingStep step;
GSimpleAsyncResult *result; GSimpleAsyncResult *result;
GCancellable *cancellable;
MmGdbusModemCdma *skeleton; MmGdbusModemCdma *skeleton;
}; };
static EnablingContext * static EnablingContext *
enabling_context_new (MMIfaceModemCdma *self, enabling_context_new (MMIfaceModemCdma *self,
GCancellable *cancellable,
GAsyncReadyCallback callback, GAsyncReadyCallback callback,
gpointer user_data) gpointer user_data)
{ {
@@ -1221,6 +1223,7 @@ enabling_context_new (MMIfaceModemCdma *self,
ctx = g_new0 (EnablingContext, 1); ctx = g_new0 (EnablingContext, 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,
@@ -1240,10 +1243,25 @@ enabling_context_complete_and_free (EnablingContext *ctx)
g_simple_async_result_complete_in_idle (ctx->result); g_simple_async_result_complete_in_idle (ctx->result);
g_object_unref (ctx->self); g_object_unref (ctx->self);
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_cdma_enable_finish (MMIfaceModemCdma *self, mm_iface_modem_cdma_enable_finish (MMIfaceModemCdma *self,
GAsyncResult *res, GAsyncResult *res,
@@ -1275,6 +1293,10 @@ run_all_registration_checks_ready (MMIfaceModemCdma *self,
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 */
@@ -1303,10 +1325,12 @@ interface_enabling_step (EnablingContext *ctx)
void void
mm_iface_modem_cdma_enable (MMIfaceModemCdma *self, mm_iface_modem_cdma_enable (MMIfaceModemCdma *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));
} }
@@ -1326,12 +1350,14 @@ typedef enum {
struct _InitializationContext { struct _InitializationContext {
MMIfaceModemCdma *self; MMIfaceModemCdma *self;
MmGdbusModemCdma *skeleton; MmGdbusModemCdma *skeleton;
GCancellable *cancellable;
GSimpleAsyncResult *result; GSimpleAsyncResult *result;
InitializationStep step; InitializationStep step;
}; };
static InitializationContext * static InitializationContext *
initialization_context_new (MMIfaceModemCdma *self, initialization_context_new (MMIfaceModemCdma *self,
GCancellable *cancellable,
GAsyncReadyCallback callback, GAsyncReadyCallback callback,
gpointer user_data) gpointer user_data)
{ {
@@ -1339,6 +1365,7 @@ initialization_context_new (MMIfaceModemCdma *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,
@@ -1357,10 +1384,25 @@ 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->self); g_object_unref (ctx->self);
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
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 \
@@ -1391,6 +1433,10 @@ STR_REPLY_READY_FN (esn, "ESN")
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:
/* Fall down to next step */ /* Fall down to next step */
@@ -1466,6 +1512,7 @@ mm_iface_modem_cdma_initialize_finish (MMIfaceModemCdma *self,
void void
mm_iface_modem_cdma_initialize (MMIfaceModemCdma *self, mm_iface_modem_cdma_initialize (MMIfaceModemCdma *self,
GCancellable *cancellable,
GAsyncReadyCallback callback, GAsyncReadyCallback callback,
gpointer user_data) gpointer user_data)
{ {
@@ -1501,6 +1548,7 @@ mm_iface_modem_cdma_initialize (MMIfaceModemCdma *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);

View File

@@ -160,6 +160,7 @@ GType mm_iface_modem_cdma_get_type (void);
/* Initialize CDMA interface (async) */ /* Initialize CDMA interface (async) */
void mm_iface_modem_cdma_initialize (MMIfaceModemCdma *self, void mm_iface_modem_cdma_initialize (MMIfaceModemCdma *self,
GCancellable *cancellable,
GAsyncReadyCallback callback, GAsyncReadyCallback callback,
gpointer user_data); gpointer user_data);
gboolean mm_iface_modem_cdma_initialize_finish (MMIfaceModemCdma *self, gboolean mm_iface_modem_cdma_initialize_finish (MMIfaceModemCdma *self,
@@ -168,6 +169,7 @@ gboolean mm_iface_modem_cdma_initialize_finish (MMIfaceModemCdma *self,
/* Enable CDMA interface (async) */ /* Enable CDMA interface (async) */
void mm_iface_modem_cdma_enable (MMIfaceModemCdma *self, void mm_iface_modem_cdma_enable (MMIfaceModemCdma *self,
GCancellable *cancellable,
GAsyncReadyCallback callback, GAsyncReadyCallback callback,
gpointer user_data); gpointer user_data);
gboolean mm_iface_modem_cdma_enable_finish (MMIfaceModemCdma *self, gboolean mm_iface_modem_cdma_enable_finish (MMIfaceModemCdma *self,