[Telepathy-commits] [telepathy-glib/master] BaseConnection: add a channel manager iterator

Will Thompson will.thompson at collabora.co.uk
Fri Sep 12 04:12:01 PDT 2008


---
 docs/reference/telepathy-glib-sections.txt |    4 ++
 telepathy-glib/base-connection.c           |   64 ++++++++++++++++++++++++++++
 telepathy-glib/base-connection.h           |   26 +++++++++++
 3 files changed, 94 insertions(+), 0 deletions(-)

diff --git a/docs/reference/telepathy-glib-sections.txt b/docs/reference/telepathy-glib-sections.txt
index 89e5ddc..0ebd19d 100644
--- a/docs/reference/telepathy-glib-sections.txt
+++ b/docs/reference/telepathy-glib-sections.txt
@@ -47,6 +47,10 @@ tp_base_connection_add_interfaces
 tp_base_connection_dbus_request_handles
 TP_BASE_CONNECTION_ERROR_IF_NOT_CONNECTED
 tp_base_connection_register_with_contacts_mixin
+<SUBSECTION>
+TpChannelManagerIter
+tp_base_connection_channel_manager_iter_init
+tp_base_connection_channel_manager_iter_next
 <SUBSECTION Standard>
 TP_BASE_CONNECTION
 TP_IS_BASE_CONNECTION
diff --git a/telepathy-glib/base-connection.c b/telepathy-glib/base-connection.c
index 03ea59d..f597c08 100644
--- a/telepathy-glib/base-connection.c
+++ b/telepathy-glib/base-connection.c
@@ -2725,6 +2725,70 @@ requests_iface_init (gpointer g_iface,
 }
 
 
+/**
+ * tp_base_connection_channel_manager_iter_init:
+ * @iter: an uninitialized #TpChannelManagerIter
+ * @self: a connection
+ *
+ * Initializes an iterator over the #TpChannelManager objects known to
+ * @self.  It is intended to be used as followed:
+ *
+ * <informalexample><programlisting>
+ * TpChannelManagerIter iter;
+ * TpChannelManager manager;
+ *
+ * tp_base_connection_channel_manager_iter_init (&iter, base_conn);
+ * while (tp_base_connection_channel_manager_iter_next (&iter, &manager))
+ *   {
+ *     ...do something with manager...
+ *   }
+ * </programlisting></informalexample>
+ */
+void
+tp_base_connection_channel_manager_iter_init (TpChannelManagerIter *iter,
+                                              TpBaseConnection *self)
+{
+  iter->self = self;
+  iter->index = 0;
+}
+
+
+/**
+ * tp_base_connection_channel_manager_iter_next:
+ * @iter: an initialized #TpChannelManagerIter
+ * @manager_out: a location to store the channel manager, or %NULL.
+ *
+ * Advances @iter, and retrieves the #TpChannelManager it now points to.  If
+ * there are no more channel managers, @manager_out is not set and %FALSE is
+ * returned.
+ *
+ * Returns: %FALSE if there are no more channel managers; else %TRUE.
+ */
+gboolean
+tp_base_connection_channel_manager_iter_next (TpChannelManagerIter *iter,
+                                              TpChannelManager **manager_out)
+{
+  TpBaseConnectionPrivate *priv;
+
+  /* Check the caller initialized the iterator properly. */
+  g_assert (TP_IS_BASE_CONNECTION (iter->self));
+
+  priv = TP_BASE_CONNECTION_GET_PRIVATE (iter->self);
+
+  /* Be noisy if something's gone really wrong */
+  g_return_val_if_fail (iter->index <= priv->channel_managers->len, FALSE);
+
+  if (iter->index == priv->channel_managers->len)
+    return FALSE;
+
+  if (manager_out != NULL)
+    *manager_out = TP_CHANNEL_MANAGER (
+        g_ptr_array_index (priv->channel_managers, iter->index));
+  iter->index++;
+  return TRUE;
+}
+
+
 static void
 tp_base_connection_fill_contact_attributes (GObject *obj,
   const GArray *contacts, GHashTable *attributes_hash)
diff --git a/telepathy-glib/base-connection.h b/telepathy-glib/base-connection.h
index d1ad10a..68e8e47 100644
--- a/telepathy-glib/base-connection.h
+++ b/telepathy-glib/base-connection.h
@@ -25,6 +25,7 @@
 #include <dbus/dbus-glib.h>
 #include <glib-object.h>
 
+#include <telepathy-glib/channel-manager.h>
 #include <telepathy-glib/defs.h>
 #include <telepathy-glib/enums.h>
 #include <telepathy-glib/handle-repo.h>
@@ -295,6 +296,31 @@ void tp_base_connection_dbus_request_handles (TpSvcConnection *iface,
 
 void tp_base_connection_register_with_contacts_mixin (TpBaseConnection *self);
 
+
+typedef struct _TpChannelManagerIter TpChannelManagerIter;
+
+/**
+ * TpChannelManagerIter:
+ * @see_also: tp_base_connection_channel_manager_iter_init(),
+ *            tp_base_connection_channel_manager_iter_next()
+ *
+ * An iterator over the #TpChannelManager objects known to a #TpBaseConnection.
+ * It has no public fields.
+ */
+struct _TpChannelManagerIter {
+    /*<private>*/
+    TpBaseConnection *self;
+    guint index;
+    gpointer _future[2];
+};
+
+void tp_base_connection_channel_manager_iter_init (TpChannelManagerIter *iter,
+    TpBaseConnection *self);
+
+gboolean tp_base_connection_channel_manager_iter_next (
+    TpChannelManagerIter *iter, TpChannelManager **manager_out);
+
+
 /* TYPE MACROS */
 #define TP_TYPE_BASE_CONNECTION \
   (tp_base_connection_get_type ())
-- 
1.5.6.5




More information about the Telepathy-commits mailing list