broadband-modem-qmi: port modem_cdma_{activate,activate_manual} to use GTask

This commit is contained in:
Ben Chan
2018-05-01 18:19:06 -07:00
committed by Aleksander Morgado
parent 856d931a7e
commit bf4af8b82a

View File

@@ -106,7 +106,7 @@ struct _MMBroadbandModemQmiPrivate {
/* CDMA activation helpers */ /* CDMA activation helpers */
MMModemCdmaActivationState activation_state; MMModemCdmaActivationState activation_state;
guint activation_event_report_indication_id; guint activation_event_report_indication_id;
gpointer activation_ctx; GTask *activation_task;
/* Messaging helpers */ /* Messaging helpers */
gboolean messaging_fallback_at; gboolean messaging_fallback_at;
@@ -5691,7 +5691,6 @@ typedef enum {
typedef struct { typedef struct {
MMBroadbandModemQmi *self; MMBroadbandModemQmi *self;
QmiClientDms *client; QmiClientDms *client;
GSimpleAsyncResult *result;
CdmaActivationStep step; CdmaActivationStep step;
/* OTA activation... */ /* OTA activation... */
QmiMessageDmsActivateAutomaticInput *input_automatic; QmiMessageDmsActivateAutomaticInput *input_automatic;
@@ -5705,10 +5704,10 @@ typedef struct {
} CdmaActivationContext; } CdmaActivationContext;
static void static void
cdma_activation_context_complete_and_free (CdmaActivationContext *ctx) cdma_activation_context_free (CdmaActivationContext *ctx)
{ {
/* Cleanup the activation context from the private info */ /* Cleanup the activation task from the private info */
ctx->self->priv->activation_ctx = NULL; ctx->self->priv->activation_task = NULL;
for (ctx->segment_i = 0; ctx->segment_i < ctx->n_segments; ctx->segment_i++) for (ctx->segment_i = 0; ctx->segment_i < ctx->n_segments; ctx->segment_i++)
g_array_unref (ctx->segments[ctx->segment_i]); g_array_unref (ctx->segments[ctx->segment_i]);
@@ -5718,8 +5717,6 @@ cdma_activation_context_complete_and_free (CdmaActivationContext *ctx)
qmi_message_dms_activate_automatic_input_unref (ctx->input_automatic); qmi_message_dms_activate_automatic_input_unref (ctx->input_automatic);
if (ctx->input_manual) if (ctx->input_manual)
qmi_message_dms_activate_manual_input_unref (ctx->input_manual); qmi_message_dms_activate_manual_input_unref (ctx->input_manual);
g_simple_async_result_complete (ctx->result);
g_object_unref (ctx->result);
g_object_unref (ctx->client); g_object_unref (ctx->client);
g_object_unref (ctx->self); g_object_unref (ctx->self);
g_slice_free (CdmaActivationContext, ctx); g_slice_free (CdmaActivationContext, ctx);
@@ -5730,7 +5727,7 @@ modem_cdma_activate_finish (MMIfaceModemCdma *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 gboolean static gboolean
@@ -5738,10 +5735,10 @@ modem_cdma_activate_manual_finish (MMIfaceModemCdma *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 cdma_activation_context_step (CdmaActivationContext *ctx); static void cdma_activation_context_step (GTask *task);
static void static void
cdma_activation_disable_indications (CdmaActivationContext *ctx) cdma_activation_disable_indications (CdmaActivationContext *ctx)
@@ -5763,38 +5760,43 @@ cdma_activation_disable_indications (CdmaActivationContext *ctx)
static void static void
activation_power_cycle_ready (MMBroadbandModemQmi *self, activation_power_cycle_ready (MMBroadbandModemQmi *self,
GAsyncResult *res, GAsyncResult *res,
CdmaActivationContext *ctx) GTask *task)
{ {
CdmaActivationContext *ctx;
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);
cdma_activation_context_complete_and_free (ctx); g_object_unref (task);
return; return;
} }
/* And go on to next step */ /* And go on to next step */
ctx = g_task_get_task_data (task);
ctx->step++; ctx->step++;
cdma_activation_context_step (ctx); cdma_activation_context_step (task);
} }
static gboolean static gboolean
retry_msisdn_check_cb (CdmaActivationContext *ctx) retry_msisdn_check_cb (GTask *task)
{ {
cdma_activation_context_step (ctx); cdma_activation_context_step (task);
return G_SOURCE_REMOVE; return G_SOURCE_REMOVE;
} }
static void static void
activate_manual_get_msisdn_ready (QmiClientDms *client, activate_manual_get_msisdn_ready (QmiClientDms *client,
GAsyncResult *res, GAsyncResult *res,
CdmaActivationContext *ctx) GTask *task)
{ {
CdmaActivationContext *ctx;
QmiMessageDmsGetMsisdnOutput *output = NULL; QmiMessageDmsGetMsisdnOutput *output = NULL;
GError *error = NULL; GError *error = NULL;
const gchar *current_mdn = NULL; const gchar *current_mdn = NULL;
const gchar *expected_mdn = NULL; const gchar *expected_mdn = NULL;
ctx = g_task_get_task_data (task);
qmi_message_dms_activate_manual_input_get_info (ctx->input_manual, qmi_message_dms_activate_manual_input_get_info (ctx->input_manual,
NULL, /* spc */ NULL, /* spc */
NULL, /* sid */ NULL, /* sid */
@@ -5811,7 +5813,7 @@ activate_manual_get_msisdn_ready (QmiClientDms *client,
qmi_message_dms_get_msisdn_output_unref (output); qmi_message_dms_get_msisdn_output_unref (output);
/* And go on to next step */ /* And go on to next step */
ctx->step++; ctx->step++;
cdma_activation_context_step (ctx); cdma_activation_context_step (task);
return; return;
} }
@@ -5821,16 +5823,16 @@ activate_manual_get_msisdn_ready (QmiClientDms *client,
if (ctx->n_mdn_check_retries < MAX_MDN_CHECK_RETRIES) { if (ctx->n_mdn_check_retries < MAX_MDN_CHECK_RETRIES) {
/* Retry after some time */ /* Retry after some time */
mm_dbg ("MDN not yet updated, retrying..."); mm_dbg ("MDN not yet updated, retrying...");
g_timeout_add (1, (GSourceFunc) retry_msisdn_check_cb, ctx); g_timeout_add (1, (GSourceFunc) retry_msisdn_check_cb, task);
return; return;
} }
/* Well, all retries consumed already, return error */ /* Well, all retries consumed already, return error */
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,
"MDN was not correctly set during manual activation"); "MDN was not correctly set during manual activation");
cdma_activation_context_complete_and_free (ctx); g_object_unref (task);
} }
static void static void
@@ -5871,24 +5873,26 @@ activation_event_report_indication_cb (QmiClientDms *client,
/* Now, if we have a FINAL state, finish the ongoing activation state request */ /* Now, if we have a FINAL state, finish the ongoing activation state request */
if (new != MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATING) { if (new != MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATING) {
GTask *task;
CdmaActivationContext *ctx; CdmaActivationContext *ctx;
g_assert (self->priv->activation_ctx != NULL); g_assert (self->priv->activation_task != NULL);
ctx = (CdmaActivationContext *)self->priv->activation_ctx; task = self->priv->activation_task;
ctx = g_task_get_task_data (task);
/* Disable further indications. */ /* Disable further indications. */
cdma_activation_disable_indications (ctx); cdma_activation_disable_indications (ctx);
/* If there is any error, finish the async method */ /* If there is any error, finish the async method */
if (error) { if (error) {
g_simple_async_result_take_error (ctx->result, error); g_task_return_error (task, error);
cdma_activation_context_complete_and_free (ctx); g_object_unref (task);
return; return;
} }
/* Otherwise, go on to next step */ /* Otherwise, go on to next step */
ctx->step++; ctx->step++;
cdma_activation_context_step (ctx); cdma_activation_context_step (task);
return; return;
} }
@@ -5898,26 +5902,29 @@ activation_event_report_indication_cb (QmiClientDms *client,
static void static void
activate_automatic_ready (QmiClientDms *client, activate_automatic_ready (QmiClientDms *client,
GAsyncResult *res, GAsyncResult *res,
CdmaActivationContext *ctx) GTask *task)
{ {
CdmaActivationContext *ctx;
QmiMessageDmsActivateAutomaticOutput *output; QmiMessageDmsActivateAutomaticOutput *output;
GError *error = NULL; GError *error = NULL;
ctx = g_task_get_task_data (task);
output = qmi_client_dms_activate_automatic_finish (client, res, &error); output = qmi_client_dms_activate_automatic_finish (client, res, &error);
if (!output) { if (!output) {
g_prefix_error (&error, "QMI operation failed: ");
g_simple_async_result_take_error (ctx->result, error);
cdma_activation_disable_indications (ctx); cdma_activation_disable_indications (ctx);
cdma_activation_context_complete_and_free (ctx); g_prefix_error (&error, "QMI operation failed: ");
g_task_return_error (task, error);
g_object_unref (task);
return; return;
} }
if (!qmi_message_dms_activate_automatic_output_get_result (output, &error)) { if (!qmi_message_dms_activate_automatic_output_get_result (output, &error)) {
g_prefix_error (&error, "Couldn't request OTA activation: ");
g_simple_async_result_take_error (ctx->result, error);
qmi_message_dms_activate_automatic_output_unref (output); qmi_message_dms_activate_automatic_output_unref (output);
cdma_activation_disable_indications (ctx); cdma_activation_disable_indications (ctx);
cdma_activation_context_complete_and_free (ctx); g_prefix_error (&error, "Couldn't request OTA activation: ");
g_task_return_error (task, error);
g_object_unref (task);
return; return;
} }
@@ -5925,30 +5932,33 @@ activate_automatic_ready (QmiClientDms *client,
/* Keep on */ /* Keep on */
ctx->step++; ctx->step++;
cdma_activation_context_step (ctx); cdma_activation_context_step (task);
} }
static void static void
activate_manual_ready (QmiClientDms *client, activate_manual_ready (QmiClientDms *client,
GAsyncResult *res, GAsyncResult *res,
CdmaActivationContext *ctx) GTask *task)
{ {
CdmaActivationContext *ctx;
QmiMessageDmsActivateManualOutput *output; QmiMessageDmsActivateManualOutput *output;
GError *error = NULL; GError *error = NULL;
ctx = g_task_get_task_data (task);
output = qmi_client_dms_activate_manual_finish (client, res, &error); output = qmi_client_dms_activate_manual_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 (ctx->result, error); g_task_return_error (task, error);
cdma_activation_context_complete_and_free (ctx); g_object_unref (task);
return; return;
} }
if (!qmi_message_dms_activate_manual_output_get_result (output, &error)) { if (!qmi_message_dms_activate_manual_output_get_result (output, &error)) {
g_prefix_error (&error, "Couldn't request manual activation: ");
g_simple_async_result_take_error (ctx->result, error);
qmi_message_dms_activate_manual_output_unref (output); qmi_message_dms_activate_manual_output_unref (output);
cdma_activation_context_complete_and_free (ctx); g_prefix_error (&error, "Couldn't request manual activation: ");
g_task_return_error (task, error);
g_object_unref (task);
return; return;
} }
@@ -5959,40 +5969,43 @@ activate_manual_ready (QmiClientDms *client,
ctx->segment_i++; ctx->segment_i++;
if (ctx->segment_i < ctx->n_segments) { if (ctx->segment_i < ctx->n_segments) {
/* There's a pending segment */ /* There's a pending segment */
cdma_activation_context_step (ctx); cdma_activation_context_step (task);
return; return;
} }
} }
/* No more segments to send, go on */ /* No more segments to send, go on */
ctx->step++; ctx->step++;
cdma_activation_context_step (ctx); cdma_activation_context_step (task);
} }
static void static void
ser_activation_state_ready (QmiClientDms *client, ser_activation_state_ready (QmiClientDms *client,
GAsyncResult *res, GAsyncResult *res,
CdmaActivationContext *ctx) GTask *task)
{ {
CdmaActivationContext *ctx;
QmiMessageDmsSetEventReportOutput *output; QmiMessageDmsSetEventReportOutput *output;
GError *error = NULL; GError *error = NULL;
ctx = g_task_get_task_data (task);
/* We cannot ignore errors, we NEED the indications to finish the /* We cannot ignore errors, we NEED the indications to finish the
* activation request properly */ * activation request properly */
output = qmi_client_dms_set_event_report_finish (client, res, &error); output = qmi_client_dms_set_event_report_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 (ctx->result, error); g_task_return_error (task, error);
cdma_activation_context_complete_and_free (ctx); g_object_unref (task);
return; return;
} }
if (!qmi_message_dms_set_event_report_output_get_result (output, &error)) { if (!qmi_message_dms_set_event_report_output_get_result (output, &error)) {
g_prefix_error (&error, "Couldn't set event report: ");
g_simple_async_result_take_error (ctx->result, error);
qmi_message_dms_set_event_report_output_unref (output); qmi_message_dms_set_event_report_output_unref (output);
cdma_activation_context_complete_and_free (ctx); g_prefix_error (&error, "Couldn't set event report: ");
g_task_return_error (task, error);
g_object_unref (task);
return; return;
} }
@@ -6008,12 +6021,16 @@ ser_activation_state_ready (QmiClientDms *client,
/* Keep on */ /* Keep on */
ctx->step++; ctx->step++;
cdma_activation_context_step (ctx); cdma_activation_context_step (task);
} }
static void static void
cdma_activation_context_step (CdmaActivationContext *ctx) cdma_activation_context_step (GTask *task)
{ {
CdmaActivationContext *ctx;
ctx = g_task_get_task_data (task);
switch (ctx->step) { switch (ctx->step) {
case CDMA_ACTIVATION_STEP_FIRST: case CDMA_ACTIVATION_STEP_FIRST:
ctx->step++; ctx->step++;
@@ -6034,7 +6051,7 @@ cdma_activation_context_step (CdmaActivationContext *ctx)
5, 5,
NULL, NULL,
(GAsyncReadyCallback)ser_activation_state_ready, (GAsyncReadyCallback)ser_activation_state_ready,
ctx); task);
qmi_message_dms_set_event_report_input_unref (input); qmi_message_dms_set_event_report_input_unref (input);
return; return;
} }
@@ -6055,7 +6072,7 @@ cdma_activation_context_step (CdmaActivationContext *ctx)
10, 10,
NULL, NULL,
(GAsyncReadyCallback)activate_automatic_ready, (GAsyncReadyCallback)activate_automatic_ready,
ctx); task);
return; return;
} }
@@ -6079,7 +6096,7 @@ cdma_activation_context_step (CdmaActivationContext *ctx)
10, 10,
NULL, NULL,
(GAsyncReadyCallback)activate_manual_ready, (GAsyncReadyCallback)activate_manual_ready,
ctx); task);
return; return;
case CDMA_ACTIVATION_STEP_WAIT_UNTIL_FINISHED: case CDMA_ACTIVATION_STEP_WAIT_UNTIL_FINISHED:
@@ -6099,20 +6116,20 @@ cdma_activation_context_step (CdmaActivationContext *ctx)
5, 5,
NULL, NULL,
(GAsyncReadyCallback)activate_manual_get_msisdn_ready, (GAsyncReadyCallback)activate_manual_get_msisdn_ready,
ctx); task);
return; return;
case CDMA_ACTIVATION_STEP_POWER_CYCLE: case CDMA_ACTIVATION_STEP_POWER_CYCLE:
mm_info ("Activation step [4/5]: power-cycling..."); mm_info ("Activation step [4/5]: power-cycling...");
power_cycle (ctx->self, power_cycle (ctx->self,
(GAsyncReadyCallback)activation_power_cycle_ready, (GAsyncReadyCallback)activation_power_cycle_ready,
ctx); task);
return; return;
case CDMA_ACTIVATION_STEP_LAST: case CDMA_ACTIVATION_STEP_LAST:
mm_info ("Activation step [5/5]: finished"); mm_info ("Activation step [5/5]: finished");
g_simple_async_result_set_op_res_gboolean (ctx->result, TRUE); g_task_return_boolean (task, TRUE);
cdma_activation_context_complete_and_free (ctx); g_object_unref (task);
return; return;
default: default:
@@ -6127,29 +6144,24 @@ modem_cdma_activate (MMIfaceModemCdma *_self,
gpointer user_data) gpointer user_data)
{ {
MMBroadbandModemQmi *self = MM_BROADBAND_MODEM_QMI (_self); MMBroadbandModemQmi *self = MM_BROADBAND_MODEM_QMI (_self);
GSimpleAsyncResult *result; GTask *task;
CdmaActivationContext *ctx; CdmaActivationContext *ctx;
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_DMS, &client, QMI_SERVICE_DMS, &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_cdma_activate);
/* Fail if we have already an activation ongoing */ /* Fail if we have already an activation ongoing */
if (self->priv->activation_ctx) { if (self->priv->activation_task) {
g_simple_async_result_set_error ( g_task_return_new_error (task,
result, MM_CORE_ERROR,
MM_CORE_ERROR, MM_CORE_ERROR_IN_PROGRESS,
MM_CORE_ERROR_IN_PROGRESS, "An activation operation is already in progress");
"An activation operation is already in progress"); g_object_unref (task);
g_simple_async_result_complete_in_idle (result);
g_object_unref (result);
return; return;
} }
@@ -6157,17 +6169,18 @@ modem_cdma_activate (MMIfaceModemCdma *_self,
ctx = g_slice_new0 (CdmaActivationContext); ctx = g_slice_new0 (CdmaActivationContext);
ctx->self = g_object_ref (self); ctx->self = g_object_ref (self);
ctx->client = g_object_ref (client); ctx->client = g_object_ref (client);
ctx->result = result;
ctx->step = CDMA_ACTIVATION_STEP_FIRST; ctx->step = CDMA_ACTIVATION_STEP_FIRST;
/* Build base input bundle for the Automatic activation */ /* Build base input bundle for the Automatic activation */
ctx->input_automatic = qmi_message_dms_activate_automatic_input_new (); ctx->input_automatic = qmi_message_dms_activate_automatic_input_new ();
qmi_message_dms_activate_automatic_input_set_activation_code (ctx->input_automatic, carrier_code, NULL); qmi_message_dms_activate_automatic_input_set_activation_code (ctx->input_automatic, carrier_code, NULL);
/* We keep the activation context in the private data, so that we don't g_task_set_task_data (task, ctx, (GDestroyNotify)cdma_activation_context_free);
/* We keep the activation task in the private data, so that we don't
* allow multiple activation requests at the same time. */ * allow multiple activation requests at the same time. */
self->priv->activation_ctx = ctx; self->priv->activation_task = task;
cdma_activation_context_step (ctx); cdma_activation_context_step (task);
} }
static void static void
@@ -6177,29 +6190,24 @@ modem_cdma_activate_manual (MMIfaceModemCdma *_self,
gpointer user_data) gpointer user_data)
{ {
MMBroadbandModemQmi *self = MM_BROADBAND_MODEM_QMI (_self); MMBroadbandModemQmi *self = MM_BROADBAND_MODEM_QMI (_self);
GSimpleAsyncResult *result; GTask *task;
CdmaActivationContext *ctx; CdmaActivationContext *ctx;
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_DMS, &client, QMI_SERVICE_DMS, &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_cdma_activate_manual);
/* Fail if we have already an activation ongoing */ /* Fail if we have already an activation ongoing */
if (self->priv->activation_ctx) { if (self->priv->activation_task) {
g_simple_async_result_set_error ( g_task_return_new_error (task,
result, MM_CORE_ERROR,
MM_CORE_ERROR, MM_CORE_ERROR_IN_PROGRESS,
MM_CORE_ERROR_IN_PROGRESS, "An activation operation is already in progress");
"An activation operation is already in progress"); g_object_unref (task);
g_simple_async_result_complete_in_idle (result);
g_object_unref (result);
return; return;
} }
@@ -6207,11 +6215,12 @@ modem_cdma_activate_manual (MMIfaceModemCdma *_self,
ctx = g_slice_new0 (CdmaActivationContext); ctx = g_slice_new0 (CdmaActivationContext);
ctx->self = g_object_ref (self); ctx->self = g_object_ref (self);
ctx->client = g_object_ref (client); ctx->client = g_object_ref (client);
ctx->result = result;
/* We keep the activation context in the private data, so that we don't g_task_set_task_data (task, ctx, (GDestroyNotify)cdma_activation_context_free);
/* We keep the activation task in the private data, so that we don't
* allow multiple activation requests at the same time. */ * allow multiple activation requests at the same time. */
self->priv->activation_ctx = ctx; self->priv->activation_task = task;
/* Build base input bundle for the Manual activation */ /* Build base input bundle for the Manual activation */
ctx->input_manual = qmi_message_dms_activate_manual_input_new (); ctx->input_manual = qmi_message_dms_activate_manual_input_new ();
@@ -6278,7 +6287,7 @@ modem_cdma_activate_manual (MMIfaceModemCdma *_self,
#undef MAX_PRL_SEGMENT_SIZE #undef MAX_PRL_SEGMENT_SIZE
} }
cdma_activation_context_step (ctx); cdma_activation_context_step (task);
} }
/*****************************************************************************/ /*****************************************************************************/