From a65e942b04c4c9741d5f124bce71e5883c9ca5c3 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Mon, 5 Mar 2012 16:05:12 +0000 Subject: [PATCH 1/2] Remove TpChannel-specific readiness, just use TpProxy preparation Bug: https://bugs.freedesktop.org/show_bug.cgi?id=45842 --- docs/reference/telepathy-glib-sections.txt | 3 - telepathy-glib/channel-internal.h | 2 - telepathy-glib/channel.c | 191 ---------------------------- telepathy-glib/channel.h | 12 -- tests/dbus/channel-introspect.c | 73 ++--------- 5 files changed, 9 insertions(+), 272 deletions(-) diff --git a/docs/reference/telepathy-glib-sections.txt b/docs/reference/telepathy-glib-sections.txt index a2bc48d..f308c84 100644 --- a/docs/reference/telepathy-glib-sections.txt +++ b/docs/reference/telepathy-glib-sections.txt @@ -2972,10 +2972,7 @@ TpChannel TpChannelClass tp_channel_new tp_channel_new_from_properties -TpChannelWhenReadyCb -tp_channel_call_when_ready tp_channel_init_known_interfaces -tp_channel_is_ready TP_CHANNEL_FEATURE_CORE TP_CHANNEL_FEATURE_CONTACTS diff --git a/telepathy-glib/channel-internal.h b/telepathy-glib/channel-internal.h index b39b45c..d770144 100644 --- a/telepathy-glib/channel-internal.h +++ b/telepathy-glib/channel-internal.h @@ -87,8 +87,6 @@ struct _TpChannelPrivate { /* These are really booleans, but gboolean is signed. Thanks, GLib */ - /* channel-ready */ - unsigned ready:1; /* Enough method calls have succeeded that we believe that the channel * exists (implied by ready) */ unsigned exists:1; diff --git a/telepathy-glib/channel.c b/telepathy-glib/channel.c index 792f420..b056318 100644 --- a/telepathy-glib/channel.c +++ b/telepathy-glib/channel.c @@ -95,7 +95,6 @@ enum PROP_HANDLE_TYPE, PROP_HANDLE, PROP_IDENTIFIER, - PROP_CHANNEL_READY, PROP_CHANNEL_PROPERTIES, PROP_GROUP_SELF_HANDLE, PROP_GROUP_FLAGS, @@ -141,12 +140,6 @@ G_DEFINE_TYPE_WITH_CODE (TpChannel, * - any extra interfaces will have been set up in TpProxy (i.e. * #TpProxy:interfaces contains at least all extra Channel interfaces) * - * (These are a subset of the guarantees offered by the older - * #TpChannel:channel-ready - * and tp_channel_call_when_ready() mechanisms, which are now equivalent to - * (%TP_CHANNEL_FEATURE_CORE, %TP_CHANNEL_FEATURE_GROUP) if the channel is - * a group, or just %TP_CHANNEL_FEATURE_CORE otherwise.) - * * One can ask for a feature to be prepared using the * tp_proxy_prepare_async() function, and waiting for it to callback. * @@ -174,9 +167,6 @@ tp_channel_get_feature_quark_core (void) * - the initial value of the #TpChannel:group-flags property will * have been fetched and change notification will have been set up * - * (These are the same guarantees offered for Group channels by the older - * #TpChannel:channel-ready and tp_channel_call_when_ready() mechanisms.) - * * One can ask for a feature to be prepared using the * tp_proxy_prepare_async() function, and waiting for it to callback. * @@ -351,39 +341,6 @@ tp_channel_get_identifier (TpChannel *self) } /** - * tp_channel_is_ready: (skip) - * @self: a channel - * - * Returns the same thing as the #TpChannel:channel-ready property. - * - * New code should use tp_proxy_is_prepared(), which is a more general form of - * this method. - * - * For group channels, this method is equivalent to checking for the - * combination of %TP_CHANNEL_FEATURE_CORE and %TP_CHANNEL_FEATURE_GROUP; for - * non-group channels, it's equivalent to checking for - * %TP_CHANNEL_FEATURE_CORE. - * - * One important difference is that after #TpProxy::invalidated is - * signalled, #TpChannel:channel-ready keeps its current value - which might - * be %TRUE, if the channel was successfully prepared before it became - * invalidated - but tp_proxy_is_prepared() returns %FALSE for all features. - * - * Returns: %TRUE if introspection has completed - * Since: 0.7.12 - * Deprecated: 0.17.UNRELEASED: use tp_proxy_is_prepared() with - * %TP_CHANNEL_FEATURE_CORE - */ -gboolean -tp_channel_is_ready (TpChannel *self) -{ - g_return_val_if_fail (TP_IS_CHANNEL (self), FALSE); - - return self->priv->ready; -} - - -/** * tp_channel_borrow_connection: * @self: a channel * @@ -448,9 +405,6 @@ tp_channel_get_property (GObject *object, case PROP_CONNECTION: g_value_set_object (value, self->priv->connection); break; - case PROP_CHANNEL_READY: - g_value_set_boolean (value, self->priv->ready); - break; case PROP_CHANNEL_TYPE: g_value_set_static_string (value, g_quark_to_string (self->priv->channel_type)); @@ -792,8 +746,6 @@ _tp_channel_continue_introspection (TpChannel *self) self->priv->introspect_needed = NULL; DEBUG ("%p: channel ready", self); - self->priv->ready = TRUE; - g_object_notify ((GObject *) self, "channel-ready"); /* for now, we only have one introspection queue, so CORE and * (if supported) GROUP turn up simultaneously */ @@ -1304,33 +1256,6 @@ tp_channel_class_init (TpChannelClass *klass) param_spec); /** - * TpChannel:channel-ready: - * - * Initially %FALSE; changes to %TRUE when tp_proxy_prepare_async() has - * finished preparing %TP_CHANNEL_FEATURE_CORE, and if the channel is a - * group, %TP_CHANNEL_FEATURE_GROUP. - * - * This is a less general form of tp_proxy_is_prepared(), which should be - * used in new code. - * - * One important difference is that after #TpProxy::invalidated is - * signalled, #TpChannel:channel-ready keeps its current value - which might - * be %TRUE, if the channel was successfully prepared before it became - * invalidated - but tp_proxy_is_prepared() returns %FALSE for all features. - * - * Change notification is via notify::channel-ready. - * - * Deprecated: 0.17.UNRELEASED: use tp_proxy_is_prepared() with - * %TP_CHANNEL_FEATURE_CORE for checks, or tp_proxy_prepare_async() for - * notification - */ - param_spec = g_param_spec_boolean ("channel-ready", "Channel ready?", - "Initially FALSE; changes to TRUE when introspection finishes", FALSE, - G_PARAM_READABLE | G_PARAM_STATIC_STRINGS | G_PARAM_DEPRECATED); - g_object_class_install_property (object_class, PROP_CHANNEL_READY, - param_spec); - - /** * TpChannel:connection: * * The #TpConnection to which this #TpChannel belongs. Used for e.g. @@ -1789,122 +1714,6 @@ finally: return ret; } -typedef struct { - TpChannelWhenReadyCb callback; - gpointer user_data; - gulong invalidated_id; - gulong ready_id; -} CallWhenReadyContext; - -static void -cwr_invalidated (TpChannel *self, - guint domain, - gint code, - gchar *message, - gpointer user_data) -{ - CallWhenReadyContext *ctx = user_data; - GError e = { domain, code, message }; - - DEBUG ("enter"); - - g_assert (ctx->callback != NULL); - - ctx->callback (self, &e, ctx->user_data); - - g_signal_handler_disconnect (self, ctx->invalidated_id); - g_signal_handler_disconnect (self, ctx->ready_id); - - ctx->callback = NULL; /* poison it to detect errors */ - g_slice_free (CallWhenReadyContext, ctx); -} - -static void -cwr_ready (TpChannel *self, - GParamSpec *unused G_GNUC_UNUSED, - gpointer user_data) -{ - CallWhenReadyContext *ctx = user_data; - - DEBUG ("enter"); - - g_assert (ctx->callback != NULL); - - ctx->callback (self, NULL, ctx->user_data); - - g_signal_handler_disconnect (self, ctx->invalidated_id); - g_signal_handler_disconnect (self, ctx->ready_id); - - ctx->callback = NULL; /* poison it to detect errors */ - g_slice_free (CallWhenReadyContext, ctx); -} - -/** - * TpChannelWhenReadyCb: - * @channel: the channel (which may be in the middle of being disposed, - * if error is non-%NULL, error->domain is TP_DBUS_ERRORS and error->code is - * TP_DBUS_ERROR_PROXY_UNREFERENCED) - * @error: %NULL if the channel is ready for use, or the error with which - * it was invalidated if it is now invalid - * @user_data: whatever was passed to tp_channel_call_when_ready() - * - * Signature of a callback passed to tp_channel_call_when_ready(), which - * will be called exactly once, when the channel becomes ready or - * invalid (whichever happens first) - * - * Deprecated: 0.17.UNRELEASED - */ - -/** - * tp_channel_call_when_ready: (skip) - * @self: a channel - * @callback: called when the channel becomes ready or invalidated, whichever - * happens first - * @user_data: arbitrary user-supplied data passed to the callback - * - * If @self is ready for use or has been invalidated, call @callback - * immediately, then return. Otherwise, arrange - * for @callback to be called when @self either becomes ready for use - * or becomes invalid. - * - * This is a less general form of tp_proxy_prepare_async(), which should be - * used in new code. (One important difference is that this function can call - * @callback before it has returned, whereas tp_proxy_prepare_async() always - * calls @callback from the main loop.) - * - * Since: 0.7.7 - * Deprecated: 0.17.UNRELEASED: Use tp_proxy_prepare_async() - */ -void -tp_channel_call_when_ready (TpChannel *self, - TpChannelWhenReadyCb callback, - gpointer user_data) -{ - TpProxy *as_proxy = (TpProxy *) self; - - g_return_if_fail (TP_IS_CHANNEL (self)); - g_return_if_fail (callback != NULL); - - if (self->priv->ready || as_proxy->invalidated != NULL) - { - DEBUG ("already ready or invalidated"); - callback (self, as_proxy->invalidated, user_data); - } - else - { - CallWhenReadyContext *ctx = g_slice_new (CallWhenReadyContext); - - DEBUG ("arranging callback later"); - - ctx->callback = callback; - ctx->user_data = user_data; - ctx->invalidated_id = g_signal_connect (self, "invalidated", - G_CALLBACK (cwr_invalidated), ctx); - ctx->ready_id = g_signal_connect (self, "notify::channel-ready", - G_CALLBACK (cwr_ready), ctx); - } -} - static gpointer tp_channel_once (gpointer data G_GNUC_UNUSED) { diff --git a/telepathy-glib/channel.h b/telepathy-glib/channel.h index 15b1802..b868b3d 100644 --- a/telepathy-glib/channel.h +++ b/telepathy-glib/channel.h @@ -82,18 +82,6 @@ TpChannel *tp_channel_new_from_properties (TpConnection *conn, const gchar *object_path, const GHashTable *immutable_properties, GError **error) G_GNUC_WARN_UNUSED_RESULT; -#ifndef TP_DISABLE_DEPRECATED -typedef void (*TpChannelWhenReadyCb) (TpChannel *channel, const GError *error, - gpointer user_data); - -void tp_channel_call_when_ready (TpChannel *self, - TpChannelWhenReadyCb callback, - gpointer user_data) _TP_GNUC_DEPRECATED_FOR (tp_proxy_prepare_async); - -gboolean tp_channel_is_ready (TpChannel *self) - _TP_GNUC_DEPRECATED_FOR (tp_proxy_is_ready); -#endif - void tp_channel_init_known_interfaces (void); const gchar *tp_channel_get_channel_type (TpChannel *self); diff --git a/tests/dbus/channel-introspect.c b/tests/dbus/channel-introspect.c index 3fce3fb..4793239 100644 --- a/tests/dbus/channel-introspect.c +++ b/tests/dbus/channel-introspect.c @@ -24,35 +24,9 @@ #define IDENTIFIER "them@example.org" -static GError *invalidated = NULL; static GMainLoop *mainloop; static void -channel_ready (TpChannel *channel, - const GError *error, - gpointer user_data) -{ - gboolean *set = user_data; - - *set = TRUE; - - if (error == NULL) - { - g_message ("channel %p ready", channel); - } - else - { - g_message ("channel %p invalidated: %s #%u \"%s\"", channel, - g_quark_to_string (error->domain), error->code, error->message); - - invalidated = g_error_copy (error); - } - - if (mainloop != NULL) - g_main_loop_quit (mainloop); -} - -static void channel_prepared_cb (GObject *object, GAsyncResult *res, gpointer user_data) @@ -76,7 +50,8 @@ assert_chan_sane (TpChannel *chan, GHashTable *asv; TpHandleType type; - g_assert (tp_channel_is_ready (chan)); + g_assert_cmpint (tp_proxy_is_prepared (chan, TP_CHANNEL_FEATURE_CORE), ==, + TRUE); g_assert_cmpuint (tp_channel_get_handle (chan, NULL), ==, handle); g_assert_cmpuint (tp_channel_get_handle (chan, &type), ==, handle); g_assert_cmpuint (type, ==, TP_HANDLE_TYPE_CONTACT); @@ -125,7 +100,6 @@ main (int argc, gchar *props_group_chan_path; gchar *bad_chan_path; TpHandle handle; - gboolean was_ready; GHashTable *asv; GAsyncResult *prepare_result; GQuark some_features[] = { TP_CHANNEL_FEATURE_CORE, @@ -316,28 +290,7 @@ main (int argc, g_object_unref (chan); chan = NULL; - g_message ("channel does not, in fact, exist (callback)"); - - bad_chan_path = g_strdup_printf ("%s/Does/Not/Actually/Exist", - tp_proxy_get_object_path (conn)); - chan = tp_channel_new (conn, bad_chan_path, NULL, - TP_UNKNOWN_HANDLE_TYPE, 0, &error); - g_assert_no_error (error); - - was_ready = FALSE; - tp_channel_call_when_ready (chan, channel_ready, &was_ready); - g_main_loop_run (mainloop); - g_assert (was_ready); - g_assert_error (invalidated, DBUS_GERROR, DBUS_GERROR_UNKNOWN_METHOD); - g_error_free (invalidated); - invalidated = NULL; - - g_object_unref (chan); - chan = NULL; - g_free (bad_chan_path); - bad_chan_path = NULL; - - g_message ("channel does not, in fact, exist (run_until_ready)"); + g_message ("channel does not, in fact, exist"); bad_chan_path = g_strdup_printf ("%s/Does/Not/Actually/Exist", tp_proxy_get_object_path (conn)); @@ -429,7 +382,7 @@ main (int argc, g_clear_object (&chan2); g_clear_object (&conn2); - g_message ("Channel already dead, so we are called back synchronously"); + g_message ("Channel already dead"); chan = tp_channel_new (conn, props_chan_path, NULL, TP_UNKNOWN_HANDLE_TYPE, 0, &error); @@ -452,37 +405,29 @@ main (int argc, tp_tests_connection_assert_disconnect_succeeds (conn); - was_ready = FALSE; - prepare_result = NULL; tp_proxy_prepare_async (chan, some_features, channel_prepared_cb, &prepare_result); - tp_channel_call_when_ready (chan, channel_ready, &was_ready); - g_assert (was_ready); - g_assert_error (invalidated, TP_ERRORS, TP_ERROR_CANCELLED); - /* is_prepared becomes FALSE because the channel broke */ g_assert_cmpint (tp_proxy_is_prepared (chan, TP_CHANNEL_FEATURE_CORE), ==, FALSE); g_assert_cmpint (tp_proxy_is_prepared (chan, TP_CHANNEL_FEATURE_CHAT_STATES), ==, FALSE); - g_assert_error (invalidated, tp_proxy_get_invalidated (chan)->domain, - tp_proxy_get_invalidated (chan)->code); - g_assert_cmpstr (invalidated->message, ==, - tp_proxy_get_invalidated (chan)->message); + g_assert_error (tp_proxy_get_invalidated (chan), + TP_ERRORS, TP_ERROR_CANCELLED); /* ... but prepare_async still hasn't finished until we run the main loop */ g_assert (prepare_result == NULL); g_main_loop_run (mainloop); g_assert (prepare_result != NULL); MYASSERT (!tp_proxy_prepare_finish (chan, prepare_result, &error), ""); - g_assert_error (error, invalidated->domain, invalidated->code); - g_assert_cmpstr (error->message, ==, invalidated->message); + g_assert_error (error, TP_ERRORS, TP_ERROR_CANCELLED); + g_assert_cmpstr (error->message, ==, + tp_proxy_get_invalidated (chan)->message); tp_clear_object (&prepare_result); g_clear_error (&error); - g_clear_error (&invalidated); g_object_unref (chan); chan = NULL; -- 1.7.9.1