altair-lte: port modem_create_bearer to use GTask

This commit is contained in:
Ben Chan
2017-07-18 22:33:18 -07:00
committed by Aleksander Morgado
parent 555883d107
commit a96e8f824b

View File

@@ -104,33 +104,23 @@ modem_create_bearer_finish (MMIfaceModem *self,
GAsyncResult *res, GAsyncResult *res,
GError **error) GError **error)
{ {
MMBaseBearer *bearer; return g_task_propagate_pointer (G_TASK (res), error);
if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error))
return NULL;
bearer = g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (res));
return g_object_ref (bearer);
} }
static void static void
broadband_bearer_new_ready (GObject *source, broadband_bearer_new_ready (GObject *source,
GAsyncResult *res, GAsyncResult *res,
GSimpleAsyncResult *simple) GTask *task)
{ {
MMBaseBearer *bearer = NULL; MMBaseBearer *bearer = NULL;
GError *error = NULL; GError *error = NULL;
bearer = mm_broadband_bearer_altair_lte_new_finish (res, &error); bearer = mm_broadband_bearer_altair_lte_new_finish (res, &error);
if (!bearer) if (!bearer)
g_simple_async_result_take_error (simple, error); g_task_return_error (task, error);
else else
g_simple_async_result_set_op_res_gpointer (simple, g_task_return_pointer (task, bearer, g_object_unref);
bearer, g_object_unref (task);
g_object_unref);
g_simple_async_result_complete (simple);
g_object_unref (simple);
} }
static void static void
@@ -139,20 +129,16 @@ modem_create_bearer (MMIfaceModem *self,
GAsyncReadyCallback callback, GAsyncReadyCallback callback,
gpointer user_data) gpointer user_data)
{ {
GSimpleAsyncResult *result; GTask *task;
/* Set a new ref to the bearer object as result */ task = g_task_new (self, NULL, callback, user_data);
result = g_simple_async_result_new (G_OBJECT (self),
callback,
user_data,
modem_create_bearer);
/* We just create a MMBroadbandBearer */ /* We just create a MMBroadbandBearer */
mm_broadband_bearer_altair_lte_new (MM_BROADBAND_MODEM_ALTAIR_LTE (self), mm_broadband_bearer_altair_lte_new (MM_BROADBAND_MODEM_ALTAIR_LTE (self),
properties, properties,
NULL, /* cancellable */ NULL, /* cancellable */
(GAsyncReadyCallback)broadband_bearer_new_ready, (GAsyncReadyCallback)broadband_bearer_new_ready,
result); task);
} }
/*****************************************************************************/ /*****************************************************************************/