summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAleksander Morgado <aleksander@lanedo.com>2012-03-13 11:58:32 +0100
committerAleksander Morgado <aleksander@lanedo.com>2012-03-16 14:53:24 +0100
commit0d4b644572603114d9b6eda46778af6a8a5c021d (patch)
treecbe2b01564c267c46689a64cbc47dbec5e4fa17c /src
parente140ff3c5f1dda2e1310b79b81e73fada5b6d312 (diff)
downloadModemManager-0d4b644572603114d9b6eda46778af6a8a5c021d.tar.gz
iface-modem-3gpp: let initialization and enabling sequences get cancelled
Diffstat (limited to 'src')
-rw-r--r--src/mm-broadband-modem.c2
-rw-r--r--src/mm-iface-modem-3gpp.c48
-rw-r--r--src/mm-iface-modem-3gpp.h2
3 files changed, 52 insertions, 0 deletions
diff --git a/src/mm-broadband-modem.c b/src/mm-broadband-modem.c
index 68c712f40..7ab217efe 100644
--- a/src/mm-broadband-modem.c
+++ b/src/mm-broadband-modem.c
@@ -6235,6 +6235,7 @@ enabling_step (EnablingContext *ctx)
mm_dbg ("Modem has 3GPP capabilities, enabling the Modem 3GPP interface...");
/* Enabling the Modem 3GPP interface */
mm_iface_modem_3gpp_enable (MM_IFACE_MODEM_3GPP (ctx->self),
+ ctx->cancellable,
(GAsyncReadyCallback)iface_modem_3gpp_enable_ready,
ctx);
return;
@@ -6608,6 +6609,7 @@ initialize_step (InitializeContext *ctx)
if (mm_iface_modem_is_3gpp (MM_IFACE_MODEM (ctx->self))) {
/* Initialize the 3GPP interface */
mm_iface_modem_3gpp_initialize (MM_IFACE_MODEM_3GPP (ctx->self),
+ ctx->cancellable,
(GAsyncReadyCallback)iface_modem_3gpp_initialize_ready,
ctx);
return;
diff --git a/src/mm-iface-modem-3gpp.c b/src/mm-iface-modem-3gpp.c
index 16ddce6d3..222d88367 100644
--- a/src/mm-iface-modem-3gpp.c
+++ b/src/mm-iface-modem-3gpp.c
@@ -1163,11 +1163,13 @@ struct _EnablingContext {
MMIfaceModem3gpp *self;
EnablingStep step;
GSimpleAsyncResult *result;
+ GCancellable *cancellable;
MmGdbusModem3gpp *skeleton;
};
static EnablingContext *
enabling_context_new (MMIfaceModem3gpp *self,
+ GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
{
@@ -1175,6 +1177,7 @@ enabling_context_new (MMIfaceModem3gpp *self,
ctx = g_new0 (EnablingContext, 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,
@@ -1194,10 +1197,25 @@ enabling_context_complete_and_free (EnablingContext *ctx)
g_simple_async_result_complete_in_idle (ctx->result);
g_object_unref (ctx->self);
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_3gpp_enable_finish (MMIfaceModem3gpp *self,
GAsyncResult *res,
@@ -1394,6 +1412,10 @@ setup_unsolicited_registration_ready (MMIfaceModem3gpp *self,
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:
/* Setup quarks if we didn't do it before */
@@ -1531,10 +1553,12 @@ interface_enabling_step (EnablingContext *ctx)
void
mm_iface_modem_3gpp_enable (MMIfaceModem3gpp *self,
+ GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
{
interface_enabling_step (enabling_context_new (self,
+ cancellable,
callback,
user_data));
}
@@ -1555,11 +1579,13 @@ struct _InitializationContext {
MMIfaceModem3gpp *self;
MmGdbusModem3gpp *skeleton;
GSimpleAsyncResult *result;
+ GCancellable *cancellable;
InitializationStep step;
};
static InitializationContext *
initialization_context_new (MMIfaceModem3gpp *self,
+ GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
{
@@ -1567,6 +1593,7 @@ initialization_context_new (MMIfaceModem3gpp *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,
@@ -1585,10 +1612,25 @@ initialization_context_complete_and_free (InitializationContext *ctx)
g_simple_async_result_complete_in_idle (ctx->result);
g_object_unref (ctx->self);
g_object_unref (ctx->result);
+ g_object_unref (ctx->cancellable);
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;
+}
+
static void
sim_pin_lock_enabled_cb (MMSim *self,
gboolean enabled,
@@ -1666,6 +1708,10 @@ load_imei_ready (MMIfaceModem3gpp *self,
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:
/* Fall down to next step */
@@ -1738,6 +1784,7 @@ mm_iface_modem_3gpp_initialize_finish (MMIfaceModem3gpp *self,
void
mm_iface_modem_3gpp_initialize (MMIfaceModem3gpp *self,
+ GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
{
@@ -1779,6 +1826,7 @@ mm_iface_modem_3gpp_initialize (MMIfaceModem3gpp *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-3gpp.h b/src/mm-iface-modem-3gpp.h
index 3168399cc..bea68f5b9 100644
--- a/src/mm-iface-modem-3gpp.h
+++ b/src/mm-iface-modem-3gpp.h
@@ -213,6 +213,7 @@ GType mm_iface_modem_3gpp_get_type (void);
/* Initialize Modem 3GPP interface (async) */
void mm_iface_modem_3gpp_initialize (MMIfaceModem3gpp *self,
+ GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
gboolean mm_iface_modem_3gpp_initialize_finish (MMIfaceModem3gpp *self,
@@ -221,6 +222,7 @@ gboolean mm_iface_modem_3gpp_initialize_finish (MMIfaceModem3gpp *self,
/* Enable Modem interface (async) */
void mm_iface_modem_3gpp_enable (MMIfaceModem3gpp *self,
+ GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
gboolean mm_iface_modem_3gpp_enable_finish (MMIfaceModem3gpp *self,