[PATCH 4/5] libmm-glib, modem: port mm_modem_create_bearer to use GTask

Ben Chan benchan at chromium.org
Fri Jun 23 16:11:07 UTC 2017


---
 libmm-glib/mm-modem.c | 52 +++++++++++++--------------------------------------
 1 file changed, 13 insertions(+), 39 deletions(-)

diff --git a/libmm-glib/mm-modem.c b/libmm-glib/mm-modem.c
index 629e227e..7359357a 100644
--- a/libmm-glib/mm-modem.c
+++ b/libmm-glib/mm-modem.c
@@ -1970,21 +1970,6 @@ mm_modem_list_bearers_sync (MMModem *self,
 
 /*****************************************************************************/
 
-typedef struct {
-    GSimpleAsyncResult *result;
-    GCancellable *cancellable;
-} CreateBearerContext;
-
-static void
-create_bearer_context_complete_and_free (CreateBearerContext *ctx)
-{
-    g_simple_async_result_complete (ctx->result);
-    g_object_unref (ctx->result);
-    if (ctx->cancellable)
-        g_object_unref (ctx->cancellable);
-    g_slice_free (CreateBearerContext, ctx);
-}
-
 /**
  * mm_modem_create_bearer_finish:
  * @self: A #MMModem.
@@ -2002,16 +1987,13 @@ mm_modem_create_bearer_finish (MMModem *self,
 {
     g_return_val_if_fail (MM_IS_MODEM (self), NULL);
 
-    if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error))
-        return NULL;
-
-    return g_object_ref (g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (res)));
+    return g_task_propagate_pointer (G_TASK (res), error);
 }
 
 static void
 modem_new_bearer_ready (GDBusConnection *connection,
                         GAsyncResult *res,
-                        CreateBearerContext *ctx)
+                        GTask *task)
 {
     GError *error = NULL;
     GObject *bearer;
@@ -2022,19 +2004,17 @@ modem_new_bearer_ready (GDBusConnection *connection,
     g_object_unref (source_object);
 
     if (error)
-        g_simple_async_result_take_error (ctx->result, error);
+        g_task_return_error (task, error);
     else
-        g_simple_async_result_set_op_res_gpointer (ctx->result,
-                                                   bearer,
-                                                   g_object_unref);
+        g_task_return_pointer (task, bearer, g_object_unref);
 
-    create_bearer_context_complete_and_free (ctx);
+    g_object_unref (task);
 }
 
 static void
 modem_create_bearer_ready (MMModem *self,
                            GAsyncResult *res,
-                           CreateBearerContext *ctx)
+                           GTask *task)
 {
     GError *error = NULL;
     gchar *bearer_path = NULL;
@@ -2043,17 +2023,17 @@ modem_create_bearer_ready (MMModem *self,
                                                    &bearer_path,
                                                    res,
                                                    &error)) {
-        g_simple_async_result_take_error (ctx->result, error);
-        create_bearer_context_complete_and_free (ctx);
+        g_task_return_error (task, error);
+        g_object_unref (task);
         g_free (bearer_path);
         return;
     }
 
     g_async_initable_new_async (MM_TYPE_BEARER,
                                 G_PRIORITY_DEFAULT,
-                                ctx->cancellable,
+                                g_task_get_cancellable (task),
                                 (GAsyncReadyCallback)modem_new_bearer_ready,
-                                ctx,
+                                task,
                                 "g-flags",          G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START,
                                 "g-name",           MM_DBUS_SERVICE,
                                 "g-connection",     g_dbus_proxy_get_connection (G_DBUS_PROXY (self)),
@@ -2090,18 +2070,12 @@ mm_modem_create_bearer (MMModem *self,
                         GAsyncReadyCallback callback,
                         gpointer user_data)
 {
-    CreateBearerContext *ctx;
+    GTask *task;
     GVariant *dictionary;
 
     g_return_if_fail (MM_IS_MODEM (self));
 
-    ctx = g_slice_new0 (CreateBearerContext);
-    ctx->result = g_simple_async_result_new (G_OBJECT (self),
-                                             callback,
-                                             user_data,
-                                             mm_modem_create_bearer);
-    if (cancellable)
-        ctx->cancellable = g_object_ref (cancellable);
+    task = g_task_new (self, cancellable, callback, user_data);
 
     dictionary = mm_bearer_properties_get_dictionary (properties);
 
@@ -2110,7 +2084,7 @@ mm_modem_create_bearer (MMModem *self,
         dictionary,
         cancellable,
         (GAsyncReadyCallback)modem_create_bearer_ready,
-        ctx);
+        task);
 
     g_variant_unref (dictionary);
 }
-- 
2.13.1.611.g7e3b11ae1-goog



More information about the ModemManager-devel mailing list