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

Murray Cumming murrayc at murrayc.com
Mon Dec 15 08:11:16 PST 2008


* docs/examples/set_presence/main.c:
* docs/examples/list_contacts/main.c: Use the *_call_when_ready()
functions instead of *_run_until_ready().
---
 ChangeLog                          |    6 ++
 docs/examples/list_contacts/main.c |  152 +++++++++++++++++++-----------------
 docs/examples/set_presence/example |  Bin 14650 -> 14686 bytes
 docs/examples/set_presence/main.c  |   55 ++++++-------
 4 files changed, 112 insertions(+), 101 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 9013d7e..98d526a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 2008-12-15  Murray Cumming  <murrayc at murrayc.com>
 
+	* docs/examples/set_presence/main.c: 
+	* docs/examples/list_contacts/main.c: Use the *_call_when_ready() 
+	functions instead of *_run_until_ready().
+
+2008-12-15  Murray Cumming  <murrayc at murrayc.com>
+
 	* docs/examples/set_presence/main.c: Wait until the connection is 
 	ready, so that setting of the presence can succeed. 
 
diff --git a/docs/examples/list_contacts/main.c b/docs/examples/list_contacts/main.c
index ddc9e6a..81d1d36 100644
--- a/docs/examples/list_contacts/main.c
+++ b/docs/examples/list_contacts/main.c
@@ -27,6 +27,7 @@ GMainLoop *mainloop = NULL;
 TpDBusDaemon *bus_daemon = NULL;
 TpConnection *connection = NULL;
 guint contact_list_handle = 0;
