From 19fd0c69ae3d557f9ed430ecced67701ec6a8c9f Mon Sep 17 00:00:00 2001 From: Jonny Lamb Date: Wed, 4 Jul 2012 17:57:38 +0100 Subject: base-connection-manager: add get_interfaces vfunc to class struct This is a lot like 74bd945252. Signed-off-by: Jonny Lamb --- 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 75fa60718..95bd49ccd 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 5386f9306..abec982a6 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 6658c6924..9df0db950 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; /**/ - gpointer _future2; gpointer _future3; gpointer _future4; diff --git a/tests/dbus/protocol-objects.c b/tests/dbus/protocol-objects.c index 1645751d5..dcaea52f2 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 ed18e6b01..300a0adc0 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; } -- cgit v1.2.1 From 245d48040d0b52aab05b57c7c859b4118b0af776 Mon Sep 17 00:00:00 2001 From: Jonny Lamb Date: Wed, 4 Jul 2012 17:58:16 +0100 Subject: base-room-config: fix old comment referring to TpBaseChannelClass.interfaces Signed-off-by: Jonny Lamb --- telepathy-glib/base-room-config.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/telepathy-glib/base-room-config.c b/telepathy-glib/base-room-config.c index 8d40e727e..d37e62d6b 100644 --- a/telepathy-glib/base-room-config.c +++ b/telepathy-glib/base-room-config.c @@ -71,8 +71,8 @@ * ]| * * - * include %TP_IFACE_CHANNEL_INTERFACE_ROOM_CONFIG in - * #TpBaseChannelClass.interfaces. + * include %TP_IFACE_CHANNEL_INTERFACE_ROOM_CONFIG in the return of + * #TpBaseChannelClass.get_interfaces. * * * -- cgit v1.2.1 From bcde9c87323454f946be989825b2dc74f61d16f7 Mon Sep 17 00:00:00 2001 From: Jonny Lamb Date: Thu, 5 Jul 2012 15:04:00 +0100 Subject: =?UTF-8?q?base-connection:=20add=20get=5Finterfaces=E2=80=A6=20vf?= =?UTF-8?q?unc=20to=20class=20struct?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is a lot like 74bd945252. Signed-off-by: Jonny Lamb --- docs/reference/telepathy-glib-sections.txt | 1 + telepathy-glib/base-connection.c | 152 ++++++++++++++++++----------- telepathy-glib/base-connection.h | 4 + telepathy-glib/base-contact-list.c | 7 +- 4 files changed, 104 insertions(+), 60 deletions(-) diff --git a/docs/reference/telepathy-glib-sections.txt b/docs/reference/telepathy-glib-sections.txt index 95bd49ccd..74f21bb2c 100644 --- a/docs/reference/telepathy-glib-sections.txt +++ b/docs/reference/telepathy-glib-sections.txt @@ -61,6 +61,7 @@ TpBaseConnectionCreateChannelFactoriesImpl TpBaseConnectionCreateChannelManagersImpl TpBaseConnectionCreateHandleReposImpl TpBaseConnectionGetUniqueConnectionNameImpl +TpBaseConnectionGetInterfacesImpl TpBaseConnectionProc TpBaseConnectionStartConnectingImpl tp_base_connection_get_bus_name diff --git a/telepathy-glib/base-connection.c b/telepathy-glib/base-connection.c index f8b6137b5..28b95b01c 100644 --- a/telepathy-glib/base-connection.c +++ b/telepathy-glib/base-connection.c @@ -121,6 +121,38 @@ * free with #g_free. */ +/** + * TpBaseChannelGetInterfacesImpl: + * @chan: a channel + * + * Signature of an implementation of + * #TpBaseConnectionClass.get_interfaces_always_present virtual + * function. + * + * Implementation must first chainup on parent class implementation and then + * add extra interfaces into the #GPtrArray. + * + * |[ + * static GPtrArray * + * my_channel_get_interfaces_always_present (TpBaseConnection *self) + * { + * GPtrArray *interfaces; + * + * interfaces = TP_BASE_CONNECTION_CLASS ( + * my_connection_parent_class)->get_interfaces_always_present (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 + */ + /** * TpBaseConnectionClass: * @parent_class: The superclass' structure @@ -151,12 +183,14 @@ * @start_connecting: Asynchronously start connecting - called to implement * the Connect D-Bus method. See #TpBaseConnectionStartConnectingImpl for * details. May not be left as %NULL. - * @interfaces_always_present: A strv of extra D-Bus interfaces which are - * always implemented by instances of this class, which may be filled in - * by subclasses. The default is to list no additional interfaces. - * Individual instances may detect which additional interfaces they support - * and signal them before going to state CONNECTED by calling - * tp_base_connection_add_interfaces(). + * @interfaces_always_present: deprecated since 0.UNRELEASED: implement + * @get_interfaces_always_present instead. + * @get_interfaces_always_present: Returns a #GPtrArray of extra D-Bus + * interfaces which are always implemented by instances of this class, + * which may be filled in by subclasses. The default is to list no + * additional interfaces. Individual instances may detect which + * additional interfaces they support and signal them before going + * to state CONNECTED by calling tp_base_connection_add_interfaces(). * @create_channel_managers: Create an array of channel managers for this * Connection. At least one of this or @create_channel_factories must be set * by subclasses to a non-%NULL value. Since: 0.7.15 @@ -371,9 +405,8 @@ struct _TpBaseConnectionPrivate TpHandleRepoIface *handles[TP_NUM_HANDLE_TYPES]; - /* If not %NULL, contains strings representing our interfaces. - * If %NULL, we have no interfaces except those in - * klass->interfaces_always_present (i.e. this is lazily allocated). + /* Created in constructed, this is an array of static strings which + * represent the interfaces on this connection. * * Note that this is a GArray of gchar*, not a GPtrArray, * so that we can use GArray's convenient auto-null-termination. */ @@ -1249,6 +1282,29 @@ _tp_base_connection_set_handle_repo (TpBaseConnection *self, self->priv->handles[handle_type] = g_object_ref (handle_repo); } +static void +tp_base_connection_create_interfaces_array (TpBaseConnection *self) +{ + TpBaseConnectionPrivate *priv = self->priv; + TpBaseConnectionClass *klass = TP_BASE_CONNECTION_GET_CLASS (self); + GPtrArray *always; + guint i; + + g_assert (priv->interfaces == NULL); + + always = klass->get_interfaces_always_present (self); + + priv->interfaces = g_array_sized_new (TRUE, FALSE, sizeof (gchar *), + always->len); + for (i = 0; i < always->len; i++) + { + g_array_append_val (priv->interfaces, + g_ptr_array_index (always, i)); + } + + g_ptr_array_unref (always); +} + static GObject * tp_base_connection_constructor (GType type, guint n_construct_properties, GObjectConstructParam *construct_params) @@ -1309,6 +1365,8 @@ tp_base_connection_constructor (GType type, guint n_construct_properties, (GCallback) manager_channel_closed_cb, self); } + tp_base_connection_create_interfaces_array (self); + priv->been_constructed = TRUE; return (GObject *) self; @@ -1469,6 +1527,23 @@ conn_requests_get_dbus_property (GObject *object, } } +static GPtrArray * +tp_base_connection_get_interfaces_always_present (TpBaseConnection *self) +{ + GPtrArray *interfaces = g_ptr_array_new (); + const gchar **ptr; + + /* copy the klass->interfaces_always_present property for backwards + * compatibility */ + for (ptr = TP_BASE_CONNECTION_GET_CLASS (self)->interfaces_always_present; + ptr != NULL && *ptr != NULL; + ptr++) + { + g_ptr_array_add (interfaces, (gchar *) *ptr); + } + + return interfaces; +} static void tp_base_connection_class_init (TpBaseConnectionClass *klass) @@ -1495,6 +1570,9 @@ tp_base_connection_class_init (TpBaseConnectionClass *klass) object_class->get_property = tp_base_connection_get_property; object_class->set_property = tp_base_connection_set_property; + klass->get_interfaces_always_present = + tp_base_connection_get_interfaces_always_present; + /** * TpBaseConnection:protocol: (skip) * @@ -1977,20 +2055,7 @@ tp_base_connection_get_interfaces (TpBaseConnection *self) { g_return_val_if_fail (TP_IS_BASE_CONNECTION (self), NULL); - if (self->priv->interfaces != NULL) - { - /* There are some extra interfaces for this connection */ - return (const gchar * const *)(self->priv->interfaces->data); - } - else - { - TpBaseConnectionClass *klass = TP_BASE_CONNECTION_GET_CLASS (self); - - /* We only have the interfaces that are always present. - * Instead of bothering to duplicate the static - * array into the GArray, we just use it directly */ - return (const gchar * const *)klass->interfaces_always_present; - } + return (const gchar * const *)(self->priv->interfaces->data); } static void @@ -3123,16 +3188,15 @@ tp_base_connection_change_status (TpBaseConnection *self, * Add some interfaces to the list supported by this Connection. If you're * going to call this function at all, you must do so before moving to state * CONNECTED (or DISCONNECTED); if you don't call it, only the set of - * interfaces always present (@interfaces_always_present in + * interfaces always present (@get_interfaces_always_present in * #TpBaseConnectionClass) will be supported. */ void tp_base_connection_add_interfaces (TpBaseConnection *self, const gchar **interfaces) { - guint i, n_new; + guint i, n_new, size; TpBaseConnectionPrivate *priv = self->priv; - TpBaseConnectionClass *klass = TP_BASE_CONNECTION_GET_CLASS (self); g_return_if_fail (TP_IS_BASE_CONNECTION (self)); g_return_if_fail (self->status != TP_CONNECTION_STATUS_CONNECTED); @@ -3145,39 +3209,13 @@ tp_base_connection_add_interfaces (TpBaseConnection *self, } n_new = g_strv_length ((gchar **) interfaces); + size = priv->interfaces->len; - if (priv->interfaces) + g_array_set_size (priv->interfaces, size + n_new); + for (i = 0; i < n_new; i++) { - guint size = priv->interfaces->len; - - g_array_set_size (priv->interfaces, size + n_new); - for (i = 0; i < n_new; i++) - { - g_array_index (priv->interfaces, const gchar *, size + i) = - interfaces[i]; - } - } - else - { - /* It's the first time anyone has added interfaces - create the array */ - guint n_static = 0; - - if (klass->interfaces_always_present) - { - n_static = g_strv_length ( - (gchar **) klass->interfaces_always_present); - } - priv->interfaces = g_array_sized_new (TRUE, FALSE, sizeof (gchar *), - n_static + n_new); - for (i = 0; i < n_static; i++) - { - g_array_append_val (priv->interfaces, - klass->interfaces_always_present[i]); - } - for (i = 0; i < n_new; i++) - { - g_array_append_val (priv->interfaces, interfaces[i]); - } + g_array_index (priv->interfaces, const gchar *, size + i) = + interfaces[i]; } } diff --git a/telepathy-glib/base-connection.h b/telepathy-glib/base-connection.h index cd8c70e75..0e65d840e 100644 --- a/telepathy-glib/base-connection.h +++ b/telepathy-glib/base-connection.h @@ -60,6 +60,9 @@ typedef GPtrArray *(*TpBaseConnectionCreateChannelManagersImpl) ( typedef gchar *(*TpBaseConnectionGetUniqueConnectionNameImpl) ( TpBaseConnection *self); +typedef GPtrArray *(*TpBaseConnectionGetInterfacesImpl) ( + TpBaseConnection *self); + struct _TpBaseConnection { /**/ GObject parent; @@ -104,6 +107,7 @@ struct _TpBaseConnectionClass { TpBaseConnectionStartConnectingImpl start_connecting; const gchar **interfaces_always_present; + TpBaseConnectionGetInterfacesImpl get_interfaces_always_present; TpBaseConnectionCreateChannelManagersImpl create_channel_managers; diff --git a/telepathy-glib/base-contact-list.c b/telepathy-glib/base-contact-list.c index 107b4c11c..7e6275308 100644 --- a/telepathy-glib/base-contact-list.c +++ b/telepathy-glib/base-contact-list.c @@ -75,7 +75,8 @@ * // ... * ]| * and include %TP_IFACE_CONNECTION_INTERFACE_CONTACT_LIST in - * #TpBaseConnectionClass.interfaces_always_present; + * the output of + * #TpBaseConnectionClass.get_interfaces_always_present; * * * in the #TpBaseConnectionClass.create_channel_managers @@ -91,8 +92,8 @@ * * To support user-defined contact groups too, additionally implement * %TP_TYPE_CONTACT_GROUP_LIST in the #TpBaseContactList subclass, add the - * %TP_IFACE_CONNECTION_INTERFACE_CONTACT_GROUPS interface to - * #TpBaseConnectionClass.interfaces_always_present, and implement the + * %TP_IFACE_CONNECTION_INTERFACE_CONTACT_GROUPS interface to the output of + * #TpBaseConnectionClass.get interfaces_always_present, and implement the * %TP_TYPE_SVC_CONNECTION_INTERFACE_CONTACT_GROUPS in the #TpBaseConnection * subclass using tp_base_contact_list_mixin_groups_iface_init(). * -- cgit v1.2.1 From aaea3147323cd1ad1b67e17c06504a5a6d6517cc Mon Sep 17 00:00:00 2001 From: Jonny Lamb Date: Thu, 5 Jul 2012 15:05:34 +0100 Subject: =?UTF-8?q?example=20&=20test=20connections:=20update=20to=20use?= =?UTF-8?q?=20new=20get=5Finterfaces=E2=80=A6=20vfunc?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jonny Lamb --- examples/cm/call/conn.c | 17 +++++++- examples/cm/channelspecific/conn.c | 17 +++++++- examples/cm/contactlist/conn.c | 18 +++++++- examples/cm/echo-message-parts/conn.c | 17 +++++++- examples/cm/extended/conn.c | 17 +++++++- tests/dbus/connection-balance.c | 20 ++++++--- tests/lib/bug16307-conn.c | 24 +++++++---- tests/lib/contacts-conn.c | 78 +++++++++++++++++++++++------------ tests/lib/echo-conn.c | 18 ++++++-- tests/lib/simple-conn.c | 17 ++++++-- 10 files changed, 192 insertions(+), 51 deletions(-) diff --git a/examples/cm/call/conn.c b/examples/cm/call/conn.c index 720cbf13f..187e34b08 100644 --- a/examples/cm/call/conn.c +++ b/examples/cm/call/conn.c @@ -377,6 +377,21 @@ example_call_connection_get_possible_interfaces (void) return interfaces_always_present; } +static GPtrArray * +get_interfaces_always_present (TpBaseConnection *base) +{ + GPtrArray *interfaces; + guint i; + + interfaces = TP_BASE_CONNECTION_CLASS ( + example_call_connection_parent_class)->get_interfaces_always_present (base); + + for (i = 0; interfaces_always_present[i] != NULL; i++) + g_ptr_array_add (interfaces, (gchar *) interfaces_always_present[i]); + + return interfaces; +} + static void example_call_connection_class_init ( ExampleCallConnectionClass *klass) @@ -397,7 +412,7 @@ example_call_connection_class_init ( base_class->create_channel_managers = create_channel_managers; base_class->start_connecting = start_connecting; base_class->shut_down = shut_down; - base_class->interfaces_always_present = interfaces_always_present; + base_class->get_interfaces_always_present = get_interfaces_always_present; param_spec = g_param_spec_string ("account", "Account name", "The username of this user", NULL, diff --git a/examples/cm/channelspecific/conn.c b/examples/cm/channelspecific/conn.c index 59dba2707..c14b368fb 100644 --- a/examples/cm/channelspecific/conn.c +++ b/examples/cm/channelspecific/conn.c @@ -246,6 +246,21 @@ example_csh_connection_get_possible_interfaces (void) return interfaces_always_present; } +static GPtrArray * +get_interfaces_always_present (TpBaseConnection *base) +{ + GPtrArray *interfaces; + guint i; + + interfaces = TP_BASE_CONNECTION_CLASS ( + example_csh_connection_parent_class)->get_interfaces_always_present (base); + + for (i = 0; interfaces_always_present[i] != NULL; i++) + g_ptr_array_add (interfaces, (gchar *) interfaces_always_present[i]); + + return interfaces; +} + static void example_csh_connection_class_init (ExampleCSHConnectionClass *klass) { @@ -265,7 +280,7 @@ example_csh_connection_class_init (ExampleCSHConnectionClass *klass) base_class->create_channel_managers = create_channel_managers; base_class->start_connecting = start_connecting; base_class->shut_down = shut_down; - base_class->interfaces_always_present = interfaces_always_present; + base_class->get_interfaces_always_present = get_interfaces_always_present; param_spec = g_param_spec_string ("account", "Account name", "The username of this user", NULL, diff --git a/examples/cm/contactlist/conn.c b/examples/cm/contactlist/conn.c index ab4507740..a28ae8547 100644 --- a/examples/cm/contactlist/conn.c +++ b/examples/cm/contactlist/conn.c @@ -410,6 +410,22 @@ example_contact_list_connection_get_possible_interfaces (void) return interfaces_always_present; } +static GPtrArray * +get_interfaces_always_present (TpBaseConnection *base) +{ + GPtrArray *interfaces; + guint i; + + interfaces = TP_BASE_CONNECTION_CLASS ( + example_contact_list_connection_parent_class)->get_interfaces_always_present ( + base); + + for (i = 0; interfaces_always_present[i] != NULL; i++) + g_ptr_array_add (interfaces, (gchar *) interfaces_always_present[i]); + + return interfaces; +} + static void example_contact_list_connection_class_init ( ExampleContactListConnectionClass *klass) @@ -430,7 +446,7 @@ example_contact_list_connection_class_init ( base_class->create_channel_managers = create_channel_managers; base_class->start_connecting = start_connecting; base_class->shut_down = shut_down; - base_class->interfaces_always_present = interfaces_always_present; + base_class->get_interfaces_always_present = get_interfaces_always_present; param_spec = g_param_spec_string ("account", "Account name", "The username of this user", NULL, diff --git a/examples/cm/echo-message-parts/conn.c b/examples/cm/echo-message-parts/conn.c index d93229f15..115622bd1 100644 --- a/examples/cm/echo-message-parts/conn.c +++ b/examples/cm/echo-message-parts/conn.c @@ -172,6 +172,21 @@ example_echo_2_connection_get_possible_interfaces (void) return interfaces_always_present; } +static GPtrArray * +get_interfaces_always_present (TpBaseConnection *base) +{ + GPtrArray *interfaces; + guint i; + + interfaces = TP_BASE_CONNECTION_CLASS ( + example_echo_2_connection_parent_class)->get_interfaces_always_present (base); + + for (i = 0; interfaces_always_present[i] != NULL; i++) + g_ptr_array_add (interfaces, (gchar *) interfaces_always_present[i]); + + return interfaces; +} + static void constructed (GObject *object) { @@ -206,7 +221,7 @@ example_echo_2_connection_class_init (ExampleEcho2ConnectionClass *klass) base_class->create_channel_managers = create_channel_managers; base_class->start_connecting = start_connecting; base_class->shut_down = shut_down; - base_class->interfaces_always_present = interfaces_always_present; + base_class->get_interfaces_always_present = get_interfaces_always_present; param_spec = g_param_spec_string ("account", "Account name", "The username of this user", NULL, diff --git a/examples/cm/extended/conn.c b/examples/cm/extended/conn.c index 8b2560564..873fcf2b0 100644 --- a/examples/cm/extended/conn.c +++ b/examples/cm/extended/conn.c @@ -203,6 +203,21 @@ example_extended_connection_get_possible_interfaces (void) return interfaces_always_present; } +static GPtrArray * +get_interfaces_always_present (TpBaseConnection *base) +{ + GPtrArray *interfaces; + guint i; + + interfaces = TP_BASE_CONNECTION_CLASS ( + example_extended_connection_parent_class)->get_interfaces_always_present (base); + + for (i = 0; interfaces_always_present[i] != NULL; i++) + g_ptr_array_add (interfaces, (gchar *) interfaces_always_present[i]); + + return interfaces; +} + static void example_extended_connection_class_init (ExampleExtendedConnectionClass *klass) { @@ -223,7 +238,7 @@ example_extended_connection_class_init (ExampleExtendedConnectionClass *klass) base_class->start_connecting = start_connecting; base_class->shut_down = shut_down; - base_class->interfaces_always_present = interfaces_always_present; + base_class->get_interfaces_always_present = get_interfaces_always_present; param_spec = g_param_spec_string ("account", "Account name", "The username of this user", NULL, diff --git a/tests/dbus/connection-balance.c b/tests/dbus/connection-balance.c index 3140e404f..4d022aba3 100644 --- a/tests/dbus/connection-balance.c +++ b/tests/dbus/connection-balance.c @@ -79,6 +79,19 @@ balanced_connection_init (BalancedConnection *self G_GNUC_UNUSED) { } +static GPtrArray * +get_interfaces (TpBaseConnection *base) +{ + GPtrArray *interfaces; + + interfaces = TP_BASE_CONNECTION_CLASS ( + balanced_connection_parent_class)->get_interfaces_always_present (base); + + g_ptr_array_add (interfaces, TP_IFACE_CONNECTION_INTERFACE_BALANCE); + + return interfaces; +} + static void balanced_connection_class_init (BalancedConnectionClass *cls) { @@ -91,14 +104,9 @@ balanced_connection_class_init (BalancedConnectionClass *cls) { NULL } }; - static const gchar *interfaces[] = { - TP_IFACE_CONNECTION_INTERFACE_BALANCE, - NULL - }; - object_class->get_property = balanced_connection_get_property; - base_class->interfaces_always_present = interfaces; + base_class->get_interfaces_always_present = get_interfaces; g_object_class_install_property (object_class, PROP_ACCOUNT_BALANCE, g_param_spec_boxed ("account-balance", "", "", diff --git a/tests/lib/bug16307-conn.c b/tests/lib/bug16307-conn.c index cbabf7393..414d931a0 100644 --- a/tests/lib/bug16307-conn.c +++ b/tests/lib/bug16307-conn.c @@ -135,18 +135,28 @@ start_connecting (TpBaseConnection *conn, return TRUE; } +static GPtrArray * +get_interfaces_always_present (TpBaseConnection *base) +{ + GPtrArray *interfaces; + + interfaces = TP_BASE_CONNECTION_CLASS ( + tp_tests_bug16307_connection_parent_class)->get_interfaces_always_present (base); + + g_ptr_array_add (interfaces, TP_IFACE_CONNECTION_INTERFACE_ALIASING); + g_ptr_array_add (interfaces, TP_IFACE_CONNECTION_INTERFACE_CAPABILITIES); + g_ptr_array_add (interfaces, TP_IFACE_CONNECTION_INTERFACE_PRESENCE); + g_ptr_array_add (interfaces, TP_IFACE_CONNECTION_INTERFACE_AVATARS); + + return interfaces; +} + static void tp_tests_bug16307_connection_class_init (TpTestsBug16307ConnectionClass *klass) { TpBaseConnectionClass *base_class = (TpBaseConnectionClass *) klass; GObjectClass *object_class = (GObjectClass *) klass; - static const gchar *interfaces_always_present[] = { - TP_IFACE_CONNECTION_INTERFACE_ALIASING, - TP_IFACE_CONNECTION_INTERFACE_CAPABILITIES, - TP_IFACE_CONNECTION_INTERFACE_PRESENCE, - TP_IFACE_CONNECTION_INTERFACE_AVATARS, - NULL }; static TpDBusPropertiesMixinPropImpl connection_properties[] = { { "Status", "dbus-status-except-i-broke-it", NULL }, { NULL } @@ -157,7 +167,7 @@ tp_tests_bug16307_connection_class_init (TpTestsBug16307ConnectionClass *klass) base_class->start_connecting = start_connecting; - base_class->interfaces_always_present = interfaces_always_present; + base_class->get_interfaces_always_present = get_interfaces_always_present; signals[SIGNAL_GET_STATUS_RECEIVED] = g_signal_new ("get-status-received", G_OBJECT_CLASS_TYPE (klass), diff --git a/tests/lib/contacts-conn.c b/tests/lib/contacts-conn.c index 6f3088093..5b0dcbba2 100644 --- a/tests/lib/contacts-conn.c +++ b/tests/lib/contacts-conn.c @@ -540,13 +540,10 @@ create_channel_managers (TpBaseConnection *conn) return ret; } -static void -tp_tests_contacts_connection_class_init (TpTestsContactsConnectionClass *klass) +static GPtrArray * +tp_tests_contacts_get_interfaces_always_present (TpBaseConnection *base) { - TpBaseConnectionClass *base_class = - (TpBaseConnectionClass *) klass; - GObjectClass *object_class = (GObjectClass *) klass; - TpPresenceMixinClass *mixin_class; + GPtrArray *interfaces; static const gchar *interfaces_always_present[] = { TP_IFACE_CONNECTION_INTERFACE_ALIASING, TP_IFACE_CONNECTION_INTERFACE_AVATARS, @@ -559,8 +556,25 @@ tp_tests_contacts_connection_class_init (TpTestsContactsConnectionClass *klass) TP_IFACE_CONNECTION_INTERFACE_CLIENT_TYPES, TP_IFACE_CONNECTION_INTERFACE_CONTACT_CAPABILITIES, TP_IFACE_CONNECTION_INTERFACE_CONTACT_INFO, - TP_IFACE_CONNECTION_INTERFACE_REQUESTS, NULL }; + guint i; + + interfaces = TP_BASE_CONNECTION_CLASS ( + tp_tests_contacts_connection_parent_class)->get_interfaces_always_present (base); + + for (i = 0; interfaces_always_present[i] != NULL; i++) + g_ptr_array_add (interfaces, (gchar *) interfaces_always_present[i]); + + return interfaces; +} + +static void +tp_tests_contacts_connection_class_init (TpTestsContactsConnectionClass *klass) +{ + TpBaseConnectionClass *base_class = + (TpBaseConnectionClass *) klass; + GObjectClass *object_class = (GObjectClass *) klass; + TpPresenceMixinClass *mixin_class; static TpDBusPropertiesMixinIfaceImpl prop_interfaces[] = { { TP_IFACE_CONNECTION_INTERFACE_AVATARS, conn_avatars_properties_getter, @@ -579,7 +593,7 @@ tp_tests_contacts_connection_class_init (TpTestsContactsConnectionClass *klass) object_class->finalize = finalize; g_type_class_add_private (klass, sizeof (TpTestsContactsConnectionPrivate)); - base_class->interfaces_always_present = interfaces_always_present; + base_class->get_interfaces_always_present = tp_tests_contacts_get_interfaces_always_present; base_class->create_channel_managers = create_channel_managers; tp_contacts_mixin_class_init (object_class, @@ -1386,27 +1400,33 @@ tp_tests_legacy_contacts_connection_init (TpTestsLegacyContactsConnection *self) { } +static GPtrArray * +tp_tests_legacy_contacts_get_interfaces_always_present (TpBaseConnection *base) +{ + GPtrArray *interfaces; + + interfaces = TP_BASE_CONNECTION_CLASS ( + tp_tests_legacy_contacts_connection_parent_class)->get_interfaces_always_present (base); + + g_ptr_array_remove (interfaces, TP_IFACE_CONNECTION_INTERFACE_CONTACTS); + g_ptr_array_remove (interfaces, TP_IFACE_CONNECTION_INTERFACE_CONTACT_CAPABILITIES); + + return interfaces; +} + static void tp_tests_legacy_contacts_connection_class_init ( TpTestsLegacyContactsConnectionClass *klass) { /* Leave Contacts out of the interfaces we say are present, so clients * won't use it */ - static const gchar *interfaces_always_present[] = { - TP_IFACE_CONNECTION_INTERFACE_ALIASING, - TP_IFACE_CONNECTION_INTERFACE_AVATARS, - TP_IFACE_CONNECTION_INTERFACE_PRESENCE, - TP_IFACE_CONNECTION_INTERFACE_SIMPLE_PRESENCE, - TP_IFACE_CONNECTION_INTERFACE_LOCATION, - TP_IFACE_CONNECTION_INTERFACE_REQUESTS, - NULL }; TpBaseConnectionClass *base_class = (TpBaseConnectionClass *) klass; GObjectClass *object_class = (GObjectClass *) klass; object_class->get_property = legacy_contacts_connection_get_property; - base_class->interfaces_always_present = interfaces_always_present; + base_class->get_interfaces_always_present = tp_tests_legacy_contacts_get_interfaces_always_present; g_object_class_override_property (object_class, LEGACY_PROP_HAS_IMMORTAL_HANDLES, "has-immortal-handles"); @@ -1422,21 +1442,27 @@ tp_tests_no_requests_connection_init (TpTestsNoRequestsConnection *self) { } +static GPtrArray * +tp_tests_no_requests_get_interfaces_always_present (TpBaseConnection *base) +{ + GPtrArray *interfaces; + + interfaces = TP_BASE_CONNECTION_CLASS ( + tp_tests_no_requests_connection_parent_class)->get_interfaces_always_present (base); + + g_ptr_array_remove (interfaces, TP_IFACE_CONNECTION_INTERFACE_REQUESTS); + g_ptr_array_remove (interfaces, TP_IFACE_CONNECTION_INTERFACE_CONTACT_CAPABILITIES); + + return interfaces; +} + static void tp_tests_no_requests_connection_class_init ( TpTestsNoRequestsConnectionClass *klass) { - static const gchar *interfaces_always_present[] = { - TP_IFACE_CONNECTION_INTERFACE_ALIASING, - TP_IFACE_CONNECTION_INTERFACE_AVATARS, - TP_IFACE_CONNECTION_INTERFACE_CONTACTS, - TP_IFACE_CONNECTION_INTERFACE_PRESENCE, - TP_IFACE_CONNECTION_INTERFACE_SIMPLE_PRESENCE, - TP_IFACE_CONNECTION_INTERFACE_LOCATION, - NULL }; TpBaseConnectionClass *base_class = (TpBaseConnectionClass *) klass; - base_class->interfaces_always_present = interfaces_always_present; + base_class->get_interfaces_always_present = tp_tests_no_requests_get_interfaces_always_present; base_class->create_channel_managers = NULL; } diff --git a/tests/lib/echo-conn.c b/tests/lib/echo-conn.c index 3c63582e9..2ce06a21e 100644 --- a/tests/lib/echo-conn.c +++ b/tests/lib/echo-conn.c @@ -175,12 +175,22 @@ shut_down (TpBaseConnection *conn) tp_base_connection_finish_shutdown (conn); } +static GPtrArray * +get_interfaces_always_present (TpBaseConnection *base) +{ + GPtrArray *interfaces; + + interfaces = TP_BASE_CONNECTION_CLASS ( + tp_tests_echo_connection_parent_class)->get_interfaces_always_present (base); + + g_ptr_array_add (interfaces, TP_IFACE_CONNECTION_INTERFACE_REQUESTS); + + return interfaces; +} + static void tp_tests_echo_connection_class_init (TpTestsEchoConnectionClass *klass) { - static const gchar *interfaces_always_present[] = { - TP_IFACE_CONNECTION_INTERFACE_REQUESTS, - NULL }; TpBaseConnectionClass *base_class = (TpBaseConnectionClass *) klass; GObjectClass *object_class = (GObjectClass *) klass; @@ -196,7 +206,7 @@ tp_tests_echo_connection_class_init (TpTestsEchoConnectionClass *klass) base_class->create_channel_managers = create_channel_managers; base_class->start_connecting = start_connecting; base_class->shut_down = shut_down; - base_class->interfaces_always_present = interfaces_always_present; + base_class->get_interfaces_always_present = get_interfaces_always_present; param_spec = g_param_spec_string ("account", "Account name", "The username of this user", NULL, diff --git a/tests/lib/simple-conn.c b/tests/lib/simple-conn.c index e6ee214ef..b57e607a9 100644 --- a/tests/lib/simple-conn.c +++ b/tests/lib/simple-conn.c @@ -284,6 +284,19 @@ shut_down (TpBaseConnection *conn) conn); } +static GPtrArray * +get_interfaces_always_present (TpBaseConnection *base) +{ + GPtrArray *interfaces; + + interfaces = TP_BASE_CONNECTION_CLASS ( + tp_tests_simple_connection_parent_class)->get_interfaces_always_present (base); + + g_ptr_array_add (interfaces, TP_IFACE_CONNECTION_INTERFACE_REQUESTS); + + return interfaces; +} + static void tp_tests_simple_connection_class_init (TpTestsSimpleConnectionClass *klass) { @@ -291,8 +304,6 @@ tp_tests_simple_connection_class_init (TpTestsSimpleConnectionClass *klass) (TpBaseConnectionClass *) klass; GObjectClass *object_class = (GObjectClass *) klass; GParamSpec *param_spec; - static const gchar *interfaces_always_present[] = { - TP_IFACE_CONNECTION_INTERFACE_REQUESTS, NULL }; object_class->get_property = get_property; object_class->set_property = set_property; @@ -306,7 +317,7 @@ tp_tests_simple_connection_class_init (TpTestsSimpleConnectionClass *klass) base_class->start_connecting = start_connecting; base_class->shut_down = shut_down; - base_class->interfaces_always_present = interfaces_always_present; + base_class->get_interfaces_always_present = get_interfaces_always_present; param_spec = g_param_spec_string ("account", "Account name", "The username of this user", NULL, -- cgit v1.2.1 From 6b037b43df5104636f58ab0a3e10c075012feee5 Mon Sep 17 00:00:00 2001 From: Jonny Lamb Date: Thu, 5 Jul 2012 15:54:52 +0100 Subject: base-connection{,-manager}: seal old interfaces members gtk-doc gets confused, so they've been removed from the docs. See also: e8f9a27a388e21 Signed-off-by: Jonny Lamb --- telepathy-glib/base-connection-manager.c | 2 -- telepathy-glib/base-connection-manager.h | 4 +++- telepathy-glib/base-connection.c | 2 -- telepathy-glib/base-connection.h | 4 +++- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/telepathy-glib/base-connection-manager.c b/telepathy-glib/base-connection-manager.c index abec982a6..a9562be92 100644 --- a/telepathy-glib/base-connection-manager.c +++ b/telepathy-glib/base-connection-manager.c @@ -214,8 +214,6 @@ _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: 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. diff --git a/telepathy-glib/base-connection-manager.h b/telepathy-glib/base-connection-manager.h index 9df0db950..5668a5537 100644 --- a/telepathy-glib/base-connection-manager.h +++ b/telepathy-glib/base-connection-manager.h @@ -73,7 +73,9 @@ struct _TpBaseConnectionManagerClass { const TpCMProtocolSpec *_TP_SEAL (protocol_params); TpBaseConnectionManagerNewConnFunc _TP_SEAL (new_connection); - const gchar * const *interfaces; + /**/ + const gchar * const *_TP_SEAL (interfaces); + /**/ TpBaseConnectionManagerGetInterfacesFunc get_interfaces; /**/ diff --git a/telepathy-glib/base-connection.c b/telepathy-glib/base-connection.c index 28b95b01c..9bacd7f8d 100644 --- a/telepathy-glib/base-connection.c +++ b/telepathy-glib/base-connection.c @@ -183,8 +183,6 @@ * @start_connecting: Asynchronously start connecting - called to implement * the Connect D-Bus method. See #TpBaseConnectionStartConnectingImpl for * details. May not be left as %NULL. - * @interfaces_always_present: deprecated since 0.UNRELEASED: implement - * @get_interfaces_always_present instead. * @get_interfaces_always_present: Returns a #GPtrArray of extra D-Bus * interfaces which are always implemented by instances of this class, * which may be filled in by subclasses. The default is to list no diff --git a/telepathy-glib/base-connection.h b/telepathy-glib/base-connection.h index 0e65d840e..9e46b32fe 100644 --- a/telepathy-glib/base-connection.h +++ b/telepathy-glib/base-connection.h @@ -106,7 +106,9 @@ struct _TpBaseConnectionClass { TpBaseConnectionStartConnectingImpl start_connecting; - const gchar **interfaces_always_present; + /**/ + const gchar **_TP_SEAL (interfaces_always_present); + /**/ TpBaseConnectionGetInterfacesImpl get_interfaces_always_present; TpBaseConnectionCreateChannelManagersImpl create_channel_managers; -- cgit v1.2.1 From 05ea1395d99b67e8569dd6e50ec99b782b72ea08 Mon Sep 17 00:00:00 2001 From: Jonny Lamb Date: Thu, 5 Jul 2012 15:56:12 +0100 Subject: base-connection: simplify add_interfaces Calling set_size on the GArray is a little overkill. Signed-off-by: Jonny Lamb --- telepathy-glib/base-connection.c | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/telepathy-glib/base-connection.c b/telepathy-glib/base-connection.c index 9bacd7f8d..1983e94be 100644 --- a/telepathy-glib/base-connection.c +++ b/telepathy-glib/base-connection.c @@ -3193,28 +3193,14 @@ void tp_base_connection_add_interfaces (TpBaseConnection *self, const gchar **interfaces) { - guint i, n_new, size; TpBaseConnectionPrivate *priv = self->priv; g_return_if_fail (TP_IS_BASE_CONNECTION (self)); g_return_if_fail (self->status != TP_CONNECTION_STATUS_CONNECTED); g_return_if_fail (self->status != TP_CONNECTION_STATUS_DISCONNECTED); - if (interfaces == NULL || interfaces[0] == NULL) - { - /* If user tries to add no new interfaces, ignore it */ - return; - } - - n_new = g_strv_length ((gchar **) interfaces); - size = priv->interfaces->len; - - g_array_set_size (priv->interfaces, size + n_new); - for (i = 0; i < n_new; i++) - { - g_array_index (priv->interfaces, const gchar *, size + i) = - interfaces[i]; - } + for (; interfaces != NULL && *interfaces != NULL; interfaces++) + g_array_append_val (priv->interfaces, *interfaces); } static void -- cgit v1.2.1 From c14d25b4bf471b7d9797e097d4318af4b9da001c Mon Sep 17 00:00:00 2001 From: Jonny Lamb Date: Thu, 5 Jul 2012 16:04:46 +0100 Subject: fixup! bcde9c87323454f946be989825b2dc74f61d16f7 Signed-off-by: Jonny Lamb --- telepathy-glib/base-connection.h | 1 - 1 file changed, 1 deletion(-) diff --git a/telepathy-glib/base-connection.h b/telepathy-glib/base-connection.h index 9e46b32fe..41504e423 100644 --- a/telepathy-glib/base-connection.h +++ b/telepathy-glib/base-connection.h @@ -114,7 +114,6 @@ struct _TpBaseConnectionClass { TpBaseConnectionCreateChannelManagersImpl create_channel_managers; /**/ - gpointer _future2; gpointer _future3; gpointer _future4; -- cgit v1.2.1 From 43621978934824f2b6815ef5d5e20887d59bca28 Mon Sep 17 00:00:00 2001 From: Jonny Lamb Date: Thu, 5 Jul 2012 16:48:36 +0100 Subject: 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 --- docs/reference/telepathy-glib-sections.txt | 1 + telepathy-glib/base-protocol.c | 76 +++++++++++++++++++++++++++--- 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 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 @@ -413,6 +413,37 @@ tp_cm_param_filter_string_nonempty (const TpCMParamSpec *paramspec, * Since: 0.13.7 */ +/** + * 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: * @@ -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); + /**/ + GStrv (*_TP_SEAL (get_interfaces)) (TpBaseProtocol *self); + /**/ + + 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); /**/ - GCallback padding[5]; + GCallback padding[4]; TpBaseProtocolClassPrivate *priv; }; -- cgit v1.2.1 From ec9a04f139900957a59630a7f74015f55dffe100 Mon Sep 17 00:00:00 2001 From: Jonny Lamb Date: Thu, 5 Jul 2012 16:52:51 +0100 Subject: example protocols: update to use get_interfaces_array vfunc Signed-off-by: Jonny Lamb --- examples/cm/call/protocol.c | 7 ------- examples/cm/channelspecific/protocol.c | 7 ------- examples/cm/contactlist/protocol.c | 7 ------- examples/cm/echo-message-parts/protocol.c | 21 ++++++++++++--------- examples/cm/extended/protocol.c | 7 ------- 5 files changed, 12 insertions(+), 37 deletions(-) diff --git a/examples/cm/call/protocol.c b/examples/cm/call/protocol.c index 4233fdefc..f65c99f75 100644 --- a/examples/cm/call/protocol.c +++ b/examples/cm/call/protocol.c @@ -134,12 +134,6 @@ identify_account (TpBaseProtocol *self G_GNUC_UNUSED, return NULL; } -static GStrv -get_interfaces (TpBaseProtocol *self) -{ - return NULL; -} - static void get_connection_details (TpBaseProtocol *self G_GNUC_UNUSED, GStrv *connection_interfaces, @@ -183,6 +177,5 @@ example_call_protocol_class_init ( base_class->normalize_contact = normalize_contact; base_class->identify_account = identify_account; - base_class->get_interfaces = get_interfaces; base_class->get_connection_details = get_connection_details; } diff --git a/examples/cm/channelspecific/protocol.c b/examples/cm/channelspecific/protocol.c index 112f7cef0..6874689c0 100644 --- a/examples/cm/channelspecific/protocol.c +++ b/examples/cm/channelspecific/protocol.c @@ -174,12 +174,6 @@ identify_account (TpBaseProtocol *self G_GNUC_UNUSED, return NULL; } -static GStrv -get_interfaces (TpBaseProtocol *self) -{ - return NULL; -} - static void get_connection_details (TpBaseProtocol *self G_GNUC_UNUSED, GStrv *connection_interfaces, @@ -223,6 +217,5 @@ example_csh_protocol_class_init ( base_class->normalize_contact = normalize_contact; base_class->identify_account = identify_account; - base_class->get_interfaces = get_interfaces; base_class->get_connection_details = get_connection_details; } diff --git a/examples/cm/contactlist/protocol.c b/examples/cm/contactlist/protocol.c index fcc05ebed..3f76e1785 100644 --- a/examples/cm/contactlist/protocol.c +++ b/examples/cm/contactlist/protocol.c @@ -134,12 +134,6 @@ identify_account (TpBaseProtocol *self G_GNUC_UNUSED, return NULL; } -static GStrv -get_interfaces (TpBaseProtocol *self) -{ - return NULL; -} - static void get_connection_details (TpBaseProtocol *self G_GNUC_UNUSED, GStrv *connection_interfaces, @@ -183,6 +177,5 @@ example_contact_list_protocol_class_init ( base_class->normalize_contact = normalize_contact; base_class->identify_account = identify_account; - base_class->get_interfaces = get_interfaces; base_class->get_connection_details = get_connection_details; } diff --git a/examples/cm/echo-message-parts/protocol.c b/examples/cm/echo-message-parts/protocol.c index 7981fedaa..4512216b9 100644 --- a/examples/cm/echo-message-parts/protocol.c +++ b/examples/cm/echo-message-parts/protocol.c @@ -21,11 +21,6 @@ G_DEFINE_TYPE_WITH_CODE (ExampleEcho2Protocol, example_echo_2_protocol, TP_TYPE_BASE_PROTOCOL, G_IMPLEMENT_INTERFACE (TP_TYPE_PROTOCOL_ADDRESSING, addressing_iface_init)) -const gchar * const protocol_interfaces[] = { - TP_IFACE_PROTOCOL_INTERFACE_AVATARS, - TP_IFACE_PROTOCOL_INTERFACE_ADDRESSING, - NULL }; - const gchar * const supported_avatar_mime_types[] = { "image/png", "image/jpeg", @@ -127,10 +122,18 @@ identify_account (TpBaseProtocol *self G_GNUC_UNUSED, return NULL; } -static GStrv -get_interfaces (TpBaseProtocol *self) +static GPtrArray * +get_interfaces_array (TpBaseProtocol *self) { - return g_strdupv ((GStrv) protocol_interfaces); + GPtrArray *interfaces; + + interfaces = TP_BASE_PROTOCOL_CLASS ( + example_echo_2_protocol_parent_class)->get_interfaces_array (self); + + g_ptr_array_add (interfaces, TP_IFACE_PROTOCOL_INTERFACE_AVATARS); + g_ptr_array_add (interfaces, TP_IFACE_PROTOCOL_INTERFACE_ADDRESSING); + + return interfaces; } static void @@ -235,7 +238,7 @@ example_echo_2_protocol_class_init ( base_class->normalize_contact = normalize_contact; base_class->identify_account = identify_account; - base_class->get_interfaces = get_interfaces; + base_class->get_interfaces_array = get_interfaces_array; base_class->get_connection_details = get_connection_details; base_class->get_avatar_details = get_avatar_details; } diff --git a/examples/cm/extended/protocol.c b/examples/cm/extended/protocol.c index 0a85a504c..0b20659bd 100644 --- a/examples/cm/extended/protocol.c +++ b/examples/cm/extended/protocol.c @@ -106,12 +106,6 @@ identify_account (TpBaseProtocol *self G_GNUC_UNUSED, return NULL; } -static GStrv -get_interfaces (TpBaseProtocol *self) -{ - return NULL; -} - static void get_connection_details (TpBaseProtocol *self G_GNUC_UNUSED, GStrv *connection_interfaces, @@ -167,6 +161,5 @@ example_extended_protocol_class_init ( base_class->normalize_contact = normalize_contact; base_class->identify_account = identify_account; - base_class->get_interfaces = get_interfaces; base_class->get_connection_details = get_connection_details; } -- cgit v1.2.1