broadband-modem-qmi: port modem_load_current_bands to use GTask

This commit is contained in:
Ben Chan
2018-04-28 11:10:37 -07:00
committed by Aleksander Morgado
parent 834674b21c
commit 6b14a1cf1b

View File

@@ -2153,11 +2153,7 @@ modem_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)));
} }
#if defined WITH_NEWEST_QMI_COMMANDS #if defined WITH_NEWEST_QMI_COMMANDS
@@ -2165,7 +2161,7 @@ modem_load_current_bands_finish (MMIfaceModem *self,
static void static void
nas_get_rf_band_information_ready (QmiClientNas *client, nas_get_rf_band_information_ready (QmiClientNas *client,
GAsyncResult *res, GAsyncResult *res,
GSimpleAsyncResult *simple) GTask *task)
{ {
QmiMessageNasGetRfBandInformationOutput *output; QmiMessageNasGetRfBandInformationOutput *output;
GError *error = NULL; GError *error = NULL;
@@ -2173,10 +2169,10 @@ nas_get_rf_band_information_ready (QmiClientNas *client,
output = qmi_client_nas_get_rf_band_information_finish (client, res, &error); output = qmi_client_nas_get_rf_band_information_finish (client, res, &error);
if (!output) { if (!output) {
g_prefix_error (&error, "QMI operation failed: "); 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_nas_get_rf_band_information_output_get_result (output, &error)) { } else if (!qmi_message_nas_get_rf_band_information_output_get_result (output, &error)) {
g_prefix_error (&error, "Couldn't get current band information: "); g_prefix_error (&error, "Couldn't get current band information: ");
g_simple_async_result_take_error (simple, error); g_task_return_error (task, error);
} else { } else {
GArray *mm_bands; GArray *mm_bands;
GArray *info_array = NULL; GArray *info_array = NULL;
@@ -2187,22 +2183,19 @@ nas_get_rf_band_information_ready (QmiClientNas *client,
if (mm_bands->len == 0) { if (mm_bands->len == 0) {
g_array_unref (mm_bands); g_array_unref (mm_bands);
g_simple_async_result_set_error (simple, g_task_return_new_error (task,
MM_CORE_ERROR, MM_CORE_ERROR,
MM_CORE_ERROR_FAILED, MM_CORE_ERROR_FAILED,
"Couldn't parse the list of current bands"); "Couldn't parse the list of current bands");
} else { } else {
g_simple_async_result_set_op_res_gpointer (simple, g_task_return_pointer (task, mm_bands, (GDestroyNotify)g_array_unref);
mm_bands,
(GDestroyNotify)g_array_unref);
} }
} }
if (output) if (output)
qmi_message_nas_get_rf_band_information_output_unref (output); qmi_message_nas_get_rf_band_information_output_unref (output);
g_simple_async_result_complete (simple); g_object_unref (task);
g_object_unref (simple);
} }
#endif /* WITH_NEWEST_QMI_COMMANDS */ #endif /* WITH_NEWEST_QMI_COMMANDS */
@@ -2210,7 +2203,7 @@ nas_get_rf_band_information_ready (QmiClientNas *client,
static void static void
load_bands_get_system_selection_preference_ready (QmiClientNas *client, load_bands_get_system_selection_preference_ready (QmiClientNas *client,
GAsyncResult *res, GAsyncResult *res,
GSimpleAsyncResult *simple) GTask *task)
{ {
QmiMessageNasGetSystemSelectionPreferenceOutput *output = NULL; QmiMessageNasGetSystemSelectionPreferenceOutput *output = NULL;
GError *error = NULL; GError *error = NULL;
@@ -2218,10 +2211,10 @@ load_bands_get_system_selection_preference_ready (QmiClientNas *client,
output = qmi_client_nas_get_system_selection_preference_finish (client, res, &error); output = qmi_client_nas_get_system_selection_preference_finish (client, res, &error);
if (!output) { if (!output) {
g_prefix_error (&error, "QMI operation failed: "); 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_nas_get_system_selection_preference_output_get_result (output, &error)) { } else if (!qmi_message_nas_get_system_selection_preference_output_get_result (output, &error)) {
g_prefix_error (&error, "Couldn't get system selection preference: "); g_prefix_error (&error, "Couldn't get system selection preference: ");
g_simple_async_result_take_error (simple, error); g_task_return_error (task, error);
} else { } else {
GArray *mm_bands; GArray *mm_bands;
QmiNasBandPreference band_preference_mask = 0; QmiNasBandPreference band_preference_mask = 0;
@@ -2242,10 +2235,10 @@ load_bands_get_system_selection_preference_ready (QmiClientNas *client,
if (mm_bands->len == 0) { if (mm_bands->len == 0) {
g_array_unref (mm_bands); g_array_unref (mm_bands);
g_simple_async_result_set_error (simple, g_task_return_new_error (task,
MM_CORE_ERROR, MM_CORE_ERROR,
MM_CORE_ERROR_FAILED, MM_CORE_ERROR_FAILED,
"Couldn't parse the list of current bands"); "Couldn't parse the list of current bands");
} else { } else {
gchar *str; gchar *str;
@@ -2253,17 +2246,14 @@ load_bands_get_system_selection_preference_ready (QmiClientNas *client,
mm_dbg ("Bands reported in system selection preference: '%s'", str); mm_dbg ("Bands reported in system selection preference: '%s'", str);
g_free (str); g_free (str);
g_simple_async_result_set_op_res_gpointer (simple, g_task_return_pointer (task, mm_bands, (GDestroyNotify)g_array_unref);
mm_bands,
(GDestroyNotify)g_array_unref);
} }
} }
if (output) if (output)
qmi_message_nas_get_system_selection_preference_output_unref (output); qmi_message_nas_get_system_selection_preference_output_unref (output);
g_simple_async_result_complete (simple); g_object_unref (task);
g_object_unref (simple);
} }
static void static void
@@ -2271,18 +2261,15 @@ modem_load_current_bands (MMIfaceModem *self,
GAsyncReadyCallback callback, GAsyncReadyCallback callback,
gpointer user_data) gpointer user_data)
{ {
GSimpleAsyncResult *result; GTask *task;
QmiClient *client = NULL; QmiClient *client = NULL;
if (!ensure_qmi_client (MM_BROADBAND_MODEM_QMI (self), if (!assure_qmi_client (MM_BROADBAND_MODEM_QMI (self),
QMI_SERVICE_NAS, &client, QMI_SERVICE_NAS, &client,
callback, user_data)) callback, user_data))
return; return;
result = g_simple_async_result_new (G_OBJECT (self), task = g_task_new (self, NULL, callback, user_data);
callback,
user_data,
modem_load_current_bands);
mm_dbg ("loading current bands..."); mm_dbg ("loading current bands...");
@@ -2294,7 +2281,7 @@ modem_load_current_bands (MMIfaceModem *self,
5, 5,
NULL, NULL,
(GAsyncReadyCallback)nas_get_rf_band_information_ready, (GAsyncReadyCallback)nas_get_rf_band_information_ready,
result); task);
return; return;
} }
#endif #endif
@@ -2305,7 +2292,7 @@ modem_load_current_bands (MMIfaceModem *self,
5, 5,
NULL, /* cancellable */ NULL, /* cancellable */
(GAsyncReadyCallback)load_bands_get_system_selection_preference_ready, (GAsyncReadyCallback)load_bands_get_system_selection_preference_ready,
result); task);
} }
/*****************************************************************************/ /*****************************************************************************/