broadband-modem-qmi: port set_current_capabilities to use GTask
This commit is contained in:

committed by
Aleksander Morgado

parent
bdc3729cba
commit
c0669e98ae
@@ -697,21 +697,16 @@ modem_load_supported_capabilities (MMIfaceModem *self,
|
|||||||
/* Current capabilities setting (Modem interface) */
|
/* Current capabilities setting (Modem interface) */
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
MMBroadbandModemQmi *self;
|
|
||||||
QmiClientNas *client;
|
QmiClientNas *client;
|
||||||
GSimpleAsyncResult *result;
|
|
||||||
MMModemCapability capabilities;
|
MMModemCapability capabilities;
|
||||||
gboolean run_set_system_selection_preference;
|
gboolean run_set_system_selection_preference;
|
||||||
gboolean run_set_technology_preference;
|
gboolean run_set_technology_preference;
|
||||||
} SetCurrentCapabilitiesContext;
|
} SetCurrentCapabilitiesContext;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
set_current_capabilities_context_complete_and_free (SetCurrentCapabilitiesContext *ctx)
|
set_current_capabilities_context_free (SetCurrentCapabilitiesContext *ctx)
|
||||||
{
|
{
|
||||||
g_simple_async_result_complete_in_idle (ctx->result);
|
|
||||||
g_object_unref (ctx->result);
|
|
||||||
g_object_unref (ctx->client);
|
g_object_unref (ctx->client);
|
||||||
g_object_unref (ctx->self);
|
|
||||||
g_slice_free (SetCurrentCapabilitiesContext, ctx);
|
g_slice_free (SetCurrentCapabilitiesContext, ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -720,42 +715,49 @@ set_current_capabilities_finish (MMIfaceModem *self,
|
|||||||
GAsyncResult *res,
|
GAsyncResult *res,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
return !g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error);
|
return g_task_propagate_boolean (G_TASK (res), error);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
capabilities_power_cycle_ready (MMBroadbandModemQmi *self,
|
capabilities_power_cycle_ready (MMBroadbandModemQmi *self,
|
||||||
GAsyncResult *res,
|
GAsyncResult *res,
|
||||||
SetCurrentCapabilitiesContext *ctx)
|
GTask *task)
|
||||||
{
|
{
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
|
|
||||||
if (!power_cycle_finish (self, res, &error))
|
if (!power_cycle_finish (self, res, &error))
|
||||||
g_simple_async_result_take_error (ctx->result, error);
|
g_task_return_error (task, error);
|
||||||
else
|
else
|
||||||
g_simple_async_result_set_op_res_gboolean (ctx->result, TRUE);
|
g_task_return_boolean (task, TRUE);
|
||||||
set_current_capabilities_context_complete_and_free (ctx);
|
|
||||||
|
g_object_unref (task);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
capabilities_power_cycle (SetCurrentCapabilitiesContext *ctx)
|
capabilities_power_cycle (GTask *task)
|
||||||
{
|
{
|
||||||
|
MMBroadbandModemQmi *self;
|
||||||
|
|
||||||
|
self = g_task_get_source_object (task);
|
||||||
|
|
||||||
/* Power cycle the modem */
|
/* Power cycle the modem */
|
||||||
power_cycle (ctx->self,
|
power_cycle (self,
|
||||||
(GAsyncReadyCallback)capabilities_power_cycle_ready,
|
(GAsyncReadyCallback)capabilities_power_cycle_ready,
|
||||||
ctx);
|
task);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void set_current_capabilities_context_step (SetCurrentCapabilitiesContext *ctx);
|
static void set_current_capabilities_context_step (GTask *task);
|
||||||
|
|
||||||
static void
|
static void
|
||||||
capabilities_set_technology_preference_ready (QmiClientNas *client,
|
capabilities_set_technology_preference_ready (QmiClientNas *client,
|
||||||
GAsyncResult *res,
|
GAsyncResult *res,
|
||||||
SetCurrentCapabilitiesContext *ctx)
|
GTask *task)
|
||||||
{
|
{
|
||||||
|
SetCurrentCapabilitiesContext *ctx;
|
||||||
QmiMessageNasSetTechnologyPreferenceOutput *output = NULL;
|
QmiMessageNasSetTechnologyPreferenceOutput *output = NULL;
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
|
|
||||||
|
ctx = g_task_get_task_data (task);
|
||||||
output = qmi_client_nas_set_technology_preference_finish (client, res, &error);
|
output = qmi_client_nas_set_technology_preference_finish (client, res, &error);
|
||||||
if (!output) {
|
if (!output) {
|
||||||
mm_dbg ("QMI operation failed: %s", error->message);
|
mm_dbg ("QMI operation failed: %s", error->message);
|
||||||
@@ -772,23 +774,25 @@ capabilities_set_technology_preference_ready (QmiClientNas *client,
|
|||||||
g_error_free (error);
|
g_error_free (error);
|
||||||
|
|
||||||
/* Good! now reboot the modem */
|
/* Good! now reboot the modem */
|
||||||
capabilities_power_cycle (ctx);
|
capabilities_power_cycle (task);
|
||||||
qmi_message_nas_set_technology_preference_output_unref (output);
|
qmi_message_nas_set_technology_preference_output_unref (output);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx->run_set_technology_preference = FALSE;
|
ctx->run_set_technology_preference = FALSE;
|
||||||
set_current_capabilities_context_step (ctx);
|
set_current_capabilities_context_step (task);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
capabilities_set_system_selection_preference_ready (QmiClientNas *client,
|
capabilities_set_system_selection_preference_ready (QmiClientNas *client,
|
||||||
GAsyncResult *res,
|
GAsyncResult *res,
|
||||||
SetCurrentCapabilitiesContext *ctx)
|
GTask *task)
|
||||||
{
|
{
|
||||||
|
SetCurrentCapabilitiesContext *ctx;
|
||||||
QmiMessageNasSetSystemSelectionPreferenceOutput *output = NULL;
|
QmiMessageNasSetSystemSelectionPreferenceOutput *output = NULL;
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
|
|
||||||
|
ctx = g_task_get_task_data (task);
|
||||||
output = qmi_client_nas_set_system_selection_preference_finish (client, res, &error);
|
output = qmi_client_nas_set_system_selection_preference_finish (client, res, &error);
|
||||||
if (!output) {
|
if (!output) {
|
||||||
mm_dbg ("QMI operation failed: %s", error->message);
|
mm_dbg ("QMI operation failed: %s", error->message);
|
||||||
@@ -799,19 +803,22 @@ capabilities_set_system_selection_preference_ready (QmiClientNas *client,
|
|||||||
qmi_message_nas_set_system_selection_preference_output_unref (output);
|
qmi_message_nas_set_system_selection_preference_output_unref (output);
|
||||||
} else {
|
} else {
|
||||||
/* Good! now reboot the modem */
|
/* Good! now reboot the modem */
|
||||||
capabilities_power_cycle (ctx);
|
capabilities_power_cycle (task);
|
||||||
qmi_message_nas_set_system_selection_preference_output_unref (output);
|
qmi_message_nas_set_system_selection_preference_output_unref (output);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Try with the deprecated command */
|
/* Try with the deprecated command */
|
||||||
ctx->run_set_system_selection_preference = FALSE;
|
ctx->run_set_system_selection_preference = FALSE;
|
||||||
set_current_capabilities_context_step (ctx);
|
set_current_capabilities_context_step (task);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
set_current_capabilities_context_step (SetCurrentCapabilitiesContext *ctx)
|
set_current_capabilities_context_step (GTask *task)
|
||||||
{
|
{
|
||||||
|
SetCurrentCapabilitiesContext *ctx;
|
||||||
|
|
||||||
|
ctx = g_task_get_task_data (task);
|
||||||
if (ctx->run_set_system_selection_preference) {
|
if (ctx->run_set_system_selection_preference) {
|
||||||
QmiMessageNasSetSystemSelectionPreferenceInput *input;
|
QmiMessageNasSetSystemSelectionPreferenceInput *input;
|
||||||
QmiNasRatModePreference pref;
|
QmiNasRatModePreference pref;
|
||||||
@@ -821,13 +828,13 @@ set_current_capabilities_context_step (SetCurrentCapabilitiesContext *ctx)
|
|||||||
gchar *str;
|
gchar *str;
|
||||||
|
|
||||||
str = mm_modem_capability_build_string_from_mask (ctx->capabilities);
|
str = mm_modem_capability_build_string_from_mask (ctx->capabilities);
|
||||||
g_simple_async_result_set_error (ctx->result,
|
g_task_return_new_error (task,
|
||||||
MM_CORE_ERROR,
|
MM_CORE_ERROR,
|
||||||
MM_CORE_ERROR_FAILED,
|
MM_CORE_ERROR_FAILED,
|
||||||
"Unhandled capabilities setting: '%s'",
|
"Unhandled capabilities setting: '%s'",
|
||||||
str);
|
str);
|
||||||
|
g_object_unref (task);
|
||||||
g_free (str);
|
g_free (str);
|
||||||
set_current_capabilities_context_complete_and_free (ctx);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -841,7 +848,7 @@ set_current_capabilities_context_step (SetCurrentCapabilitiesContext *ctx)
|
|||||||
5,
|
5,
|
||||||
NULL, /* cancellable */
|
NULL, /* cancellable */
|
||||||
(GAsyncReadyCallback)capabilities_set_system_selection_preference_ready,
|
(GAsyncReadyCallback)capabilities_set_system_selection_preference_ready,
|
||||||
ctx);
|
task);
|
||||||
qmi_message_nas_set_system_selection_preference_input_unref (input);
|
qmi_message_nas_set_system_selection_preference_input_unref (input);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -855,13 +862,13 @@ set_current_capabilities_context_step (SetCurrentCapabilitiesContext *ctx)
|
|||||||
gchar *str;
|
gchar *str;
|
||||||
|
|
||||||
str = mm_modem_capability_build_string_from_mask (ctx->capabilities);
|
str = mm_modem_capability_build_string_from_mask (ctx->capabilities);
|
||||||
g_simple_async_result_set_error (ctx->result,
|
g_task_return_new_error (task,
|
||||||
MM_CORE_ERROR,
|
MM_CORE_ERROR,
|
||||||
MM_CORE_ERROR_FAILED,
|
MM_CORE_ERROR_FAILED,
|
||||||
"Unhandled capabilities setting: '%s'",
|
"Unhandled capabilities setting: '%s'",
|
||||||
str);
|
str);
|
||||||
|
g_object_unref (task);
|
||||||
g_free (str);
|
g_free (str);
|
||||||
set_current_capabilities_context_complete_and_free (ctx);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -874,17 +881,16 @@ set_current_capabilities_context_step (SetCurrentCapabilitiesContext *ctx)
|
|||||||
5,
|
5,
|
||||||
NULL, /* cancellable */
|
NULL, /* cancellable */
|
||||||
(GAsyncReadyCallback)capabilities_set_technology_preference_ready,
|
(GAsyncReadyCallback)capabilities_set_technology_preference_ready,
|
||||||
ctx);
|
task);
|
||||||
qmi_message_nas_set_technology_preference_input_unref (input);
|
qmi_message_nas_set_technology_preference_input_unref (input);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
g_simple_async_result_set_error (
|
g_task_return_new_error (task,
|
||||||
ctx->result,
|
|
||||||
MM_CORE_ERROR,
|
MM_CORE_ERROR,
|
||||||
MM_CORE_ERROR_UNSUPPORTED,
|
MM_CORE_ERROR_UNSUPPORTED,
|
||||||
"Setting capabilities is not supported by this device");
|
"Setting capabilities is not supported by this device");
|
||||||
set_current_capabilities_context_complete_and_free (ctx);
|
g_object_unref (task);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -894,20 +900,16 @@ set_current_capabilities (MMIfaceModem *self,
|
|||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
SetCurrentCapabilitiesContext *ctx;
|
SetCurrentCapabilitiesContext *ctx;
|
||||||
|
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;
|
||||||
|
|
||||||
ctx = g_slice_new0 (SetCurrentCapabilitiesContext);
|
ctx = g_slice_new0 (SetCurrentCapabilitiesContext);
|
||||||
ctx->self = g_object_ref (self);
|
|
||||||
ctx->client = g_object_ref (client);
|
ctx->client = g_object_ref (client);
|
||||||
ctx->result = g_simple_async_result_new (G_OBJECT (self),
|
|
||||||
callback,
|
|
||||||
user_data,
|
|
||||||
set_current_capabilities);
|
|
||||||
ctx->capabilities = capabilities;
|
ctx->capabilities = capabilities;
|
||||||
|
|
||||||
/* System selection preference introduced in NAS 1.1 */
|
/* System selection preference introduced in NAS 1.1 */
|
||||||
@@ -916,7 +918,12 @@ set_current_capabilities (MMIfaceModem *self,
|
|||||||
/* Technology preference introduced in NAS 1.0, so always available */
|
/* Technology preference introduced in NAS 1.0, so always available */
|
||||||
ctx->run_set_technology_preference = TRUE;
|
ctx->run_set_technology_preference = TRUE;
|
||||||
|
|
||||||
set_current_capabilities_context_step (ctx);
|
task = g_task_new (self, NULL, callback, user_data);
|
||||||
|
g_task_set_task_data (task,
|
||||||
|
ctx,
|
||||||
|
(GDestroyNotify)set_current_capabilities_context_free);
|
||||||
|
|
||||||
|
set_current_capabilities_context_step (task);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
Reference in New Issue
Block a user