[PATCH 3/4] iface-modem-3gpp: port mm_iface_modem_3gpp_disable to use GTask

Aleksander Morgado aleksander at aleksander.es
Fri Jun 30 09:01:47 UTC 2017


On 29/06/17 13:46, Ben Chan wrote:
> ---
>  src/mm-iface-modem-3gpp.c | 103 ++++++++++++++++++++++++----------------------
>  1 file changed, 53 insertions(+), 50 deletions(-)
> 

Pushed to git master, thanks.

> diff --git a/src/mm-iface-modem-3gpp.c b/src/mm-iface-modem-3gpp.c
> index b9446507..772d3609 100644
> --- a/src/mm-iface-modem-3gpp.c
> +++ b/src/mm-iface-modem-3gpp.c
> @@ -1386,7 +1386,7 @@ periodic_registration_check_enable (MMIfaceModem3gpp *self)
>  /*****************************************************************************/
>  
>  typedef struct _DisablingContext DisablingContext;
> -static void interface_disabling_step (DisablingContext *ctx);
> +static void interface_disabling_step (GTask *task);
>  
>  typedef enum {
>      DISABLING_STEP_FIRST,
> @@ -1400,18 +1400,13 @@ typedef enum {
>  } DisablingStep;
>  
>  struct _DisablingContext {
> -    MMIfaceModem3gpp *self;
>      DisablingStep step;
> -    GSimpleAsyncResult *result;
>      MmGdbusModem *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);
> @@ -1422,7 +1417,7 @@ mm_iface_modem_3gpp_disable_finish (MMIfaceModem3gpp *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);
>  }
>  
>  #undef VOID_REPLY_READY_FN
> @@ -1430,8 +1425,9 @@ mm_iface_modem_3gpp_disable_finish (MMIfaceModem3gpp *self,
>      static void                                                         \
>      NAME##_ready (MMIfaceModem3gpp *self,                               \
>                    GAsyncResult *res,                                    \
> -                  DisablingContext *ctx)                                \
> +                  GTask *task)                                          \
>      {                                                                   \
> +        DisablingContext *ctx;                                          \
>          GError *error = NULL;                                           \
>                                                                          \
>          MM_IFACE_MODEM_3GPP_GET_INTERFACE (self)->NAME##_finish (self, res, &error); \
> @@ -1441,8 +1437,9 @@ mm_iface_modem_3gpp_disable_finish (MMIfaceModem3gpp *self,
>          }                                                               \
>                                                                          \
>          /* Go on to next step */                                        \
> +        ctx = g_task_get_task_data (task);                              \
>          ctx->step++;                                                    \
> -        interface_disabling_step (ctx);                                 \
> +        interface_disabling_step (task);                                \
>      }
>  
>  VOID_REPLY_READY_FN (cleanup_unsolicited_events,
> @@ -1455,8 +1452,14 @@ VOID_REPLY_READY_FN (disable_unsolicited_registration_events,
>                       "disable unsolicited registration events")
>  
>  static void
> -interface_disabling_step (DisablingContext *ctx)
> +interface_disabling_step (GTask *task)
>  {
> +    MMIfaceModem3gpp *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 */
> @@ -1464,7 +1467,7 @@ interface_disabling_step (DisablingContext *ctx)
>  
>      case DISABLING_STEP_PERIODIC_REGISTRATION_CHECKS:
>          /* Disable periodic registration checks, if they were set */
> -        periodic_registration_check_disable (ctx->self);
> +        periodic_registration_check_disable (self);
>          /* Fall down to next step */
>          ctx->step++;
>  
> @@ -1473,21 +1476,21 @@ interface_disabling_step (DisablingContext *ctx)
>          gboolean ps_supported = FALSE;
>          gboolean eps_supported = FALSE;
>  
> -        g_object_get (ctx->self,
> +        g_object_get (self,
>                        MM_IFACE_MODEM_3GPP_CS_NETWORK_SUPPORTED, &cs_supported,
>                        MM_IFACE_MODEM_3GPP_PS_NETWORK_SUPPORTED, &ps_supported,
>                        MM_IFACE_MODEM_3GPP_EPS_NETWORK_SUPPORTED, &eps_supported,
>                        NULL);
>  
> -        if (MM_IFACE_MODEM_3GPP_GET_INTERFACE (ctx->self)->disable_unsolicited_registration_events &&
> -            MM_IFACE_MODEM_3GPP_GET_INTERFACE (ctx->self)->disable_unsolicited_registration_events_finish) {
> -            MM_IFACE_MODEM_3GPP_GET_INTERFACE (ctx->self)->disable_unsolicited_registration_events (
> -                ctx->self,
> +        if (MM_IFACE_MODEM_3GPP_GET_INTERFACE (self)->disable_unsolicited_registration_events &&
> +            MM_IFACE_MODEM_3GPP_GET_INTERFACE (self)->disable_unsolicited_registration_events_finish) {
> +            MM_IFACE_MODEM_3GPP_GET_INTERFACE (self)->disable_unsolicited_registration_events (
> +                self,
>                  cs_supported,
>                  ps_supported,
>                  eps_supported,
>                  (GAsyncReadyCallback)disable_unsolicited_registration_events_ready,
> -                ctx);
> +                task);
>              return;
>          }
>          /* Fall down to next step */
> @@ -1495,52 +1498,52 @@ interface_disabling_step (DisablingContext *ctx)
>      }
>  
>      case DISABLING_STEP_CLEANUP_UNSOLICITED_REGISTRATION_EVENTS:
> -        if (MM_IFACE_MODEM_3GPP_GET_INTERFACE (ctx->self)->cleanup_unsolicited_registration_events &&
> -            MM_IFACE_MODEM_3GPP_GET_INTERFACE (ctx->self)->cleanup_unsolicited_registration_events_finish) {
> -            MM_IFACE_MODEM_3GPP_GET_INTERFACE (ctx->self)->cleanup_unsolicited_registration_events (
> -                ctx->self,
> +        if (MM_IFACE_MODEM_3GPP_GET_INTERFACE (self)->cleanup_unsolicited_registration_events &&
> +            MM_IFACE_MODEM_3GPP_GET_INTERFACE (self)->cleanup_unsolicited_registration_events_finish) {
> +            MM_IFACE_MODEM_3GPP_GET_INTERFACE (self)->cleanup_unsolicited_registration_events (
> +                self,
>                  (GAsyncReadyCallback)cleanup_unsolicited_registration_events_ready,
> -                ctx);
> +                task);
>              return;
>          }
>          /* Fall down to next step */
>          ctx->step++;
>  
>      case DISABLING_STEP_CLEANUP_UNSOLICITED_EVENTS:
> -        if (MM_IFACE_MODEM_3GPP_GET_INTERFACE (ctx->self)->cleanup_unsolicited_events &&
> -            MM_IFACE_MODEM_3GPP_GET_INTERFACE (ctx->self)->cleanup_unsolicited_events_finish) {
> -            MM_IFACE_MODEM_3GPP_GET_INTERFACE (ctx->self)->cleanup_unsolicited_events (
> -                ctx->self,
> +        if (MM_IFACE_MODEM_3GPP_GET_INTERFACE (self)->cleanup_unsolicited_events &&
> +            MM_IFACE_MODEM_3GPP_GET_INTERFACE (self)->cleanup_unsolicited_events_finish) {
> +            MM_IFACE_MODEM_3GPP_GET_INTERFACE (self)->cleanup_unsolicited_events (
> +                self,
>                  (GAsyncReadyCallback)cleanup_unsolicited_events_ready,
> -                ctx);
> +                task);
>              return;
>          }
>          /* Fall down to next step */
>          ctx->step++;
>  
>      case DISABLING_STEP_DISABLE_UNSOLICITED_EVENTS:
> -        if (MM_IFACE_MODEM_3GPP_GET_INTERFACE (ctx->self)->disable_unsolicited_events &&
> -            MM_IFACE_MODEM_3GPP_GET_INTERFACE (ctx->self)->disable_unsolicited_events_finish) {
> -            MM_IFACE_MODEM_3GPP_GET_INTERFACE (ctx->self)->disable_unsolicited_events (
> -                ctx->self,
> +        if (MM_IFACE_MODEM_3GPP_GET_INTERFACE (self)->disable_unsolicited_events &&
> +            MM_IFACE_MODEM_3GPP_GET_INTERFACE (self)->disable_unsolicited_events_finish) {
> +            MM_IFACE_MODEM_3GPP_GET_INTERFACE (self)->disable_unsolicited_events (
> +                self,
>                  (GAsyncReadyCallback)disable_unsolicited_events_ready,
> -                ctx);
> +                task);
>              return;
>          }
>          /* Fall down to next step */
>          ctx->step++;
>  
>      case DISABLING_STEP_REGISTRATION_STATE:
> -        update_registration_state (ctx->self, MM_MODEM_3GPP_REGISTRATION_STATE_UNKNOWN, FALSE);
> -        mm_iface_modem_3gpp_update_access_technologies (ctx->self, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN);
> -        mm_iface_modem_3gpp_update_location (ctx->self, 0, 0);
> +        update_registration_state (self, MM_MODEM_3GPP_REGISTRATION_STATE_UNKNOWN, FALSE);
> +        mm_iface_modem_3gpp_update_access_technologies (self, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN);
> +        mm_iface_modem_3gpp_update_location (self, 0, 0);
>          /* Fall down to next step */
>          ctx->step++;
>  
>      case DISABLING_STEP_LAST:
>          /* 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;
>      }
>  
> @@ -1553,27 +1556,27 @@ mm_iface_modem_3gpp_disable (MMIfaceModem3gpp *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_3gpp_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_3GPP_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);
>  }
>  
>  /*****************************************************************************/
> 


-- 
Aleksander
https://aleksander.es


More information about the ModemManager-devel mailing list