diff options
author | Simon McVittie <simon.mcvittie@collabora.co.uk> | 2010-09-27 20:20:53 +0100 |
---|---|---|
committer | Simon McVittie <simon.mcvittie@collabora.co.uk> | 2010-09-27 20:20:53 +0100 |
commit | 0a0ebe5bfabbe3304ff0f1dc7a1ac47361a8b2ca (patch) | |
tree | e3f8418247027a55a433a7f302b365c7ffbf8194 /telepathy-glib/contacts-mixin.c | |
parent | e6ba83cbbf46890c7b1321c992c8dd5630833a42 (diff) | |
parent | e10fad6e76b8add8777823c6af91d364026af66d (diff) | |
download | telepathy-glib-0a0ebe5bfabbe3304ff0f1dc7a1ac47361a8b2ca.tar.gz |
Merge remote branch 'eitan/contacts-iface-tweaks'
Conflicts:
telepathy-glib/contacts-mixin.c
Diffstat (limited to 'telepathy-glib/contacts-mixin.c')
-rw-r--r-- | telepathy-glib/contacts-mixin.c | 116 |
1 files changed, 81 insertions, 35 deletions
diff --git a/telepathy-glib/contacts-mixin.c b/telepathy-glib/contacts-mixin.c index c0b326d61..f1d68f5be 100644 --- a/telepathy-glib/contacts-mixin.c +++ b/telepathy-glib/contacts-mixin.c @@ -263,34 +263,43 @@ tp_contacts_mixin_finalize (GObject *obj) g_slice_free (TpContactsMixinPrivate, mixin->priv); } -static void -tp_contacts_mixin_get_contact_attributes ( - TpSvcConnectionInterfaceContacts *iface, - const GArray *handles, - const char **interfaces, - gboolean hold, - DBusGMethodInvocation *context) -{ - _tp_contacts_mixin_get_contact_attributes ( - TP_BASE_CONNECTION (iface), handles, interfaces, hold, context); -} - -void -_tp_contacts_mixin_get_contact_attributes (TpBaseConnection *conn, - const GArray *handles, - const char **interfaces, - gboolean hold, - DBusGMethodInvocation *context) +/** + * tp_contacts_mixin_get_contact_attributes: (skip) + * @obj: A connection instance that uses this mixin. The connection must be connected. + * @handles: List of handles to retrieve contacts for. Any invalid handles will be + * dropped from the returned mapping. + * @interfaces: A list of interfaces to retrieve attributes for. The Connection + * interface will always be included. + * @sender: The DBus client's unique name. If this is not NULL, the requested handles + * will be held on behalf of this client. + * + * Get contact attributes for the given contacts. Provide attributes for all requested + * interfaces. If contact attributes are not immediately known, the behaviour is defined + * by the interface; the attribute should either be omitted from the result or replaced + * with a default value. + * + * Returns: A dictionary mapping the contact handles to contact attributes. + * + */ +GHashTable * +tp_contacts_mixin_get_contact_attributes (GObject *obj, + const GArray *handles, + const gchar **interfaces, + const gchar **assumed_interfaces, + const gchar *sender) { - TpContactsMixin *self = TP_CONTACTS_MIXIN (conn); GHashTable *result; guint i; + TpBaseConnection *conn = TP_BASE_CONNECTION (obj); + TpContactsMixin *self = TP_CONTACTS_MIXIN (obj); TpHandleRepoIface *contact_repo = tp_base_connection_get_handles (conn, TP_HANDLE_TYPE_CONTACT); GArray *valid_handles; TpContactsMixinFillContactAttributesFunc func; - TP_BASE_CONNECTION_ERROR_IF_NOT_CONNECTED (conn, context); + g_return_val_if_fail (TP_IS_BASE_CONNECTION (obj), NULL); + g_return_val_if_fail (TP_CONTACTS_MIXIN_OFFSET (obj) != 0, NULL); + g_return_val_if_fail (conn->status == TP_CONNECTION_STATUS_CONNECTED, NULL); /* Setup handle array and hash with valid handles, optionally holding them */ valid_handles = g_array_sized_new (TRUE, TRUE, sizeof (TpHandle), @@ -311,22 +320,23 @@ _tp_contacts_mixin_get_contact_attributes (TpBaseConnection *conn, } } - if (hold) - { - gchar *sender = dbus_g_method_get_sender (context); - - tp_handles_client_hold (contact_repo, sender, valid_handles, NULL); - g_free (sender); - } + if (sender != NULL) + tp_handles_client_hold (contact_repo, sender, valid_handles, NULL); /* ensure the handles don't disappear while calling out to various functions */ tp_handles_ref (contact_repo, valid_handles); - func = g_hash_table_lookup (self->priv->interfaces, TP_IFACE_CONNECTION); + for (i = 0; assumed_interfaces[i] != NULL; i++) + { + func = g_hash_table_lookup (self->priv->interfaces, assumed_interfaces[i]); - if (func != NULL) - func (G_OBJECT (conn), valid_handles, result); + if (func == NULL) + DEBUG ("non-inspectable assumed interface %s given; ignoring", + assumed_interfaces[i]); + else + func (obj, valid_handles, result); + } for (i = 0; interfaces[i] != NULL; i++) { @@ -336,16 +346,52 @@ _tp_contacts_mixin_get_contact_attributes (TpBaseConnection *conn, if (func == NULL) DEBUG ("non-inspectable interface %s given; ignoring", interfaces[i]); else - func (G_OBJECT(conn), valid_handles, result); + func (obj, valid_handles, result); } + tp_handles_unref (contact_repo, valid_handles); + g_array_free (valid_handles, TRUE); + + return result; +} + +void +_tp_contacts_mixin_get_contact_attributes ( + TpBaseConnection *conn, const GArray *handles, + const gchar **interfaces, gboolean hold, DBusGMethodInvocation *context) +{ + GHashTable *result; + gchar *sender = NULL; + const gchar *assumed_interfaces[] = { + TP_IFACE_CONNECTION, + NULL + }; + + TP_BASE_CONNECTION_ERROR_IF_NOT_CONNECTED (conn, context); + + if (hold) + sender = dbus_g_method_get_sender (context); + + result = tp_contacts_mixin_get_contact_attributes (G_OBJECT (conn), + handles, interfaces, assumed_interfaces, sender); + tp_svc_connection_interface_contacts_return_from_get_contact_attributes ( - context, result); + context, result); + g_free (sender); g_hash_table_destroy (result); +} - tp_handles_unref (contact_repo, valid_handles); - g_array_free (valid_handles, TRUE); +static void +tp_contacts_mixin_get_contact_attributes_impl ( + TpSvcConnectionInterfaceContacts *iface, + const GArray *handles, + const char **interfaces, + gboolean hold, + DBusGMethodInvocation *context) +{ + _tp_contacts_mixin_get_contact_attributes ( + TP_BASE_CONNECTION (iface), handles, interfaces, hold, context); } /** @@ -368,7 +414,7 @@ tp_contacts_mixin_iface_init (gpointer g_iface, gpointer iface_data) (TpSvcConnectionInterfaceContactsClass *) g_iface; #define IMPLEMENT(x) tp_svc_connection_interface_contacts_implement_##x ( \ - klass, tp_contacts_mixin_##x) + klass, tp_contacts_mixin_##x##_impl) IMPLEMENT(get_contact_attributes); #undef IMPLEMENT } |