From 476db658257a9024ee6204dbc9b801ab38ad2fdd Mon Sep 17 00:00:00 2001 From: Xavier Claessens Date: Thu, 30 Jun 2011 13:09:11 +0200 Subject: [PATCH] Add _tp_contacts_to_handles() Help implementing _async(guint n_contacts, TpContact **contacts) methods --- telepathy-glib/util-internal.h | 7 +++++++ telepathy-glib/util.c | 30 ++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 0 deletions(-) diff --git a/telepathy-glib/util-internal.h b/telepathy-glib/util-internal.h index 3ab4b63..12fa1e2 100644 --- a/telepathy-glib/util-internal.h +++ b/telepathy-glib/util-internal.h @@ -27,6 +27,8 @@ #include #include +#include +#include GArray *_tp_quark_array_copy (const GQuark *quarks) G_GNUC_WARN_UNUSED_RESULT; void _tp_quark_array_merge (GArray *array, const GQuark *quarks, gssize n); @@ -90,4 +92,9 @@ gboolean _tp_set_socket_address_type_and_access_control_type ( GSocket * _tp_create_client_socket (TpSocketAddressType socket_type, GError **error); +gboolean _tp_contacts_to_handles (TpConnection *connection, + guint n_contacts, + TpContact * const *contacts, + GArray **handles); + #endif /* __TP_UTIL_INTERNAL_H__ */ diff --git a/telepathy-glib/util.c b/telepathy-glib/util.c index ed48f65..809028e 100644 --- a/telepathy-glib/util.c +++ b/telepathy-glib/util.c @@ -1888,3 +1888,33 @@ _tp_create_client_socket (TpSocketAddressType socket_type, return client_socket; } + +gboolean +_tp_contacts_to_handles (TpConnection *connection, + guint n_contacts, + TpContact * const *contacts, + GArray **handles) +{ + guint i; + + g_return_val_if_fail (handles != NULL, FALSE); + + *handles = g_array_sized_new (FALSE, FALSE, sizeof (TpHandle), n_contacts); + + for (i = 0; i < n_contacts; i++) + { + TpHandle handle; + + if (!TP_IS_CONTACT (contacts[i]) || + tp_contact_get_connection (contacts[i]) != connection) + { + tp_clear_pointer (handles, g_array_unref); + return FALSE; + } + + handle = tp_contact_get_handle (contacts[i]); + g_array_append_val (*handles, handle); + } + + return TRUE; +} -- 1.7.4.1