Commit f15a4c40 authored by Colomban Wendling's avatar Colomban Wendling

OVCCGtkClient: use GTask instead of hand-made thing

parent ade9f458
......@@ -140,54 +140,24 @@ ovccgtk_client_new (const gchar *name)
}
typedef struct
{
OVCCGtkClient *self;
GCancellable *cancellable;
GSimpleAsyncResult *result;
gboolean success;
} JoinData;
static JoinData *
join_data_new (void)
{
JoinData *jdata;
jdata = g_slice_alloc (sizeof *jdata);
return jdata;
}
static void
join_data_free (JoinData *jdata)
{
g_object_unref (jdata->self);
if (jdata->cancellable) {
g_object_unref (jdata->cancellable);
}
g_slice_free1 (sizeof *jdata, jdata);
}
static void
ovccgtk_client_join_table_ready (GObject *object,
GAsyncResult *result,
gpointer data)
{
JoinData *jdata = data;
GError *error = NULL;
GTask *task = data;
GError *error = NULL;
g_debug ("ovccclient_client_join_table_finish()");
if (! ovccclient_client_join_table_finish (OVCCCLIENT_CLIENT (object),
result, &error)) {
ovccclient_client_leave (OVCCCLIENT_CLIENT (object), NULL);
g_simple_async_result_take_error (jdata->result, error);
g_simple_async_result_complete (jdata->result);
g_object_unref (jdata->result);
g_task_return_error (task, error);
g_object_unref (task);
} else {
g_debug ("joined!");
jdata->success = TRUE;
g_simple_async_result_complete (jdata->result);
g_object_unref (jdata->result);
g_task_return_boolean (task, TRUE);
g_object_unref (task);
}
}
......@@ -196,21 +166,20 @@ ovccgtk_client_login_ready (GObject *object,
GAsyncResult *result,
gpointer data)
{
JoinData *jdata = data;
GError *error = NULL;
GTask *task = data;
GError *error = NULL;
g_debug ("ovccclient_client_login_finish()");
if (! ovccclient_client_login_finish (OVCCCLIENT_CLIENT (object), result,
&error)) {
ovccclient_client_leave (OVCCCLIENT_CLIENT (object), NULL);
g_simple_async_result_take_error (jdata->result, error);
g_simple_async_result_complete (jdata->result);
g_object_unref (jdata->result);
g_task_return_error (task, error);
g_object_unref (task);
} else {
g_debug ("ovccclient_client_join_table()");
ovccclient_client_join_table (OVCCCLIENT_CLIENT (object), -1,
jdata->cancellable,
ovccgtk_client_join_table_ready, jdata);
g_task_get_cancellable (task),
ovccgtk_client_join_table_ready, task);
}
}
......@@ -219,20 +188,22 @@ ovccgtk_client_bind_to_ready (GObject *object,
GAsyncResult *result,
gpointer data)
{
JoinData *jdata = data;
GError *error = NULL;
GTask *task = data;
GError *error = NULL;
g_debug ("ovccclient_client_bind_to_finish()");
if (! ovccclient_client_bind_to_finish (OVCCCLIENT_CLIENT (object), result,
&error)) {
g_simple_async_result_take_error (jdata->result, error);
g_simple_async_result_complete (jdata->result);
g_object_unref (jdata->result);
g_task_return_error (task, error);
g_object_unref (task);
} else {
OVCCGtkClient *self = g_task_get_source_object (task);
g_debug ("ovccclient_client_login()");
ovccclient_client_login (OVCCCLIENT_CLIENT (object),
jdata->self->priv->name, "xxx", jdata->cancellable,
ovccgtk_client_login_ready, jdata);
self->priv->name, "xxx",
g_task_get_cancellable (task),
ovccgtk_client_login_ready, task);
}
}
......@@ -243,44 +214,22 @@ ovccgtk_client_join_async (OVCCGtkClient *self,
GAsyncReadyCallback callback,
gpointer data)
{
JoinData *jdata;
GTask *task;
g_return_if_fail (OVCCGTK_IS_CLIENT (self));
g_return_if_fail (OVCCCLIENT_IS_SERVER (server));
g_return_if_fail (self->priv->name != NULL);
jdata = join_data_new ();
jdata->success = FALSE;
jdata->self = g_object_ref (self);
if (cancellable) {
jdata->cancellable = g_object_ref (cancellable);
} else {
jdata->cancellable = NULL;
}
jdata->result = g_simple_async_result_new (G_OBJECT (self), callback, data,
(gpointer) ovccgtk_client_join_async);
g_simple_async_result_set_op_res_gpointer (jdata->result, jdata,
(GDestroyNotify) join_data_free);
task = g_task_new (self, cancellable, callback, data);
g_debug ("ovccclient_client_bind_to()");
ovccclient_client_bind_to (OVCCCLIENT_CLIENT (self), server,
jdata->cancellable, ovccgtk_client_bind_to_ready,
jdata);
cancellable, ovccgtk_client_bind_to_ready, task);
}
gboolean
ovccgtk_client_join_finish (GAsyncResult *result,
GError **error)
{
gboolean success = FALSE;
GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
if (! g_simple_async_result_propagate_error (simple, error)) {
JoinData *jdata;
jdata = g_simple_async_result_get_op_res_gpointer (simple);
success = jdata->success;
}
return success;
return g_task_propagate_boolean (G_TASK (result), error);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment