summaryrefslogtreecommitdiff
path: root/telepathy-glib/base-channel.c
diff options
context:
space:
mode:
authorDanielle Madeley <danielle.madeley@collabora.co.uk>2012-01-19 12:50:12 +1100
committerXavier Claessens <xavier.claessens@collabora.co.uk>2012-01-20 16:37:37 +0100
commit74bd9452523bef1280a708eb31f08b91971bdb1e (patch)
treed46d9360f6f707491b1e723034f48f06afc48087 /telepathy-glib/base-channel.c
parent139a0f63b6d832ddbff78fb507e1f21ff36680be (diff)
downloadtelepathy-glib-74bd9452523bef1280a708eb31f08b91971bdb1e.tar.gz
base-channel: deprecate interfaces class property for get_interfaces() method
With the interfaces class property, programmers writing a concrete class could not chain-up to inherit the interfaces implemented by the base class. Using a get_interfaces() class method, the programmer can simply add the interfaces she is implementing to those of the base class. Furthermore, classes that only implement an interface in specific instances required a subclass that had to be instantiated by the manager. This is no longer required. For backwards compatibility, the base get_interfaces() method returns the value of the interfaces class property.
Diffstat (limited to 'telepathy-glib/base-channel.c')
-rw-r--r--telepathy-glib/base-channel.c79
1 files changed, 71 insertions, 8 deletions
diff --git a/telepathy-glib/base-channel.c b/telepathy-glib/base-channel.c
index 43c173406..9929d0912 100644
--- a/telepathy-glib/base-channel.c
+++ b/telepathy-glib/base-channel.c
@@ -29,9 +29,10 @@
* implementations by implementing some of its properties, and defining other
* relevant properties.
*
- * Subclasses should fill in #TpBaseChannelClass.channel_type,
- * #TpBaseChannelClass.target_handle_type and #TpBaseChannelClass.interfaces,
- * and implement the #TpBaseChannelClass.close virtual function.
+ * Subclasses should fill in #TpBaseChannelClass.channel_type and
+ * #TpBaseChannelClass.target_handle_type; and implement the
+ * #TpBaseChannelClass.get_interfaces and
+ * #TpBaseChannelClass.close virtual functions.
*
* If the channel type and/or interfaces being implemented define immutable
* D-Bus properties besides those on the Channel interface, the subclass should
@@ -60,8 +61,7 @@
* (e.g. #TP_IFACE_CHANNEL_TYPE_TEXT)
* @target_handle_type: The type of handle that is the target of channels of
* this type
- * @interfaces: Extra interfaces provided by this channel (this SHOULD NOT
- * include the channel type and interface itself)
+ * @interfaces: Deprecated. Replaced by @get_interfaces.
* @close: A virtual function called to close the channel, which will be called
* by tp_base_channel_close() and by the implementation of the Closed D-Bus
* method.
@@ -75,6 +75,10 @@
* #TpExportableChannel:object-path property is not set. The default
* implementation simply generates a unique path based on the object's address
* in memory. The returned string will be freed automatically.
+ * @get_interfaces: Extra interfaces provided by this channel (this SHOULD NOT
+ * include the channel type and interface itself). Implementation must first
+ * chainup on parent class implementation and then add extra interfaces into
+ * the #GPtrArray. Replaces @interfaces.
*
* The class structure for #TpBaseChannel
*
@@ -199,6 +203,36 @@
* Since: 0.11.14
*/
+/**
+ * TpBaseChannelGetInterfacesFunc:
+ * @chan: a channel
+ *
+ * Signature of an implementation of #TpBaseChannelClass.get_interfaces virtual
+ * function.
+ *
+ * Implementation must first chainup on parent class implementation and then
+ * add extra interfaces into the #GPtrArray.
+ *
+ * |[
+ * static GPtrArray *
+ * my_channel_get_interfaces (TpBaseChannel *self)
+ * {
+ * GPtrArray *interfaces;
+ *
+ * interfaces = TP_BASE_CHANNEL_CLASS (my_channel_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: UNRELEASED
+ */
+
#include "config.h"
#include "base-channel.h"
@@ -559,6 +593,23 @@ tp_base_channel_get_basic_object_path_suffix (TpBaseChannel *self)
return escaped;
}
+static GPtrArray *
+tp_base_channel_get_basic_interfaces (TpBaseChannel *self)
+{
+ GPtrArray *interfaces = g_ptr_array_new ();
+ const char **ptr;
+
+ /* copy the klass->interfaces property for backwards compatibility */
+ for (ptr = TP_BASE_CHANNEL_GET_CLASS (self)->interfaces;
+ ptr != NULL && *ptr != NULL;
+ ptr++)
+ {
+ g_ptr_array_add (interfaces, (char *) *ptr);
+ }
+
+ return interfaces;
+}
+
static void
tp_base_channel_init (TpBaseChannel *self)
{
@@ -671,8 +722,14 @@ tp_base_channel_get_property (GObject *object,
g_value_set_object (value, chan->priv->conn);
break;
case PROP_INTERFACES:
- g_value_set_boxed (value, klass->interfaces);
- break;
+ {
+ GPtrArray *interfaces = klass->get_interfaces (chan);
+
+ g_ptr_array_add (interfaces, NULL);
+ g_value_set_boxed (value, interfaces->pdata);
+ g_ptr_array_unref (interfaces);
+ break;
+ }
case PROP_CHANNEL_DESTROYED:
g_value_set_boolean (value, chan->priv->destroyed);
break;
@@ -878,6 +935,8 @@ tp_base_channel_class_init (TpBaseChannelClass *tp_base_channel_class)
tp_base_channel_fill_basic_immutable_properties;
tp_base_channel_class->get_object_path_suffix =
tp_base_channel_get_basic_object_path_suffix;
+ tp_base_channel_class->get_interfaces =
+ tp_base_channel_get_basic_interfaces;
}
static void
@@ -906,8 +965,12 @@ tp_base_channel_get_interfaces (TpSvcChannel *iface,
{
TpBaseChannel *chan = TP_BASE_CHANNEL (iface);
TpBaseChannelClass *klass = TP_BASE_CHANNEL_GET_CLASS (chan);
+ GPtrArray *interfaces = klass->get_interfaces (chan);
- tp_svc_channel_return_from_get_interfaces (context, klass->interfaces);
+ g_ptr_array_add (interfaces, NULL);
+ tp_svc_channel_return_from_get_interfaces (context,
+ (const char **) interfaces->pdata);
+ g_ptr_array_unref (interfaces);
}
static void