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

committed by
Aleksander Morgado

parent
3e374e228a
commit
dba8702952
@@ -575,35 +575,18 @@ modem_load_current_capabilities (MMIfaceModem *self,
|
|||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/* Supported capabilities loading (Modem interface) */
|
/* Supported capabilities loading (Modem interface) */
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
MMBroadbandModemQmi *self;
|
|
||||||
GSimpleAsyncResult *result;
|
|
||||||
} LoadSupportedCapabilitiesContext;
|
|
||||||
|
|
||||||
static void
|
|
||||||
load_supported_capabilities_context_complete_and_free (LoadSupportedCapabilitiesContext *ctx)
|
|
||||||
{
|
|
||||||
g_simple_async_result_complete (ctx->result);
|
|
||||||
g_object_unref (ctx->result);
|
|
||||||
g_object_unref (ctx->self);
|
|
||||||
g_slice_free (LoadSupportedCapabilitiesContext, ctx);
|
|
||||||
}
|
|
||||||
|
|
||||||
static GArray *
|
static GArray *
|
||||||
modem_load_supported_capabilities_finish (MMIfaceModem *self,
|
modem_load_supported_capabilities_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 g_array_ref (g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (res)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
dms_get_capabilities_ready (QmiClientDms *client,
|
dms_get_capabilities_ready (QmiClientDms *client,
|
||||||
GAsyncResult *res,
|
GAsyncResult *res,
|
||||||
LoadSupportedCapabilitiesContext *ctx)
|
GTask *task)
|
||||||
{
|
{
|
||||||
QmiMessageDmsGetCapabilitiesOutput *output = NULL;
|
QmiMessageDmsGetCapabilitiesOutput *output = NULL;
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
@@ -611,11 +594,12 @@ dms_get_capabilities_ready (QmiClientDms *client,
|
|||||||
output = qmi_client_dms_get_capabilities_finish (client, res, &error);
|
output = qmi_client_dms_get_capabilities_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);
|
||||||
} else if (!qmi_message_dms_get_capabilities_output_get_result (output, &error)) {
|
} else if (!qmi_message_dms_get_capabilities_output_get_result (output, &error)) {
|
||||||
g_prefix_error (&error, "Couldn't get supported capabilities: ");
|
g_prefix_error (&error, "Couldn't get supported capabilities: ");
|
||||||
g_simple_async_result_take_error (ctx->result, error);
|
g_task_return_error (task, error);
|
||||||
} else {
|
} else {
|
||||||
|
MMBroadbandModemQmi *self;
|
||||||
guint i;
|
guint i;
|
||||||
MMModemCapability mask = MM_MODEM_CAPABILITY_NONE;
|
MMModemCapability mask = MM_MODEM_CAPABILITY_NONE;
|
||||||
MMModemCapability single;
|
MMModemCapability single;
|
||||||
@@ -623,6 +607,8 @@ dms_get_capabilities_ready (QmiClientDms *client,
|
|||||||
GArray *supported_combinations;
|
GArray *supported_combinations;
|
||||||
GArray *filtered_combinations;
|
GArray *filtered_combinations;
|
||||||
|
|
||||||
|
self = g_task_get_source_object (task);
|
||||||
|
|
||||||
qmi_message_dms_get_capabilities_output_get_info (
|
qmi_message_dms_get_capabilities_output_get_info (
|
||||||
output,
|
output,
|
||||||
NULL, /* info_max_tx_channel_rate */
|
NULL, /* info_max_tx_channel_rate */
|
||||||
@@ -639,9 +625,9 @@ dms_get_capabilities_ready (QmiClientDms *client,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Cache supported radio interfaces */
|
/* Cache supported radio interfaces */
|
||||||
if (ctx->self->priv->supported_radio_interfaces)
|
if (self->priv->supported_radio_interfaces)
|
||||||
g_array_unref (ctx->self->priv->supported_radio_interfaces);
|
g_array_unref (self->priv->supported_radio_interfaces);
|
||||||
ctx->self->priv->supported_radio_interfaces = g_array_ref (radio_interface_list);
|
self->priv->supported_radio_interfaces = g_array_ref (radio_interface_list);
|
||||||
|
|
||||||
supported_combinations = g_array_sized_new (FALSE, FALSE, sizeof (MMModemCapability), 7);
|
supported_combinations = g_array_sized_new (FALSE, FALSE, sizeof (MMModemCapability), 7);
|
||||||
|
|
||||||
@@ -675,15 +661,15 @@ dms_get_capabilities_ready (QmiClientDms *client,
|
|||||||
supported_combinations);
|
supported_combinations);
|
||||||
g_array_unref (supported_combinations);
|
g_array_unref (supported_combinations);
|
||||||
|
|
||||||
g_simple_async_result_set_op_res_gpointer (ctx->result,
|
g_task_return_pointer (task,
|
||||||
filtered_combinations,
|
filtered_combinations,
|
||||||
(GDestroyNotify) g_array_unref);
|
(GDestroyNotify) g_array_unref);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (output)
|
if (output)
|
||||||
qmi_message_dms_get_capabilities_output_unref (output);
|
qmi_message_dms_get_capabilities_output_unref (output);
|
||||||
|
|
||||||
load_supported_capabilities_context_complete_and_free (ctx);
|
g_object_unref (task);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -691,28 +677,20 @@ modem_load_supported_capabilities (MMIfaceModem *self,
|
|||||||
GAsyncReadyCallback callback,
|
GAsyncReadyCallback callback,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
LoadSupportedCapabilitiesContext *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;
|
||||||
|
|
||||||
ctx = g_slice_new (LoadSupportedCapabilitiesContext);
|
|
||||||
ctx->self = g_object_ref (self);
|
|
||||||
ctx->result = g_simple_async_result_new (G_OBJECT (self),
|
|
||||||
callback,
|
|
||||||
user_data,
|
|
||||||
modem_load_supported_capabilities);
|
|
||||||
|
|
||||||
mm_dbg ("loading supported capabilities...");
|
mm_dbg ("loading supported capabilities...");
|
||||||
qmi_client_dms_get_capabilities (QMI_CLIENT_DMS (client),
|
qmi_client_dms_get_capabilities (QMI_CLIENT_DMS (client),
|
||||||
NULL,
|
NULL,
|
||||||
5,
|
5,
|
||||||
NULL,
|
NULL,
|
||||||
(GAsyncReadyCallback)dms_get_capabilities_ready,
|
(GAsyncReadyCallback)dms_get_capabilities_ready,
|
||||||
ctx);
|
g_task_new (self, NULL, callback, user_data));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
Reference in New Issue
Block a user