aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBen Chan <benchan@chromium.org>2017-04-12 13:15:04 -0700
committerAleksander Morgado <aleksander@aleksander.es>2017-04-18 15:07:50 +0200
commitc9df8bd60110f798776579156cb7bb6bcf587dac (patch)
tree111c98f000e34457fb20532ca9476278293ff7fa
parent4da476f676678d83a5c73b94c4337c9a437fb6a1 (diff)
downloadexternal_libqmi-c9df8bd60110f798776579156cb7bb6bcf587dac.zip
external_libqmi-c9df8bd60110f798776579156cb7bb6bcf587dac.tar.gz
external_libqmi-c9df8bd60110f798776579156cb7bb6bcf587dac.tar.bz2
libqmi-glib,device: port initable_init_async to use GTask
-rw-r--r--src/libqmi-glib/qmi-device.c101
1 files changed, 41 insertions, 60 deletions
diff --git a/src/libqmi-glib/qmi-device.c b/src/libqmi-glib/qmi-device.c
index 2c96a65..6999f75 100644
--- a/src/libqmi-glib/qmi-device.c
+++ b/src/libqmi-glib/qmi-device.c
@@ -2805,29 +2805,12 @@ qmi_device_new (GFile *file,
/*****************************************************************************/
/* Async init */
-typedef struct {
- QmiDevice *self;
- GSimpleAsyncResult *result;
- GCancellable *cancellable;
-} InitContext;
-
-static void
-init_context_complete_and_free (InitContext *ctx)
-{
- g_simple_async_result_complete_in_idle (ctx->result);
- if (ctx->cancellable)
- g_object_unref (ctx->cancellable);
- g_object_unref (ctx->result);
- g_object_unref (ctx->self);
- g_slice_free (InitContext, ctx);
-}
-
static gboolean
initable_init_finish (GAsyncInitable *initable,
GAsyncResult *result,
GError **error)
{
- return !g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result), error);
+ return g_task_propagate_boolean (G_TASK (result), error);
}
static void
@@ -2840,39 +2823,42 @@ sync_indication_cb (QmiClientCtl *client_ctl,
}
static void
-client_ctl_setup (InitContext *ctx)
+client_ctl_setup (GTask *task)
{
+ QmiDevice *self;
GError *error = NULL;
+ self = g_task_get_source_object (task);
+
/* Create the implicit CTL client */
- ctx->self->priv->client_ctl = g_object_new (QMI_TYPE_CLIENT_CTL,
- QMI_CLIENT_DEVICE, ctx->self,
- QMI_CLIENT_SERVICE, QMI_SERVICE_CTL,
- QMI_CLIENT_CID, QMI_CID_NONE,
- NULL);
+ self->priv->client_ctl = g_object_new (QMI_TYPE_CLIENT_CTL,
+ QMI_CLIENT_DEVICE, self,
+ QMI_CLIENT_SERVICE, QMI_SERVICE_CTL,
+ QMI_CLIENT_CID, QMI_CID_NONE,
+ NULL);
/* Register the CTL client to get indications */
- register_client (ctx->self,
- QMI_CLIENT (ctx->self->priv->client_ctl),
+ register_client (self,
+ QMI_CLIENT (self->priv->client_ctl),
&error);
g_assert_no_error (error);
/* Connect to 'Sync' indications */
- ctx->self->priv->sync_indication_id =
- g_signal_connect (ctx->self->priv->client_ctl,
+ self->priv->sync_indication_id =
+ g_signal_connect (self->priv->client_ctl,
"sync",
G_CALLBACK (sync_indication_cb),
- ctx->self);
+ self);
/* Done we are */
- g_simple_async_result_set_op_res_gboolean (ctx->result, TRUE);
- init_context_complete_and_free (ctx);
+ g_task_return_boolean (task, TRUE);
+ g_object_unref (task);
}
static void
query_info_async_ready (GFile *file,
GAsyncResult *res,
- InitContext *ctx)
+ GTask *task)
{
GError *error = NULL;
GFileInfo *info;
@@ -2881,24 +2867,24 @@ query_info_async_ready (GFile *file,
if (!info) {
g_prefix_error (&error,
"Couldn't query file info: ");
- g_simple_async_result_take_error (ctx->result, error);
- init_context_complete_and_free (ctx);
+ g_task_return_error (task, error);
+ g_object_unref (task);
return;
}
/* Our QMI device must be of SPECIAL type */
if (g_file_info_get_file_type (info) != G_FILE_TYPE_SPECIAL) {
- g_simple_async_result_set_error (ctx->result,
- QMI_CORE_ERROR,
- QMI_CORE_ERROR_FAILED,
- "Wrong file type");
- init_context_complete_and_free (ctx);
+ g_task_return_new_error (task,
+ QMI_CORE_ERROR,
+ QMI_CORE_ERROR_FAILED,
+ "Wrong file type");
+ g_object_unref (task);
return;
}
g_object_unref (info);
/* Go on with client CTL setup */
- client_ctl_setup (ctx);
+ client_ctl_setup (task);
}
static void
@@ -2908,43 +2894,38 @@ initable_init_async (GAsyncInitable *initable,
GAsyncReadyCallback callback,
gpointer user_data)
{
- InitContext *ctx;
+ QmiDevice *self;
+ GTask *task;
- ctx = g_slice_new0 (InitContext);
- ctx->self = g_object_ref (initable);
- if (cancellable)
- ctx->cancellable = g_object_ref (cancellable);
- ctx->result = g_simple_async_result_new (G_OBJECT (initable),
- callback,
- user_data,
- initable_init_async);
+ self = QMI_DEVICE (initable);
+ task = g_task_new (self, cancellable, callback, user_data);
/* We need a proper file to initialize */
- if (!ctx->self->priv->file) {
- g_simple_async_result_set_error (ctx->result,
- QMI_CORE_ERROR,
- QMI_CORE_ERROR_INVALID_ARGS,
- "Cannot initialize QMI device: No file given");
- init_context_complete_and_free (ctx);
+ if (!self->priv->file) {
+ g_task_return_new_error (task,
+ QMI_CORE_ERROR,
+ QMI_CORE_ERROR_INVALID_ARGS,
+ "Cannot initialize QMI device: No file given");
+ g_object_unref (task);
return;
}
/* If no file check requested, don't do it */
- if (ctx->self->priv->no_file_check) {
- client_ctl_setup (ctx);
+ if (self->priv->no_file_check) {
+ client_ctl_setup (task);
return;
}
/* Check the file type. Note that this is just a quick check to avoid
* creating QmiDevices pointing to a location already known not to be a QMI
* device. */
- g_file_query_info_async (ctx->self->priv->file,
+ g_file_query_info_async (self->priv->file,
G_FILE_ATTRIBUTE_STANDARD_TYPE,
G_FILE_QUERY_INFO_NONE,
G_PRIORITY_DEFAULT,
- ctx->cancellable,
+ cancellable,
(GAsyncReadyCallback)query_info_async_ready,
- ctx);
+ task);
}
/*****************************************************************************/