[next] telepathy-glib: client-factory: track protocol features

Guillaume Desmottes gdesmott at kemper.freedesktop.org
Mon Mar 17 07:25:42 PDT 2014


Module: telepathy-glib
Branch: next
Commit: 0edd445a31ff9ef45eb10fe9f7b783463c8f8379
URL:    http://cgit.freedesktop.org/telepathy/telepathy-glib/commit/?id=0edd445a31ff9ef45eb10fe9f7b783463c8f8379

Author: Guillaume Desmottes <guillaume.desmottes at collabora.co.uk>
Date:   Thu Mar  6 17:17:13 2014 +0100

client-factory: track protocol features

---

 .../telepathy-glib/telepathy-glib-sections.txt     |    3 +
 telepathy-glib/client-factory.c                    |   97 ++++++++++++++++++++
 telepathy-glib/client-factory.h                    |   12 +++
 tests/dbus/protocol-objects.c                      |    9 ++
 4 files changed, 121 insertions(+)

diff --git a/docs/reference/telepathy-glib/telepathy-glib-sections.txt b/docs/reference/telepathy-glib/telepathy-glib-sections.txt
index 0e0dcce..5fa3052 100644
--- a/docs/reference/telepathy-glib/telepathy-glib-sections.txt
+++ b/docs/reference/telepathy-glib/telepathy-glib-sections.txt
@@ -5787,6 +5787,9 @@ tp_client_factory_add_contact_features
 tp_client_factory_add_contact_features_varargs
 <SUBSECTION>
 tp_client_factory_ensure_protocol
+tp_client_factory_dup_protocol_features
+tp_client_factory_add_protocol_features
+tp_client_factory_add_protocol_features_varargs
 <SUBSECTION Standard>
 TP_IS_CLIENT_FACTORY
 TP_IS_CLIENT_FACTORY_CLASS
diff --git a/telepathy-glib/client-factory.c b/telepathy-glib/client-factory.c
index f3e14a1..b703737 100644
--- a/telepathy-glib/client-factory.c
+++ b/telepathy-glib/client-factory.c
@@ -94,6 +94,7 @@
  * @dup_contact_features: implementation of tp_client_factory_dup_contact_features()
  * @create_protocol: create a #TpProtocol;
  *  see tp_client_factory_ensure_protocol()
+ * @dup_protocol_features: implementation of tp_client_factory_dup_protocol_features()
  *
  * The class structure for #TpClientFactory.
  *
@@ -143,6 +144,7 @@ struct _TpClientFactoryPrivate
   GArray *desired_connection_features;
   GArray *desired_channel_features;
   GArray *desired_contact_features;
+  GArray *desired_protocol_features;
 };
 
 enum
@@ -339,6 +341,7 @@ tp_client_factory_finalize (GObject *object)
   tp_clear_pointer (&self->priv->desired_connection_features, g_array_unref);
   tp_clear_pointer (&self->priv->desired_channel_features, g_array_unref);
   tp_clear_pointer (&self->priv->desired_contact_features, g_array_unref);
+  tp_clear_pointer (&self->priv->desired_protocol_features, g_array_unref);
 
   G_OBJECT_CLASS (tp_client_factory_parent_class)->finalize (object);
 }
@@ -372,6 +375,11 @@ tp_client_factory_init (TpClientFactory *self)
 
   self->priv->desired_contact_features = g_array_new (TRUE, FALSE,
       sizeof (GQuark));
+
+  self->priv->desired_protocol_features = g_array_new (TRUE, FALSE,
+      sizeof (GQuark));
+  feature = TP_PROTOCOL_FEATURE_CORE;
+  g_array_append_val (self->priv->desired_protocol_features, feature);
 }
 
 static TpProtocol *
@@ -385,6 +393,14 @@ create_protocol_impl (TpClientFactory *self,
       immutable_properties, error);
 }
 
