[Telepathy-commits] [telepathy-doc/master] 2008-09-26 Murray Cumming <murrayc at murrayc.com>

Murray Cumming murrayc at murrayc.com
Wed Oct 29 03:02:09 PDT 2008


* docs/examples/list_contacts/main.c: Try to catch connection problems
via the status_changed callback.
---
 ChangeLog                          |    5 ++++
 docs/examples/list_contacts/main.c |   41 ++++++++++++++++++++++++++++++++++++
 2 files changed, 46 insertions(+), 0 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 2a1ab0b..3538065 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 2008-09-26  Murray Cumming  <murrayc at murrayc.com>
 
+	* docs/examples/list_contacts/main.c: Try to catch connection problems 
+	via the status_changed callback. 
+
+2008-09-26  Murray Cumming  <murrayc at murrayc.com>
+
 	* docs/examples/list_contacts/: Added the beginnings of another example.
 	So far it just tries to create the connection so it can later get the 
 	contacts from it.
diff --git a/docs/examples/list_contacts/main.c b/docs/examples/list_contacts/main.c
index 0a8d397..d78ac1d 100644
--- a/docs/examples/list_contacts/main.c
+++ b/docs/examples/list_contacts/main.c
@@ -20,7 +20,31 @@
 
 GMainLoop *mainloop = NULL;
 
+void on_connection_status_changed(TpConnection *proxy,
+  guint arg_Status,
+  guint arg_Reason,
+  gpointer user_data,
+  GObject *weak_object)
+{
+  switch(arg_Status)
+    {
+      case TP_CONNECTION_STATUS_CONNECTED:
+        g_printf ("Connection status: Connected: reason=%d.\n", arg_Reason);
+        break;
 
+      case TP_CONNECTION_STATUS_CONNECTING:
+        g_printf ("Connection status: Connecting: reason=%d.\n", arg_Reason);
+        break;
+
+      case TP_CONNECTION_STATUS_DISCONNECTED:
+        g_printf ("Connection status: Disconnected: reason=%d.\n", arg_Reason);
+        break;
+
+      default:
+        g_printf ("Connection status: Unknown status.\n");
+        break;
+    }
+}
 
 int
 main (int argc, char **argv)
@@ -93,6 +117,23 @@ main (int argc, char **argv)
 
   g_printf("DEBUG: Connection created.\n");
 
+  /* React to connection status changes,
+   * including errors when we try to connect: */
+  TpProxySignalConnection* signal_connection = 
+    tp_cli_connection_connect_to_status_changed (connection,
+      &on_connection_status_changed,
+      NULL, /* user_data */
+      NULL, /* destroy_callback */
+      NULL, /* weak_object */
+      &error);
+
+  if (error)
+    {
+      g_printf ("tp_cli_connection_run_connect () failed: %s\n", error->message);
+      g_clear_error (&error);
+    }
+
+
   /* Connect the connection: */
   success = tp_cli_connection_run_connect (connection, -1, &error, NULL);
 
-- 
1.5.6.5



More information about the Telepathy-commits mailing list