call-list: port mm_call_list_delete_call to use GTask

This commit is contained in:
Ben Chan
2017-04-06 12:54:30 -07:00
committed by Aleksander Morgado
parent 21195f8e54
commit a080644924

View File

@@ -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 gboolean
mm_call_list_delete_call_finish (MMCallList *self, mm_call_list_delete_call_finish (MMCallList *self,
GAsyncResult *res, GAsyncResult *res,
GError **error) 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 static guint
@@ -248,25 +232,29 @@ cmp_call_by_path (MMBaseCall *call,
static void static void
delete_ready (MMBaseCall *call, delete_ready (MMBaseCall *call,
GAsyncResult *res, GAsyncResult *res,
DeleteCallContext *ctx) GTask *task)
{ {
MMCallList *self;
const gchar *path;
GError *error = NULL; GError *error = NULL;
GList *l; GList *l;
self = g_task_get_source_object (task);
path = g_task_get_task_data (task);
if (!mm_base_call_delete_finish (call, res, &error)) { if (!mm_base_call_delete_finish (call, res, &error)) {
/* We report the error */ /* We report the error */
g_simple_async_result_take_error (ctx->result, error); g_task_return_error (task, error);
delete_call_context_complete_and_free (ctx); g_object_unref (task);
return; return;
} }
/* The CALL was properly deleted, we now remove it from our list */ /* The CALL was properly deleted, we now remove it from our list */
l = g_list_find_custom (ctx->self->priv->list, l = g_list_find_custom (self->priv->list,
ctx->path, path,
(GCompareFunc)cmp_call_by_path); (GCompareFunc)cmp_call_by_path);
if (l) { if (l) {
g_object_unref (MM_BASE_CALL (l->data)); 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 /* 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. */ * during the async operation. */
mm_base_call_unexport (call); mm_base_call_unexport (call);
g_signal_emit (ctx->self, g_signal_emit (self,
signals[SIGNAL_CALL_DELETED], 0, signals[SIGNAL_CALL_DELETED], 0,
ctx->path); path);
g_simple_async_result_set_op_res_gboolean (ctx->result, TRUE); g_task_return_boolean (task, TRUE);
delete_call_context_complete_and_free (ctx); g_object_unref (task);
} }
void void
@@ -288,8 +276,8 @@ mm_call_list_delete_call (MMCallList *self,
GAsyncReadyCallback callback, GAsyncReadyCallback callback,
gpointer user_data) gpointer user_data)
{ {
DeleteCallContext *ctx;
GList *l; GList *l;
GTask *task;
l = g_list_find_custom (self->priv->list, l = g_list_find_custom (self->priv->list,
(gpointer)call_path, (gpointer)call_path,
@@ -306,17 +294,12 @@ mm_call_list_delete_call (MMCallList *self,
} }
/* Delete all CALL parts */ /* Delete all CALL parts */
ctx = g_new0 (DeleteCallContext, 1); task = g_task_new (self, NULL, callback, user_data);
ctx->self = g_object_ref (self); g_task_set_task_data (task, g_strdup (call_path), g_free);
ctx->path = g_strdup (call_path);
ctx->result = g_simple_async_result_new (G_OBJECT (self),
callback,
user_data,
mm_call_list_delete_call);
mm_base_call_delete (MM_BASE_CALL (l->data), mm_base_call_delete (MM_BASE_CALL (l->data),
(GAsyncReadyCallback)delete_ready, (GAsyncReadyCallback)delete_ready,
ctx); task);
} }
/*****************************************************************************/ /*****************************************************************************/