From 8b4bafba07908bd61e1d951fde112782fd180a83 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Wed, 2 Oct 2013 19:46:41 +0100 Subject: [PATCH 6/6] Make ServicePoint setup more sensible mcd_connection_service_point_setup shouldn't call GetInterfaces - TpConnection already knows how to do that. As currently implemented, mcd_connection_service_point_setup() is only called from the status-changed callback for CONNECTED, which telepathy-glib guarantees not to call until core features are ready. However, it's a lot more clearly correct if we do this in on_connection_ready(). --- src/mcd-connection-service-points.c | 50 ++++++++----------------------------- src/mcd-connection.c | 12 ++++++--- 2 files changed, 19 insertions(+), 43 deletions(-) diff --git a/src/mcd-connection-service-points.c b/src/mcd-connection-service-points.c index 896f4bc..b52abe3 100644 --- a/src/mcd-connection-service-points.c +++ b/src/mcd-connection-service-points.c @@ -90,31 +90,16 @@ service_points_fetched_cb (TpProxy *proxy, parse_services_list (connection, g_value_get_boxed (value)); } -static void -service_point_interface_check (TpConnection *tp_conn, - const gchar **interfaces, - const GError *error, - gpointer data, - GObject *connection) +void +mcd_connection_service_point_setup (McdConnection *connection, + gboolean watch) { - const gchar *interface; - gboolean found = FALSE; - gboolean watch = GPOINTER_TO_UINT (data); - guint i = 0; - - if (interfaces == NULL) - return; - - for (interface = interfaces[0]; - !found && !tp_str_empty (interface); - interface = interfaces[++i]) - { - if (!tp_strdiff (interface, TP_IFACE_CONNECTION_INTERFACE_SERVICE_POINT)) - found = TRUE; - } + TpConnection *tp_conn = mcd_connection_get_tp_connection (connection); - if (!found) - return; + g_return_if_fail (MCD_IS_CONNECTION (connection)); + g_return_if_fail (TP_IS_PROXY (tp_conn)); + g_return_if_fail (tp_proxy_is_prepared (tp_conn, + TP_CONNECTION_FEATURE_CONNECTED)); /* so we know if/when the service points change (eg the SIM might not be * accessible yet, in which case the call below won't return any entries) @@ -122,25 +107,12 @@ service_point_interface_check (TpConnection *tp_conn, */ if (watch) tp_cli_connection_interface_service_point_connect_to_service_points_changed - (tp_conn, service_points_changed_cb, NULL, NULL, connection, NULL); + (tp_conn, service_points_changed_cb, NULL, NULL, + (GObject *) connection, NULL); /* fetch the current list to initialise our state */ tp_cli_dbus_properties_call_get (tp_conn, -1, TP_IFACE_CONNECTION_INTERFACE_SERVICE_POINT, "KnownServicePoints", service_points_fetched_cb, - NULL, NULL, connection); -} - -void -mcd_connection_service_point_setup (McdConnection *connection, gboolean watch) -{ - TpConnection *tp_conn = mcd_connection_get_tp_connection (connection); - - if (G_UNLIKELY (!tp_conn)) - return; - - /* see if the connection supports the service point interface */ - tp_cli_connection_call_get_interfaces (tp_conn, -1, - service_point_interface_check, - GUINT_TO_POINTER (watch), NULL, G_OBJECT (connection)); + NULL, NULL, (GObject *) connection); } diff --git a/src/mcd-connection.c b/src/mcd-connection.c index 0e1a377..cf8044e 100644 --- a/src/mcd-connection.c +++ b/src/mcd-connection.c @@ -591,10 +591,6 @@ on_connection_status_changed (TpConnection *tp_conn, GParamSpec *pspec, priv->probation_drop_count = 0; } - mcd_connection_service_point_setup (connection, - !priv->service_points_watched); - priv->service_points_watched = TRUE; - priv->connected = TRUE; } break; @@ -1094,6 +1090,14 @@ on_connection_ready (GObject *source_object, GAsyncResult *result, DEBUG ("connection is ready"); priv = MCD_CONNECTION_PRIV (connection); + if (tp_proxy_has_interface_by_id (tp_conn, + TP_IFACE_QUARK_CONNECTION_INTERFACE_SERVICE_POINT)) + { + mcd_connection_service_point_setup (connection, + !priv->service_points_watched); + priv->service_points_watched = TRUE; + } + priv->has_presence_if = tp_proxy_has_interface_by_id (tp_conn, TP_IFACE_QUARK_CONNECTION_INTERFACE_SIMPLE_PRESENCE); priv->has_contact_capabilities_if = tp_proxy_has_interface_by_id (tp_conn, -- 1.8.4.rc3