altair-lte: port load_current_bands to use GTask

This commit is contained in:
Ben Chan
2017-07-19 17:26:40 +02:00
committed by Aleksander Morgado
parent 2d82c505e4
commit 282ed056a6
+12 -24
View File
@@ -317,11 +317,7 @@ load_current_bands_finish (MMIfaceModem *self,
GAsyncResult *res,
GError **error)
{
if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error))
return NULL;
return (GArray *) g_array_ref (g_simple_async_result_get_op_res_gpointer (
G_SIMPLE_ASYNC_RESULT (res)));
return g_task_propagate_pointer (G_TASK (res), error);
}
#define CFGBANDS_TAG "Bands: "
@@ -329,7 +325,7 @@ load_current_bands_finish (MMIfaceModem *self,
static void
load_current_bands_done (MMIfaceModem *self,
GAsyncResult *res,
GSimpleAsyncResult *operation_result)
GTask *task)
{
GArray *bands;
const gchar *response;
@@ -338,9 +334,8 @@ load_current_bands_done (MMIfaceModem *self,
response = mm_base_modem_at_command_finish (MM_BASE_MODEM (self), res, &error);
if (!response) {
mm_dbg ("Couldn't query current bands: '%s'", error->message);
g_simple_async_result_take_error (operation_result, error);
g_simple_async_result_complete_in_idle (operation_result);
g_object_unref (operation_result);
g_task_return_error (task, error);
g_object_unref (task);
return;
}
@@ -352,21 +347,17 @@ load_current_bands_done (MMIfaceModem *self,
bands = mm_altair_parse_bands_response (response);
if (!bands) {
mm_dbg ("Failed to parse current bands response");
g_simple_async_result_set_error (
operation_result,
g_task_return_new_error (
task,
MM_CORE_ERROR,
MM_CORE_ERROR_FAILED,
"Failed to parse current bands response");
g_simple_async_result_complete_in_idle (operation_result);
g_object_unref (operation_result);
g_object_unref (task);
return;
}
g_simple_async_result_set_op_res_gpointer (operation_result,
bands,
(GDestroyNotify)g_array_unref);
g_simple_async_result_complete_in_idle (operation_result);
g_object_unref (operation_result);
g_task_return_pointer (task, bands, (GDestroyNotify)g_array_unref);
g_object_unref (task);
}
static void
@@ -374,12 +365,9 @@ load_current_bands (MMIfaceModem *self,
GAsyncReadyCallback callback,
gpointer user_data)
{
GSimpleAsyncResult *result;
GTask *task;
result = g_simple_async_result_new (G_OBJECT (self),
callback,
user_data,
load_current_bands);
task = g_task_new (self, NULL, callback, user_data);
mm_base_modem_at_command (
MM_BASE_MODEM (self),
@@ -387,7 +375,7 @@ load_current_bands (MMIfaceModem *self,
3,
FALSE,
(GAsyncReadyCallback)load_current_bands_done,
result);
task);
}
/*****************************************************************************/