Re: ModemManager: symbol lookup error: ModemManager: undefined symbol: mm_kernel_event_properties_get_type

2017-04-07 Thread Aleksander Morgado
On Fri, Apr 7, 2017 at 12:14 AM, Jan Graczyk  wrote:
> I found no qmi wwan device present in /dev directory even though the 
> qmi_wwan.ko module is inserted. I am running Linux version 4.1.15 and I have 
> mini PCie Quectel UC20 modem module installed on my development board. Is 
> that the qmi wwan device is only created when USB based modem is installed on 
> a development board?

Looks like 4.1.15 isn't new enough. This is what another user, Einar
Jón, replied to you some days ago:
https://lists.freedesktop.org/archives/modemmanager-devel/2017-April/004409.html

-- 
Aleksander
https://aleksander.es
___
ModemManager-devel mailing list
ModemManager-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/modemmanager-devel


Re: [PATCH] call-list: port mm_call_list_delete_call to use GTask

2017-04-07 Thread Aleksander Morgado
On 06/04/17 21:54, Ben Chan wrote:
> ---
>  src/mm-call-list.c | 55 
> +++---
>  1 file changed, 19 insertions(+), 36 deletions(-)
> 

Pushed to git master, thanks!

> diff --git a/src/mm-call-list.c b/src/mm-call-list.c
> index fae66035..1cc1f543 100644
> --- a/src/mm-call-list.c
> +++ b/src/mm-call-list.c
> @@ -214,28 +214,12 @@ gboolean 
> mm_call_list_send_dtmf_to_active_calls(MMCallList *self, gchar *dtmf)
>  
>  
> /*/
>  
> -typedef struct {
> -MMCallList *self;
> -GSimpleAsyncResult *result;
> -gchar *path;
> -} DeleteCallContext;
> -
> -static void
> -delete_call_context_complete_and_free (DeleteCallContext *ctx)
> -{
> -g_simple_async_result_complete (ctx->result);
> -g_object_unref (ctx->result);
> -g_object_unref (ctx->self);
> -g_free (ctx->path);
> -g_free (ctx);
> -}
> -
>  gboolean
>  mm_call_list_delete_call_finish (MMCallList *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 guint
> @@ -248,25 +232,29 @@ cmp_call_by_path (MMBaseCall *call,
>  static void
>  delete_ready (MMBaseCall *call,
>GAsyncResult *res,
> -  DeleteCallContext *ctx)
> +  GTask *task)
>  {
> +MMCallList *self;
> +const gchar *path;
>  GError *error = NULL;
>  GList *l;
>  
> +self = g_task_get_source_object (task);
> +path = g_task_get_task_data (task);
>  if (!mm_base_call_delete_finish (call, res, )) {
>  /* We report the error */
> -g_simple_async_result_take_error (ctx->result, error);
> -delete_call_context_complete_and_free (ctx);
> +g_task_return_error (task, error);
> +g_object_unref (task);
>  return;
>  }
>  
>  /* The CALL was properly deleted, we now remove it from our list */
> -l = g_list_find_custom (ctx->self->priv->list,
> -ctx->path,
> +l = g_list_find_custom (self->priv->list,
> +path,
>  (GCompareFunc)cmp_call_by_path);
>  if (l) {
>  g_object_unref (MM_BASE_CALL (l->data));
> -ctx->self->priv->list = g_list_delete_link (ctx->self->priv->list, 
> l);
> +self->priv->list = g_list_delete_link (self->priv->list, l);
>  }
>  
>  /* We don't need to unref the CALL any more, but we can use the
> @@ -274,12 +262,12 @@ delete_ready (MMBaseCall *call,
>   * during the async operation. */
>  mm_base_call_unexport (call);
>  
> -g_signal_emit (ctx->self,
> +g_signal_emit (self,
> signals[SIGNAL_CALL_DELETED], 0,
> -   ctx->path);
> +   path);
>  
> -g_simple_async_result_set_op_res_gboolean (ctx->result, TRUE);
> -delete_call_context_complete_and_free (ctx);
> +g_task_return_boolean (task, TRUE);
> +g_object_unref (task);
>  }
>  
>  void
> @@ -288,8 +276,8 @@ mm_call_list_delete_call (MMCallList *self,
>  GAsyncReadyCallback callback,
>  gpointer user_data)
>  {
> -DeleteCallContext *ctx;
>  GList *l;
> +GTask *task;
>  
>  l = g_list_find_custom (self->priv->list,
>  (gpointer)call_path,
> @@ -306,17 +294,12 @@ mm_call_list_delete_call (MMCallList *self,
>  }
>  
>  /* Delete all CALL parts */
> -ctx = g_new0 (DeleteCallContext, 1);
> -ctx->self = g_object_ref (self);
> -ctx->path = g_strdup (call_path);
> -ctx->result = g_simple_async_result_new (G_OBJECT (self),
> - callback,
> - user_data,
> - mm_call_list_delete_call);
> +task = g_task_new (self, NULL, callback, user_data);
> +g_task_set_task_data (task, g_strdup (call_path), g_free);
>  
>  mm_base_call_delete (MM_BASE_CALL (l->data),
>  (GAsyncReadyCallback)delete_ready,
> -ctx);
> +task);
>  }
>  
>  
> /*/
> 


-- 
Aleksander
https://aleksander.es
___
ModemManager-devel mailing list
ModemManager-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/modemmanager-devel


Re: [PATCH] sms-list: port mm_sms_list_delete_sms to use GTask

2017-04-07 Thread Aleksander Morgado
On 06/04/17 21:42, Ben Chan wrote:
> ---
>  src/mm-sms-list.c | 70 
> +--
>  1 file changed, 27 insertions(+), 43 deletions(-)
> 

Pushed to git master, thanks!

> diff --git a/src/mm-sms-list.c b/src/mm-sms-list.c
> index 7819b3ad..22c2cd9a 100644
> --- a/src/mm-sms-list.c
> +++ b/src/mm-sms-list.c
> @@ -113,28 +113,12 @@ mm_sms_list_get_paths (MMSmsList *self)
>  
>  
> /*/
>  
> -typedef struct {
> -MMSmsList *self;
> -GSimpleAsyncResult *result;
> -gchar *path;
> -} DeleteSmsContext;
> -
> -static void
> -delete_sms_context_complete_and_free (DeleteSmsContext *ctx)
> -{
> -g_simple_async_result_complete (ctx->result);
> -g_object_unref (ctx->result);
> -g_object_unref (ctx->self);
> -g_free (ctx->path);
> -g_free (ctx);
> -}
> -
>  gboolean
>  mm_sms_list_delete_sms_finish (MMSmsList *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 guint
> @@ -147,25 +131,29 @@ cmp_sms_by_path (MMBaseSms *sms,
>  static void
>  delete_ready (MMBaseSms *sms,
>GAsyncResult *res,
> -  DeleteSmsContext *ctx)
> +  GTask *task)
>  {
> +MMSmsList *self;
> +const gchar *path;
>  GError *error = NULL;
>  GList *l;
>  
>  if (!mm_base_sms_delete_finish (sms, res, )) {
>  /* We report the error */
> -g_simple_async_result_take_error (ctx->result, error);
> -delete_sms_context_complete_and_free (ctx);
> +g_task_return_error (task, error);
> +g_object_unref (task);
>  return;
>  }
>  
> +self = g_task_get_source_object (task);
> +path = g_task_get_task_data (task);
>  /* The SMS was properly deleted, we now remove it from our list */
> -l = g_list_find_custom (ctx->self->priv->list,
> -ctx->path,
> +l = g_list_find_custom (self->priv->list,
> +path,
>  (GCompareFunc)cmp_sms_by_path);
>  if (l) {
>  g_object_unref (MM_BASE_SMS (l->data));
> -ctx->self->priv->list = g_list_delete_link (ctx->self->priv->list, 
> l);
> +self->priv->list = g_list_delete_link (self->priv->list, l);
>  }
>  
>  /* We don't need to unref the SMS any more, but we can use the
> @@ -173,12 +161,12 @@ delete_ready (MMBaseSms *sms,
>   * during the async operation. */
>  mm_base_sms_unexport (sms);
>  
> -g_signal_emit (ctx->self,
> +g_signal_emit (self,
> signals[SIGNAL_DELETED], 0,
> -   ctx->path);
> +   path);
>  
> -g_simple_async_result_set_op_res_gboolean (ctx->result, TRUE);
> -delete_sms_context_complete_and_free (ctx);
> +g_task_return_boolean (task, TRUE);
> +g_object_unref (task);
>  }
>  
>  void
> @@ -187,35 +175,31 @@ mm_sms_list_delete_sms (MMSmsList *self,
>  GAsyncReadyCallback callback,
>  gpointer user_data)
>  {
> -DeleteSmsContext *ctx;
>  GList *l;
> +GTask *task;
>  
>  l = g_list_find_custom (self->priv->list,
>  (gpointer)sms_path,
>  (GCompareFunc)cmp_sms_by_path);
>  if (!l) {
> -g_simple_async_report_error_in_idle (G_OBJECT (self),
> - callback,
> - user_data,
> - MM_CORE_ERROR,
> - MM_CORE_ERROR_NOT_FOUND,
> - "No SMS found with path '%s'",
> - sms_path);
> +g_task_report_new_error (self,
> + callback,
> + user_data,
> + mm_sms_list_delete_sms,
> + MM_CORE_ERROR,
> + MM_CORE_ERROR_NOT_FOUND,
> + "No SMS found with path '%s'",
> + sms_path);
>  return;
>  }
>  
>  /* Delete all SMS parts */
> -ctx = g_new0 (DeleteSmsContext, 1);
> -ctx->self = g_object_ref (self);
> -ctx->path = g_strdup (sms_path);
> -ctx->result = g_simple_async_result_new (G_OBJECT (self),
> - callback,
> - user_data,
> - mm_sms_list_delete_sms);
> +task = g_task_new (self, NULL, callback, user_data);
> +g_task_set_task_data (task, g_strdup (sms_path), 

Re: [PATCH] port-mbim: port mm_port_mbim_{open,close} to use GTask

2017-04-07 Thread Aleksander Morgado
Hey Ben,

See some comments below.


On 06/04/17 22:46, Ben Chan wrote:
> ---
>  src/mm-port-mbim.c | 130 
> +
>  1 file changed, 50 insertions(+), 80 deletions(-)
> 
> diff --git a/src/mm-port-mbim.c b/src/mm-port-mbim.c
> index 2b649963..5015c388 100644
> --- a/src/mm-port-mbim.c
> +++ b/src/mm-port-mbim.c
> @@ -31,90 +31,58 @@ struct _MMPortMbimPrivate {
>  
>  
> /*/
>  
> -typedef struct {
> -MMPortMbim *self;
> -GSimpleAsyncResult *result;
> -GCancellable *cancellable;
> -} PortContext;
> -
> -static void
> -port_context_complete_and_free (PortContext *ctx)
> -{
> -g_simple_async_result_complete_in_idle (ctx->result);
> -if (ctx->cancellable)
> -g_object_unref (ctx->cancellable);
> -g_object_unref (ctx->result);
> -g_object_unref (ctx->self);
> -g_slice_free (PortContext, ctx);
> -}
> -
> -static PortContext *
> -port_context_new (MMPortMbim *self,
> -  GCancellable *cancellable,
> -  GAsyncReadyCallback callback,
> -  gpointer user_data)
> -{
> -PortContext *ctx;
> -
> -ctx = g_slice_new0 (PortContext);
> -ctx->self = g_object_ref (self);
> -ctx->result = g_simple_async_result_new (G_OBJECT (self),
> - callback,
> - user_data,
> - port_context_new);
> -ctx->cancellable = cancellable ? g_object_ref (cancellable) : NULL;
> -return ctx;
> -}
> -
> -/*/
> -
>  gboolean
>  mm_port_mbim_open_finish (MMPortMbim *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
>  mbim_device_open_ready (MbimDevice *mbim_device,
>  GAsyncResult *res,
> -PortContext *ctx)
> +GTask *task)
>  {
>  GError *error = NULL;
> +MMPortMbim *self;
> +
> +self = g_task_get_source_object (task);
>  
>  /* Reset the progress flag */
> -ctx->self->priv->in_progress = FALSE;
> +self->priv->in_progress = FALSE;
>  if (!mbim_device_open_full_finish (mbim_device, res, )) {
> -g_clear_object (>self->priv->mbim_device);
> -g_simple_async_result_take_error (ctx->result, error);
> +g_clear_object (>priv->mbim_device);
> +g_task_return_error (task, error);
>  } else
> -g_simple_async_result_set_op_res_gboolean (ctx->result, TRUE);
> +g_task_return_boolean (task, TRUE);
>  
> -port_context_complete_and_free (ctx);
> +g_object_unref (task);
>  }
>  
>  static void
>  mbim_device_new_ready (GObject *unused,
> GAsyncResult *res,
> -   PortContext *ctx)
> +   GTask *task)
>  {
>  GError *error = NULL;
> +MMPortMbim *self;
>  
> -ctx->self->priv->mbim_device = mbim_device_new_finish (res, );
> -if (!ctx->self->priv->mbim_device) {
> -g_simple_async_result_take_error (ctx->result, error);
> -port_context_complete_and_free (ctx);
> +self = g_task_get_source_object (task);
> +self->priv->mbim_device = mbim_device_new_finish (res, );
> +if (!self->priv->mbim_device) {
> +g_task_return_error (task, error);
> +g_object_unref (task);
>  return;
>  }
>  
>  /* Now open the MBIM device */
> -mbim_device_open_full (ctx->self->priv->mbim_device,
> +mbim_device_open_full (self->priv->mbim_device,
> MBIM_DEVICE_OPEN_FLAGS_PROXY,
> 30,
> -   ctx->cancellable,
> +   g_task_get_cancellable (task),
> (GAsyncReadyCallback)mbim_device_open_ready,
> -   ctx);
> +   task);
>  }
>  
>  void
> @@ -125,24 +93,24 @@ mm_port_mbim_open (MMPortMbim *self,
>  {
>  GFile *file;
>  gchar *fullpath;
> -PortContext *ctx;
> +GTask *task;
>  
>  g_return_if_fail (MM_IS_PORT_MBIM (self));
>  
> -ctx = port_context_new (self, cancellable, callback, user_data);
> +task = g_task_new (self, cancellable, callback, user_data);
>  
>  if (self->priv->in_progress) {
> -g_simple_async_result_set_error (ctx->result,
> - MM_CORE_ERROR,
> - MM_CORE_ERROR_IN_PROGRESS,
> - "MBIM device open/close operation 
> in progress");
> -port_context_complete_and_free (ctx);
> +

Re: [PATCH 2/2] port-qmi: port mm_port_qmi_allocate_client to use GTask

2017-04-07 Thread Aleksander Morgado
Hey Ben,

See comments below.

On 06/04/17 22:41, Ben Chan wrote:
> ---
>  src/mm-port-qmi.c | 51 ++-
>  1 file changed, 26 insertions(+), 25 deletions(-)
> 
> diff --git a/src/mm-port-qmi.c b/src/mm-port-qmi.c
> index c6ae0615..2baeea7c 100644
> --- a/src/mm-port-qmi.c
> +++ b/src/mm-port-qmi.c
> @@ -73,21 +73,16 @@ mm_port_qmi_get_client (MMPortQmi *self,
>  
> /*/
>  
>  typedef struct {
> -MMPortQmi *self;
> -GSimpleAsyncResult *result;
>  ServiceInfo *info;
>  } AllocateClientContext;
>  

I believe we could remove the AllocateClientContext struct all together
and just pass the ServiceInfo as task data, right?


>  static void
> -allocate_client_context_complete_and_free (AllocateClientContext *ctx)
> +allocate_client_context_free (AllocateClientContext *ctx)
>  {
> -g_simple_async_result_complete (ctx->result);
>  if (ctx->info) {
>  g_assert (ctx->info->client == NULL);
>  g_free (ctx->info);
>  }
> -g_object_unref (ctx->result);
> -g_object_unref (ctx->self);
>  g_free (ctx);
>  }
>  
> @@ -96,30 +91,34 @@ mm_port_qmi_allocate_client_finish (MMPortQmi *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
>  allocate_client_ready (QmiDevice *qmi_device,
> GAsyncResult *res,
> -   AllocateClientContext *ctx)
> +   GTask *task)
>  {
> +MMPortQmi *self;
> +AllocateClientContext *ctx;
>  GError *error = NULL;
>  
> +self = g_task_get_source_object (task);
> +ctx = g_task_get_task_data (task);
>  ctx->info->client = qmi_device_allocate_client_finish (qmi_device, res, 
> );
>  if (!ctx->info->client) {
>  g_prefix_error (,
>  "Couldn't create client for service '%s': ",
>  qmi_service_get_string (ctx->info->service));
> -g_simple_async_result_take_error (ctx->result, error);
> +g_task_return_error (task, error);
>  } else {
> -g_simple_async_result_set_op_res_gboolean (ctx->result, TRUE);
> +g_task_return_boolean (task, TRUE);
>  /* Move the service info to our internal list */
> -ctx->self->priv->services = g_list_prepend 
> (ctx->self->priv->services, ctx->info);
> +self->priv->services = g_list_prepend (self->priv->services, 
> ctx->info);
>  ctx->info = NULL;
>  }
>  
> -allocate_client_context_complete_and_free (ctx);
> +g_object_unref (task);
>  }
>  
>  void
> @@ -131,35 +130,37 @@ mm_port_qmi_allocate_client (MMPortQmi *self,
>   gpointer user_data)
>  {
>  AllocateClientContext *ctx;
> +GTask *task;
>  
>  if (!!mm_port_qmi_peek_client (self, service, flag)) {
> -g_simple_async_report_error_in_idle (G_OBJECT (self),
> - callback,
> - user_data,
> - MM_CORE_ERROR,
> - MM_CORE_ERROR_EXISTS,
> - "Client for service '%s' 
> already allocated",
> - qmi_service_get_string 
> (service));
> +g_task_report_new_error (self,
> + callback,
> + user_data,
> + mm_port_qmi_allocate_client,
> + MM_CORE_ERROR,
> + MM_CORE_ERROR_EXISTS,
> + "Client for service '%s' already allocated",
> + qmi_service_get_string (service));
>  return;
>  }
>  
>  ctx = g_new0 (AllocateClientContext, 1);
> -ctx->self = g_object_ref (self);
> -ctx->result = g_simple_async_result_new (G_OBJECT (self),
> - callback,
> - user_data,
> - mm_port_qmi_allocate_client);
>  ctx->info = g_new0 (ServiceInfo, 1);
>  ctx->info->service = service;
>  ctx->info->flag = flag;
>  
> +task = g_task_new (self, cancellable, callback, user_data);
> +g_task_set_task_data (task,
> +  ctx,
> +  (GDestroyNotify)allocate_client_context_free);
> +
>  qmi_device_allocate_client (self->priv->qmi_device,
>  service,
>  QMI_CID_NONE,
>  10,
> 

Re: [PATCH 1/2] auth: port authorize to use GTask

2017-04-07 Thread Aleksander Morgado
On 06/04/17 21:38, Ben Chan wrote:
> ---
>  src/mm-auth-provider.c | 11 ---
>  1 file changed, 4 insertions(+), 7 deletions(-)
> 

Pushed to git master, thanks!

> diff --git a/src/mm-auth-provider.c b/src/mm-auth-provider.c
> index 4ef56234..4d8766c0 100644
> --- a/src/mm-auth-provider.c
> +++ b/src/mm-auth-provider.c
> @@ -75,15 +75,12 @@ authorize (MMAuthProvider *self,
> GAsyncReadyCallback callback,
> gpointer user_data)
>  {
> -GSimpleAsyncResult *result;
> +GTask *task;
>  
>  /* Just create the result and complete it */
> -result = g_simple_async_result_new (G_OBJECT (self),
> -callback,
> -user_data,
> -authorize);
> -g_simple_async_result_complete_in_idle (result);
> -g_object_unref (result);
> +task = g_task_new (self, cancellable, callback, user_data);
> +g_task_return_boolean (task, TRUE);
> +g_object_unref (task);
>  }
>  
>  
> /*/
> 


-- 
Aleksander
https://aleksander.es
___
ModemManager-devel mailing list
ModemManager-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/modemmanager-devel


[PATCH] base-call: remove unnecessary string duplications

2017-04-07 Thread Ben Chan
---
 src/mm-base-call.c | 10 ++
 1 file changed, 2 insertions(+), 8 deletions(-)

diff --git a/src/mm-base-call.c b/src/mm-base-call.c
index 6ce85d0d..606d24f2 100644
--- a/src/mm-base-call.c
+++ b/src/mm-base-call.c
@@ -754,7 +754,6 @@ call_accept (MMBaseCall *self,
  gpointer user_data)
 {
 CallAcceptContext *ctx;
-gchar *cmd;
 
 /* Setup the context */
 ctx = g_new0 (CallAcceptContext, 1);
@@ -765,14 +764,12 @@ call_accept (MMBaseCall *self,
 ctx->self = g_object_ref (self);
 ctx->modem = g_object_ref (self->priv->modem);
 
-cmd = g_strdup_printf ("ATA");
 mm_base_modem_at_command (ctx->modem,
-  cmd,
+  "ATA",
   2,
   FALSE,
   (GAsyncReadyCallback)call_accept_ready,
   ctx);
-g_free (cmd);
 }
 
 /*/
@@ -843,7 +840,6 @@ call_hangup (MMBaseCall *self,
  gpointer user_data)
 {
 CallHangupContext *ctx;
-gchar *cmd;
 
 /* Setup the context */
 ctx = g_new0 (CallHangupContext, 1);
@@ -854,14 +850,12 @@ call_hangup (MMBaseCall *self,
 ctx->self = g_object_ref (self);
 ctx->modem = g_object_ref (self->priv->modem);
 
-cmd = g_strdup_printf ("+CHUP");
 mm_base_modem_at_command (ctx->modem,
-  cmd,
+  "+CHUP",
   2,
   FALSE,
   (GAsyncReadyCallback)call_hangup_ready,
   ctx);
-g_free (cmd);
 }
 
 /*/
-- 
2.12.2.715.g7642488e1d-goog

___
ModemManager-devel mailing list
ModemManager-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/modemmanager-devel


[PATCH v2] port-mbim: port mm_port_mbim_{open,close} to use GTask

2017-04-07 Thread Ben Chan
---
Good catch!

 src/mm-port-mbim.c | 132 +
 1 file changed, 51 insertions(+), 81 deletions(-)

diff --git a/src/mm-port-mbim.c b/src/mm-port-mbim.c
index 2b649963..a0534fea 100644
--- a/src/mm-port-mbim.c
+++ b/src/mm-port-mbim.c
@@ -31,90 +31,58 @@ struct _MMPortMbimPrivate {
 
 /*/
 
-typedef struct {
-MMPortMbim *self;
-GSimpleAsyncResult *result;
-GCancellable *cancellable;
-} PortContext;
-
-static void
-port_context_complete_and_free (PortContext *ctx)
-{
-g_simple_async_result_complete_in_idle (ctx->result);
-if (ctx->cancellable)
-g_object_unref (ctx->cancellable);
-g_object_unref (ctx->result);
-g_object_unref (ctx->self);
-g_slice_free (PortContext, ctx);
-}
-
-static PortContext *
-port_context_new (MMPortMbim *self,
-  GCancellable *cancellable,
-  GAsyncReadyCallback callback,
-  gpointer user_data)
-{
-PortContext *ctx;
-
-ctx = g_slice_new0 (PortContext);
-ctx->self = g_object_ref (self);
-ctx->result = g_simple_async_result_new (G_OBJECT (self),
- callback,
- user_data,
- port_context_new);
-ctx->cancellable = cancellable ? g_object_ref (cancellable) : NULL;
-return ctx;
-}
-
-/*/
-
 gboolean
 mm_port_mbim_open_finish (MMPortMbim *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
 mbim_device_open_ready (MbimDevice *mbim_device,
 GAsyncResult *res,
-PortContext *ctx)
+GTask *task)
 {
 GError *error = NULL;
+MMPortMbim *self;
+
+self = g_task_get_source_object (task);
 
 /* Reset the progress flag */
-ctx->self->priv->in_progress = FALSE;
+self->priv->in_progress = FALSE;
 if (!mbim_device_open_full_finish (mbim_device, res, )) {
-g_clear_object (>self->priv->mbim_device);
-g_simple_async_result_take_error (ctx->result, error);
+g_clear_object (>priv->mbim_device);
+g_task_return_error (task, error);
 } else
-g_simple_async_result_set_op_res_gboolean (ctx->result, TRUE);
+g_task_return_boolean (task, TRUE);
 
-port_context_complete_and_free (ctx);
+g_object_unref (task);
 }
 
 static void
 mbim_device_new_ready (GObject *unused,
GAsyncResult *res,
-   PortContext *ctx)
+   GTask *task)
 {
 GError *error = NULL;
+MMPortMbim *self;
 
-ctx->self->priv->mbim_device = mbim_device_new_finish (res, );
-if (!ctx->self->priv->mbim_device) {
-g_simple_async_result_take_error (ctx->result, error);
-port_context_complete_and_free (ctx);
+self = g_task_get_source_object (task);
+self->priv->mbim_device = mbim_device_new_finish (res, );
+if (!self->priv->mbim_device) {
+g_task_return_error (task, error);
+g_object_unref (task);
 return;
 }
 
 /* Now open the MBIM device */
-mbim_device_open_full (ctx->self->priv->mbim_device,
+mbim_device_open_full (self->priv->mbim_device,
MBIM_DEVICE_OPEN_FLAGS_PROXY,
30,
-   ctx->cancellable,
+   g_task_get_cancellable (task),
(GAsyncReadyCallback)mbim_device_open_ready,
-   ctx);
+   task);
 }
 
 void
@@ -125,24 +93,24 @@ mm_port_mbim_open (MMPortMbim *self,
 {
 GFile *file;
 gchar *fullpath;
-PortContext *ctx;
+GTask *task;
 
 g_return_if_fail (MM_IS_PORT_MBIM (self));
 
-ctx = port_context_new (self, cancellable, callback, user_data);
+task = g_task_new (self, cancellable, callback, user_data);
 
 if (self->priv->in_progress) {
-g_simple_async_result_set_error (ctx->result,
- MM_CORE_ERROR,
- MM_CORE_ERROR_IN_PROGRESS,
- "MBIM device open/close operation in 
progress");
-port_context_complete_and_free (ctx);
+g_task_return_new_error (task,
+ MM_CORE_ERROR,
+ MM_CORE_ERROR_IN_PROGRESS,
+ "MBIM device open/close operation in 
progress");
+g_object_unref (task);
 return;
 }
 
 if (self->priv->mbim_device) {
-

Re: [PATCH 2/2] port-qmi: port mm_port_qmi_allocate_client to use GTask

2017-04-07 Thread Ben Chan
On Fri, Apr 7, 2017 at 2:03 AM, Aleksander Morgado
 wrote:
> Hey Ben,
>
> See comments below.
>
> On 06/04/17 22:41, Ben Chan wrote:
>> ---
>>  src/mm-port-qmi.c | 51 ++-
>>  1 file changed, 26 insertions(+), 25 deletions(-)
>>
>> diff --git a/src/mm-port-qmi.c b/src/mm-port-qmi.c
>> index c6ae0615..2baeea7c 100644
>> --- a/src/mm-port-qmi.c
>> +++ b/src/mm-port-qmi.c
>> @@ -73,21 +73,16 @@ mm_port_qmi_get_client (MMPortQmi *self,
>>  
>> /*/
>>
>>  typedef struct {
>> -MMPortQmi *self;
>> -GSimpleAsyncResult *result;
>>  ServiceInfo *info;
>>  } AllocateClientContext;
>>
>
> I believe we could remove the AllocateClientContext struct all together
> and just pass the ServiceInfo as task data, right?

That was my first attempt, but then I realized that
g_task_set_task_data would free any existing data it holds. As
indicated below, the ServiceInfo may be transferred to the internal
list.

>
>
>>  static void
>> -allocate_client_context_complete_and_free (AllocateClientContext *ctx)
>> +allocate_client_context_free (AllocateClientContext *ctx)
>>  {
>> -g_simple_async_result_complete (ctx->result);
>>  if (ctx->info) {
>>  g_assert (ctx->info->client == NULL);
>>  g_free (ctx->info);
>>  }
>> -g_object_unref (ctx->result);
>> -g_object_unref (ctx->self);
>>  g_free (ctx);
>>  }
>>
>> @@ -96,30 +91,34 @@ mm_port_qmi_allocate_client_finish (MMPortQmi *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
>>  allocate_client_ready (QmiDevice *qmi_device,
>> GAsyncResult *res,
>> -   AllocateClientContext *ctx)
>> +   GTask *task)
>>  {
>> +MMPortQmi *self;
>> +AllocateClientContext *ctx;
>>  GError *error = NULL;
>>
>> +self = g_task_get_source_object (task);
>> +ctx = g_task_get_task_data (task);
>>  ctx->info->client = qmi_device_allocate_client_finish (qmi_device, res, 
>> );
>>  if (!ctx->info->client) {
>>  g_prefix_error (,
>>  "Couldn't create client for service '%s': ",
>>  qmi_service_get_string (ctx->info->service));
>> -g_simple_async_result_take_error (ctx->result, error);
>> +g_task_return_error (task, error);
>>  } else {
>> -g_simple_async_result_set_op_res_gboolean (ctx->result, TRUE);
>> +g_task_return_boolean (task, TRUE);

Here --->

>>  /* Move the service info to our internal list */
>> -ctx->self->priv->services = g_list_prepend 
>> (ctx->self->priv->services, ctx->info);
>> +self->priv->services = g_list_prepend (self->priv->services, 
>> ctx->info);
>>  ctx->info = NULL;
>>  }
>>
>> -allocate_client_context_complete_and_free (ctx);
>> +g_object_unref (task);
>>  }
>>
>>  void
>> @@ -131,35 +130,37 @@ mm_port_qmi_allocate_client (MMPortQmi *self,
>>   gpointer user_data)
>>  {
>>  AllocateClientContext *ctx;
>> +GTask *task;
>>
>>  if (!!mm_port_qmi_peek_client (self, service, flag)) {
>> -g_simple_async_report_error_in_idle (G_OBJECT (self),
>> - callback,
>> - user_data,
>> - MM_CORE_ERROR,
>> - MM_CORE_ERROR_EXISTS,
>> - "Client for service '%s' 
>> already allocated",
>> - qmi_service_get_string 
>> (service));
>> +g_task_report_new_error (self,
>> + callback,
>> + user_data,
>> + mm_port_qmi_allocate_client,
>> + MM_CORE_ERROR,
>> + MM_CORE_ERROR_EXISTS,
>> + "Client for service '%s' already 
>> allocated",
>> + qmi_service_get_string (service));
>>  return;
>>  }
>>
>>  ctx = g_new0 (AllocateClientContext, 1);
>> -ctx->self = g_object_ref (self);
>> -ctx->result = g_simple_async_result_new (G_OBJECT (self),
>> - callback,
>> - user_data,
>> - mm_port_qmi_allocate_client);
>>  ctx->info = g_new0 (ServiceInfo, 1);
>>  ctx->info->service = service;
>>  ctx->info->flag = flag;
>>
>> +task = g_task_new (self,