iface-modem-messaging: let initialization and enabling sequences get cancelled
This commit is contained in:
@@ -6293,6 +6293,7 @@ enabling_step (EnablingContext *ctx)
|
|||||||
mm_dbg ("Modem has messaging capabilities, enabling the Messaging interface...");
|
mm_dbg ("Modem has messaging capabilities, enabling the Messaging interface...");
|
||||||
/* Enabling the Modem Messaging interface */
|
/* Enabling the Modem Messaging interface */
|
||||||
mm_iface_modem_messaging_enable (MM_IFACE_MODEM_MESSAGING (ctx->self),
|
mm_iface_modem_messaging_enable (MM_IFACE_MODEM_MESSAGING (ctx->self),
|
||||||
|
ctx->cancellable,
|
||||||
(GAsyncReadyCallback)iface_modem_messaging_enable_ready,
|
(GAsyncReadyCallback)iface_modem_messaging_enable_ready,
|
||||||
ctx);
|
ctx);
|
||||||
return;
|
return;
|
||||||
@@ -6662,6 +6663,7 @@ initialize_step (InitializeContext *ctx)
|
|||||||
case INITIALIZE_STEP_IFACE_MESSAGING:
|
case INITIALIZE_STEP_IFACE_MESSAGING:
|
||||||
/* Initialize the Messaging interface */
|
/* Initialize the Messaging interface */
|
||||||
mm_iface_modem_messaging_initialize (MM_IFACE_MODEM_MESSAGING (ctx->self),
|
mm_iface_modem_messaging_initialize (MM_IFACE_MODEM_MESSAGING (ctx->self),
|
||||||
|
ctx->cancellable,
|
||||||
(GAsyncReadyCallback)iface_modem_messaging_initialize_ready,
|
(GAsyncReadyCallback)iface_modem_messaging_initialize_ready,
|
||||||
ctx);
|
ctx);
|
||||||
return;
|
return;
|
||||||
|
@@ -647,13 +647,14 @@ struct _EnablingContext {
|
|||||||
MMIfaceModemMessaging *self;
|
MMIfaceModemMessaging *self;
|
||||||
EnablingStep step;
|
EnablingStep step;
|
||||||
GSimpleAsyncResult *result;
|
GSimpleAsyncResult *result;
|
||||||
|
GCancellable *cancellable;
|
||||||
MmGdbusModemMessaging *skeleton;
|
MmGdbusModemMessaging *skeleton;
|
||||||
|
|
||||||
guint mem1_storage_index;
|
guint mem1_storage_index;
|
||||||
};
|
};
|
||||||
|
|
||||||
static EnablingContext *
|
static EnablingContext *
|
||||||
enabling_context_new (MMIfaceModemMessaging *self,
|
enabling_context_new (MMIfaceModemMessaging *self,
|
||||||
|
GCancellable *cancellable,
|
||||||
GAsyncReadyCallback callback,
|
GAsyncReadyCallback callback,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
@@ -661,6 +662,7 @@ enabling_context_new (MMIfaceModemMessaging *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,
|
||||||
@@ -680,10 +682,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_messaging_enable_finish (MMIfaceModemMessaging *self,
|
mm_iface_modem_messaging_enable_finish (MMIfaceModemMessaging *self,
|
||||||
GAsyncResult *res,
|
GAsyncResult *res,
|
||||||
@@ -812,6 +829,10 @@ enable_unsolicited_events_ready (MMIfaceModemMessaging *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: {
|
||||||
MMSmsList *list;
|
MMSmsList *list;
|
||||||
@@ -909,10 +930,12 @@ interface_enabling_step (EnablingContext *ctx)
|
|||||||
|
|
||||||
void
|
void
|
||||||
mm_iface_modem_messaging_enable (MMIfaceModemMessaging *self,
|
mm_iface_modem_messaging_enable (MMIfaceModemMessaging *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));
|
||||||
}
|
}
|
||||||
@@ -933,12 +956,14 @@ typedef enum {
|
|||||||
struct _InitializationContext {
|
struct _InitializationContext {
|
||||||
MMIfaceModemMessaging *self;
|
MMIfaceModemMessaging *self;
|
||||||
MmGdbusModemMessaging *skeleton;
|
MmGdbusModemMessaging *skeleton;
|
||||||
|
GCancellable *cancellable;
|
||||||
GSimpleAsyncResult *result;
|
GSimpleAsyncResult *result;
|
||||||
InitializationStep step;
|
InitializationStep step;
|
||||||
};
|
};
|
||||||
|
|
||||||
static InitializationContext *
|
static InitializationContext *
|
||||||
initialization_context_new (MMIfaceModemMessaging *self,
|
initialization_context_new (MMIfaceModemMessaging *self,
|
||||||
|
GCancellable *cancellable,
|
||||||
GAsyncReadyCallback callback,
|
GAsyncReadyCallback callback,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
@@ -946,6 +971,7 @@ initialization_context_new (MMIfaceModemMessaging *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,
|
||||||
@@ -964,10 +990,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_supported_storages_ready (MMIfaceModemMessaging *self,
|
load_supported_storages_ready (MMIfaceModemMessaging *self,
|
||||||
GAsyncResult *res,
|
GAsyncResult *res,
|
||||||
@@ -1042,6 +1083,10 @@ check_support_ready (MMIfaceModemMessaging *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:
|
||||||
/* Setup quarks if we didn't do it before */
|
/* Setup quarks if we didn't do it before */
|
||||||
@@ -1149,6 +1194,7 @@ mm_iface_modem_messaging_initialize_finish (MMIfaceModemMessaging *self,
|
|||||||
|
|
||||||
void
|
void
|
||||||
mm_iface_modem_messaging_initialize (MMIfaceModemMessaging *self,
|
mm_iface_modem_messaging_initialize (MMIfaceModemMessaging *self,
|
||||||
|
GCancellable *cancellable,
|
||||||
GAsyncReadyCallback callback,
|
GAsyncReadyCallback callback,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
@@ -1168,9 +1214,9 @@ mm_iface_modem_messaging_initialize (MMIfaceModemMessaging *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);
|
||||||
|
@@ -132,6 +132,7 @@ GType mm_iface_modem_messaging_get_type (void);
|
|||||||
|
|
||||||
/* Initialize Messaging interface (async) */
|
/* Initialize Messaging interface (async) */
|
||||||
void mm_iface_modem_messaging_initialize (MMIfaceModemMessaging *self,
|
void mm_iface_modem_messaging_initialize (MMIfaceModemMessaging *self,
|
||||||
|
GCancellable *cancellable,
|
||||||
GAsyncReadyCallback callback,
|
GAsyncReadyCallback callback,
|
||||||
gpointer user_data);
|
gpointer user_data);
|
||||||
gboolean mm_iface_modem_messaging_initialize_finish (MMIfaceModemMessaging *self,
|
gboolean mm_iface_modem_messaging_initialize_finish (MMIfaceModemMessaging *self,
|
||||||
@@ -140,6 +141,7 @@ gboolean mm_iface_modem_messaging_initialize_finish (MMIfaceModemMessaging *self
|
|||||||
|
|
||||||
/* Enable Messaging interface (async) */
|
/* Enable Messaging interface (async) */
|
||||||
void mm_iface_modem_messaging_enable (MMIfaceModemMessaging *self,
|
void mm_iface_modem_messaging_enable (MMIfaceModemMessaging *self,
|
||||||
|
GCancellable *cancellable,
|
||||||
GAsyncReadyCallback callback,
|
GAsyncReadyCallback callback,
|
||||||
gpointer user_data);
|
gpointer user_data);
|
||||||
gboolean mm_iface_modem_messaging_enable_finish (MMIfaceModemMessaging *self,
|
gboolean mm_iface_modem_messaging_enable_finish (MMIfaceModemMessaging *self,
|
||||||
|
Reference in New Issue
Block a user