broadband-modem-qmi: port modem_3gpp_load_enabled_facility_locks to use GTask

This commit is contained in:
Ben Chan
2018-05-01 12:46:48 -07:00
committed by Aleksander Morgado
parent 8ad01d31ac
commit f3b2deadda

View File

@@ -3844,23 +3844,18 @@ modem_3gpp_load_imei (MMIfaceModem3gpp *_self,
/* Facility locks status loading (3GPP interface) */
typedef struct {
MMBroadbandModem *self;
GSimpleAsyncResult *result;
QmiClient *client;
guint current;
MMModem3gppFacility facilities;
MMModem3gppFacility locks;
} LoadEnabledFacilityLocksContext;
static void get_next_facility_lock_status (LoadEnabledFacilityLocksContext *ctx);
static void get_next_facility_lock_status (GTask *task);
static void
load_enabled_facility_locks_context_complete_and_free (LoadEnabledFacilityLocksContext *ctx)
load_enabled_facility_locks_context_free (LoadEnabledFacilityLocksContext *ctx)
{
g_simple_async_result_complete (ctx->result);
g_object_unref (ctx->result);
g_object_unref (ctx->client);
g_object_unref (ctx->self);
g_free (ctx);
}
@@ -3869,21 +3864,28 @@ modem_3gpp_load_enabled_facility_locks_finish (MMIfaceModem3gpp *self,
GAsyncResult *res,
GError **error)
{
if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error))
return MM_MODEM_3GPP_FACILITY_NONE;
GError *inner_error = NULL;
gssize value;
return ((MMModem3gppFacility) GPOINTER_TO_UINT (
g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (res))));
value = g_task_propagate_int (G_TASK (res), &inner_error);
if (inner_error) {
g_propagate_error (error, inner_error);
return MM_MODEM_3GPP_FACILITY_NONE;
}
return (MMModem3gppFacility)value;
}
static void
get_sim_lock_status_via_pin_status_ready (QmiClientDms *client,
GAsyncResult *res,
LoadEnabledFacilityLocksContext *ctx)
GTask *task)
{
LoadEnabledFacilityLocksContext *ctx;
QmiMessageDmsUimGetPinStatusOutput *output;
gboolean enabled;
ctx = g_task_get_task_data (task);
output = qmi_client_dms_uim_get_pin_status_finish (client, res, NULL);
if (!output ||
!qmi_message_dms_uim_get_pin_status_output_get_result (output, NULL)) {
@@ -3916,17 +3918,19 @@ get_sim_lock_status_via_pin_status_ready (QmiClientDms *client,
}
/* No more facilities to query, all done */
g_simple_async_result_set_op_res_gpointer (ctx->result,
GUINT_TO_POINTER (ctx->locks),
NULL);
load_enabled_facility_locks_context_complete_and_free (ctx);
g_task_return_int (task, ctx->locks);
g_object_unref (task);
}
/* the SIM lock cannot be queried with the qmi_get_ck_status function,
* therefore using the PIN status */
static void
get_sim_lock_status_via_pin_status (LoadEnabledFacilityLocksContext *ctx)
get_sim_lock_status_via_pin_status (GTask *task)
{
LoadEnabledFacilityLocksContext *ctx;
ctx = g_task_get_task_data (task);
mm_dbg ("Retrieving PIN status to check for enabled PIN");
/* if the SIM is locked or not can only be queried by locking at
* the PIN status */
@@ -3935,17 +3939,19 @@ get_sim_lock_status_via_pin_status (LoadEnabledFacilityLocksContext *ctx)
5,
NULL,
(GAsyncReadyCallback)get_sim_lock_status_via_pin_status_ready,
ctx);
task);
}
static void
dms_uim_get_ck_status_ready (QmiClientDms *client,
GAsyncResult *res,
LoadEnabledFacilityLocksContext *ctx)
GTask *task)
{
LoadEnabledFacilityLocksContext *ctx;
gchar *facility_str;
QmiMessageDmsUimGetCkStatusOutput *output;
ctx = g_task_get_task_data (task);
facility_str = mm_modem_3gpp_facility_build_string_from_mask (1 << ctx->current);
output = qmi_client_dms_uim_get_ck_status_finish (client, res, NULL);
if (!output ||
@@ -3981,14 +3987,17 @@ dms_uim_get_ck_status_ready (QmiClientDms *client,
/* And go on with the next one */
ctx->current++;
get_next_facility_lock_status (ctx);
get_next_facility_lock_status (task);
}
static void
get_next_facility_lock_status (LoadEnabledFacilityLocksContext *ctx)
get_next_facility_lock_status (GTask *task)
{
LoadEnabledFacilityLocksContext *ctx;
guint i;
ctx = g_task_get_task_data (task);
for (i = ctx->current; i < sizeof (MMModem3gppFacility) * 8; i++) {
guint32 facility = 1 << i;
@@ -4010,13 +4019,13 @@ get_next_facility_lock_status (LoadEnabledFacilityLocksContext *ctx)
5,
NULL,
(GAsyncReadyCallback)dms_uim_get_ck_status_ready,
ctx);
task);
qmi_message_dms_uim_get_ck_status_input_unref (input);
return;
}
}
get_sim_lock_status_via_pin_status (ctx);
get_sim_lock_status_via_pin_status (task);
}
static void
@@ -4025,20 +4034,17 @@ modem_3gpp_load_enabled_facility_locks (MMIfaceModem3gpp *self,
gpointer user_data)
{
LoadEnabledFacilityLocksContext *ctx;
GTask *task;
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;
ctx = g_new (LoadEnabledFacilityLocksContext, 1);
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_3gpp_load_enabled_facility_locks);
/* Set initial list of facilities to query */
ctx->facilities = (MM_MODEM_3GPP_FACILITY_PH_SIM |
MM_MODEM_3GPP_FACILITY_NET_PERS |
@@ -4048,7 +4054,10 @@ modem_3gpp_load_enabled_facility_locks (MMIfaceModem3gpp *self,
ctx->locks = MM_MODEM_3GPP_FACILITY_NONE;
ctx->current = 0;
get_next_facility_lock_status (ctx);
task = g_task_new (self, NULL, callback, user_data);
g_task_set_task_data (task, ctx, (GDestroyNotify)load_enabled_facility_locks_context_free);
get_next_facility_lock_status (task);
}
/*****************************************************************************/