[PATCH 3/3] iface-modem-messaging: port mm_iface_modem_messaging_disable to use GTask

Aleksander Morgado aleksander at aleksander.es
Wed Jun 28 08:23:59 UTC 2017


On Tue, Jun 27, 2017 at 5:54 PM, Ben Chan <benchan at chromium.org> wrote:
> ---
>  src/mm-iface-modem-messaging.c | 89 ++++++++++++++++++++++--------------------
>  1 file changed, 47 insertions(+), 42 deletions(-)
>

Pushed to git master, thanks!

> diff --git a/src/mm-iface-modem-messaging.c b/src/mm-iface-modem-messaging.c
> index a21cc8d0..5bcd606e 100644
> --- a/src/mm-iface-modem-messaging.c
> +++ b/src/mm-iface-modem-messaging.c
> @@ -526,7 +526,7 @@ sms_deleted (MMSmsList *list,
>  /*****************************************************************************/
>
>  typedef struct _DisablingContext DisablingContext;
> -static void interface_disabling_step (DisablingContext *ctx);
> +static void interface_disabling_step (GTask *task);
>
>  typedef enum {
>      DISABLING_STEP_FIRST,
> @@ -536,18 +536,13 @@ typedef enum {
>  } DisablingStep;
>
>  struct _DisablingContext {
> -    MMIfaceModemMessaging *self;
>      DisablingStep step;
> -    GSimpleAsyncResult *result;
>      MmGdbusModemMessaging *skeleton;
>  };
>
>  static void
> -disabling_context_complete_and_free (DisablingContext *ctx)
> +disabling_context_free (DisablingContext *ctx)
>  {
> -    g_simple_async_result_complete_in_idle (ctx->result);
> -    g_object_unref (ctx->self);
> -    g_object_unref (ctx->result);
>      if (ctx->skeleton)
>          g_object_unref (ctx->skeleton);
>      g_free (ctx);
> @@ -558,50 +553,60 @@ mm_iface_modem_messaging_disable_finish (MMIfaceModemMessaging *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
>  disable_unsolicited_events_ready (MMIfaceModemMessaging *self,
>                                    GAsyncResult *res,
> -                                  DisablingContext *ctx)
> +                                  GTask *task)
>  {
> +    DisablingContext *ctx;
>      GError *error = NULL;
>
>      MM_IFACE_MODEM_MESSAGING_GET_INTERFACE (self)->disable_unsolicited_events_finish (self, res, &error);
>      if (error) {
> -        g_simple_async_result_take_error (ctx->result, error);
> -        disabling_context_complete_and_free (ctx);
> +        g_task_return_error (task, error);
> +        g_object_unref (task);
>          return;
>      }
>
>      /* Go on to next step */
> +    ctx = g_task_get_task_data (task);
>      ctx->step++;
> -    interface_disabling_step (ctx);
> +    interface_disabling_step (task);
>  }
>
>  static void
>  cleanup_unsolicited_events_ready (MMIfaceModemMessaging *self,
>                                    GAsyncResult *res,
> -                                  DisablingContext *ctx)
> +                                  GTask *task)
>  {
> +    DisablingContext *ctx;
>      GError *error = NULL;
>
>      MM_IFACE_MODEM_MESSAGING_GET_INTERFACE (self)->cleanup_unsolicited_events_finish (self, res, &error);
>      if (error) {
> -        g_simple_async_result_take_error (ctx->result, error);
> -        disabling_context_complete_and_free (ctx);
> +        g_task_return_error (task, error);
> +        g_object_unref (task);
>          return;
>      }
>
>      /* Go on to next step */
> +    ctx = g_task_get_task_data (task);
>      ctx->step++;
> -    interface_disabling_step (ctx);
> +    interface_disabling_step (task);
>  }
>
>  static void
> -interface_disabling_step (DisablingContext *ctx)
> +interface_disabling_step (GTask *task)
>  {
> +    MMIfaceModemMessaging *self;
> +    DisablingContext *ctx;
> +
> +    self = g_task_get_source_object (task);
> +    ctx = g_task_get_task_data (task);
> +
>      switch (ctx->step) {
>      case DISABLING_STEP_FIRST:
>          /* Fall down to next step */
> @@ -609,12 +614,12 @@ interface_disabling_step (DisablingContext *ctx)
>
>      case DISABLING_STEP_DISABLE_UNSOLICITED_EVENTS:
>          /* Allow cleaning up unsolicited events */
> -        if (MM_IFACE_MODEM_MESSAGING_GET_INTERFACE (ctx->self)->disable_unsolicited_events &&
> -            MM_IFACE_MODEM_MESSAGING_GET_INTERFACE (ctx->self)->disable_unsolicited_events_finish) {
> -            MM_IFACE_MODEM_MESSAGING_GET_INTERFACE (ctx->self)->disable_unsolicited_events (
> -                ctx->self,
> +        if (MM_IFACE_MODEM_MESSAGING_GET_INTERFACE (self)->disable_unsolicited_events &&
> +            MM_IFACE_MODEM_MESSAGING_GET_INTERFACE (self)->disable_unsolicited_events_finish) {
> +            MM_IFACE_MODEM_MESSAGING_GET_INTERFACE (self)->disable_unsolicited_events (
> +                self,
>                  (GAsyncReadyCallback)disable_unsolicited_events_ready,
> -                ctx);
> +                task);
>              return;
>          }
>          /* Fall down to next step */
> @@ -622,12 +627,12 @@ interface_disabling_step (DisablingContext *ctx)
>
>      case DISABLING_STEP_CLEANUP_UNSOLICITED_EVENTS:
>          /* Allow cleaning up unsolicited events */
> -        if (MM_IFACE_MODEM_MESSAGING_GET_INTERFACE (ctx->self)->cleanup_unsolicited_events &&
> -            MM_IFACE_MODEM_MESSAGING_GET_INTERFACE (ctx->self)->cleanup_unsolicited_events_finish) {
> -            MM_IFACE_MODEM_MESSAGING_GET_INTERFACE (ctx->self)->cleanup_unsolicited_events (
> -                ctx->self,
> +        if (MM_IFACE_MODEM_MESSAGING_GET_INTERFACE (self)->cleanup_unsolicited_events &&
> +            MM_IFACE_MODEM_MESSAGING_GET_INTERFACE (self)->cleanup_unsolicited_events_finish) {
> +            MM_IFACE_MODEM_MESSAGING_GET_INTERFACE (self)->cleanup_unsolicited_events (
> +                self,
>                  (GAsyncReadyCallback)cleanup_unsolicited_events_ready,
> -                ctx);
> +                task);
>              return;
>          }
>          /* Fall down to next step */
> @@ -635,13 +640,13 @@ interface_disabling_step (DisablingContext *ctx)
>
>      case DISABLING_STEP_LAST:
>          /* Clear SMS list */
> -        g_object_set (ctx->self,
> +        g_object_set (self,
>                        MM_IFACE_MODEM_MESSAGING_SMS_LIST, NULL,
>                        NULL);
>
>          /* We are done without errors! */
> -        g_simple_async_result_set_op_res_gboolean (ctx->result, TRUE);
> -        disabling_context_complete_and_free (ctx);
> +        g_task_return_boolean (task, TRUE);
> +        g_object_unref (task);
>          return;
>      }
>
> @@ -654,27 +659,27 @@ mm_iface_modem_messaging_disable (MMIfaceModemMessaging *self,
>                                    gpointer user_data)
>  {
>      DisablingContext *ctx;
> +    GTask *task;
>
>      ctx = g_new0 (DisablingContext, 1);
> -    ctx->self = g_object_ref (self);
> -    ctx->result = g_simple_async_result_new (G_OBJECT (self),
> -                                             callback,
> -                                             user_data,
> -                                             mm_iface_modem_messaging_disable);
>      ctx->step = DISABLING_STEP_FIRST;
> -    g_object_get (ctx->self,
> +
> +    task = g_task_new (self, NULL, callback, user_data);
> +    g_task_set_task_data (task, ctx, (GDestroyNotify)disabling_context_free);
> +
> +    g_object_get (self,
>                    MM_IFACE_MODEM_MESSAGING_DBUS_SKELETON, &ctx->skeleton,
>                    NULL);
>      if (!ctx->skeleton) {
> -        g_simple_async_result_set_error (ctx->result,
> -                                         MM_CORE_ERROR,
> -                                         MM_CORE_ERROR_FAILED,
> -                                         "Couldn't get interface skeleton");
> -        disabling_context_complete_and_free (ctx);
> +        g_task_return_new_error (task,
> +                                 MM_CORE_ERROR,
> +                                 MM_CORE_ERROR_FAILED,
> +                                 "Couldn't get interface skeleton");
> +        g_object_unref (task);
>          return;
>      }
>
> -    interface_disabling_step (ctx);
> +    interface_disabling_step (task);
>  }
>
>  /*****************************************************************************/
> --
> 2.13.1
>



-- 
Aleksander
https://aleksander.es


More information about the ModemManager-devel mailing list