iface-modem-location: let initialization and enabling sequences get cancelled
This commit is contained in:
@@ -6280,6 +6280,7 @@ enabling_step (EnablingContext *ctx)
|
|||||||
mm_dbg ("Modem has location capabilities, enabling the Location interface...");
|
mm_dbg ("Modem has location capabilities, enabling the Location interface...");
|
||||||
/* Enabling the Modem Location interface */
|
/* Enabling the Modem Location interface */
|
||||||
mm_iface_modem_location_enable (MM_IFACE_MODEM_LOCATION (ctx->self),
|
mm_iface_modem_location_enable (MM_IFACE_MODEM_LOCATION (ctx->self),
|
||||||
|
ctx->cancellable,
|
||||||
(GAsyncReadyCallback)iface_modem_location_enable_ready,
|
(GAsyncReadyCallback)iface_modem_location_enable_ready,
|
||||||
ctx);
|
ctx);
|
||||||
return;
|
return;
|
||||||
@@ -6653,6 +6654,7 @@ initialize_step (InitializeContext *ctx)
|
|||||||
case INITIALIZE_STEP_IFACE_LOCATION:
|
case INITIALIZE_STEP_IFACE_LOCATION:
|
||||||
/* Initialize the Location interface */
|
/* Initialize the Location interface */
|
||||||
mm_iface_modem_location_initialize (MM_IFACE_MODEM_LOCATION (ctx->self),
|
mm_iface_modem_location_initialize (MM_IFACE_MODEM_LOCATION (ctx->self),
|
||||||
|
ctx->cancellable,
|
||||||
(GAsyncReadyCallback)iface_modem_location_initialize_ready,
|
(GAsyncReadyCallback)iface_modem_location_initialize_ready,
|
||||||
ctx);
|
ctx);
|
||||||
return;
|
return;
|
||||||
|
@@ -574,11 +574,13 @@ struct _EnablingContext {
|
|||||||
MMIfaceModemLocation *self;
|
MMIfaceModemLocation *self;
|
||||||
EnablingStep step;
|
EnablingStep step;
|
||||||
GSimpleAsyncResult *result;
|
GSimpleAsyncResult *result;
|
||||||
|
GCancellable *cancellable;
|
||||||
MmGdbusModemLocation *skeleton;
|
MmGdbusModemLocation *skeleton;
|
||||||
};
|
};
|
||||||
|
|
||||||
static EnablingContext *
|
static EnablingContext *
|
||||||
enabling_context_new (MMIfaceModemLocation *self,
|
enabling_context_new (MMIfaceModemLocation *self,
|
||||||
|
GCancellable *cancellable,
|
||||||
GAsyncReadyCallback callback,
|
GAsyncReadyCallback callback,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
@@ -586,6 +588,7 @@ enabling_context_new (MMIfaceModemLocation *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,
|
||||||
@@ -605,10 +608,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_location_enable_finish (MMIfaceModemLocation *self,
|
mm_iface_modem_location_enable_finish (MMIfaceModemLocation *self,
|
||||||
GAsyncResult *res,
|
GAsyncResult *res,
|
||||||
@@ -640,6 +658,10 @@ enabling_location_gathering_ready (MMIfaceModemLocation *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 */
|
||||||
@@ -670,10 +692,12 @@ interface_enabling_step (EnablingContext *ctx)
|
|||||||
|
|
||||||
void
|
void
|
||||||
mm_iface_modem_location_enable (MMIfaceModemLocation *self,
|
mm_iface_modem_location_enable (MMIfaceModemLocation *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));
|
||||||
}
|
}
|
||||||
@@ -693,6 +717,7 @@ typedef enum {
|
|||||||
struct _InitializationContext {
|
struct _InitializationContext {
|
||||||
MMIfaceModemLocation *self;
|
MMIfaceModemLocation *self;
|
||||||
MmGdbusModemLocation *skeleton;
|
MmGdbusModemLocation *skeleton;
|
||||||
|
GCancellable *cancellable;
|
||||||
GSimpleAsyncResult *result;
|
GSimpleAsyncResult *result;
|
||||||
InitializationStep step;
|
InitializationStep step;
|
||||||
MMModemLocationSource capabilities;
|
MMModemLocationSource capabilities;
|
||||||
@@ -700,6 +725,7 @@ struct _InitializationContext {
|
|||||||
|
|
||||||
static InitializationContext *
|
static InitializationContext *
|
||||||
initialization_context_new (MMIfaceModemLocation *self,
|
initialization_context_new (MMIfaceModemLocation *self,
|
||||||
|
GCancellable *cancellable,
|
||||||
GAsyncReadyCallback callback,
|
GAsyncReadyCallback callback,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
@@ -708,6 +734,7 @@ initialization_context_new (MMIfaceModemLocation *self,
|
|||||||
ctx = g_new0 (InitializationContext, 1);
|
ctx = g_new0 (InitializationContext, 1);
|
||||||
ctx->self = g_object_ref (self);
|
ctx->self = g_object_ref (self);
|
||||||
ctx->capabilities = MM_MODEM_LOCATION_SOURCE_NONE;
|
ctx->capabilities = MM_MODEM_LOCATION_SOURCE_NONE;
|
||||||
|
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,
|
||||||
@@ -726,10 +753,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;
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
load_capabilities_ready (MMIfaceModemLocation *self,
|
load_capabilities_ready (MMIfaceModemLocation *self,
|
||||||
GAsyncResult *res,
|
GAsyncResult *res,
|
||||||
@@ -753,6 +795,10 @@ load_capabilities_ready (MMIfaceModemLocation *self,
|
|||||||
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 */
|
||||||
@@ -826,6 +872,7 @@ mm_iface_modem_location_initialize_finish (MMIfaceModemLocation *self,
|
|||||||
|
|
||||||
void
|
void
|
||||||
mm_iface_modem_location_initialize (MMIfaceModemLocation *self,
|
mm_iface_modem_location_initialize (MMIfaceModemLocation *self,
|
||||||
|
GCancellable *cancellable,
|
||||||
GAsyncReadyCallback callback,
|
GAsyncReadyCallback callback,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
@@ -852,9 +899,9 @@ mm_iface_modem_location_initialize (MMIfaceModemLocation *self,
|
|||||||
NULL);
|
NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* 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);
|
||||||
|
@@ -62,6 +62,7 @@ GType mm_iface_modem_location_get_type (void);
|
|||||||
|
|
||||||
/* Initialize Location interface (async) */
|
/* Initialize Location interface (async) */
|
||||||
void mm_iface_modem_location_initialize (MMIfaceModemLocation *self,
|
void mm_iface_modem_location_initialize (MMIfaceModemLocation *self,
|
||||||
|
GCancellable *cancellable,
|
||||||
GAsyncReadyCallback callback,
|
GAsyncReadyCallback callback,
|
||||||
gpointer user_data);
|
gpointer user_data);
|
||||||
gboolean mm_iface_modem_location_initialize_finish (MMIfaceModemLocation *self,
|
gboolean mm_iface_modem_location_initialize_finish (MMIfaceModemLocation *self,
|
||||||
@@ -70,6 +71,7 @@ gboolean mm_iface_modem_location_initialize_finish (MMIfaceModemLocation *self,
|
|||||||
|
|
||||||
/* Enable Location interface (async) */
|
/* Enable Location interface (async) */
|
||||||
void mm_iface_modem_location_enable (MMIfaceModemLocation *self,
|
void mm_iface_modem_location_enable (MMIfaceModemLocation *self,
|
||||||
|
GCancellable *cancellable,
|
||||||
GAsyncReadyCallback callback,
|
GAsyncReadyCallback callback,
|
||||||
gpointer user_data);
|
gpointer user_data);
|
||||||
gboolean mm_iface_modem_location_enable_finish (MMIfaceModemLocation *self,
|
gboolean mm_iface_modem_location_enable_finish (MMIfaceModemLocation *self,
|
||||||
|
Reference in New Issue
Block a user