[PATCH 2/3] iface-modem-3gpp-ussd: port mm_iface_modem_3gpp_ussd_enable to use GTask
Ben Chan
benchan at chromium.org
Wed Jun 28 16:30:02 UTC 2017
---
src/mm-iface-modem-3gpp-ussd.c | 73 ++++++++++++++++++++++--------------------
1 file changed, 39 insertions(+), 34 deletions(-)
diff --git a/src/mm-iface-modem-3gpp-ussd.c b/src/mm-iface-modem-3gpp-ussd.c
index 9dd4150f..ff6168d1 100644
--- a/src/mm-iface-modem-3gpp-ussd.c
+++ b/src/mm-iface-modem-3gpp-ussd.c
@@ -602,7 +602,7 @@ mm_iface_modem_3gpp_ussd_disable (MMIfaceModem3gppUssd *self,
/*****************************************************************************/
typedef struct _EnablingContext EnablingContext;
-static void interface_enabling_step (EnablingContext *ctx);
+static void interface_enabling_step (GTask *task);
typedef enum {
ENABLING_STEP_FIRST,
@@ -612,18 +612,13 @@ typedef enum {
} EnablingStep;
struct _EnablingContext {
- MMIfaceModem3gppUssd *self;
EnablingStep step;
- GSimpleAsyncResult *result;
MmGdbusModem3gppUssd *skeleton;
};
static void
-enabling_context_complete_and_free (EnablingContext *ctx)
+enabling_context_free (EnablingContext *ctx)
{
- g_simple_async_result_complete_in_idle (ctx->result);
- g_object_unref (ctx->self);
- g_object_unref (ctx->result);
if (ctx->skeleton)
g_object_unref (ctx->skeleton);
g_free (ctx);
@@ -634,14 +629,15 @@ mm_iface_modem_3gpp_ussd_enable_finish (MMIfaceModem3gppUssd *self,
GAsyncResult *res,
GError **error)
{
- return !g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error);
+ return g_task_propagate_boolean (G_TASK (res), error);
}
static void
setup_unsolicited_result_codes_ready (MMIfaceModem3gppUssd *self,
GAsyncResult *res,
- EnablingContext *ctx)
+ GTask *task)
{
+ EnablingContext *ctx;
GError *error = NULL;
MM_IFACE_MODEM_3GPP_USSD_GET_INTERFACE (self)->setup_unsolicited_result_codes_finish (self,
@@ -654,15 +650,17 @@ setup_unsolicited_result_codes_ready (MMIfaceModem3gppUssd *self,
}
/* Go on to next step */
+ ctx = g_task_get_task_data (task);
ctx->step++;
- interface_enabling_step (ctx);
+ interface_enabling_step (task);
}
static void
enable_unsolicited_result_codes_ready (MMIfaceModem3gppUssd *self,
GAsyncResult *res,
- EnablingContext *ctx)
+ GTask *task)
{
+ EnablingContext *ctx;
GError *error = NULL;
MM_IFACE_MODEM_3GPP_USSD_GET_INTERFACE (self)->enable_unsolicited_result_codes_finish (self,
@@ -675,38 +673,45 @@ enable_unsolicited_result_codes_ready (MMIfaceModem3gppUssd *self,
}
/* Go on to next step */
+ ctx = g_task_get_task_data (task);
ctx->step++;
- interface_enabling_step (ctx);
+ interface_enabling_step (task);
}
static void
-interface_enabling_step (EnablingContext *ctx)
+interface_enabling_step (GTask *task)
{
+ MMIfaceModem3gppUssd *self;
+ EnablingContext *ctx;
+
+ self = g_task_get_source_object (task);
+ ctx = g_task_get_task_data (task);
+
switch (ctx->step) {
case ENABLING_STEP_FIRST:
/* Fall down to next step */
ctx->step++;
case ENABLING_STEP_SETUP_UNSOLICITED_RESULT_CODES:
- MM_IFACE_MODEM_3GPP_USSD_GET_INTERFACE (ctx->self)->setup_unsolicited_result_codes (
- ctx->self,
+ MM_IFACE_MODEM_3GPP_USSD_GET_INTERFACE (self)->setup_unsolicited_result_codes (
+ self,
(GAsyncReadyCallback)setup_unsolicited_result_codes_ready,
- ctx);
+ task);
return;
case ENABLING_STEP_ENABLE_UNSOLICITED_RESULT_CODES:
- MM_IFACE_MODEM_3GPP_USSD_GET_INTERFACE (ctx->self)->enable_unsolicited_result_codes (
- ctx->self,
+ MM_IFACE_MODEM_3GPP_USSD_GET_INTERFACE (self)->enable_unsolicited_result_codes (
+ self,
(GAsyncReadyCallback)enable_unsolicited_result_codes_ready,
- ctx);
+ task);
return;
case ENABLING_STEP_LAST:
/* We are done without errors! */
- mm_iface_modem_3gpp_ussd_update_state (MM_IFACE_MODEM_3GPP_USSD (ctx->self),
+ mm_iface_modem_3gpp_ussd_update_state (MM_IFACE_MODEM_3GPP_USSD (self),
MM_MODEM_3GPP_USSD_SESSION_STATE_IDLE);
- g_simple_async_result_set_op_res_gboolean (ctx->result, TRUE);
- enabling_context_complete_and_free (ctx);
+ g_task_return_boolean (task, TRUE);
+ g_object_unref (task);
return;
}
@@ -719,27 +724,27 @@ mm_iface_modem_3gpp_ussd_enable (MMIfaceModem3gppUssd *self,
gpointer user_data)
{
EnablingContext *ctx;
+ GTask *task;
ctx = g_new0 (EnablingContext, 1);
- ctx->self = g_object_ref (self);
- ctx->result = g_simple_async_result_new (G_OBJECT (self),
- callback,
- user_data,
- mm_iface_modem_3gpp_ussd_enable);
ctx->step = ENABLING_STEP_FIRST;
- g_object_get (ctx->self,
+
+ task = g_task_new (self, NULL, callback, user_data);
+ g_task_set_task_data (task, ctx, (GDestroyNotify)enabling_context_free);
+
+ g_object_get (self,
MM_IFACE_MODEM_3GPP_USSD_DBUS_SKELETON, &ctx->skeleton,
NULL);
if (!ctx->skeleton) {
- g_simple_async_result_set_error (ctx->result,
- MM_CORE_ERROR,
- MM_CORE_ERROR_FAILED,
- "Couldn't get interface skeleton");
- enabling_context_complete_and_free (ctx);
+ g_task_return_new_error (task,
+ MM_CORE_ERROR,
+ MM_CORE_ERROR_FAILED,
+ "Couldn't get interface skeleton");
+ g_object_unref (task);
return;
}
- interface_enabling_step (ctx);
+ interface_enabling_step (task);
}
/*****************************************************************************/
--
2.13.2.725.g09c95d1e9-goog
More information about the ModemManager-devel
mailing list