+static GArray *
+dup_protocol_features_impl (TpClientFactory *self,
+    TpProtocol *protocol)
+{
+  return _tp_quark_array_copy (
+      (GQuark *) self->priv->desired_protocol_features->data);
+}
+
 static void
 tp_client_factory_class_init (TpClientFactoryClass *klass)
 {
@@ -407,6 +423,7 @@ tp_client_factory_class_init (TpClientFactoryClass *klass)
   klass->create_contact = create_contact_impl;
   klass->dup_contact_features = dup_contact_features_impl;
   klass->create_protocol = create_protocol_impl;
+  klass->dup_protocol_features = dup_protocol_features_impl;
 
   /**
    * TpClientFactory:dbus-daemon:
@@ -1370,3 +1387,83 @@ tp_client_factory_ensure_protocol (TpClientFactory *self,
 
   return protocol;
 }
+
+/**
+ * tp_client_factory_dup_protocol_features:
+ * @self: a #TpClientFactory object
+ * @protocol: a #TpProtocol
+ *
+ * Return a zero-terminated #GArray containing the #TpProtocol features that
+ * should be prepared on @protocol.
+ *
+ * Returns: (transfer full) (element-type GLib.Quark): a newly allocated
+ *  #GArray
+ *
+ * Since: UNRELEASED
+ */
+GArray *
+tp_client_factory_dup_protocol_features (TpClientFactory *self,
+    TpProtocol *protocol)
+{
+  g_return_val_if_fail (TP_IS_CLIENT_FACTORY (self), NULL);
+  g_return_val_if_fail (TP_IS_PROTOCOL (protocol), NULL);
+
+  return TP_CLIENT_FACTORY_GET_CLASS (self)->dup_protocol_features (
+      self, protocol);
+}
+
+/**
+ * tp_client_factory_add_protocol_features:
+ * @self: a #TpClientFactory object
+ * @features: (transfer none) (array zero-terminated=1) (allow-none): an array
+ *  of desired features, ending with 0; %NULL is equivalent to an array
+ *  containing only 0
+ *
+ * Add @features to the desired features to be prepared on #TpProtocol
+ * objects. Those features will be added to the features already returned be
+ * tp_client_factory_dup_protocol_features().
+ *
+ * It is not necessary to add %TP_PROTOCOL_FEATURE_CORE as it is already
+ * included by default.
+ *
+ * Note that these features will not be added to existing #TpProtocol
+ * objects; the user must call tp_proxy_prepare_async() themself.
+ *
+ * Since: UNRELEASED
+ */
+void
+tp_client_factory_add_protocol_features (
+    TpClientFactory *self,
+    const GQuark *features)
+{
+  g_return_if_fail (TP_IS_CLIENT_FACTORY (self));
+
+  _tp_quark_array_merge (self->priv->desired_protocol_features, features, -1);
+}
+
+/**
+ * tp_client_factory_add_protocol_features_varargs: (skip)
+ * @self: a #TpClientFactory
+ * @feature: the first feature
+ * @...: the second and subsequent features, if any, ending with 0
+ *
+ * The same as tp_client_factory_add_protocol_features(), but with a
+ * more convenient calling convention from C.
+ *
+ * Since: UNRELEASED
+ */
+void
+tp_client_factory_add_protocol_features_varargs (
+    TpClientFactory *self,
+    GQuark feature,
+    ...)
+{
+  va_list var_args;
+
+  g_return_if_fail (TP_IS_CLIENT_FACTORY (self));
+
+  va_start (var_args, feature);
+  _tp_quark_array_merge_valist (self->priv->desired_protocol_features,
+      feature, var_args);
+  va_end (var_args);
+}
diff --git a/telepathy-glib/client-factory.h b/telepathy-glib/client-factory.h
index 76efb8f..8051ba1 100644
--- a/telepathy-glib/client-factory.h
+++ b/telepathy-glib/client-factory.h
@@ -83,6 +83,8 @@ struct _TpClientFactoryClass {
         const gchar *protocol_name,
         GVariant *immutable_properties,
         GError **error);
+    GArray * (*dup_protocol_features) (TpClientFactory *self,
+        TpProtocol *protocol);
 
     /*<private>*/
     GCallback padding[20];
@@ -198,6 +200,16 @@ TpProtocol *tp_client_factory_ensure_protocol (TpClientFactory *self,
     const gchar *protocol_name,
     GVariant *immutable_properties,
     GError **error);
+_TP_AVAILABLE_IN_UNRELEASED
+GArray *tp_client_factory_dup_protocol_features (TpClientFactory *self,
+    TpProtocol *protocol);
+_TP_AVAILABLE_IN_UNRELEASED
+void tp_client_factory_add_protocol_features (TpClientFactory *self,
+    const GQuark *features);
+_TP_AVAILABLE_IN_UNRELEASED
+void tp_client_factory_add_protocol_features_varargs (TpClientFactory *self,
+    GQuark feature,
+    ...);
 
 G_END_DECLS
 
diff --git a/tests/dbus/protocol-objects.c b/tests/dbus/protocol-objects.c
index 139f7d5..68da80c 100644
--- a/tests/dbus/protocol-objects.c
+++ b/tests/dbus/protocol-objects.c
@@ -620,6 +620,7 @@ test_factory (Test *test,
     gconstpointer data G_GNUC_UNUSED)
 {
   TpProtocol *p1, *p2, *p3;
+  GArray *arr;
 
   p1 = tp_client_factory_ensure_protocol (test->factory,
       "example_echo_2", "example", NULL, NULL);
@@ -638,6 +639,14 @@ test_factory (Test *test,
   /* the object has been removed from the cache */
   g_assert (p3 != p1);
 
+  arr = tp_client_factory_dup_protocol_features (test->factory,
+      p3);
+  g_assert (arr != NULL);
+  g_assert_cmpuint (arr->len, ==, 1);
+  g_assert_cmpuint (g_array_index (arr, guint, 0), ==,
+      TP_PROTOCOL_FEATURE_CORE);
+  g_array_unref (arr);
+
   g_object_unref (p3);
 }
 



More information about the telepathy-commits mailing list