telepathy-glib: base-connection-manager: add get_interfaces vfunc to class struct

Jonny Lamb jonny at kemper.freedesktop.org
Fri Jul 6 09:09:34 PDT 2012


Module: telepathy-glib
Branch: master
Commit: 19fd0c69ae3d557f9ed430ecced67701ec6a8c9f
URL:    http://cgit.freedesktop.org/telepathy/telepathy-glib/commit/?id=19fd0c69ae3d557f9ed430ecced67701ec6a8c9f

Author: Jonny Lamb <jonny.lamb at collabora.co.uk>
Date:   Wed Jul  4 17:57:38 2012 +0100

base-connection-manager: add get_interfaces vfunc to class struct

This is a lot like 74bd945252.

Signed-off-by: Jonny Lamb <jonny.lamb at collabora.co.uk>

---

 docs/reference/telepathy-glib-sections.txt |    1 +
 telepathy-glib/base-connection-manager.c   |   71 ++++++++++++++++++++++++++--
 telepathy-glib/base-connection-manager.h   |    5 ++-
 tests/dbus/protocol-objects.c              |    8 ++-
 tests/lib/echo-cm.c                        |   14 ++++++
 5 files changed, 92 insertions(+), 7 deletions(-)

diff --git a/docs/reference/telepathy-glib-sections.txt b/docs/reference/telepathy-glib-sections.txt
index 75fa607..95bd49c 100644
--- a/docs/reference/telepathy-glib-sections.txt
+++ b/docs/reference/telepathy-glib-sections.txt
@@ -112,6 +112,7 @@ TpCMProtocolSpec
 TpBaseConnectionManager
 TpBaseConnectionManagerClass
 TpBaseConnectionManagerNewConnFunc
+TpBaseConnectionManagerGetInterfacesFunc
 tp_base_connection_manager_get_dbus_daemon
 tp_base_connection_manager_register
 tp_base_connection_manager_add_protocol
