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