iface-modem-cdma: port mm_iface_modem_cdma_initialize to use GTask
This commit is contained in:

committed by
Aleksander Morgado

parent
1bfe5434bb
commit
d9918afa99
@@ -1583,7 +1583,7 @@ mm_iface_modem_cdma_enable (MMIfaceModemCdma *self,
|
|||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
||||||
typedef struct _InitializationContext InitializationContext;
|
typedef struct _InitializationContext InitializationContext;
|
||||||
static void interface_initialization_step (InitializationContext *ctx);
|
static void interface_initialization_step (GTask *task);
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
INITIALIZATION_STEP_FIRST,
|
INITIALIZATION_STEP_FIRST,
|
||||||
@@ -1594,48 +1594,30 @@ typedef enum {
|
|||||||
} InitializationStep;
|
} InitializationStep;
|
||||||
|
|
||||||
struct _InitializationContext {
|
struct _InitializationContext {
|
||||||
MMIfaceModemCdma *self;
|
|
||||||
MmGdbusModemCdma *skeleton;
|
MmGdbusModemCdma *skeleton;
|
||||||
GCancellable *cancellable;
|
|
||||||
GSimpleAsyncResult *result;
|
|
||||||
InitializationStep step;
|
InitializationStep step;
|
||||||
};
|
};
|
||||||
|
|
||||||
static void
|
static void
|
||||||
initialization_context_complete_and_free (InitializationContext *ctx)
|
initialization_context_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_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 \
|
||||||
load_##NAME##_ready (MMIfaceModemCdma *self, \
|
load_##NAME##_ready (MMIfaceModemCdma *self, \
|
||||||
GAsyncResult *res, \
|
GAsyncResult *res, \
|
||||||
InitializationContext *ctx) \
|
GTask *task) \
|
||||||
{ \
|
{ \
|
||||||
|
InitializationContext *ctx; \
|
||||||
GError *error = NULL; \
|
GError *error = NULL; \
|
||||||
gchar *val; \
|
gchar *val; \
|
||||||
\
|
\
|
||||||
|
ctx = g_task_get_task_data (task); \
|
||||||
|
\
|
||||||
val = MM_IFACE_MODEM_CDMA_GET_INTERFACE (self)->load_##NAME##_finish (self, res, &error); \
|
val = MM_IFACE_MODEM_CDMA_GET_INTERFACE (self)->load_##NAME##_finish (self, res, &error); \
|
||||||
mm_gdbus_modem_cdma_set_##NAME (ctx->skeleton, val); \
|
mm_gdbus_modem_cdma_set_##NAME (ctx->skeleton, val); \
|
||||||
g_free (val); \
|
g_free (val); \
|
||||||
@@ -1647,7 +1629,7 @@ initialization_context_complete_and_free_if_cancelled (InitializationContext *ct
|
|||||||
\
|
\
|
||||||
/* Go on to next step */ \
|
/* Go on to next step */ \
|
||||||
ctx->step++; \
|
ctx->step++; \
|
||||||
interface_initialization_step (ctx); \
|
interface_initialization_step (task); \
|
||||||
}
|
}
|
||||||
|
|
||||||
STR_REPLY_READY_FN (meid, "MEID")
|
STR_REPLY_READY_FN (meid, "MEID")
|
||||||
@@ -1656,11 +1638,14 @@ STR_REPLY_READY_FN (esn, "ESN")
|
|||||||
static void
|
static void
|
||||||
load_activation_state_ready (MMIfaceModemCdma *self,
|
load_activation_state_ready (MMIfaceModemCdma *self,
|
||||||
GAsyncResult *res,
|
GAsyncResult *res,
|
||||||
InitializationContext *ctx)
|
GTask *task)
|
||||||
{
|
{
|
||||||
|
InitializationContext *ctx;
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
MMModemCdmaActivationState state;
|
MMModemCdmaActivationState state;
|
||||||
|
|
||||||
|
ctx = g_task_get_task_data (task);
|
||||||
|
|
||||||
state = MM_IFACE_MODEM_CDMA_GET_INTERFACE (self)->load_activation_state_finish (self, res, &error);
|
state = MM_IFACE_MODEM_CDMA_GET_INTERFACE (self)->load_activation_state_finish (self, res, &error);
|
||||||
mm_gdbus_modem_cdma_set_activation_state (ctx->skeleton, state);
|
mm_gdbus_modem_cdma_set_activation_state (ctx->skeleton, state);
|
||||||
|
|
||||||
@@ -1671,15 +1656,23 @@ load_activation_state_ready (MMIfaceModemCdma *self,
|
|||||||
|
|
||||||
/* Go on to next step */
|
/* Go on to next step */
|
||||||
ctx->step++;
|
ctx->step++;
|
||||||
interface_initialization_step (ctx);
|
interface_initialization_step (task);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
interface_initialization_step (InitializationContext *ctx)
|
interface_initialization_step (GTask *task)
|
||||||
{
|
{
|
||||||
|
MMIfaceModemCdma *self;
|
||||||
|
InitializationContext *ctx;
|
||||||
|
|
||||||
/* Don't run new steps if we're cancelled */
|
/* Don't run new steps if we're cancelled */
|
||||||
if (initialization_context_complete_and_free_if_cancelled (ctx))
|
if (g_task_return_error_if_cancelled (task)) {
|
||||||
|
g_object_unref (task);
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
self = g_task_get_source_object (task);
|
||||||
|
ctx = g_task_get_task_data (task);
|
||||||
|
|
||||||
switch (ctx->step) {
|
switch (ctx->step) {
|
||||||
case INITIALIZATION_STEP_FIRST:
|
case INITIALIZATION_STEP_FIRST:
|
||||||
@@ -1691,12 +1684,12 @@ interface_initialization_step (InitializationContext *ctx)
|
|||||||
* lifetime of the modem. Therefore, if we already have it loaded,
|
* lifetime of the modem. Therefore, if we already have it loaded,
|
||||||
* don't try to load it again. */
|
* don't try to load it again. */
|
||||||
if (!mm_gdbus_modem_cdma_get_meid (ctx->skeleton) &&
|
if (!mm_gdbus_modem_cdma_get_meid (ctx->skeleton) &&
|
||||||
MM_IFACE_MODEM_CDMA_GET_INTERFACE (ctx->self)->load_meid &&
|
MM_IFACE_MODEM_CDMA_GET_INTERFACE (self)->load_meid &&
|
||||||
MM_IFACE_MODEM_CDMA_GET_INTERFACE (ctx->self)->load_meid_finish) {
|
MM_IFACE_MODEM_CDMA_GET_INTERFACE (self)->load_meid_finish) {
|
||||||
MM_IFACE_MODEM_CDMA_GET_INTERFACE (ctx->self)->load_meid (
|
MM_IFACE_MODEM_CDMA_GET_INTERFACE (self)->load_meid (
|
||||||
ctx->self,
|
self,
|
||||||
(GAsyncReadyCallback)load_meid_ready,
|
(GAsyncReadyCallback)load_meid_ready,
|
||||||
ctx);
|
task);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
/* Fall down to next step */
|
/* Fall down to next step */
|
||||||
@@ -1707,12 +1700,12 @@ interface_initialization_step (InitializationContext *ctx)
|
|||||||
* lifetime of the modem. Therefore, if we already have it loaded,
|
* lifetime of the modem. Therefore, if we already have it loaded,
|
||||||
* don't try to load it again. */
|
* don't try to load it again. */
|
||||||
if (!mm_gdbus_modem_cdma_get_esn (ctx->skeleton) &&
|
if (!mm_gdbus_modem_cdma_get_esn (ctx->skeleton) &&
|
||||||
MM_IFACE_MODEM_CDMA_GET_INTERFACE (ctx->self)->load_esn &&
|
MM_IFACE_MODEM_CDMA_GET_INTERFACE (self)->load_esn &&
|
||||||
MM_IFACE_MODEM_CDMA_GET_INTERFACE (ctx->self)->load_esn_finish) {
|
MM_IFACE_MODEM_CDMA_GET_INTERFACE (self)->load_esn_finish) {
|
||||||
MM_IFACE_MODEM_CDMA_GET_INTERFACE (ctx->self)->load_esn (
|
MM_IFACE_MODEM_CDMA_GET_INTERFACE (self)->load_esn (
|
||||||
ctx->self,
|
self,
|
||||||
(GAsyncReadyCallback)load_esn_ready,
|
(GAsyncReadyCallback)load_esn_ready,
|
||||||
ctx);
|
task);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
/* Fall down to next step */
|
/* Fall down to next step */
|
||||||
@@ -1723,12 +1716,12 @@ interface_initialization_step (InitializationContext *ctx)
|
|||||||
* whole lifetime of the modem. Therefore, if we already have it loaded,
|
* whole lifetime of the modem. Therefore, if we already have it loaded,
|
||||||
* don't try to load it again. */
|
* don't try to load it again. */
|
||||||
if (mm_gdbus_modem_cdma_get_activation_state (ctx->skeleton) == MM_MODEM_CDMA_ACTIVATION_STATE_UNKNOWN &&
|
if (mm_gdbus_modem_cdma_get_activation_state (ctx->skeleton) == MM_MODEM_CDMA_ACTIVATION_STATE_UNKNOWN &&
|
||||||
MM_IFACE_MODEM_CDMA_GET_INTERFACE (ctx->self)->load_activation_state &&
|
MM_IFACE_MODEM_CDMA_GET_INTERFACE (self)->load_activation_state &&
|
||||||
MM_IFACE_MODEM_CDMA_GET_INTERFACE (ctx->self)->load_activation_state_finish) {
|
MM_IFACE_MODEM_CDMA_GET_INTERFACE (self)->load_activation_state_finish) {
|
||||||
MM_IFACE_MODEM_CDMA_GET_INTERFACE (ctx->self)->load_activation_state (
|
MM_IFACE_MODEM_CDMA_GET_INTERFACE (self)->load_activation_state (
|
||||||
ctx->self,
|
self,
|
||||||
(GAsyncReadyCallback)load_activation_state_ready,
|
(GAsyncReadyCallback)load_activation_state_ready,
|
||||||
ctx);
|
task);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
/* Fall down to next step */
|
/* Fall down to next step */
|
||||||
@@ -1741,18 +1734,18 @@ interface_initialization_step (InitializationContext *ctx)
|
|||||||
g_signal_connect (ctx->skeleton,
|
g_signal_connect (ctx->skeleton,
|
||||||
"handle-activate",
|
"handle-activate",
|
||||||
G_CALLBACK (handle_activate),
|
G_CALLBACK (handle_activate),
|
||||||
ctx->self);
|
self);
|
||||||
g_signal_connect (ctx->skeleton,
|
g_signal_connect (ctx->skeleton,
|
||||||
"handle-activate-manual",
|
"handle-activate-manual",
|
||||||
G_CALLBACK (handle_activate_manual),
|
G_CALLBACK (handle_activate_manual),
|
||||||
ctx->self);
|
self);
|
||||||
|
|
||||||
/* Finally, export the new interface */
|
/* Finally, export the new interface */
|
||||||
mm_gdbus_object_skeleton_set_modem_cdma (MM_GDBUS_OBJECT_SKELETON (ctx->self),
|
mm_gdbus_object_skeleton_set_modem_cdma (MM_GDBUS_OBJECT_SKELETON (self),
|
||||||
MM_GDBUS_MODEM_CDMA (ctx->skeleton));
|
MM_GDBUS_MODEM_CDMA (ctx->skeleton));
|
||||||
|
|
||||||
g_simple_async_result_set_op_res_gboolean (ctx->result, TRUE);
|
g_task_return_boolean (task, TRUE);
|
||||||
initialization_context_complete_and_free (ctx);
|
g_object_unref (task);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1764,7 +1757,7 @@ mm_iface_modem_cdma_initialize_finish (MMIfaceModemCdma *self,
|
|||||||
GAsyncResult *res,
|
GAsyncResult *res,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
return !g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error);
|
return g_task_propagate_boolean (G_TASK (res), error);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -1775,6 +1768,7 @@ mm_iface_modem_cdma_initialize (MMIfaceModemCdma *self,
|
|||||||
{
|
{
|
||||||
InitializationContext *ctx;
|
InitializationContext *ctx;
|
||||||
MmGdbusModemCdma *skeleton = NULL;
|
MmGdbusModemCdma *skeleton = NULL;
|
||||||
|
GTask *task;
|
||||||
|
|
||||||
/* Did we already create it? */
|
/* Did we already create it? */
|
||||||
g_object_get (self,
|
g_object_get (self,
|
||||||
@@ -1806,16 +1800,13 @@ mm_iface_modem_cdma_initialize (MMIfaceModemCdma *self,
|
|||||||
/* Perform async initialization here */
|
/* Perform async initialization here */
|
||||||
|
|
||||||
ctx = g_new0 (InitializationContext, 1);
|
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,
|
|
||||||
mm_iface_modem_cdma_initialize);
|
|
||||||
ctx->step = INITIALIZATION_STEP_FIRST;
|
ctx->step = INITIALIZATION_STEP_FIRST;
|
||||||
ctx->skeleton = skeleton;
|
ctx->skeleton = skeleton;
|
||||||
|
|
||||||
interface_initialization_step (ctx);
|
task = g_task_new (self, cancellable, callback, user_data);
|
||||||
|
g_task_set_task_data (task, ctx, (GDestroyNotify)initialization_context_free);
|
||||||
|
|
||||||
|
interface_initialization_step (task);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
Reference in New Issue
Block a user