aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Chan <benchan@chromium.org>2017-09-12 03:57:10 -0700
committerAleksander Morgado <aleksander@aleksander.es>2017-09-13 16:36:49 +0200
commitd6bd83e5cfc0fe684cf96f254415fe7458860a24 (patch)
tree2c5bb00873117fd93eeb2773a2b7a7be10c40220
parent6612ffcb8b264e83acc814fccc112f761f535ecd (diff)
icera: port modem_set_current_bands to use GTask
-rw-r--r--plugins/icera/mm-broadband-modem-icera.c56
1 files changed, 26 insertions, 30 deletions
diff --git a/plugins/icera/mm-broadband-modem-icera.c b/plugins/icera/mm-broadband-modem-icera.c
index d2d81394..7b4fe97c 100644
--- a/plugins/icera/mm-broadband-modem-icera.c
+++ b/plugins/icera/mm-broadband-modem-icera.c
@@ -1424,7 +1424,6 @@ modem_load_current_bands (MMIfaceModem *self,
/* Set current bands (Modem interface) */
typedef struct {
- GSimpleAsyncResult *result;
guint bandbits;
guint enablebits;
guint disablebits;
@@ -1442,43 +1441,38 @@ modem_set_current_bands_finish (MMIfaceModem *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 set_one_band (MMIfaceModem *self, SetCurrentBandsContext *ctx);
-
-static void
-set_current_bands_context_complete_and_free (SetCurrentBandsContext *ctx)
-{
- g_simple_async_result_complete (ctx->result);
- g_object_unref (ctx->result);
- g_slice_free (SetCurrentBandsContext, ctx);
-}
+static void set_one_band (MMIfaceModem *self, GTask *task);
static void
set_current_bands_next (MMIfaceModem *self,
GAsyncResult *res,
- SetCurrentBandsContext *ctx)
+ GTask *task)
{
GError *error = NULL;
if (!mm_base_modem_at_command_finish (MM_BASE_MODEM (self), res, &error)) {
mm_dbg ("Couldn't set current bands: '%s'", error->message);
- g_simple_async_result_take_error (ctx->result, error);
- set_current_bands_context_complete_and_free (ctx);
+ g_task_return_error (task, error);
+ g_object_unref (task);
return;
}
- set_one_band (self, ctx);
+ set_one_band (self, task);
}
static void
set_one_band (MMIfaceModem *self,
- SetCurrentBandsContext *ctx)
+ GTask *task)
{
+ SetCurrentBandsContext *ctx;
guint enable, band;
gchar *command;
+ ctx = g_task_get_task_data (task);
+
/* Find the next band to enable or disable, always doing enables first */
enable = 1;
band = ffs (ctx->enablebits);
@@ -1488,8 +1482,8 @@ set_one_band (MMIfaceModem *self,
}
if (band == 0) {
/* Both enabling and disabling are done */
- g_simple_async_result_set_op_res_gboolean (ctx->result, TRUE);
- set_current_bands_context_complete_and_free (ctx);
+ g_task_return_boolean (task, TRUE);
+ g_object_unref (task);
return;
}
@@ -1514,7 +1508,7 @@ set_one_band (MMIfaceModem *self,
10,
FALSE,
(GAsyncReadyCallback)set_current_bands_next,
- ctx);
+ task);
g_free (command);
}
@@ -1542,24 +1536,26 @@ band_array_to_bandbits (GArray *bands)
static void
set_current_bands_got_current_bands (MMIfaceModem *self,
GAsyncResult *res,
- SetCurrentBandsContext *ctx)
+ GTask *task)
{
+ SetCurrentBandsContext *ctx;
GArray *bands;
GError *error = NULL;
guint currentbits;
bands = modem_load_current_bands_finish (self, res, &error);
if (!bands) {
- g_simple_async_result_take_error (ctx->result, error);
- set_current_bands_context_complete_and_free (ctx);
+ g_task_return_error (task, error);
+ g_object_unref (task);
return;
}
+ ctx = g_task_get_task_data (task);
currentbits = band_array_to_bandbits (bands);
ctx->enablebits = ctx->bandbits & ~currentbits;
ctx->disablebits = currentbits & ~ctx->bandbits;
- set_one_band (self, ctx);
+ set_one_band (self, task);
}
static void
@@ -1569,27 +1565,27 @@ modem_set_current_bands (MMIfaceModem *self,
gpointer user_data)
{
SetCurrentBandsContext *ctx;
+ GTask *task;
- ctx = g_slice_new0 (SetCurrentBandsContext);
- ctx->result = g_simple_async_result_new (G_OBJECT (self),
- callback,
- user_data,
- modem_set_current_bands);
+ ctx = g_new0 (SetCurrentBandsContext, 1);
ctx->bandbits = band_array_to_bandbits (bands_array);
+ task = g_task_new (self, NULL, callback, user_data);
+ g_task_set_task_data (task, ctx, g_free);
+
/*
* If ANY is requested, simply enable ANY to activate all bands except for
* those forbidden. */
if (ctx->bandbits & modem_band_any_bit) {
ctx->enablebits = modem_band_any_bit;
ctx->disablebits = 0;
- set_one_band (self, ctx);
+ set_one_band (self, task);
return;
}
modem_load_current_bands (self,
(GAsyncReadyCallback)set_current_bands_got_current_bands,
- ctx);
+ task);
}
/*****************************************************************************/