iface-modem-3gpp-ussd: port mm_iface_modem_3gpp_ussd_disable to use GTask

This commit is contained in:
Ben Chan
2017-06-28 09:30:03 -07:00
committed by Aleksander Morgado
parent bee90dc103
commit 04425e8ee0

View File

@@ -459,7 +459,7 @@ mm_iface_modem_3gpp_ussd_update_network_request (MMIfaceModem3gppUssd *self,
/*****************************************************************************/ /*****************************************************************************/
typedef struct _DisablingContext DisablingContext; typedef struct _DisablingContext DisablingContext;
static void interface_disabling_step (DisablingContext *ctx); static void interface_disabling_step (GTask *task);
typedef enum { typedef enum {
DISABLING_STEP_FIRST, DISABLING_STEP_FIRST,
@@ -469,18 +469,13 @@ typedef enum {
} DisablingStep; } DisablingStep;
struct _DisablingContext { struct _DisablingContext {
MMIfaceModem3gppUssd *self;
DisablingStep step; DisablingStep step;
GSimpleAsyncResult *result;
MmGdbusModem3gppUssd *skeleton; MmGdbusModem3gppUssd *skeleton;
}; };
static void static void
disabling_context_complete_and_free (DisablingContext *ctx) disabling_context_free (DisablingContext *ctx)
{ {
g_simple_async_result_complete_in_idle (ctx->result);
g_object_unref (ctx->self);
g_object_unref (ctx->result);
if (ctx->skeleton) if (ctx->skeleton)
g_object_unref (ctx->skeleton); g_object_unref (ctx->skeleton);
g_free (ctx); g_free (ctx);
@@ -491,14 +486,15 @@ mm_iface_modem_3gpp_ussd_disable_finish (MMIfaceModem3gppUssd *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);
} }
static void static void
disable_unsolicited_result_codes_ready (MMIfaceModem3gppUssd *self, disable_unsolicited_result_codes_ready (MMIfaceModem3gppUssd *self,
GAsyncResult *res, GAsyncResult *res,
DisablingContext *ctx) GTask *task)
{ {
DisablingContext *ctx;
GError *error = NULL; GError *error = NULL;
MM_IFACE_MODEM_3GPP_USSD_GET_INTERFACE (self)->disable_unsolicited_result_codes_finish (self, MM_IFACE_MODEM_3GPP_USSD_GET_INTERFACE (self)->disable_unsolicited_result_codes_finish (self,
@@ -511,15 +507,17 @@ disable_unsolicited_result_codes_ready (MMIfaceModem3gppUssd *self,
} }
/* Go on to next step */ /* Go on to next step */
ctx = g_task_get_task_data (task);
ctx->step++; ctx->step++;
interface_disabling_step (ctx); interface_disabling_step (task);
} }
static void static void
cleanup_unsolicited_result_codes_ready (MMIfaceModem3gppUssd *self, cleanup_unsolicited_result_codes_ready (MMIfaceModem3gppUssd *self,
GAsyncResult *res, GAsyncResult *res,
DisablingContext *ctx) GTask *task)
{ {
DisablingContext *ctx;
GError *error = NULL; GError *error = NULL;
MM_IFACE_MODEM_3GPP_USSD_GET_INTERFACE (self)->cleanup_unsolicited_result_codes_finish (self, MM_IFACE_MODEM_3GPP_USSD_GET_INTERFACE (self)->cleanup_unsolicited_result_codes_finish (self,
@@ -532,38 +530,45 @@ cleanup_unsolicited_result_codes_ready (MMIfaceModem3gppUssd *self,
} }
/* Go on to next step */ /* Go on to next step */
ctx = g_task_get_task_data (task);
ctx->step++; ctx->step++;
interface_disabling_step (ctx); interface_disabling_step (task);
} }
static void static void
interface_disabling_step (DisablingContext *ctx) interface_disabling_step (GTask *task)
{ {
MMIfaceModem3gppUssd *self;
DisablingContext *ctx;
self = g_task_get_source_object (task);
ctx = g_task_get_task_data (task);
switch (ctx->step) { switch (ctx->step) {
case DISABLING_STEP_FIRST: case DISABLING_STEP_FIRST:
/* Fall down to next step */ /* Fall down to next step */
ctx->step++; ctx->step++;
case DISABLING_STEP_DISABLE_UNSOLICITED_RESULT_CODES: case DISABLING_STEP_DISABLE_UNSOLICITED_RESULT_CODES:
MM_IFACE_MODEM_3GPP_USSD_GET_INTERFACE (ctx->self)->disable_unsolicited_result_codes ( MM_IFACE_MODEM_3GPP_USSD_GET_INTERFACE (self)->disable_unsolicited_result_codes (
ctx->self, self,
(GAsyncReadyCallback)disable_unsolicited_result_codes_ready, (GAsyncReadyCallback)disable_unsolicited_result_codes_ready,
ctx); task);
return; return;
case DISABLING_STEP_CLEANUP_UNSOLICITED_RESULT_CODES: case DISABLING_STEP_CLEANUP_UNSOLICITED_RESULT_CODES:
MM_IFACE_MODEM_3GPP_USSD_GET_INTERFACE (ctx->self)->cleanup_unsolicited_result_codes ( MM_IFACE_MODEM_3GPP_USSD_GET_INTERFACE (self)->cleanup_unsolicited_result_codes (
ctx->self, self,
(GAsyncReadyCallback)cleanup_unsolicited_result_codes_ready, (GAsyncReadyCallback)cleanup_unsolicited_result_codes_ready,
ctx); task);
return; return;
case DISABLING_STEP_LAST: case DISABLING_STEP_LAST:
/* We are done without errors! */ /* 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_UNKNOWN); MM_MODEM_3GPP_USSD_SESSION_STATE_UNKNOWN);
g_simple_async_result_set_op_res_gboolean (ctx->result, TRUE); g_task_return_boolean (task, TRUE);
disabling_context_complete_and_free (ctx); g_object_unref (task);
return; return;
} }
@@ -576,27 +581,27 @@ mm_iface_modem_3gpp_ussd_disable (MMIfaceModem3gppUssd *self,
gpointer user_data) gpointer user_data)
{ {
DisablingContext *ctx; DisablingContext *ctx;
GTask *task;
ctx = g_new0 (DisablingContext, 1); ctx = g_new0 (DisablingContext, 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_disable);
ctx->step = DISABLING_STEP_FIRST; ctx->step = DISABLING_STEP_FIRST;
g_object_get (ctx->self,
task = g_task_new (self, NULL, callback, user_data);
g_task_set_task_data (task, ctx, (GDestroyNotify)disabling_context_free);
g_object_get (self,
MM_IFACE_MODEM_3GPP_USSD_DBUS_SKELETON, &ctx->skeleton, MM_IFACE_MODEM_3GPP_USSD_DBUS_SKELETON, &ctx->skeleton,
NULL); NULL);
if (!ctx->skeleton) { if (!ctx->skeleton) {
g_simple_async_result_set_error (ctx->result, g_task_return_new_error (task,
MM_CORE_ERROR, MM_CORE_ERROR,
MM_CORE_ERROR_FAILED, MM_CORE_ERROR_FAILED,
"Couldn't get interface skeleton"); "Couldn't get interface skeleton");
disabling_context_complete_and_free (ctx); g_object_unref (task);
return; return;
} }
interface_disabling_step (ctx); interface_disabling_step (task);
} }
/*****************************************************************************/ /*****************************************************************************/