From bddef6c47dcec82fa28172077150d65793def518 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Thu, 9 Feb 2012 15:58:04 +0000 Subject: [PATCH 2/7] Use tp_proxy_prepare_async() to prepare connections in example code Bug: https://bugs.freedesktop.org/show_bug.cgi?id=45842 Signed-off-by: Simon McVittie --- examples/client/extended-client.c | 28 ++++++++++++++-------------- examples/client/inspect-channel.c | 13 ++++++++----- examples/client/inspect-connection.c | 11 +++++++---- examples/client/inspect-contact.c | 11 +++++++---- 4 files changed, 36 insertions(+), 27 deletions(-) diff --git a/examples/client/extended-client.c b/examples/client/extended-client.c index 57582fc..724ff2c 100644 --- a/examples/client/extended-client.c +++ b/examples/client/extended-client.c @@ -168,11 +168,21 @@ contacts_ready_cb (TpConnection *conn, } static void -conn_ready (TpConnection *conn, - GParamSpec *unused, - gpointer user_data) +conn_ready (GObject *source, + GAsyncResult *result, + gpointer user_data) { + GError *error = NULL; static const gchar * const names[] = { "myself@server", "other@server" }; + TpConnection *conn = TP_CONNECTION (source); + + if (!tp_proxy_prepare_finish (conn, result, &error)) + { + g_warning ("%s", error->message); + g_main_loop_quit (mainloop); + g_clear_error (&error); + return; + } if (!tp_proxy_has_interface_by_id (conn, EXAMPLE_IFACE_QUARK_CONNECTION_INTERFACE_HATS)) @@ -214,7 +224,6 @@ cm_requested_connection (TpConnectionManager *manager, GError *e = NULL; TpConnection *conn; TpProxy *proxy = (TpProxy *) manager; - gboolean ready; if (die_if (error, "RequestConnection()")) return; @@ -235,16 +244,7 @@ cm_requested_connection (TpConnectionManager *manager, tp_cli_connection_connect_to_status_changed (conn, conn_status_changed, NULL, NULL, NULL, NULL); - g_object_get (conn, - "connection-ready", &ready, - NULL); - - if (ready) - conn_ready (conn, NULL, NULL); - else - g_signal_connect (conn, "notify::connection-ready", - G_CALLBACK (conn_ready), NULL); - + tp_proxy_prepare_async (conn, NULL, conn_ready, NULL); tp_cli_connection_call_connect (conn, -1, NULL, NULL, NULL, NULL); } diff --git a/examples/client/inspect-channel.c b/examples/client/inspect-channel.c index 9272a77..a4987b6 100644 --- a/examples/client/inspect-channel.c +++ b/examples/client/inspect-channel.c @@ -83,19 +83,22 @@ channel_ready_cb (GObject *source, } static void -connection_ready_cb (TpConnection *connection, - const GError *ready_error, +connection_ready_cb (GObject *source, + GAsyncResult *result, gpointer user_data) { InspectChannelData *data = user_data; GError *error = NULL; + TpConnection *connection = TP_CONNECTION (source); TpChannel *channel = NULL; - if (ready_error != NULL) + + if (!tp_proxy_prepare_finish (connection, result, &error)) { - g_warning ("%s", ready_error->message); + g_warning ("%s", error->message); data->exit_status = 1; g_main_loop_quit (data->main_loop); + g_clear_error (&error); return; } @@ -175,7 +178,7 @@ main (int argc, * else has called (or will call) Connect(), so we won't call Connect() * on it ourselves */ - tp_connection_call_when_ready (connection, connection_ready_cb, &data); + tp_proxy_prepare_async (connection, NULL, connection_ready_cb, &data); g_main_loop_run (data.main_loop); diff --git a/examples/client/inspect-connection.c b/examples/client/inspect-connection.c index 53fc8b0..edf0cfc 100644 --- a/examples/client/inspect-connection.c +++ b/examples/client/inspect-connection.c @@ -53,16 +53,19 @@ got_channels (TpConnection *connection, } static void -connection_ready_cb (TpConnection *connection, - const GError *error, +connection_ready_cb (GObject *source, + GAsyncResult *result, gpointer user_data) { GMainLoop *mainloop = user_data; + GError *error = NULL; + TpConnection *connection = TP_CONNECTION (source); - if (error != NULL) + if (!tp_proxy_prepare_finish (connection, result, &error)) { g_warning ("%s", error->message); g_main_loop_quit (mainloop); + g_clear_error (&error); return; } @@ -131,7 +134,7 @@ main (int argc, * else has called (or will call) Connect(), so we won't call Connect() * on it ourselves */ - tp_connection_call_when_ready (connection, connection_ready_cb, mainloop); + tp_proxy_prepare_async (connection, NULL, connection_ready_cb, mainloop); g_main_loop_run (mainloop); diff --git a/examples/client/inspect-contact.c b/examples/client/inspect-contact.c index a1d1847..c1b6bb3 100644 --- a/examples/client/inspect-contact.c +++ b/examples/client/inspect-contact.c @@ -127,8 +127,8 @@ got_contacts_by_id (TpConnection *connection, } static void -connection_ready_cb (TpConnection *connection, - const GError *error, +connection_ready_cb (GObject *source, + GAsyncResult *result, gpointer user_data) { static TpContactFeature features[] = { @@ -137,12 +137,15 @@ connection_ready_cb (TpConnection *connection, TP_CONTACT_FEATURE_PRESENCE }; InspectContactData *data = user_data; + TpConnection *connection = TP_CONNECTION (source); + GError *error = NULL; - if (error != NULL) + if (!tp_proxy_prepare_finish (connection, result, &error)) { g_warning ("%s", error->message); data->exit_status = 1; g_main_loop_quit (data->main_loop); + g_clear_error (&error); return; } @@ -227,7 +230,7 @@ main (int argc, * else has called (or will call) Connect(), so we won't call Connect() * on it ourselves */ - tp_connection_call_when_ready (connection, connection_ready_cb, &data); + tp_proxy_prepare_async (connection, NULL, connection_ready_cb, &data); g_main_loop_run (data.main_loop); -- 1.7.9.1