diff --git a/telepathy-glib/base-connection-manager.c b/telepathy-glib/base-connection-manager.c
index 5386f93..abec982 100644
--- a/telepathy-glib/base-connection-manager.c
+++ b/telepathy-glib/base-connection-manager.c
@@ -214,9 +214,14 @@ _tp_legacy_protocol_new (TpBaseConnectionManager *cm,
  *  whose name member is %NULL; or %NULL if this CM uses Protocol objects.
  * @new_connection: A #TpBaseConnectionManagerNewConnFunc used to construct
  *  new connections, or %NULL if this CM uses Protocol objects.
- * @interfaces: A #GStrv of extra D-Bus interfaces implemented
- *  by instances of this class, which may be filled in by subclasses. The
- *  default is to list no additional interfaces. Since: 0.11.11
+ * @interfaces: deprecated since 0.UNRELEASED; implement @get_interfaces
+ *  instead.
+ * @get_interfaces: Returns a #GPtrArray of static strings of extra
+ *  D-Bus interfaces implemented by instances of this class, which may be
+ *  filled in by subclasses. The default is to list no additional interfaces.
+ *  Implementations must first chainup on parent class implementation and then
+ *  add extra interfaces to the #GPtrArray. Replaces @interfaces. Since:
+ *  0.UNRELEASED
  *
  * The class structure for #TpBaseConnectionManager.
  *
@@ -255,6 +260,37 @@ _tp_legacy_protocol_new (TpBaseConnectionManager *cm,
  * Returns: the new connection object, or %NULL on error.
  */
 
+/**
+ * TpBaseConnectionManagerGetInterfacesFunc:
+ * @self: a #TpBaseConnectionManager
+ *
+ * Signature of an implementation of
+ * #TpBaseConnectionManagerClass.get_interfaces virtual function.
+ *
+ * Implementation must first chainup on parent class implementation and then
+ * add extra interfaces into the #GPtrArray.
+ *
+ * |[
+ * static GPtrArray *
+ * my_connection_manager_get_interfaces (TpBaseConnectionManager *self)
+ * {
+ *   GPtrArray *interfaces;
+ *
+ *   interfaces = TP_BASE_CONNECTION_MANAGER_CLASS (
+ *       my_connection_manager_parent_class)->get_interfaces (self);
+ *
+ *   g_ptr_array_add (interfaces, TP_IFACE_BADGERS);
+ *
+ *   return interfaces;
+ * }
+ * ]|
+ *
+ * Returns: (transfer container): a #GPtrArray of static strings for D-Bus
+ *   interfaces implemented by this client.
+ *
+ * Since: 0.UNRELEASED
+ */
+
 static void service_iface_init (gpointer, gpointer);
 
 G_DEFINE_ABSTRACT_TYPE_WITH_CODE(TpBaseConnectionManager,
@@ -396,7 +432,15 @@ tp_base_connection_manager_get_property (GObject *object,
       break;
 
     case PROP_INTERFACES:
-      g_value_set_boxed (value, cls->interfaces);
+      {
+        GPtrArray *interfaces = cls->get_interfaces (self);
+
+        /* make sure there's a terminating NULL */
+        g_ptr_array_add (interfaces, NULL);
+        g_value_set_boxed (value, interfaces->pdata);
+
+        g_ptr_array_unref (interfaces);
+      }
       break;
 
     case PROP_PROTOCOLS:
@@ -456,6 +500,23 @@ tp_base_connection_manager_set_property (GObject *object,
   }
 }
 
+static GPtrArray *
+tp_base_connection_manager_get_interfaces (TpBaseConnectionManager *self)
+{
+  GPtrArray *interfaces = g_ptr_array_new ();
+  const char * const *ptr;
+
+  /* copy the klass->interfaces property for backwards compatibility */
+  for (ptr = TP_BASE_CONNECTION_MANAGER_GET_CLASS (self)->interfaces;
+       ptr != NULL && *ptr != NULL;
+       ptr++)
+    {
+      g_ptr_array_add (interfaces, (char *) *ptr);
+    }
+
+  return interfaces;
+}
+
 static void
 tp_base_connection_manager_class_init (TpBaseConnectionManagerClass *klass)
 {
@@ -473,6 +534,8 @@ tp_base_connection_manager_class_init (TpBaseConnectionManagerClass *klass)
   object_class->dispose = tp_base_connection_manager_dispose;
   object_class->finalize = tp_base_connection_manager_finalize;
 
+  klass->get_interfaces = tp_base_connection_manager_get_interfaces;
+
   /**
    * TpBaseConnectionManager:dbus-daemon:
    *
diff --git a/telepathy-glib/base-connection-manager.h b/telepathy-glib/base-connection-manager.h
index 6658c69..9df0db9 100644
--- a/telepathy-glib/base-connection-manager.h
+++ b/telepathy-glib/base-connection-manager.h
@@ -63,6 +63,9 @@ typedef TpBaseConnection *(*TpBaseConnectionManagerNewConnFunc)(
     TpBaseConnectionManager *self, const gchar *proto,
     TpIntset *params_present, void *parsed_params, GError **error);
 
+typedef GPtrArray * (*TpBaseConnectionManagerGetInterfacesFunc) (
+    TpBaseConnectionManager *self);
+
 struct _TpBaseConnectionManagerClass {
     GObjectClass parent_class;
 
@@ -71,9 +74,9 @@ struct _TpBaseConnectionManagerClass {
     TpBaseConnectionManagerNewConnFunc _TP_SEAL (new_connection);
 
     const gchar * const *interfaces;
+    TpBaseConnectionManagerGetInterfacesFunc get_interfaces;
 
     /*<private>*/
-    gpointer _future2;
     gpointer _future3;
     gpointer _future4;
 
diff --git a/tests/dbus/protocol-objects.c b/tests/dbus/protocol-objects.c
index 1645751..dcaea52 100644
--- a/tests/dbus/protocol-objects.c
+++ b/tests/dbus/protocol-objects.c
@@ -119,6 +119,10 @@ const gchar * const expected_protocol_interfaces[] = {
     TP_IFACE_PROTOCOL_INTERFACE_ADDRESSING,
     NULL };
 
+const gchar * const expected_cm_interfaces[] = {
+    "im.telepathy.Tests.Example",
+    NULL };
+
 const gchar * const expected_supported_avatar_mime_types[] = {
   "image/png",
   "image/jpeg",
@@ -333,8 +337,8 @@ test_protocols_property_old (Test *test,
   g_assert_no_error (test->error);
 
   g_assert (tp_asv_lookup (properties, "Interfaces") != NULL);
-  test_assert_empty_strv (tp_asv_get_boxed (properties, "Interfaces",
-        G_TYPE_STRV));
+  tp_tests_assert_strv_equals (tp_asv_get_boxed (properties,
+          "Interfaces", G_TYPE_STRV), expected_cm_interfaces);
 
   protocols = tp_asv_get_boxed (properties, "Protocols",
       TP_HASH_TYPE_PROTOCOL_PROPERTIES_MAP);
diff --git a/tests/lib/echo-cm.c b/tests/lib/echo-cm.c
index ed18e6b..300a0ad 100644
--- a/tests/lib/echo-cm.c
+++ b/tests/lib/echo-cm.c
@@ -85,6 +85,19 @@ new_connection (TpBaseConnectionManager *self,
   return (TpBaseConnection *) conn;
 }
 
+static GPtrArray *
+get_interfaces (TpBaseConnectionManager *self)
+{
+  GPtrArray *interfaces;
+
+  interfaces = TP_BASE_CONNECTION_MANAGER_CLASS (
+      tp_tests_echo_connection_manager_parent_class)->get_interfaces (self);
+
+  g_ptr_array_add (interfaces, "im.telepathy.Tests.Example");
+
+  return interfaces;
+}
+
 static void
 tp_tests_echo_connection_manager_class_init (
     TpTestsEchoConnectionManagerClass *klass)
@@ -95,4 +108,5 @@ tp_tests_echo_connection_manager_class_init (
   base_class->new_connection = new_connection;
   base_class->cm_dbus_name = "example_echo";
   base_class->protocol_params = example_protocols;
+  base_class->get_interfaces = get_interfaces;
 }



More information about the telepathy-commits mailing list