From ed4f48dda54d174379726a1cc082559df49742af Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Wed, 1 Feb 2012 19:30:39 +0000 Subject: [PATCH] Complete results of TpProxy D-Bus calls in an idle GAsyncResult guarantees to call your callback from the main loop. For historical reasons (basically "5 years ago I didn't know any better"), TpProxy does not: if the interface is missing or the proxy has been invalidated, the callback is called re-entrantly. I'm going to fix that in Telepathy 1.0, but for now, let's give GAsyncResult the correct semantics. --- telepathy-glib/account-channel-request.c | 2 +- telepathy-glib/account-manager.c | 4 +- telepathy-glib/account.c | 33 +++++++------------------- telepathy-glib/base-client.c | 2 +- telepathy-glib/channel-dispatch-operation.c | 14 +++++----- telepathy-glib/channel-dispatcher.c | 2 +- telepathy-glib/channel.c | 8 +++--- telepathy-glib/connection-aliasing.c | 2 +- telepathy-glib/connection-avatars.c | 2 +- telepathy-glib/connection-contact-info.c | 2 +- telepathy-glib/connection-contact-list.c | 10 ++++---- telepathy-glib/connection.c | 4 +- telepathy-glib/contact.c | 2 +- telepathy-glib/file-transfer-channel.c | 6 ++-- telepathy-glib/stream-tube-channel.c | 4 +- telepathy-glib/text-channel.c | 18 +++++++------- 16 files changed, 50 insertions(+), 65 deletions(-) diff --git a/telepathy-glib/account-channel-request.c b/telepathy-glib/account-channel-request.c index 4c221d1..bf7e30e 100644 --- a/telepathy-glib/account-channel-request.c +++ b/telepathy-glib/account-channel-request.c @@ -534,7 +534,7 @@ complete_result (TpAccountChannelRequest *self) request_disconnect (self); - g_simple_async_result_complete (self->priv->result); + g_simple_async_result_complete_in_idle (self->priv->result); tp_clear_object (&self->priv->result); } diff --git a/telepathy-glib/account-manager.c b/telepathy-glib/account-manager.c index d166593..5d0732d 100644 --- a/telepathy-glib/account-manager.c +++ b/telepathy-glib/account-manager.c @@ -1238,7 +1238,7 @@ _tp_account_manager_created_cb (TpAccountManager *proxy, if (error != NULL) { g_simple_async_result_set_from_error (my_res, error); - g_simple_async_result_complete (my_res); + g_simple_async_result_complete_in_idle (my_res); return; } @@ -1247,7 +1247,7 @@ _tp_account_manager_created_cb (TpAccountManager *proxy, if (account == NULL) { g_simple_async_result_take_error (my_res, e); - g_simple_async_result_complete (my_res); + g_simple_async_result_complete_in_idle (my_res); return; } diff --git a/telepathy-glib/account.c b/telepathy-glib/account.c index 62cbb71..86388f9 100644 --- a/telepathy-glib/account.c +++ b/telepathy-glib/account.c @@ -562,7 +562,7 @@ _tp_account_got_all_storage_cb (TpProxy *proxy, if (self->priv->storage_provider == NULL) self->priv->storage_provider = g_strdup (""); - g_simple_async_result_complete (result); + g_simple_async_result_complete_in_idle (result); } static void @@ -2276,7 +2276,7 @@ _tp_account_property_set_cb (TpProxy *proxy, g_simple_async_result_set_from_error (result, error); } - g_simple_async_result_complete (result); + g_simple_async_result_complete_in_idle (result); g_object_unref (result); } @@ -2338,7 +2338,7 @@ tp_account_set_enabled_async (TpAccount *account, } static void -_tp_account_reconnected_cb (TpAccount *proxy, +_tp_account_void_cb (TpAccount *proxy, const GError *error, gpointer user_data, GObject *weak_object) @@ -2348,7 +2348,7 @@ _tp_account_reconnected_cb (TpAccount *proxy, if (error != NULL) g_simple_async_result_set_from_error (result, error); - g_simple_async_result_complete (result); + g_simple_async_result_complete_in_idle (result); g_object_unref (result); } @@ -2396,7 +2396,7 @@ tp_account_reconnect_async (TpAccount *account, result = g_simple_async_result_new (G_OBJECT (account), callback, user_data, tp_account_reconnect_finish); - tp_cli_account_call_reconnect (account, -1, _tp_account_reconnected_cb, + tp_cli_account_call_reconnect (account, -1, _tp_account_void_cb, result, NULL, G_OBJECT (account)); } @@ -2549,7 +2549,7 @@ _tp_account_updated_cb (TpAccount *proxy, else g_simple_async_result_set_op_res_gpointer (result, reconnect_required, NULL); - g_simple_async_result_complete (result); + g_simple_async_result_complete_in_idle (result); g_object_unref (G_OBJECT (result)); } @@ -2801,21 +2801,6 @@ tp_account_set_icon_name_finish (TpAccount *account, _tp_implement_finish_void (account, tp_account_set_icon_name_finish); } -static void -_tp_account_void_cb (TpAccount *proxy, - const GError *error, - gpointer user_data, - GObject *weak_object) -{ - GSimpleAsyncResult *result = G_SIMPLE_ASYNC_RESULT (user_data); - - if (error != NULL) - g_simple_async_result_set_from_error (result, error); - - g_simple_async_result_complete (result); - g_object_unref (G_OBJECT (result)); -} - /** * tp_account_remove_async: * @account: a #TpAccount @@ -3175,7 +3160,7 @@ _tp_account_got_avatar_cb (TpProxy *proxy, g_simple_async_result_set_op_res_gpointer (result, res, NULL); } - g_simple_async_result_complete (result); + g_simple_async_result_complete_in_idle (result); g_object_unref (result); } @@ -3623,7 +3608,7 @@ _tp_account_get_storage_specific_information_cb (TpProxy *self, g_simple_async_result_set_op_res_gpointer (result, info, NULL); } - g_simple_async_result_complete (result); + g_simple_async_result_complete_in_idle (result); g_object_unref (result); } @@ -3705,7 +3690,7 @@ _tp_account_got_all_addressing_cb (TpProxy *proxy, if (self->priv->uri_schemes == NULL) self->priv->uri_schemes = g_new0 (gchar *, 1); - g_simple_async_result_complete (result); + g_simple_async_result_complete_in_idle (result); } static void diff --git a/telepathy-glib/base-client.c b/telepathy-glib/base-client.c index 557feef..b42b5bd 100644 --- a/telepathy-glib/base-client.c +++ b/telepathy-glib/base-client.c @@ -3182,7 +3182,7 @@ delegate_channels_cb (TpChannelDispatcher *cd, } } - g_simple_async_result_complete (result); + g_simple_async_result_complete_in_idle (result); } /** diff --git a/telepathy-glib/channel-dispatch-operation.c b/telepathy-glib/channel-dispatch-operation.c index c9ae5e4..6a4e3a9 100644 --- a/telepathy-glib/channel-dispatch-operation.c +++ b/telepathy-glib/channel-dispatch-operation.c @@ -648,7 +648,7 @@ out: if (e != NULL) g_simple_async_result_set_from_error (result, e); - g_simple_async_result_complete (result); + g_simple_async_result_complete_in_idle (result); if (!prepared) { @@ -1079,7 +1079,7 @@ handle_with_cb (TpChannelDispatchOperation *self, g_simple_async_result_set_from_error (result, error); } - g_simple_async_result_complete (result); + g_simple_async_result_complete_in_idle (result); g_object_unref (result); } @@ -1167,7 +1167,7 @@ claim_cb (TpChannelDispatchOperation *self, g_simple_async_result_set_from_error (result, error); } - g_simple_async_result_complete (result); + g_simple_async_result_complete_in_idle (result); g_object_unref (result); } @@ -1339,7 +1339,7 @@ claim_with_cb (TpChannelDispatchOperation *self, _tp_base_client_now_handling_channels (client, self->priv->channels); - g_simple_async_result_complete (result); + g_simple_async_result_complete_in_idle (result); g_object_unref (result); } @@ -1450,7 +1450,7 @@ claim_close_channels_cb (TpChannelDispatchOperation *self, tp_channel_close_async (channel, channel_close_cb, NULL); } - g_simple_async_result_complete (result); + g_simple_async_result_complete_in_idle (result); g_object_unref (result); } @@ -1580,7 +1580,7 @@ claim_leave_channels_cb (TpChannelDispatchOperation *self, channel_leave_cb, NULL); } - g_simple_async_result_complete (result); + g_simple_async_result_complete_in_idle (result); g_object_unref (result); } @@ -1691,7 +1691,7 @@ claim_destroy_channels_cb (TpChannelDispatchOperation *self, tp_channel_destroy_async (channel, channel_destroy_cb, NULL); } - g_simple_async_result_complete (result); + g_simple_async_result_complete_in_idle (result); g_object_unref (result); } diff --git a/telepathy-glib/channel-dispatcher.c b/telepathy-glib/channel-dispatcher.c index 3123047..88d809a 100644 --- a/telepathy-glib/channel-dispatcher.c +++ b/telepathy-glib/channel-dispatcher.c @@ -181,7 +181,7 @@ present_channel_cb (TpChannelDispatcher *cd, g_simple_async_result_set_from_error (result, error); } - g_simple_async_result_complete (result); + g_simple_async_result_complete_in_idle (result); } /** diff --git a/telepathy-glib/channel.c b/telepathy-glib/channel.c index 73bf696..c6c3d09 100644 --- a/telepathy-glib/channel.c +++ b/telepathy-glib/channel.c @@ -741,7 +741,7 @@ tp_channel_get_initial_chat_states_cb (TpProxy *proxy, /* else just ignore it and assume everyone was initially in the default * Inactive state, unless we already saw a signal for them */ - g_simple_async_result_complete (result); + g_simple_async_result_complete_in_idle (result); } static void @@ -1424,7 +1424,7 @@ got_password_flags_cb (TpChannel *self, } } - g_simple_async_result_complete (result); + g_simple_async_result_complete_in_idle (result); } static void @@ -2750,7 +2750,7 @@ channel_destroy_cb (TpChannel *channel, return; } - g_simple_async_result_complete (result); + g_simple_async_result_complete_in_idle (result); g_object_unref (result); } @@ -2875,7 +2875,7 @@ provide_password_cb (TpChannel *self, TP_ERROR_AUTHENTICATION_FAILED, "Password was not correct"); } - g_simple_async_result_complete (result); + g_simple_async_result_complete_in_idle (result); } /** diff --git a/telepathy-glib/connection-aliasing.c b/telepathy-glib/connection-aliasing.c index 9581f36..785320a 100644 --- a/telepathy-glib/connection-aliasing.c +++ b/telepathy-glib/connection-aliasing.c @@ -88,7 +88,7 @@ get_alias_flag_cb (TpConnection *self, self->priv->alias_flags = flags; finally: - g_simple_async_result_complete (result); + g_simple_async_result_complete_in_idle (result); } void diff --git a/telepathy-glib/connection-avatars.c b/telepathy-glib/connection-avatars.c index d75e391..ccb548d 100644 --- a/telepathy-glib/connection-avatars.c +++ b/telepathy-glib/connection-avatars.c @@ -83,7 +83,7 @@ tp_connection_get_avatar_requirements_cb (TpProxy *proxy, tp_asv_get_uint32 (properties, "MaximumAvatarBytes", NULL)); finally: - g_simple_async_result_complete (result); + g_simple_async_result_complete_in_idle (result); } void diff --git a/telepathy-glib/connection-contact-info.c b/telepathy-glib/connection-contact-info.c index da9f78d..9f4204d 100644 --- a/telepathy-glib/connection-contact-info.c +++ b/telepathy-glib/connection-contact-info.c @@ -473,7 +473,7 @@ tp_connection_get_contact_info_cb (TpProxy *proxy, } finally: - g_simple_async_result_complete (result); + g_simple_async_result_complete_in_idle (result); } void diff --git a/telepathy-glib/connection-contact-list.c b/telepathy-glib/connection-contact-list.c index 862c04e..ef42f16 100644 --- a/telepathy-glib/connection-contact-list.c +++ b/telepathy-glib/connection-contact-list.c @@ -287,7 +287,7 @@ got_contact_list_attributes_cb (TpConnection *self, OUT: if (result != NULL) { - g_simple_async_result_complete (result); + g_simple_async_result_complete_in_idle (result); g_object_unref (result); } } @@ -402,7 +402,7 @@ prepare_contact_list_props_cb (TpProxy *proxy, self->priv->contact_list_state); OUT: - g_simple_async_result_complete (result); + g_simple_async_result_complete_in_idle (result); } void _tp_connection_prepare_contact_list_async (TpProxy *proxy, @@ -612,7 +612,7 @@ prepare_contact_groups_cb (TpProxy *proxy, g_ptr_array_add (self->priv->contact_groups, NULL); OUT: - g_simple_async_result_complete (result); + g_simple_async_result_complete_in_idle (result); } void @@ -1645,7 +1645,7 @@ blocked_changed_head_ready (TpConnection *self) _tp_connection_set_contact_blocked (self, contact); } - g_simple_async_result_complete (item->result); + g_simple_async_result_complete_in_idle (item->result); } blocked_changed_item_free (item); @@ -1819,7 +1819,7 @@ request_blocked_contacts_cb (TpConnection *self, { DEBUG ("Error calling RequestBlockedContacts: %s", error->message); g_simple_async_result_set_from_error (result, error); - g_simple_async_result_complete (result); + g_simple_async_result_complete_in_idle (result); return; } diff --git a/telepathy-glib/connection.c b/telepathy-glib/connection.c index a8e677f..0b34bbe 100644 --- a/telepathy-glib/connection.c +++ b/telepathy-glib/connection.c @@ -466,7 +466,7 @@ tp_connection_get_balance_cb (TpProxy *proxy, g_object_thaw_notify ((GObject *) self); finally: - g_simple_async_result_complete (result); + g_simple_async_result_complete_in_idle (result); } static void @@ -541,7 +541,7 @@ tp_connection_get_rcc_cb (TpProxy *proxy, finally: while ((result = g_queue_pop_head (&self->priv->capabilities_queue)) != NULL) { - g_simple_async_result_complete (result); + g_simple_async_result_complete_in_idle (result); g_object_unref (result); } diff --git a/telepathy-glib/contact.c b/telepathy-glib/contact.c index 7e51a50..29c2884 100644 --- a/telepathy-glib/contact.c +++ b/telepathy-glib/contact.c @@ -697,7 +697,7 @@ set_contact_groups_cb (TpConnection *connection, g_simple_async_result_set_from_error (result, error); } - g_simple_async_result_complete (result); + g_simple_async_result_complete_in_idle (result); g_object_unref (result); } diff --git a/telepathy-glib/file-transfer-channel.c b/telepathy-glib/file-transfer-channel.c index e306f79..08d8e4c 100644 --- a/telepathy-glib/file-transfer-channel.c +++ b/telepathy-glib/file-transfer-channel.c @@ -185,7 +185,7 @@ operation_failed (TpFileTransferChannel *self, GError *error) { g_simple_async_result_take_error (self->priv->result, error); - g_simple_async_result_complete (self->priv->result); + g_simple_async_result_complete_in_idle (self->priv->result); tp_clear_object (&self->priv->result); } @@ -442,7 +442,7 @@ tp_file_transfer_channel_prepare_core_cb (TpProxy *proxy, self->priv->file = g_file_new_for_uri (uri); out: - g_simple_async_result_complete (result); + g_simple_async_result_complete_in_idle (result); } static void @@ -1169,7 +1169,7 @@ accept_or_provide_file_cb (TpChannel *proxy, start_transfer (self); } - g_simple_async_result_complete (self->priv->result); + g_simple_async_result_complete_in_idle (self->priv->result); } static gboolean diff --git a/telepathy-glib/stream-tube-channel.c b/telepathy-glib/stream-tube-channel.c index 45a778a..e8018eb 100644 --- a/telepathy-glib/stream-tube-channel.c +++ b/telepathy-glib/stream-tube-channel.c @@ -533,7 +533,7 @@ operation_failed (TpStreamTubeChannel *self, { g_simple_async_result_set_from_error (self->priv->result, error); - g_simple_async_result_complete (self->priv->result); + g_simple_async_result_complete_in_idle (self->priv->result); tp_clear_object (&self->priv->result); } @@ -1203,7 +1203,7 @@ _channel_offered (TpChannel *channel, DEBUG ("Stream Tube offered"); - g_simple_async_result_complete (self->priv->result); + g_simple_async_result_complete_in_idle (self->priv->result); tp_clear_object (&self->priv->result); } diff --git a/telepathy-glib/text-channel.c b/telepathy-glib/text-channel.c index 3ef0c56..8588de8 100644 --- a/telepathy-glib/text-channel.c +++ b/telepathy-glib/text-channel.c @@ -641,7 +641,7 @@ get_pending_messages_cb (TpProxy *proxy, error->domain, error->code, "Failed to get PendingMessages property: %s", error->message); - g_simple_async_result_complete (self->priv->pending_messages_result); + g_simple_async_result_complete_in_idle (self->priv->pending_messages_result); g_clear_object (&self->priv->pending_messages_result); return; } @@ -654,7 +654,7 @@ get_pending_messages_cb (TpProxy *proxy, TP_ERRORS, TP_ERROR_CONFUSED, "PendingMessages property is of the wrong type"); - g_simple_async_result_complete (self->priv->pending_messages_result); + g_simple_async_result_complete_in_idle (self->priv->pending_messages_result); g_clear_object (&self->priv->pending_messages_result); return; } @@ -663,7 +663,7 @@ get_pending_messages_cb (TpProxy *proxy, if (messages->len == 0) { - g_simple_async_result_complete (self->priv->pending_messages_result); + g_simple_async_result_complete_in_idle (self->priv->pending_messages_result); g_clear_object (&self->priv->pending_messages_result); return; } @@ -755,7 +755,7 @@ get_sms_channel_cb (TpProxy *proxy, g_object_notify (G_OBJECT (self), "is-sms-channel"); out: - g_simple_async_result_complete (result); + g_simple_async_result_complete_in_idle (result); g_object_unref (result); } @@ -1218,7 +1218,7 @@ send_message_cb (TpChannel *proxy, g_simple_async_result_set_op_res_gpointer (result, tp_str_empty (token) ? NULL : g_strdup (token), g_free); - g_simple_async_result_complete (result); + g_simple_async_result_complete_in_idle (result); g_object_unref (result); } @@ -1295,7 +1295,7 @@ acknowledge_pending_messages_ready_cb (GObject *object, _tp_channel_contacts_queue_prepare_finish (channel, res, NULL, NULL); - g_simple_async_result_complete (result); + g_simple_async_result_complete_in_idle (result); g_object_unref (result); } @@ -1312,7 +1312,7 @@ acknowledge_pending_messages_cb (TpChannel *channel, DEBUG ("Failed to ack messages: %s", error->message); g_simple_async_result_set_from_error (result, error); - g_simple_async_result_complete (result); + g_simple_async_result_complete_in_idle (result); g_object_unref (result); return; } @@ -1513,7 +1513,7 @@ set_chat_state_cb (TpChannel *proxy, g_simple_async_result_set_from_error (result, error); } - g_simple_async_result_complete (result); + g_simple_async_result_complete_in_idle (result); g_object_unref (result); } @@ -1725,7 +1725,7 @@ get_sms_length_cb (TpChannel *proxy, (GDestroyNotify) get_sms_length_return_free); out: - g_simple_async_result_complete (result); + g_simple_async_result_complete_in_idle (result); } /** -- 1.7.9