Re: [PATCH 4/4] iface-modem-time: port update_network_timezone to use GTask

2017-06-29 Thread Aleksander Morgado
On 29/06/17 06:44, Ben Chan wrote:
> ---
>  src/mm-iface-modem-time.c | 120 
> +++---
>  1 file changed, 61 insertions(+), 59 deletions(-)
> 

Pushed to git master, thanks.

> diff --git a/src/mm-iface-modem-time.c b/src/mm-iface-modem-time.c
> index eec340ed..41ca2f0e 100644
> --- a/src/mm-iface-modem-time.c
> +++ b/src/mm-iface-modem-time.c
> @@ -125,53 +125,46 @@ handle_get_network_time (MmGdbusModemTime *skeleton,
>  
> /*/
>  
>  typedef struct {
> -MMIfaceModemTime *self;
> -GSimpleAsyncResult *result;
> -GCancellable *cancellable;
>  gulong cancelled_id;
>  gulong state_changed_id;
>  guint network_timezone_poll_id;
>  guint network_timezone_poll_retries;
>  } UpdateNetworkTimezoneContext;
>  
> -static gboolean timezone_poll_cb (UpdateNetworkTimezoneContext *ctx);
> -
> -static void
> -update_network_timezone_context_complete_and_free 
> (UpdateNetworkTimezoneContext *ctx)
> -{
> -g_simple_async_result_complete (ctx->result);
> -g_object_unref (ctx->result);
> -g_object_unref (ctx->cancellable);
> -g_object_unref (ctx->self);
> -g_free (ctx);
> -}
> +static gboolean timezone_poll_cb (GTask *task);
>  
>  static gboolean
>  update_network_timezone_finish (MMIfaceModemTime *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
>  cancelled (GCancellable *cancellable,
> -   UpdateNetworkTimezoneContext *ctx)
> +   GTask *task)
>  {
> +MMIfaceModemTime *self;
> +UpdateNetworkTimezoneContext *ctx;
> +
> +self = g_task_get_source_object (task);
> +ctx = g_task_get_task_data (task);
> +
>  /* If waiting to get registered, disconnect signal */
>  if (ctx->state_changed_id)
> -g_signal_handler_disconnect (ctx->self,
> +g_signal_handler_disconnect (self,
>   ctx->state_changed_id);
>  
>  /* If waiting in the timeout loop, remove the timeout */
>  else if (ctx->network_timezone_poll_id)
>  g_source_remove (ctx->network_timezone_poll_id);
>  
> -g_simple_async_result_set_error (ctx->result,
> - MM_CORE_ERROR,
> - MM_CORE_ERROR_CANCELLED,
> - "Network timezone loading cancelled");
> -update_network_timezone_context_complete_and_free (ctx);
> +g_task_return_new_error (task,
> + MM_CORE_ERROR,
> + MM_CORE_ERROR_CANCELLED,
> + "Network timezone loading cancelled");
> +g_object_unref (task);
>  }
>  
>  static void
> @@ -198,21 +191,19 @@ update_network_timezone_dictionary (MMIfaceModemTime 
> *self,
>  static void
>  load_network_timezone_ready (MMIfaceModemTime *self,
>   GAsyncResult *res,
> - UpdateNetworkTimezoneContext *ctx)
> + GTask *task)
>  {
> +UpdateNetworkTimezoneContext *ctx;
>  GError *error = NULL;
>  MMNetworkTimezone *tz;
>  
> -if (g_cancellable_is_cancelled (ctx->cancellable)) {
> -g_simple_async_result_set_error (ctx->result,
> - MM_CORE_ERROR,
> - MM_CORE_ERROR_CANCELLED,
> - "Finished network timezone loading, 
> "
> - "but cancelled meanwhile");
> -update_network_timezone_context_complete_and_free (ctx);
> +if (g_task_return_error_if_cancelled (task)) {
> +g_object_unref (task);
>  return;
>  }
>  
> +ctx = g_task_get_task_data (task);
> +
>  /* Finish the async operation */
>  tz = MM_IFACE_MODEM_TIME_GET_INTERFACE 
> (self)->load_network_timezone_finish (self,
>   
> res,
> @@ -226,69 +217,80 @@ load_network_timezone_ready (MMIfaceModemTime *self,
>  !g_error_matches (error,
>MM_CORE_ERROR,
>MM_CORE_ERROR_RETRY)) {
> -g_simple_async_result_take_error (ctx->result, error);
> -update_network_timezone_context_complete_and_free (ctx);
> +g_task_return_error (task, error);
> +g_object_unref (task);
>  return;
>  }
>  
>  /* Otherwise, reconnect cancellable and relaunch timeout to query a 
> bit
>   * later */
> -ctx->cancelled_id = g_cancellable_connect (ctx->cancellable,
> +ctx->cancelled_id = g_cancellable_connect 

[PATCH 4/4] iface-modem-time: port update_network_timezone to use GTask

2017-06-28 Thread Ben Chan
---
 src/mm-iface-modem-time.c | 120 +++---
 1 file changed, 61 insertions(+), 59 deletions(-)

diff --git a/src/mm-iface-modem-time.c b/src/mm-iface-modem-time.c
index eec340ed..41ca2f0e 100644
--- a/src/mm-iface-modem-time.c
+++ b/src/mm-iface-modem-time.c
@@ -125,53 +125,46 @@ handle_get_network_time (MmGdbusModemTime *skeleton,
 /*/
 
 typedef struct {
-MMIfaceModemTime *self;
-GSimpleAsyncResult *result;
-GCancellable *cancellable;
 gulong cancelled_id;
 gulong state_changed_id;
 guint network_timezone_poll_id;
 guint network_timezone_poll_retries;
 } UpdateNetworkTimezoneContext;
 
-static gboolean timezone_poll_cb (UpdateNetworkTimezoneContext *ctx);
-
-static void
-update_network_timezone_context_complete_and_free 
(UpdateNetworkTimezoneContext *ctx)
-{
-g_simple_async_result_complete (ctx->result);
-g_object_unref (ctx->result);
-g_object_unref (ctx->cancellable);
-g_object_unref (ctx->self);
-g_free (ctx);
-}
+static gboolean timezone_poll_cb (GTask *task);
 
 static gboolean
 update_network_timezone_finish (MMIfaceModemTime *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
 cancelled (GCancellable *cancellable,
-   UpdateNetworkTimezoneContext *ctx)
+   GTask *task)
 {
+MMIfaceModemTime *self;
+UpdateNetworkTimezoneContext *ctx;
+
+self = g_task_get_source_object (task);
+ctx = g_task_get_task_data (task);
+
 /* If waiting to get registered, disconnect signal */
 if (ctx->state_changed_id)
-g_signal_handler_disconnect (ctx->self,
+g_signal_handler_disconnect (self,
  ctx->state_changed_id);
 
 /* If waiting in the timeout loop, remove the timeout */
 else if (ctx->network_timezone_poll_id)
 g_source_remove (ctx->network_timezone_poll_id);
 
-g_simple_async_result_set_error (ctx->result,
- MM_CORE_ERROR,
- MM_CORE_ERROR_CANCELLED,
- "Network timezone loading cancelled");
-update_network_timezone_context_complete_and_free (ctx);
+g_task_return_new_error (task,
+ MM_CORE_ERROR,
+ MM_CORE_ERROR_CANCELLED,
+ "Network timezone loading cancelled");
+g_object_unref (task);
 }
 
 static void
@@ -198,21 +191,19 @@ update_network_timezone_dictionary (MMIfaceModemTime 
*self,
 static void
 load_network_timezone_ready (MMIfaceModemTime *self,
  GAsyncResult *res,
- UpdateNetworkTimezoneContext *ctx)
+ GTask *task)
 {
+UpdateNetworkTimezoneContext *ctx;
 GError *error = NULL;
 MMNetworkTimezone *tz;
 
-if (g_cancellable_is_cancelled (ctx->cancellable)) {
-g_simple_async_result_set_error (ctx->result,
- MM_CORE_ERROR,
- MM_CORE_ERROR_CANCELLED,
- "Finished network timezone loading, "
- "but cancelled meanwhile");
-update_network_timezone_context_complete_and_free (ctx);
+if (g_task_return_error_if_cancelled (task)) {
+g_object_unref (task);
 return;
 }
 
+ctx = g_task_get_task_data (task);
+
 /* Finish the async operation */
 tz = MM_IFACE_MODEM_TIME_GET_INTERFACE 
(self)->load_network_timezone_finish (self,

  res,
@@ -226,69 +217,80 @@ load_network_timezone_ready (MMIfaceModemTime *self,
 !g_error_matches (error,
   MM_CORE_ERROR,
   MM_CORE_ERROR_RETRY)) {
-g_simple_async_result_take_error (ctx->result, error);
-update_network_timezone_context_complete_and_free (ctx);
+g_task_return_error (task, error);
+g_object_unref (task);
 return;
 }
 
 /* Otherwise, reconnect cancellable and relaunch timeout to query a bit
  * later */
-ctx->cancelled_id = g_cancellable_connect (ctx->cancellable,
+ctx->cancelled_id = g_cancellable_connect (g_task_get_cancellable 
(task),
G_CALLBACK (cancelled),
-   ctx,
+   task,
NULL);
 ctx->network_timezone_poll_id =