diff options
author | Jonny Lamb <jonny.lamb@collabora.co.uk> | 2012-07-05 16:48:36 +0100 |
---|---|---|
committer | Jonny Lamb <jonny.lamb@collabora.co.uk> | 2012-07-05 16:52:44 +0100 |
commit | 43621978934824f2b6815ef5d5e20887d59bca28 (patch) | |
tree | 9fe9ffde9f03d5714814299afe71c5becb1300e8 | |
parent | c14d25b4bf471b7d9797e097d4318af4b9da001c (diff) |
base-protocol: add get_interfaces_array vfunc to class struct
This is a lot like 74bd945252, but we're having to deal with another
older get_interfaces vfunc, which is slightly annoying.
Signed-off-by: Jonny Lamb <jonny.lamb@collabora.co.uk>
-rw-r--r-- | docs/reference/telepathy-glib-sections.txt | 1 | ||||
-rw-r--r-- | telepathy-glib/base-protocol.c | 76 | ||||
-rw-r--r-- | telepathy-glib/base-protocol.h | 10 |
3 files changed, 79 insertions, 8 deletions
diff --git a/docs/reference/telepathy-glib-sections.txt b/docs/reference/telepathy-glib-sections.txt index 74f21bb2c..d225152cc 100644 --- a/docs/reference/telepathy-glib-sections.txt +++ b/docs/reference/telepathy-glib-sections.txt @@ -5943,6 +5943,7 @@ TpBaseProtocolIdentifyAccountFunc TpBaseProtocolGetInterfacesFunc TpBaseProtocolGetConnectionDetailsFunc TpBaseProtocolGetAvatarDetailsFunc +TpBaseProtocolGetInterfacesArrayFunc <SUBSECTION Standard> tp_base_protocol_get_type TP_BASE_PROTOCOL diff --git a/telepathy-glib/base-protocol.c b/telepathy-glib/base-protocol.c index 3732c5bda..6621bd65e 100644 --- a/telepathy-glib/base-protocol.c +++ b/telepathy-glib/base-protocol.c @@ -414,6 +414,37 @@ tp_cm_param_filter_string_nonempty (const TpCMParamSpec *paramspec, */ /** + * TpBaseProtocolGetInterfacesArrayFunc: + * @self: a #TpBaseProtocol + * + * Signature of an implementation of + * #TpBaseProtocolClass.get_interfaces_array virtual function. + * + * Implementation must first chainup on parent class implementation and then + * add extra interfaces into the #GPtrArray. + * + * |[ + * static GPtrArray * + * my_protocol_get_interfaces_array (TpBaseProtocol *self) + * { + * GPtrArray *interfaces; + * + * interfaces = TP_BASE_PROTOCOL_CLASS ( + * my_protocol_parent_class)->get_interfaces_array (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 + */ + +/** * TP_TYPE_PROTOCOL_ADDRESSING: * * Interface representing a #TpBaseProtocol that implements @@ -517,8 +548,10 @@ tp_cm_param_filter_string_nonempty (const TpCMParamSpec *paramspec, * and must either return a newly allocated string that represents the * "identity" of the parameters in @asv (usually the "account" parameter), * or %NULL with an error raised via @error - * @get_interfaces: a callback used to implement the Interfaces D-Bus property; - * it must return a newly allocated #GStrv containing D-Bus interface names + * @get_interfaces_array: a callback used to implement the Interfaces + * D-Bus property; The implementation must first chainup to parent + * class implementation and then add extra interfaces to the + * #GPtrArray. Replaces @get_interfaces * @get_connection_details: a callback used to implement the Protocol D-Bus * properties that represent details of the connections provided by this * protocol @@ -633,14 +666,17 @@ tp_base_protocol_constructed (GObject *object) TpBaseProtocolClass *cls = TP_BASE_PROTOCOL_GET_CLASS (self); void (*chain_up) (GObject *) = ((GObjectClass *) tp_base_protocol_parent_class)->constructed; + GPtrArray *ifaces; if (chain_up != NULL) chain_up (object); - if (cls->get_interfaces != NULL) - { - self->priv->interfaces = (cls->get_interfaces) (self); - } + /* TODO: when we don't have to deal with + * TpBaseProtocolClass.get_interfaces, we won't have to do any of this */ + ifaces = (cls->get_interfaces_array) (self); + g_ptr_array_add (ifaces, NULL); + self->priv->interfaces = g_strdupv ((GStrv) ifaces->pdata); + g_ptr_array_unref (ifaces); if (cls->get_connection_details != NULL) { @@ -1112,6 +1148,32 @@ protocol_properties_getter (GObject *object, } } +static GPtrArray * +tp_base_protocol_get_interfaces_array (TpBaseProtocol *self) +{ + TpBaseProtocolClass *klass = TP_BASE_PROTOCOL_GET_CLASS (self); + GPtrArray *interfaces = g_ptr_array_new (); + gchar **old_ifaces = NULL, **ptr; + + /* copy the klass->get_interfaces property value for backwards + * compatibility */ + if (klass->get_interfaces != NULL) + old_ifaces = klass->get_interfaces (self); + + for (ptr = old_ifaces; + ptr != NULL && *ptr != NULL; + ptr++) + { + g_ptr_array_add (interfaces, (char *) *ptr); + } + + /* TODO: old_ifaces is leaked because get_interfaces returns a new + * GStrv, but we want static strings nowadays. leaking is better + * than crashing though. this'll be fixed soon */ + + return interfaces; +} + static void tp_base_protocol_class_init (TpBaseProtocolClass *klass) { @@ -1178,6 +1240,8 @@ tp_base_protocol_class_init (TpBaseProtocolClass *klass) object_class->set_property = tp_base_protocol_set_property; object_class->finalize = tp_base_protocol_finalize; + klass->get_interfaces_array = tp_base_protocol_get_interfaces_array; + g_object_class_install_property (object_class, PROP_NAME, g_param_spec_string ("name", "Name of this protocol", diff --git a/telepathy-glib/base-protocol.h b/telepathy-glib/base-protocol.h index 6fd863c90..20fbf0ee2 100644 --- a/telepathy-glib/base-protocol.h +++ b/telepathy-glib/base-protocol.h @@ -139,6 +139,8 @@ typedef void (*TpBaseProtocolGetAvatarDetailsFunc) (TpBaseProtocol *self, guint *max_width, guint *max_bytes); +typedef GPtrArray * (*TpBaseProtocolGetInterfacesArrayFunc) (TpBaseProtocol *self); + struct _TpBaseProtocolClass { GObjectClass parent_class; @@ -157,7 +159,11 @@ struct _TpBaseProtocolClass GHashTable *asv, GError **error); - GStrv (*get_interfaces) (TpBaseProtocol *self); + /*<private>*/ + GStrv (*_TP_SEAL (get_interfaces)) (TpBaseProtocol *self); + /*<public>*/ + + TpBaseProtocolGetInterfacesArrayFunc get_interfaces_array; void (*get_connection_details) (TpBaseProtocol *self, GStrv *connection_interfaces, @@ -173,7 +179,7 @@ struct _TpBaseProtocolClass GStrv (*dup_authentication_types) (TpBaseProtocol *self); /*<private>*/ - GCallback padding[5]; + GCallback padding[4]; TpBaseProtocolClassPrivate *priv; }; |