[PATCH 2/2] sms-mbim: port sms_delete to use GTask

Ben Chan benchan at chromium.org
Thu Apr 6 19:57:45 UTC 2017


---
 src/mm-sms-mbim.c | 48 +++++++++++++++++++++++-------------------------
 1 file changed, 23 insertions(+), 25 deletions(-)

diff --git a/src/mm-sms-mbim.c b/src/mm-sms-mbim.c
index 085a2d59..99e0de74 100644
--- a/src/mm-sms-mbim.c
+++ b/src/mm-sms-mbim.c
@@ -207,22 +207,17 @@ sms_send (MMBaseSms *self,
 /*****************************************************************************/
 
 typedef struct {
-    MMBaseSms *self;
     MMBaseModem *modem;
     MbimDevice *device;
-    GSimpleAsyncResult *result;
     GList *current;
     guint n_failed;
 } SmsDeletePartsContext;
 
 static void
-sms_delete_parts_context_complete_and_free (SmsDeletePartsContext *ctx)
+sms_delete_parts_context_free (SmsDeletePartsContext *ctx)
 {
-    g_simple_async_result_complete_in_idle (ctx->result);
-    g_object_unref (ctx->result);
     g_object_unref (ctx->device);
     g_object_unref (ctx->modem);
-    g_object_unref (ctx->self);
     g_slice_free (SmsDeletePartsContext, ctx);
 }
 
@@ -231,19 +226,21 @@ sms_delete_finish (MMBaseSms *self,
                    GAsyncResult *res,
                    GError **error)
 {
-    return !g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error);
+    return g_task_propagate_boolean (G_TASK (res), error);
 }
 
-static void delete_next_part (SmsDeletePartsContext *ctx);
+static void delete_next_part (GTask *task);
 
 static void
 sms_delete_set_ready (MbimDevice *device,
                       GAsyncResult *res,
-                      SmsDeletePartsContext *ctx)
+                      GTask *task)
 {
+    SmsDeletePartsContext *ctx;
     MbimMessage *response;
     GError *error = NULL;
 
+    ctx = g_task_get_task_data (task);
     response = mbim_device_command_finish (device, res, &error);
     if (response &&
         mbim_message_response_get_result (response, MBIM_MESSAGE_TYPE_COMMAND_DONE, &error))
@@ -264,14 +261,16 @@ sms_delete_set_ready (MbimDevice *device,
     mm_sms_part_set_index ((MMSmsPart *)ctx->current->data, SMS_PART_INVALID_INDEX);
 
     ctx->current = g_list_next (ctx->current);
-    delete_next_part (ctx);
+    delete_next_part (task);
 }
 
 static void
-delete_next_part (SmsDeletePartsContext *ctx)
+delete_next_part (GTask *task)
 {
+    SmsDeletePartsContext *ctx;
     MbimMessage *message;
 
+    ctx = g_task_get_task_data (task);
     /* Skip non-stored parts */
     while (ctx->current &&
            mm_sms_part_get_index ((MMSmsPart *)ctx->current->data) == SMS_PART_INVALID_INDEX)
@@ -280,15 +279,15 @@ delete_next_part (SmsDeletePartsContext *ctx)
     /* If all removed, we're done */
     if (!ctx->current) {
         if (ctx->n_failed > 0)
-            g_simple_async_result_set_error (ctx->result,
-                                             MM_CORE_ERROR,
-                                             MM_CORE_ERROR_FAILED,
-                                             "Couldn't delete %u parts from this SMS",
-                                             ctx->n_failed);
+            g_task_return_new_error (task,
+                                     MM_CORE_ERROR,
+                                     MM_CORE_ERROR_FAILED,
+                                     "Couldn't delete %u parts from this SMS",
+                                     ctx->n_failed);
         else
-            g_simple_async_result_set_op_res_gboolean (ctx->result, TRUE);
+            g_task_return_boolean (task, TRUE);
 
-        sms_delete_parts_context_complete_and_free (ctx);
+        g_object_unref (task);
         return;
     }
 
@@ -300,7 +299,7 @@ delete_next_part (SmsDeletePartsContext *ctx)
                          10,
                          NULL,
                          (GAsyncReadyCallback)sms_delete_set_ready,
-                         ctx);
+                         task);
     mbim_message_unref (message);
 
 }
@@ -312,24 +311,23 @@ sms_delete (MMBaseSms *self,
 {
     SmsDeletePartsContext *ctx;
     MbimDevice *device;
+    GTask *task;
 
     if (!peek_device (self, &device, callback, user_data))
         return;
 
     ctx = g_slice_new0 (SmsDeletePartsContext);
-    ctx->result = g_simple_async_result_new (G_OBJECT (self),
-                                             callback,
-                                             user_data,
-                                             sms_delete);
-    ctx->self = g_object_ref (self);
     ctx->device = g_object_ref (device);
     g_object_get (self,
                   MM_BASE_SMS_MODEM, &ctx->modem,
                   NULL);
 
+    task = g_task_new (self, NULL, callback, user_data);
+    g_task_set_task_data (task, ctx, (GDestroyNotify)sms_delete_parts_context_free);
+
     /* Go on deleting parts */
     ctx->current = mm_base_sms_get_parts (self);
-    delete_next_part (ctx);
+    delete_next_part (task);
 }
 
 /*****************************************************************************/
-- 
2.12.2.715.g7642488e1d-goog



More information about the ModemManager-devel mailing list