From 0866c7eb7b580086cae52618abf8dd16b502e55c Mon Sep 17 00:00:00 2001 From: Guillaume Desmottes Date: Mon, 30 May 2011 14:06:27 +0200 Subject: [PATCH] add tp_channel_dispatch_operation_destroy_channels_async() (fdo #28015) --- docs/reference/telepathy-glib-sections.txt | 2 + telepathy-glib/channel-dispatch-operation.c | 92 +++++++++++++++++++++++++++ telepathy-glib/channel-dispatch-operation.h | 10 +++ tests/dbus/channel-dispatch-operation.c | 39 +++++++++++ 4 files changed, 143 insertions(+), 0 deletions(-) diff --git a/docs/reference/telepathy-glib-sections.txt b/docs/reference/telepathy-glib-sections.txt index cc25ba4..2e144c1 100644 --- a/docs/reference/telepathy-glib-sections.txt +++ b/docs/reference/telepathy-glib-sections.txt @@ -4558,6 +4558,8 @@ tp_channel_dispatch_operation_close_channels_async tp_channel_dispatch_operation_close_channels_finish tp_channel_dispatch_operation_leave_channels_async tp_channel_dispatch_operation_leave_channels_finish +tp_channel_dispatch_operation_destroy_channels_async +tp_channel_dispatch_operation_destroy_channels_finish TP_CHANNEL_DISPATCH_OPERATION TP_CHANNEL_DISPATCH_OPERATION_CLASS diff --git a/telepathy-glib/channel-dispatch-operation.c b/telepathy-glib/channel-dispatch-operation.c index c4155bd..06eb657 100644 --- a/telepathy-glib/channel-dispatch-operation.c +++ b/telepathy-glib/channel-dispatch-operation.c @@ -1805,3 +1805,95 @@ tp_channel_dispatch_operation_leave_channels_finish ( _tp_implement_finish_void (self, \ tp_channel_dispatch_operation_leave_channels_async) } + +static void +channel_destroy_cb (GObject *source, + GAsyncResult *result, + gpointer user_data) +{ + GError *error = NULL; + + if (!tp_channel_destroy_finish (TP_CHANNEL (source), result, &error)) + { + DEBUG ("Failed to destroy %s: %s", tp_proxy_get_object_path (source), + error->message); + + g_error_free (error); + } +} + +static void +claim_destroy_channels_cb (TpChannelDispatchOperation *self, + GSimpleAsyncResult *result) +{ + guint i; + + for (i = 0; i < self->priv->channels->len; i++) + { + TpChannel *channel = g_ptr_array_index (self->priv->channels, i); + + tp_channel_destroy_async (channel, channel_destroy_cb, NULL); + } + + g_simple_async_result_complete (result); + g_object_unref (result); +} + +/** + * tp_channel_dispatch_operation_destroy_channels_async: + * @self: a #TpChannelDispatchOperation + * @callback: a callback to call when the request has been satisfied + * @user_data: data to pass to @callback + * + * Called by an approver to claim channels and destroy them all right away. + * If this method is called successfully, @self has been claimed and + * tp_channel_destroy_async() has been called on all of its channels. + * + * If successful, this method will cause the #TpProxy::invalidated signal + * to be emitted, in the same way as for + * tp_channel_dispatch_operation_handle_with_async(). + * + * This method may fail because the dispatch operation has already + * been completed. Again, see tp_channel_dispatch_operation_handle_with_async() + * for more details. + * + * Since: 0.15.UNRELEASED + */ +void +tp_channel_dispatch_operation_destroy_channels_async ( + TpChannelDispatchOperation *self, + GAsyncReadyCallback callback, + gpointer user_data) +{ + GSimpleAsyncResult *result; + + result = g_simple_async_result_new (G_OBJECT (self), callback, user_data, + tp_channel_dispatch_operation_destroy_channels_async); + + prepare_core_and_claim (self, claim_destroy_channels_cb, result); +} + +/** + * tp_channel_dispatch_operation_destroy_channels_finish: + * @self: a #TpChannelDispatchOperation + * @result: a #GAsyncResult + * @error: a #GError to fill + * + * Finishes an async operation initiated using + * tp_channel_dispatch_operation_destroy_channels_async(). + * + * Returns: %TRUE if the Claim() call was successful and + * tp_channel_destroy_async() has at least been attempted on all the + * channels, otherwise %FALSE + * + * Since: 0.15.UNRELEASED + */ +gboolean +tp_channel_dispatch_operation_destroy_channels_finish ( + TpChannelDispatchOperation *self, + GAsyncResult *result, + GError **error) +{ + _tp_implement_finish_void (self, \ + tp_channel_dispatch_operation_destroy_channels_async) +} diff --git a/telepathy-glib/channel-dispatch-operation.h b/telepathy-glib/channel-dispatch-operation.h index 6bdbff1..3efcc60 100644 --- a/telepathy-glib/channel-dispatch-operation.h +++ b/telepathy-glib/channel-dispatch-operation.h @@ -166,6 +166,16 @@ gboolean tp_channel_dispatch_operation_leave_channels_finish ( GAsyncResult *result, GError **error); +void tp_channel_dispatch_operation_destroy_channels_async ( + TpChannelDispatchOperation *self, + GAsyncReadyCallback callback, + gpointer user_data); + +gboolean tp_channel_dispatch_operation_destroy_channels_finish ( + TpChannelDispatchOperation *self, + GAsyncResult *result, + GError **error); + G_END_DECLS #include diff --git a/tests/dbus/channel-dispatch-operation.c b/tests/dbus/channel-dispatch-operation.c index 0c89cd6..734e23a 100644 --- a/tests/dbus/channel-dispatch-operation.c +++ b/tests/dbus/channel-dispatch-operation.c @@ -868,6 +868,43 @@ test_leave_channels (Test *test, g_assert_no_error (test->error); } +static void +destroy_channels_cb (GObject *source, + GAsyncResult *result, + gpointer user_data) +{ + Test *test = user_data; + + tp_channel_dispatch_operation_destroy_channels_finish ( + TP_CHANNEL_DISPATCH_OPERATION (source), result, &test->error); + + test->sig--; + if (test->sig == 0) + g_main_loop_quit (test->mainloop); +} + +static void +test_destroy_channels (Test *test, + gconstpointer data G_GNUC_UNUSED) +{ + test->cdo = tp_channel_dispatch_operation_new (test->dbus, + "/whatever", NULL, &test->error); + g_assert_no_error (test->error); + + g_signal_connect (test->text_chan, "invalidated", + G_CALLBACK (channel_invalidated_cb), test); + g_signal_connect (test->text_chan_2, "invalidated", + G_CALLBACK (channel_invalidated_cb), test); + + tp_channel_dispatch_operation_destroy_channels_async (test->cdo, + destroy_channels_cb, test); + + test->sig = 3; + g_main_loop_run (test->mainloop); + + g_assert_no_error (test->error); +} + int main (int argc, char **argv) @@ -898,6 +935,8 @@ main (int argc, test_close_channels, teardown_services); g_test_add ("/cdo/leave-channels", Test, NULL, setup_services, test_leave_channels, teardown_services); + g_test_add ("/cdo/destroy-channels", Test, NULL, setup_services, + test_destroy_channels, teardown_services); return g_test_run (); } -- 1.7.4.1