From 80db92bd642db23ae14b4b8d3fb4917b88eeeaa8 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Mon, 5 Mar 2012 16:08:10 +0000 Subject: [PATCH 2/2] Remove TpConnection-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-dispatch-operation.c | 3 +- telepathy-glib/channel-dispatcher.c | 3 +- telepathy-glib/channel-request.c | 3 +- telepathy-glib/client.c | 3 +- telepathy-glib/connection-internal.h | 1 - telepathy-glib/connection.c | 172 +-------------------------- telepathy-glib/connection.h | 12 -- tests/dbus/connection.c | 114 ++---------------- 9 files changed, 15 insertions(+), 299 deletions(-) diff --git a/docs/reference/telepathy-glib-sections.txt b/docs/reference/telepathy-glib-sections.txt index f308c84..98fc0df 100644 --- a/docs/reference/telepathy-glib-sections.txt +++ b/docs/reference/telepathy-glib-sections.txt @@ -3233,9 +3233,6 @@ TP_CONNECTION_FEATURE_CONTACT_LIST_PROPERTIES TP_CONNECTION_FEATURE_CONTACT_GROUPS TP_CONNECTION_FEATURE_CONTACT_BLOCKING TP_CONNECTION_FEATURE_ALIASING -TpConnectionWhenReadyCb -tp_connection_call_when_ready -tp_connection_is_ready tp_connection_disconnect_async tp_connection_disconnect_finish tp_connection_get_account diff --git a/telepathy-glib/channel-dispatch-operation.c b/telepathy-glib/channel-dispatch-operation.c index 690e36f..6534df0 100644 --- a/telepathy-glib/channel-dispatch-operation.c +++ b/telepathy-glib/channel-dispatch-operation.c @@ -100,8 +100,7 @@ * will be notified again. * * This proxy is usable but incomplete: accessors for the D-Bus properties will - * be added in a later version of telepathy-glib, along with a mechanism - * similar to tp_connection_call_when_ready(). + * be added in a later version of telepathy-glib. * * Since: 0.7.32 */ diff --git a/telepathy-glib/channel-dispatcher.c b/telepathy-glib/channel-dispatcher.c index 0f54524..3132589 100644 --- a/telepathy-glib/channel-dispatcher.c +++ b/telepathy-glib/channel-dispatcher.c @@ -62,8 +62,7 @@ * See the Telepathy D-Bus Interface Specification for details. * * This proxy is usable but incomplete: convenience methods will be added in - * a later version of telepathy-glib, along with a mechanism similar to - * tp_connection_call_when_ready(). + * a later version of telepathy-glib. * * Since: 0.7.32 */ diff --git a/telepathy-glib/channel-request.c b/telepathy-glib/channel-request.c index 5e8ef08..4e002cf 100644 --- a/telepathy-glib/channel-request.c +++ b/telepathy-glib/channel-request.c @@ -80,8 +80,7 @@ * * This proxy is usable but incomplete: accessors for the Account, * UserActionTime, PreferredHandler, Requests and Interfaces properties will - * be added in a later version of telepathy-glib, along with a mechanism - * similar to tp_connection_call_when_ready(). + * be added in a later version of telepathy-glib. * * Until suitable convenience methods are implemented, the generic * tp_cli_dbus_properties_call_get_all() method can be used to get those diff --git a/telepathy-glib/client.c b/telepathy-glib/client.c index 0e62a96..782fb94 100644 --- a/telepathy-glib/client.c +++ b/telepathy-glib/client.c @@ -54,8 +54,7 @@ * useful in the implementation of the ChannelDispatcher itself. * * This proxy is usable but very incomplete: accessors for D-Bus properties - * will be added in a later version of telepathy-glib, along with a mechanism - * similar to tp_connection_call_when_ready(). + * will be added in a later version of telepathy-glib. * * Many operations performed on a Client are done via D-Bus properties. * Until convenience methods for this are implemented, use of the generic diff --git a/telepathy-glib/connection-internal.h b/telepathy-glib/connection-internal.h index 9f34cf4..08af62c 100644 --- a/telepathy-glib/connection-internal.h +++ b/telepathy-glib/connection-internal.h @@ -105,7 +105,6 @@ struct _TpConnectionPrivate { TpProxyPendingCall *introspection_call; - unsigned ready:1; unsigned ready_enough_for_contacts:1; unsigned tracking_aliases_changed:1; unsigned tracking_avatar_updated:1; diff --git a/telepathy-glib/connection.c b/telepathy-glib/connection.c index 04a6227..851db5d 100644 --- a/telepathy-glib/connection.c +++ b/telepathy-glib/connection.c @@ -94,11 +94,10 @@ * * * prepared does not imply connected - * Unlike the older #TpConnection:connection-ready mechanism, this + * This * feature does not imply that the connection has successfully connected. * It only implies that an initial status (disconnected, connecting or - * connected) has been discovered. %TP_CONNECTION_FEATURE_CONNECTED - * is the closest equivalent of #TpConnection:connection-ready. + * connected) has been discovered. * * * One can ask for a feature to be prepared using the @@ -267,7 +266,6 @@ enum PROP_STATUS_REASON, PROP_CONNECTION_MANAGER_NAME, PROP_PROTOCOL_NAME, - PROP_CONNECTION_READY, PROP_SELF_CONTACT, PROP_SELF_HANDLE, PROP_CAPABILITIES, @@ -319,9 +317,6 @@ tp_connection_get_property (GObject *object, case PROP_PROTOCOL_NAME: g_value_set_string (value, self->priv->proto_name); break; - case PROP_CONNECTION_READY: - g_value_set_boolean (value, self->priv->ready); - break; case PROP_STATUS: g_value_set_uint (value, self->priv->status); break; @@ -625,7 +620,6 @@ signal_connected (TpConnection *self) tp_proxy_get_object_path (self), self); self->priv->status = TP_CONNECTION_STATUS_CONNECTED; self->priv->status_reason = TP_CONNECTION_STATUS_REASON_REQUESTED; - self->priv->ready = TRUE; _tp_proxy_set_feature_prepared ((TpProxy *) self, TP_CONNECTION_FEATURE_CONNECTED, TRUE); @@ -634,7 +628,6 @@ signal_connected (TpConnection *self) g_object_notify ((GObject *) self, "status"); g_object_notify ((GObject *) self, "status-reason"); - g_object_notify ((GObject *) self, "connection-ready"); } static void @@ -1692,30 +1685,6 @@ tp_connection_class_init (TpConnectionClass *klass) g_object_class_install_property (object_class, PROP_STATUS_REASON, param_spec); - /** - * TpConnection:connection-ready: - * - * Initially %FALSE; changes to %TRUE when the connection has gone to - * CONNECTED status, introspection has finished and it's ready for use. - * - * By the time this property becomes %TRUE, any extra interfaces will - * have been set up and the #TpProxy:interfaces property will have been - * populated. - * - * This is similar to %TP_CONNECTION_FEATURE_CONNECTED, except that once - * it has changed to %TRUE, it remains %TRUE even if the connection has - * been invalidated. - * - * Deprecated: 0.17.UNRELEASED: use tp_proxy_is_prepared() with - * %TP_CHANNEL_FEATURE_CONNECTED for checks, or tp_proxy_prepare_async() for - * notification - */ - param_spec = g_param_spec_boolean ("connection-ready", "Connection 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_CONNECTION_READY, - param_spec); - /** * TpConnection:capabilities: * @@ -2650,123 +2619,6 @@ tp_connection_init_known_interfaces (void) g_once (&once, tp_connection_once, NULL); } -typedef struct { - TpConnectionWhenReadyCb callback; - gpointer user_data; - gulong invalidated_id; - gulong ready_id; -} CallWhenReadyContext; - -static void -cwr_invalidated (TpConnection *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 (TpConnection *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); -} - -/** - * TpConnectionWhenReadyCb: - * @connection: the connection (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 connection is ready for use, or the error with which - * it was invalidated if it is now invalid - * @user_data: whatever was passed to tp_connection_call_when_ready() - * - * Signature of a callback passed to tp_connection_call_when_ready(), which - * will be called exactly once, when the connection becomes ready or - * invalid (whichever happens first) - * - * Deprecated: 0.17.UNRELEASED - */ - -/** - * tp_connection_call_when_ready: (skip) - * @self: a connection - * @callback: called when the connection 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. - * - * Note that if the connection is not in state CONNECTED, the callback will - * not be called until the connection either goes to state CONNECTED - * or is invalidated (e.g. by going to state DISCONNECTED or by becoming - * unreferenced). In particular, this method does not call Connect(). - * Call tp_cli_connection_call_connect() too, if you want to do that. - * - * Since: 0.7.7 - * Deprecated: 0.17.UNRELEASED: Use tp_proxy_prepare_async() - */ -void -tp_connection_call_when_ready (TpConnection *self, - TpConnectionWhenReadyCb callback, - gpointer user_data) -{ - TpProxy *as_proxy = (TpProxy *) self; - - g_return_if_fail (TP_IS_CONNECTION (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::connection-ready", - G_CALLBACK (cwr_ready), ctx); - } -} - static guint get_presence_type_availability (TpConnectionPresenceType type) { @@ -2911,26 +2763,6 @@ _tp_connection_add_contact (TpConnection *self, } } - -/** - * tp_connection_is_ready: (skip) - * @self: a connection - * - * Returns the same thing as the #TpConnection:connection-ready property. - * - * Returns: %TRUE if introspection has completed - * Since: 0.7.17 - * Deprecated: 0.17.UNRELEASED: use tp_proxy_is_prepared() with - * %TP_CONNECTION_FEATURE_CONNECTED - */ -gboolean -tp_connection_is_ready (TpConnection *self) -{ - g_return_val_if_fail (TP_IS_CONNECTION (self), FALSE); - - return self->priv->ready; -} - /** * tp_connection_get_capabilities: * @self: a connection diff --git a/telepathy-glib/connection.h b/telepathy-glib/connection.h index 7237af1..6d285cc 100644 --- a/telepathy-glib/connection.h +++ b/telepathy-glib/connection.h @@ -152,18 +152,6 @@ void tp_connection_set_contact_info_async (TpConnection *self, gboolean tp_connection_set_contact_info_finish (TpConnection *self, GAsyncResult *result, GError **error); -#ifndef TP_DISABLE_DEPRECATED -gboolean tp_connection_is_ready (TpConnection *self) - _TP_GNUC_DEPRECATED_FOR (tp_proxy_is_prepared); - -typedef void (*TpConnectionWhenReadyCb) (TpConnection *connection, - const GError *error, gpointer user_data); - -void tp_connection_call_when_ready (TpConnection *self, - TpConnectionWhenReadyCb callback, - gpointer user_data) _TP_GNUC_DEPRECATED_FOR (tp_proxy_prepare_async); -#endif - typedef void (*TpConnectionNameListCb) (const gchar * const *names, gsize n, const gchar * const *cms, const gchar * const *protocols, const GError *error, gpointer user_data, diff --git a/tests/dbus/connection.c b/tests/dbus/connection.c index 97a4622..68a3f03 100644 --- a/tests/dbus/connection.c +++ b/tests/dbus/connection.c @@ -28,9 +28,6 @@ typedef struct { gchar *conn_path; TpConnection *conn; - gboolean cwr_ready; - GError *cwr_error /* initialized in setup */; - GAsyncResult *prepare_result; } Test; @@ -74,9 +71,6 @@ setup (Test *test, g_assert (tp_base_connection_register (test->service_conn_as_base, "simple", &test->conn_name, &test->conn_path, &error)); g_assert_no_error (error); - - test->cwr_ready = FALSE; - test->cwr_error = NULL; } static void @@ -113,38 +107,6 @@ teardown (Test *test, } static void -conn_ready (TpConnection *connection, - const GError *error, - gpointer user_data) -{ - Test *test = user_data; - - test->cwr_ready = TRUE; - - if (error == NULL) - { - gboolean parsed; - gchar *proto = NULL; - gchar *cm_name = NULL; - - g_message ("connection %p ready", connection); - parsed = tp_connection_parse_object_path (connection, &proto, &cm_name); - g_assert (parsed); - g_assert_cmpstr (proto, ==, "simple-protocol"); - g_assert_cmpstr (cm_name, ==, "simple"); - g_free (proto); - g_free (cm_name); - } - else - { - g_message ("connection %p invalidated: %s #%u \"%s\"", connection, - g_quark_to_string (error->domain), error->code, error->message); - - test->cwr_error = g_error_copy (error); - } -} - -static void test_prepare (Test *test, gconstpointer nil G_GNUC_UNUSED) { @@ -155,6 +117,7 @@ test_prepare (Test *test, TpCapabilities *caps; GPtrArray *classes; gchar *cm_name, *protocol_name; + gboolean parsed; test->conn = tp_connection_new (test->dbus, test->conn_name, test->conn_path, &error); @@ -186,6 +149,14 @@ test_prepare (Test *test, g_assert_cmpint (tp_connection_get_status (test->conn, NULL), ==, TP_CONNECTION_STATUS_DISCONNECTED); + parsed = tp_connection_parse_object_path (test->conn, &protocol_name, + &cm_name); + g_assert (parsed); + g_assert_cmpstr (protocol_name, ==, "simple-protocol"); + g_assert_cmpstr (cm_name, ==, "simple"); + g_free (protocol_name); + g_free (cm_name); + g_assert_cmpstr (tp_connection_get_connection_manager_name (test->conn), ==, "simple"); g_assert_cmpstr (tp_connection_get_protocol_name (test->conn), ==, @@ -293,69 +264,6 @@ test_fail_to_prepare (Test *test, g_assert (asv != NULL); } -static void -test_call_when_ready (Test *test, - gconstpointer nil G_GNUC_UNUSED) -{ - GError *error = NULL; - - test->conn = tp_connection_new (test->dbus, test->conn_name, test->conn_path, - &error); - g_assert (test->conn != NULL); - g_assert_no_error (error); - - tp_cli_connection_call_connect (test->conn, -1, NULL, NULL, NULL, NULL); - - tp_connection_call_when_ready (test->conn, conn_ready, test); - - while (!test->cwr_ready) - g_main_context_iteration (NULL, TRUE); - - g_assert_no_error (test->cwr_error); - - /* Connection already ready here, so we are called back synchronously */ - - test->cwr_ready = FALSE; - test->cwr_error = NULL; - tp_connection_call_when_ready (test->conn, conn_ready, test); - g_assert_cmpint (test->cwr_ready, ==, TRUE); - g_assert_no_error (test->cwr_error); -} - -static void -test_call_when_invalid (Test *test, - gconstpointer nil G_GNUC_UNUSED) -{ - GError *error = NULL; - - test->conn = tp_connection_new (test->dbus, test->conn_name, test->conn_path, - &error); - g_assert (test->conn != NULL); - g_assert_no_error (error); - - /* Connection becomes invalid, so we are called back synchronously */ - - tp_connection_call_when_ready (test->conn, conn_ready, test); - tp_proxy_invalidate ((TpProxy *) test->conn, &invalidated_for_test); - g_assert_cmpint (test->cwr_ready, ==, TRUE); - g_assert_error (test->cwr_error, invalidated_for_test.domain, - invalidated_for_test.code); - g_assert_cmpstr (test->cwr_error->message, ==, invalidated_for_test.message); - g_clear_error (&test->cwr_error); - - /* Connection already invalid, so we are called back synchronously */ - - test->cwr_ready = FALSE; - test->cwr_error = NULL; - tp_connection_call_when_ready (test->conn, conn_ready, test); - g_assert (test->cwr_ready); - g_assert_error (test->cwr_error, invalidated_for_test.domain, - invalidated_for_test.code); - g_assert_cmpstr (test->cwr_error->message, ==, invalidated_for_test.message); - g_error_free (test->cwr_error); - test->cwr_error = NULL; -} - int main (int argc, char **argv) @@ -365,10 +273,6 @@ main (int argc, g_test_add ("/conn/prepare", Test, NULL, setup, test_prepare, teardown); g_test_add ("/conn/fail_to_prepare", Test, NULL, setup, test_fail_to_prepare, teardown); - g_test_add ("/conn/call_when_ready", Test, NULL, setup, - test_call_when_ready, teardown); - g_test_add ("/conn/call_when_invalid", Test, NULL, setup, - test_call_when_invalid, teardown); return g_test_run (); } -- 1.7.9.1