altair-lte: port load_supported_bands to use GTask

This commit is contained in:
Ben Chan
2017-07-18 22:33:23 -07:00
committed by Aleksander Morgado
parent 4ea38c26e0
commit 2d82c505e4

View File

@@ -248,11 +248,7 @@ load_supported_bands_finish (MMIfaceModem *self,
GAsyncResult *res, GAsyncResult *res,
GError **error) GError **error)
{ {
if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error)) return g_task_propagate_pointer (G_TASK (res), error);
return NULL;
return (GArray *) g_array_ref (g_simple_async_result_get_op_res_gpointer (
G_SIMPLE_ASYNC_RESULT (res)));
} }
#define BANDCAP_TAG "%BANDCAP: " #define BANDCAP_TAG "%BANDCAP: "
@@ -260,7 +256,7 @@ load_supported_bands_finish (MMIfaceModem *self,
static void static void
load_supported_bands_done (MMIfaceModem *self, load_supported_bands_done (MMIfaceModem *self,
GAsyncResult *res, GAsyncResult *res,
GSimpleAsyncResult *operation_result) GTask *task)
{ {
GArray *bands; GArray *bands;
const gchar *response; const gchar *response;
@@ -269,9 +265,8 @@ load_supported_bands_done (MMIfaceModem *self,
response = mm_base_modem_at_command_finish (MM_BASE_MODEM (self), res, &error); response = mm_base_modem_at_command_finish (MM_BASE_MODEM (self), res, &error);
if (!response) { if (!response) {
mm_dbg ("Couldn't query supported bands: '%s'", error->message); mm_dbg ("Couldn't query supported bands: '%s'", error->message);
g_simple_async_result_take_error (operation_result, error); g_task_return_error (task, error);
g_simple_async_result_complete_in_idle (operation_result); g_object_unref (task);
g_object_unref (operation_result);
return; return;
} }
@@ -283,21 +278,17 @@ load_supported_bands_done (MMIfaceModem *self,
bands = mm_altair_parse_bands_response (response); bands = mm_altair_parse_bands_response (response);
if (!bands) { if (!bands) {
mm_dbg ("Failed to parse supported bands response"); mm_dbg ("Failed to parse supported bands response");
g_simple_async_result_set_error ( g_task_return_new_error (
operation_result, task,
MM_CORE_ERROR, MM_CORE_ERROR,
MM_CORE_ERROR_FAILED, MM_CORE_ERROR_FAILED,
"Failed to parse supported bands response"); "Failed to parse supported bands response");
g_simple_async_result_complete_in_idle (operation_result); g_object_unref (task);
g_object_unref (operation_result);
return; return;
} }
g_simple_async_result_set_op_res_gpointer (operation_result, g_task_return_pointer (task, bands, (GDestroyNotify)g_array_unref);
bands, g_object_unref (task);
(GDestroyNotify)g_array_unref);
g_simple_async_result_complete_in_idle (operation_result);
g_object_unref (operation_result);
} }
static void static void
@@ -305,12 +296,9 @@ load_supported_bands (MMIfaceModem *self,
GAsyncReadyCallback callback, GAsyncReadyCallback callback,
gpointer user_data) gpointer user_data)
{ {
GSimpleAsyncResult *result; GTask *task;
result = g_simple_async_result_new (G_OBJECT (self), task = g_task_new (self, NULL, callback, user_data);
callback,
user_data,
load_supported_bands);
mm_base_modem_at_command ( mm_base_modem_at_command (
MM_BASE_MODEM (self), MM_BASE_MODEM (self),
@@ -318,7 +306,7 @@ load_supported_bands (MMIfaceModem *self,
3, 3,
FALSE, FALSE,
(GAsyncReadyCallback)load_supported_bands_done, (GAsyncReadyCallback)load_supported_bands_done,
result); task);
} }
/*****************************************************************************/ /*****************************************************************************/