broadband-modem-qmi: port modem_load_supported_bands to use GTask

This commit is contained in:
Ben Chan
2018-04-27 11:03:30 -07:00
committed by Aleksander Morgado
parent 59c8ba8642
commit 834674b21c

View File

@@ -2063,24 +2063,23 @@ modem_load_supported_bands_finish (MMIfaceModem *_self,
GError **error)
{
MMBroadbandModemQmi *self = MM_BROADBAND_MODEM_QMI (_self);
GArray *supported_bands;
if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error))
return NULL;
supported_bands = g_task_propagate_pointer (G_TASK (res), error);
if (supported_bands) {
if (self->priv->supported_bands)
g_array_unref (self->priv->supported_bands);
if (self->priv->supported_bands)
g_array_unref (self->priv->supported_bands);
/* Cache the supported bands value */
self->priv->supported_bands = g_array_ref (g_simple_async_result_get_op_res_gpointer (
G_SIMPLE_ASYNC_RESULT (res)));
return g_array_ref (self->priv->supported_bands);
/* Cache the supported bands value */
self->priv->supported_bands = g_array_ref (supported_bands);
}
return supported_bands;
}
static void
dms_get_band_capabilities_ready (QmiClientDms *client,
GAsyncResult *res,
GSimpleAsyncResult *simple)
GTask *task)
{
QmiMessageDmsGetBandCapabilitiesOutput *output;
GError *error = NULL;
@@ -2088,10 +2087,10 @@ dms_get_band_capabilities_ready (QmiClientDms *client,
output = qmi_client_dms_get_band_capabilities_finish (client, res, &error);
if (!output) {
g_prefix_error (&error, "QMI operation failed: ");
g_simple_async_result_take_error (simple, error);
g_task_return_error (task, error);
} else if (!qmi_message_dms_get_band_capabilities_output_get_result (output, &error)) {
g_prefix_error (&error, "Couldn't get band capabilities: ");
g_simple_async_result_take_error (simple, error);
g_task_return_error (task, error);
} else {
GArray *mm_bands;
QmiDmsBandCapability qmi_bands = 0;
@@ -2110,22 +2109,19 @@ dms_get_band_capabilities_ready (QmiClientDms *client,
if (mm_bands->len == 0) {
g_array_unref (mm_bands);
g_simple_async_result_set_error (simple,
MM_CORE_ERROR,
MM_CORE_ERROR_FAILED,
"Couldn't parse the list of supported bands");
g_task_return_new_error (task,
MM_CORE_ERROR,
MM_CORE_ERROR_FAILED,
"Couldn't parse the list of supported bands");
} else {
g_simple_async_result_set_op_res_gpointer (simple,
mm_bands,
(GDestroyNotify)g_array_unref);
g_task_return_pointer (task, mm_bands, (GDestroyNotify)g_array_unref);
}
}
if (output)
qmi_message_dms_get_band_capabilities_output_unref (output);
g_simple_async_result_complete (simple);
g_object_unref (simple);
g_object_unref (task);
}
static void
@@ -2133,26 +2129,20 @@ modem_load_supported_bands (MMIfaceModem *self,
GAsyncReadyCallback callback,
gpointer user_data)
{
GSimpleAsyncResult *result;
QmiClient *client = NULL;
if (!ensure_qmi_client (MM_BROADBAND_MODEM_QMI (self),
if (!assure_qmi_client (MM_BROADBAND_MODEM_QMI (self),
QMI_SERVICE_DMS, &client,
callback, user_data))
return;
result = g_simple_async_result_new (G_OBJECT (self),
callback,
user_data,
modem_load_supported_bands);
mm_dbg ("loading band capabilities...");
qmi_client_dms_get_band_capabilities (QMI_CLIENT_DMS (client),
NULL,
5,
NULL,
(GAsyncReadyCallback)dms_get_band_capabilities_ready,
result);
g_task_new (self, NULL, callback, user_data));
}
/*****************************************************************************/