+const TpIntSet* channel_members_set = NULL;
 
 void disconnect ()
 {
@@ -77,94 +78,33 @@ void on_connection_get_contacts_by_handle (TpConnection *connection,
   disconnect();
 }
 
-void on_connection_request_channel (TpConnection *proxy,
-  const gchar *channel_dbus_path,
+
+void on_connection_ready (TpConnection *connection,
   const GError *error,
-  gpointer user_data,
-  GObject *weak_object)
+  gpointer user_data)
 {
   if (error)
-    {
-      g_printf ("tp_cli_connection_run_request_channel() failed: %s\n", error->message);
-      return;
-    }
-
-  g_printf("DEBUG: channel D-Bus path received: %s\n", channel_dbus_path);
-
-
-  /* Create the channel proxy for the ContactList's Group interface: */
-  GError *error_inner = NULL;
-  TpChannel *channel = tp_channel_new (connection, 
-    channel_dbus_path, /* object_path */
-    TP_IFACE_CHANNEL_TYPE_CONTACT_LIST, /* optional_channel_type */
-    TP_HANDLE_TYPE_LIST, /* optional_handle_type */
-    contact_list_handle, /* optional_handle */
-    &error_inner);
-
-  if (error_inner)
-    {
-      g_printf ("tp_channel_new() failed: %s\n", error_inner->message);
-      g_clear_error (&error_inner);
-      return;
-    }
+  {
+    g_printf ("tp_connection_call_when_ready() failed: %s\n", error->message);
+     return;
+  }
 
-  /* Wait until the channel is ready for use: */
-  tp_channel_run_until_ready (channel, &error_inner, NULL);
-  if (error_inner)
-    {
-      g_printf ("tp_channel_run_until_ready() failed: %s\n", error_inner->message);
-      g_clear_error (&error_inner);
-      return;
-    }
-
-  if (!tp_channel_is_ready (channel))
-    g_printf ("tp_channel_is_ready() returned FALSE.\n");
+  /* Actually get the information now that the connection is ready: */
 
-  /* List the channel members: */
-  const TpIntSet* set = tp_channel_group_get_members (channel);
-  if (!set)
-    {
-      g_printf ("tp_channel_group_get_members() returned NULL.\n");
-      return;
-    }
-
-  g_printf("DEBUG: Number of members: %u\n", tp_intset_size (set));
 
   /* Get a GArray instead of a TpIntSet,
    * so we can easily create a normal array: */
   GArray *members_array = g_array_new (TRUE, TRUE, sizeof(guint));
-  TpIntSetIter iter = TP_INTSET_ITER_INIT  (set);
+  TpIntSetIter iter = TP_INTSET_ITER_INIT (channel_members_set );
   while (tp_intset_iter_next (&iter))
     {
       g_array_append_val (members_array, iter.element);
     }
-  set = NULL;  
+  channel_members_set = NULL; /* We don't need this anymore. */  
 
   g_printf("DEBUG: members_array size=%u\n", members_array->len);
 
 
-
-  /* tp_connection_get_contacts_by_handle() requires the connection to be 
-   * ready: */
-  gboolean ready = tp_connection_run_until_ready (connection, 
-    TRUE /* connect */, 
-    &error_inner,
-    NULL /* loop */);
-  
-  if (error_inner)
-    {
-      g_printf ("tp_connection_run_until_ready() failed: %s\n", error_inner->message);
-      g_clear_error (&error_inner);
-      return;
-    }
-
-  if (!ready)
-    {
-      g_printf ("Aborting because the connection could not be made ready.\n");
-    }
-
-  g_printf ("DEBUG: Calling tp_connection_get_contacts_by_handle()\n");
-
   /* Get information about each contact: */ 
   guint n_handles = members_array->len;
   TpHandle* handles = (TpHandle*)g_array_free (members_array, FALSE);
@@ -174,6 +114,8 @@ void on_connection_request_channel (TpConnection *proxy,
   TpContactFeature features[] = {TP_CONTACT_FEATURE_ALIAS, 
     TP_CONTACT_FEATURE_AVATAR_TOKEN, TP_CONTACT_FEATURE_PRESENCE};
 
+  g_printf ("DEBUG: Calling tp_connection_get_contacts_by_handle()\n");
+
   tp_connection_get_contacts_by_handle (connection,
     n_handles, handles,
     sizeof (features) / sizeof(TpContactFeature), features,
@@ -183,6 +125,72 @@ void on_connection_request_channel (TpConnection *proxy,
     NULL /* weak_object */);
 }
 
+void on_channel_ready (TpChannel *channel,
+  const GError *error,
+  gpointer user_data)
+{
+  if (error)
+  {
+    g_printf ("tp_channel_call_when_ready() failed: %s\n", error->message);
+    return;
+  }
+
+
+  /* List the channel members: */
+  channel_members_set = tp_channel_group_get_members (channel);
+  if (!channel_members_set )
+    {
+      g_printf ("tp_channel_group_get_members() returned NULL.\n");
+      return;
+    }
+
+  g_printf("DEBUG: Number of members: %u\n", tp_intset_size (channel_members_set ));
+
+ 
+  /* tp_connection_get_contacts_by_handle() requires the connection to be 
+   * ready: */
+  tp_connection_call_when_ready (connection, 
+    &on_connection_ready,
+    NULL);
+}
+
+void on_connection_request_channel (TpConnection *proxy,
+  const gchar *channel_dbus_path,
+  const GError *error,
+  gpointer user_data,
+  GObject *weak_object)
+{
+  if (error)
+    {
+      g_printf ("tp_cli_connection_call_request_channel() failed: %s\n", error->message);
+      return;
+    }
+
+  g_printf("DEBUG: channel D-Bus path received: %s\n", channel_dbus_path);
+
+
+  /* Create the channel proxy for the ContactList's Group interface: */
+  GError *error_inner = NULL;
+  TpChannel *channel = tp_channel_new (connection, 
+    channel_dbus_path, /* object_path */
+    TP_IFACE_CHANNEL_TYPE_CONTACT_LIST, /* optional_channel_type */
+    TP_HANDLE_TYPE_LIST, /* optional_handle_type */
+    contact_list_handle, /* optional_handle */
+    &error_inner);
+
+  if (error_inner)
+    {
+      g_printf ("tp_channel_new() failed: %s\n", error_inner->message);
+      g_clear_error (&error_inner);
+      return;
+    }
+
+  /* Wait until the channel is ready for use: */
+  tp_channel_call_when_ready (channel, 
+    &on_channel_ready,
+    NULL);
+}
+
 void on_connection_request_handles (TpConnection *proxy,
   const GArray *handles_array,
   const GError *error,
@@ -395,7 +403,7 @@ main (int argc, char **argv)
   g_hash_table_insert (parameters, "account", value);
 
   value = tp_g_value_slice_new (G_TYPE_STRING);
-  g_value_set_static_string (value, "passwordTODO");
+  g_value_set_static_string (value, "luftjabb");
   g_hash_table_insert (parameters, "password", value);
 
   /* This jabber-specific parameter can avoid clashes with 
diff --git a/docs/examples/set_presence/example b/docs/examples/set_presence/example
index 17e1350f2b3eeb22702b637dc1d2dd983554f08d..723291330dcd2cb9eedc9b00d20f9ca6b091eb55 100755
GIT binary patch
delta 3308
zcmZ`*eQZ<L6~FKKIXtIMV>=%XIN;bZkchT{l7!Jh8``)`Wi+ACk5Opw5|?BRPH?;d
zRj8+i3|u=S$;n!#GKtV?o7zwU?z*m`8qi9iQ->ha{@6+ at +I5my(#kNTQb_9l&hyJh
zE$vFbchB#fd(J)gzWd%i?*=~&_7+JseRH2R4%>wo?u-0ynOO*71#SoC0T!STC;@H*
zoB%fmpaQvcOmfgii&c6 at Dk{%{W)5HgOh696O#)n+Bt$-XnXIxSCmT|pt`)RWZlodk
zvh*?SH8|<8Y at s2;Yu3Z0s0zkdMXp$jFfsBePV1Hz6`ow!kkjvEAv)uI%D*IvWLf66
z1p at xYP)l2&q0!gc+OVtHA7}{reNB5PQ00!loi!%OD+Kjb7tpJ!T}CGFsZJ at 2K2}|l
zpj&EbSkbcOb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r~#Rxht%JcchN7P(#iM^$-AUS3jc?pYzk
zFXiZx?*&*0D>dnN86j9sf+r@!f)bo}Alyl2IPXhBusHT6+)mh78hev|hr(^jct0k=
zEynjTt=I2MPQgm4FzFXD?52pav|Uj)$>%F8m9ugH&zQVk=~8yeJC(0`{)Bj^VD3b`
zP59^WMqxJiPH?vzSXL1DG5?81<Mtg);coC>r11|^IPE_IXJOnkyp7#T)89+ui+L|I
zCgK!x0%AD^c%CK#%oDZzP>jX|o6`7Ra2~sT&~a*q!Ffnb`}e2W52W$a;Da*-2W;Z!
z81N$ibJ|6o_)VI_jWixj<BM<)oNg at mS#TaN93u~aw;J&sYMuy#A2YsvM?iIoHy8jF
zHRul6;vI6MF~Gw#zLZln8ui~u;{)J40JdW3xk6{b_svZ3PJAfEKEMEXQU=IP*d_;4
z9Jp=x&!?F~%o91>Mn<E3DR^pviZuOZaNZpD83lDD^{e$I`Yr|<rZ<I}E#62P==uma
uFTwd(dd}zqcva-(6&=c>|K~(7uKIzRJo%osR at PKU<riv>M*dUdSN{j9n7iKq

diff --git a/docs/examples/set_presence/main.c b/docs/examples/set_presence/main.c
index d53f318..6fddef0 100644
--- a/docs/examples/set_presence/main.c
+++ b/docs/examples/set_presence/main.c
@@ -85,6 +85,29 @@ void on_connection_set_presence(TpConnection *proxy,
 }
 
 
+void on_connection_ready (TpConnection *connection,
+  const GError *error,
+  gpointer user_data)
+{
+  if (error)
+  {
+    g_printf ("tp_connection_call_when_ready() failed: %s\n", error->message);
+     return;
+  }
+
+  /* Actually set the presence: */
+  /* See https://bugs.freedesktop.org/show_bug.cgi?id=19097 about the 
+   * difficulty of discovering valid status strings.
+   */
+  tp_cli_connection_interface_simple_presence_call_set_presence (
+    connection, 
+    -1, /* timeout */
+    "away",
+    "Gone fishing",
+    &on_connection_set_presence,
+    NULL, NULL, NULL);
+}
+
 void on_connection_status_changed(TpConnection *proxy,
   guint arg_Status,
   guint arg_Reason,
@@ -100,35 +123,9 @@ void on_connection_status_changed(TpConnection *proxy,
 
         /* tp_cli_connection_interface_simple_presence_call_set_presence() requires the connection to be 
          * ready: */
-        GError *error = NULL;
-        gboolean ready = tp_connection_run_until_ready (connection, 
-         TRUE /* connect */, 
-         &error,
-         NULL /* loop */);
-  
-        if (error)
-        {
-          g_printf ("tp_connection_run_until_ready() failed: %s\n", error->message);
-          g_clear_error (&error);
-          return;
-        }
-
-        if (!ready)
-        {
-          g_printf ("Aborting because the connection could not be made ready.\n");
-        }
-
-        /* Actually set the presence: */
-        /* See https://bugs.freedesktop.org/show_bug.cgi?id=19097 about the 
-         * difficulty of discovering valid status strings.
-         */
-        tp_cli_connection_interface_simple_presence_call_set_presence (
-          connection, 
-          -1, /* timeout */
-          "away",
-          "Gone fishing",
-          &on_connection_set_presence,
-          NULL, NULL, NULL);
+        tp_connection_call_when_ready (connection, 
+          &on_connection_ready,
+          NULL);
 
         break;
 
-- 
1.5.6.5



More information about the Telepathy-commits mailing list