broadband-modem-qmi: port modem_cdma_load_activation_state to use GTask
This commit is contained in:
committed by
Aleksander Morgado
parent
e09e4692dc
commit
3455b01b57
@@ -5600,35 +5600,23 @@ modem_cdma_run_registration_checks (MMIfaceModemCdma *self,
|
||||
/*****************************************************************************/
|
||||
/* Load initial activation state (CDMA interface) */
|
||||
|
||||
typedef struct {
|
||||
MMBroadbandModemQmi *self;
|
||||
QmiClientDms *client;
|
||||
GSimpleAsyncResult *result;
|
||||
} LoadActivationStateContext;
|
||||
|
||||
static void
|
||||
load_activation_state_context_complete_and_free (LoadActivationStateContext *ctx)
|
||||
{
|
||||
g_simple_async_result_complete (ctx->result);
|
||||
g_object_unref (ctx->result);
|
||||
g_object_unref (ctx->client);
|
||||
g_object_unref (ctx->self);
|
||||
g_slice_free (LoadActivationStateContext, ctx);
|
||||
}
|
||||
|
||||
static MMModemCdmaActivationState
|
||||
modem_cdma_load_activation_state_finish (MMIfaceModemCdma *_self,
|
||||
GAsyncResult *res,
|
||||
GError **error)
|
||||
{
|
||||
MMBroadbandModemQmi *self = MM_BROADBAND_MODEM_QMI (_self);
|
||||
GError *inner_error = NULL;
|
||||
gssize value;
|
||||
|
||||
if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error))
|
||||
value = g_task_propagate_int (G_TASK (res), &inner_error);
|
||||
if (inner_error) {
|
||||
g_propagate_error (error, inner_error);
|
||||
return MM_MODEM_CDMA_ACTIVATION_STATE_UNKNOWN;
|
||||
}
|
||||
|
||||
/* Cache the value and also return it */
|
||||
self->priv->activation_state =
|
||||
(MMModemCdmaActivationState) GPOINTER_TO_UINT (g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (res)));
|
||||
self->priv->activation_state = (MMModemCdmaActivationState)value;
|
||||
|
||||
return self->priv->activation_state;
|
||||
}
|
||||
@@ -5636,7 +5624,7 @@ modem_cdma_load_activation_state_finish (MMIfaceModemCdma *_self,
|
||||
static void
|
||||
get_activation_state_ready (QmiClientDms *client,
|
||||
GAsyncResult *res,
|
||||
LoadActivationStateContext *ctx)
|
||||
GTask *task)
|
||||
{
|
||||
QmiDmsActivationState state = QMI_DMS_ACTIVATION_STATE_NOT_ACTIVATED;
|
||||
QmiMessageDmsGetActivationStateOutput *output;
|
||||
@@ -5645,27 +5633,25 @@ get_activation_state_ready (QmiClientDms *client,
|
||||
output = qmi_client_dms_get_activation_state_finish (client, res, &error);
|
||||
if (!output) {
|
||||
g_prefix_error (&error, "QMI operation failed: ");
|
||||
g_simple_async_result_take_error (ctx->result, error);
|
||||
load_activation_state_context_complete_and_free (ctx);
|
||||
g_task_return_error (task, error);
|
||||
g_object_unref (task);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!qmi_message_dms_get_activation_state_output_get_result (output, &error)) {
|
||||
g_prefix_error (&error, "Couldn't get activation state: ");
|
||||
g_simple_async_result_take_error (ctx->result, error);
|
||||
g_task_return_error (task, error);
|
||||
g_object_unref (task);
|
||||
qmi_message_dms_get_activation_state_output_unref (output);
|
||||
load_activation_state_context_complete_and_free (ctx);
|
||||
return;
|
||||
}
|
||||
|
||||
qmi_message_dms_get_activation_state_output_get_info (output, &state, NULL);
|
||||
qmi_message_dms_get_activation_state_output_unref (output);
|
||||
|
||||
g_simple_async_result_set_op_res_gpointer (
|
||||
ctx->result,
|
||||
GUINT_TO_POINTER (mm_modem_cdma_activation_state_from_qmi_activation_state (state)),
|
||||
NULL);
|
||||
load_activation_state_context_complete_and_free (ctx);
|
||||
g_task_return_int (task,
|
||||
mm_modem_cdma_activation_state_from_qmi_activation_state (state));
|
||||
g_object_unref (task);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -5673,29 +5659,19 @@ modem_cdma_load_activation_state (MMIfaceModemCdma *self,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data)
|
||||
{
|
||||
LoadActivationStateContext *ctx;
|
||||
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;
|
||||
|
||||
/* Setup context */
|
||||
ctx = g_slice_new0 (LoadActivationStateContext);
|
||||
ctx->self = g_object_ref (self);
|
||||
ctx->client = g_object_ref (client);
|
||||
ctx->result = g_simple_async_result_new (G_OBJECT (self),
|
||||
callback,
|
||||
user_data,
|
||||
modem_cdma_load_activation_state);
|
||||
|
||||
qmi_client_dms_get_activation_state (ctx->client,
|
||||
qmi_client_dms_get_activation_state (QMI_CLIENT_DMS (client),
|
||||
NULL,
|
||||
10,
|
||||
NULL,
|
||||
(GAsyncReadyCallback)get_activation_state_ready,
|
||||
ctx);
|
||||
g_task_new (self, NULL, callback, user_data));
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
Reference in New Issue
Block a user