From 07961d71bdc15756e355c701a02856dbcd801bdd Mon Sep 17 00:00:00 2001 From: Guillaume Desmottes Date: Fri, 22 Jan 2010 12:35:35 +0000 Subject: replace empathy_connection_managers_call_when_ready by prepare_{async_finish} functions --- libempathy/empathy-connection-managers.c | 78 +++++++++++++------------------- libempathy/empathy-connection-managers.h | 11 +++-- 2 files changed, 38 insertions(+), 51 deletions(-) (limited to 'libempathy') diff --git a/libempathy/empathy-connection-managers.c b/libempathy/empathy-connection-managers.c index 7085b507b..9cda1a331 100644 --- a/libempathy/empathy-connection-managers.c +++ b/libempathy/empathy-connection-managers.c @@ -292,65 +292,51 @@ empathy_connection_managers_get_cms_num (EmpathyConnectionManagers *self) return g_list_length (priv->cms); } -typedef struct -{ - EmpathyConnectionManagers *self; - EmpathyConnectionManagersWhenReadyCb callback; - gpointer user_data; - guint ready_id; -} CallWhenReadyContext; - static void -call_when_ready_ctx_free (CallWhenReadyContext *ctx) -{ - g_signal_handler_disconnect (ctx->self, ctx->ready_id); - g_object_unref (ctx->self); - g_slice_free (CallWhenReadyContext, ctx); -} - -static void -cwr_ready (EmpathyConnectionManagers *self, +notify_ready_cb (EmpathyConnectionManagers *self, GParamSpec *spec, - CallWhenReadyContext *ctx) + GSimpleAsyncResult *result) { - g_assert (ctx->callback != NULL); - - ctx->callback (self, NULL, ctx->user_data); - - call_when_ready_ctx_free (ctx); + g_simple_async_result_complete_in_idle (result); + g_object_unref (result); } -static CallWhenReadyContext * -call_when_ready_ctx_new (EmpathyConnectionManagers *self, - EmpathyConnectionManagersWhenReadyCb callback, +void +empathy_connection_managers_prepare_async ( + EmpathyConnectionManagers *self, + GAsyncReadyCallback callback, gpointer user_data) { - CallWhenReadyContext *ctx = g_slice_new (CallWhenReadyContext); + EmpathyConnectionManagersPriv *priv = GET_PRIV (self); + GSimpleAsyncResult *result; - ctx->self = g_object_ref (self); - ctx->callback = callback; - ctx->user_data = user_data; + result = g_simple_async_result_new (G_OBJECT (managers), + callback, user_data, empathy_connection_managers_prepare_finish); - ctx->ready_id = g_signal_connect (self, "notify::ready", - G_CALLBACK (cwr_ready), ctx); + if (priv->ready) + { + g_simple_async_result_complete_in_idle (result); + g_object_unref (result); + return; + } - return ctx; + g_signal_connect (self, "notify::ready", G_CALLBACK (notify_ready_cb), + result); } -void -empathy_connection_managers_call_when_ready ( +gboolean +empathy_connection_managers_prepare_finish ( EmpathyConnectionManagers *self, - EmpathyConnectionManagersWhenReadyCb callback, - gpointer user_data) + GAsyncResult *result, + GError **error) { - EmpathyConnectionManagersPriv *priv = GET_PRIV (self); + GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result); - if (priv->ready) - { - callback (self, NULL, user_data); - } - else - { - call_when_ready_ctx_new (self, callback, user_data); - } + g_return_val_if_fail (g_simple_async_result_is_valid (result, + G_OBJECT (self), empathy_connection_managers_prepare_finish), FALSE); + + if (g_simple_async_result_propagate_error (simple, error)) + return FALSE; + + return TRUE; } diff --git a/libempathy/empathy-connection-managers.h b/libempathy/empathy-connection-managers.h index 956f24315..14833734c 100644 --- a/libempathy/empathy-connection-managers.h +++ b/libempathy/empathy-connection-managers.h @@ -22,6 +22,7 @@ #define __EMPATHY_CONNECTION_MANAGERS_H__ #include +#include #include @@ -72,15 +73,15 @@ guint empathy_connection_managers_get_cms_num TpConnectionManager *empathy_connection_managers_get_cm ( EmpathyConnectionManagers *managers, const gchar *cm); -typedef void (*EmpathyConnectionManagersWhenReadyCb) ( +void empathy_connection_managers_prepare_async ( EmpathyConnectionManagers *managers, - const GError *error, + GAsyncReadyCallback callback, gpointer user_data); -void empathy_connection_managers_call_when_ready ( +gboolean empathy_connection_managers_prepare_finish ( EmpathyConnectionManagers *managers, - EmpathyConnectionManagersWhenReadyCb callback, - gpointer user_data); + GAsyncResult *result, + GError **error); G_END_DECLS -- cgit v1.2.3