wavecom: port load_current_bands to use GTask

This commit is contained in:
Aleksander Morgado
2017-09-07 19:23:11 +02:00
parent e2b3b87674
commit dd4ef7dc23

View File

@@ -606,33 +606,27 @@ load_supported_bands (MMIfaceModem *self,
/* Load current bands (Modem interface) */ /* Load current bands (Modem interface) */
static GArray * static GArray *
load_current_bands_finish (MMIfaceModem *self, load_current_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)));
} }
static void static void
get_2g_band_ready (MMBroadbandModemWavecom *self, get_2g_band_ready (MMBaseModem *self,
GAsyncResult *res, GAsyncResult *res,
GSimpleAsyncResult *operation_result) GTask *task)
{ {
const gchar *response; const gchar *response;
const gchar *p; const gchar *p;
GError *error = NULL; GError *error = NULL;
GArray *bands_array = NULL; GArray *bands_array = NULL;
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) {
/* Let the error be critical. */ g_task_return_error (task, error);
g_simple_async_result_take_error (operation_result, error); g_object_unref (task);
g_simple_async_result_complete (operation_result);
g_object_unref (operation_result);
return; return;
} }
@@ -654,37 +648,31 @@ get_2g_band_ready (MMBroadbandModemWavecom *self,
} }
if (!bands_array) if (!bands_array)
g_simple_async_result_set_error (operation_result, g_task_return_new_error (task,
MM_CORE_ERROR, MM_CORE_ERROR,
MM_CORE_ERROR_FAILED, MM_CORE_ERROR_FAILED,
"Couldn't parse current bands reply: '%s'", "Couldn't parse current bands reply: '%s'",
response); response);
else else
g_simple_async_result_set_op_res_gpointer (operation_result, g_task_return_pointer (task, bands_array, (GDestroyNotify)g_array_unref);
bands_array, g_object_unref (task);
(GDestroyNotify)g_array_unref);
g_simple_async_result_complete (operation_result);
g_object_unref (operation_result);
} }
static void static void
get_3g_band_ready (MMBroadbandModemWavecom *self, get_3g_band_ready (MMBaseModem *self,
GAsyncResult *res, GAsyncResult *res,
GSimpleAsyncResult *operation_result) GTask *task)
{ {
const gchar *response; const gchar *response;
const gchar *p; const gchar *p;
GError *error = NULL; GError *error = NULL;
GArray *bands_array = NULL; GArray *bands_array = NULL;
guint32 wavecom_band; guint32 wavecom_band;
response = mm_base_modem_at_command_finish (MM_BASE_MODEM (self), res, &error); response = mm_base_modem_at_command_finish (self, res, &error);
if (!response) { if (!response) {
/* Let the error be critical. */ g_task_return_error (task, error);
g_simple_async_result_take_error (operation_result, error); g_object_unref (task);
g_simple_async_result_complete (operation_result);
g_object_unref (operation_result);
return; return;
} }
@@ -713,18 +701,14 @@ get_3g_band_ready (MMBroadbandModemWavecom *self,
} }
if (!bands_array) if (!bands_array)
g_simple_async_result_set_error (operation_result, g_task_return_new_error (task,
MM_CORE_ERROR, MM_CORE_ERROR,
MM_CORE_ERROR_FAILED, MM_CORE_ERROR_FAILED,
"Couldn't parse current bands reply: '%s'", "Couldn't parse current bands reply: '%s'",
response); response);
else else
g_simple_async_result_set_op_res_gpointer (operation_result, g_task_return_pointer (task, bands_array, (GDestroyNotify)g_array_unref);
bands_array, g_object_unref (task);
(GDestroyNotify)g_array_unref);
g_simple_async_result_complete (operation_result);
g_object_unref (operation_result);
} }
static void static void
@@ -732,12 +716,9 @@ load_current_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_current_bands);
if (mm_iface_modem_is_3g (self)) if (mm_iface_modem_is_3g (self))
mm_base_modem_at_command (MM_BASE_MODEM (self), mm_base_modem_at_command (MM_BASE_MODEM (self),
@@ -745,14 +726,14 @@ load_current_bands (MMIfaceModem *self,
3, 3,
FALSE, FALSE,
(GAsyncReadyCallback)get_3g_band_ready, (GAsyncReadyCallback)get_3g_band_ready,
result); task);
else else
mm_base_modem_at_command (MM_BASE_MODEM (self), mm_base_modem_at_command (MM_BASE_MODEM (self),
"AT+WMBS?", "AT+WMBS?",
3, 3,
FALSE, FALSE,
(GAsyncReadyCallback)get_2g_band_ready, (GAsyncReadyCallback)get_2g_band_ready,
result); task);
} }
/*****************************************************************************/ /*****************************************************************************/