[Telepathy-commits] [telepathy-gabble/master] Add support for capabilities in the Contacts interface
Sjoerd Simons
sjoerd.simons at collabora.co.uk
Tue Aug 19 10:54:24 PDT 2008
20080729151414-b58c9-83680204eb5d718c112d3a33703f7795048b363e.gz
---
src/connection.c | 179 +++++++++++++++++++++++++++++++++++------------------
1 files changed, 118 insertions(+), 61 deletions(-)
diff --git a/src/connection.c b/src/connection.c
index eae63d2..9dfc5cc 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -72,6 +72,8 @@ static guint disco_reply_timeout = 5000;
static void conn_service_iface_init (gpointer, gpointer);
static void capabilities_service_iface_init (gpointer, gpointer);
+static void conn_capabilities_get_contact_attributes (GObject *obj,
+ const GArray *contacts, GHashTable *attributes_hash);
G_DEFINE_TYPE_WITH_CODE(GabbleConnection,
gabble_connection,
@@ -246,6 +248,11 @@ gabble_connection_constructor (GType type,
conn_presence_init (self);
conn_olpc_activity_properties_init (self);
+ tp_contacts_mixin_add_inspectable_iface (G_OBJECT (self),
+ TP_IFACE_CONNECTION_INTERFACE_CAPABILITIES,
+ conn_capabilities_get_contact_attributes);
+
+
self->bytestream_factory = gabble_bytestream_factory_new (self);
self->avatar_requests = g_hash_table_new (NULL, NULL);
@@ -2217,6 +2224,116 @@ static const gchar *assumed_caps[] =
/**
+ * gabble_connection_get_handle_capabilities
+ *
+ * Add capabilities of handle to the given GPtrArray
+ */
+static void
+gabble_connection_get_handle_capabilities (GabbleConnection *self,
+ TpHandle handle, GPtrArray *arr)
+{
+ TpBaseConnection *base = (TpBaseConnection *) self;
+ GabblePresence *pres;
+ const CapabilityConversionData *ccd;
+ guint typeflags;
+ const gchar **assumed;
+
+ if (0 == handle)
+ {
+ /* FIXME report the magical channel types available on the
+ * connection itself */
+ return;
+ }
+
+ if (handle == base->self_handle)
+ pres = self->self_presence;
+ else
+ pres = gabble_presence_cache_get (self->presence_cache, handle);
+
+ if (NULL != pres)
+ for (ccd = capabilities_conversions; NULL != ccd->iface; ccd++)
+ {
+ typeflags = ccd->c2tf_fn (pres->caps);
+
+ if (typeflags)
+ {
+ GValue monster = {0, };
+
+ g_value_init (&monster, TP_STRUCT_TYPE_CONTACT_CAPABILITY);
+ g_value_take_boxed (&monster,
+ dbus_g_type_specialized_construct (
+ TP_STRUCT_TYPE_CONTACT_CAPABILITY));
+
+ dbus_g_type_struct_set (&monster,
+ 0, handle,
+ 1, ccd->iface,
+ 2, TP_CONNECTION_CAPABILITY_FLAG_CREATE |
+ TP_CONNECTION_CAPABILITY_FLAG_INVITE,
+ 3, typeflags,
+ G_MAXUINT);
+
+ g_ptr_array_add (arr, g_value_get_boxed (&monster));
+ }
+ }
+
+ for (assumed = assumed_caps; NULL != *assumed; assumed++)
+ {
+ GValue monster = {0, };
+
+ g_value_init (&monster, TP_STRUCT_TYPE_CONTACT_CAPABILITY);
+ g_value_take_boxed (&monster,
+ dbus_g_type_specialized_construct (
+ TP_STRUCT_TYPE_CONTACT_CAPABILITY));
+
+ dbus_g_type_struct_set (&monster,
+ 0, handle,
+ 1, *assumed,
+ 2, TP_CONNECTION_CAPABILITY_FLAG_CREATE |
+ TP_CONNECTION_CAPABILITY_FLAG_INVITE,
+ 3, 0,
+ G_MAXUINT);
+
+ g_ptr_array_add (arr, g_value_get_boxed (&monster));
+ }
+}
+
+
+static void
+conn_capabilities_get_contact_attributes (GObject *obj, const GArray *contacts,
+ GHashTable *attributes_hash)
+{
+ GabbleConnection *self = GABBLE_CONNECTION (obj);
+ guint i;
+ GPtrArray *array = NULL;
+
+ for (i = 0; i < contacts->len; i++)
+ {
+ TpHandle handle = g_array_index (contacts, guint, i);
+
+ if (array == NULL)
+ array = g_ptr_array_new ();
+
+ gabble_connection_get_handle_capabilities (self, handle, array);
+
+ if (array->len > 0)
+ {
+ GValue *val = tp_g_value_slice_new (
+ TP_ARRAY_TYPE_CONTACT_CAPABILITY_LIST);
+
+ g_value_take_boxed (val, array);
+ tp_contacts_mixin_set_contact_attribute (attributes_hash,
+ handle, TP_IFACE_CONNECTION_INTERFACE_CAPABILITIES"/caps",
+ val);
+
+ array = NULL;
+ }
+ }
+
+ if (array != NULL)
+ g_ptr_array_free (array, TRUE);
+}
+
+/**
* gabble_connection_get_capabilities
*
* Implements D-Bus method GetCapabilities
@@ -2255,68 +2372,8 @@ gabble_connection_get_capabilities (TpSvcConnectionInterfaceCapabilities *iface,
for (i = 0; i < handles->len; i++)
{
TpHandle handle = g_array_index (handles, guint, i);
- GabblePresence *pres;
- const CapabilityConversionData *ccd;
- guint typeflags;
- const gchar **assumed;
- if (0 == handle)
- {
- /* FIXME report the magical channel types available on the
- * connection itself */
- continue;
- }
-
- if (handle == base->self_handle)
- pres = self->self_presence;
- else
- pres = gabble_presence_cache_get (self->presence_cache, handle);
-
- if (NULL != pres)
- for (ccd = capabilities_conversions; NULL != ccd->iface; ccd++)
- {
- typeflags = ccd->c2tf_fn (pres->caps);
-
- if (typeflags)
- {
- GValue monster = {0, };
-
- g_value_init (&monster, TP_STRUCT_TYPE_CONTACT_CAPABILITY);
- g_value_take_boxed (&monster,
- dbus_g_type_specialized_construct (
- TP_STRUCT_TYPE_CONTACT_CAPABILITY));
-
- dbus_g_type_struct_set (&monster,
- 0, handle,
- 1, ccd->iface,
- 2, TP_CONNECTION_CAPABILITY_FLAG_CREATE |
- TP_CONNECTION_CAPABILITY_FLAG_INVITE,
- 3, typeflags,
- G_MAXUINT);
-
- g_ptr_array_add (ret, g_value_get_boxed (&monster));
- }
- }
-
- for (assumed = assumed_caps; NULL != *assumed; assumed++)
- {
- GValue monster = {0, };
-
- g_value_init (&monster, TP_STRUCT_TYPE_CONTACT_CAPABILITY);
- g_value_take_boxed (&monster,
- dbus_g_type_specialized_construct (
- TP_STRUCT_TYPE_CONTACT_CAPABILITY));
-
- dbus_g_type_struct_set (&monster,
- 0, handle,
- 1, *assumed,
- 2, TP_CONNECTION_CAPABILITY_FLAG_CREATE |
- TP_CONNECTION_CAPABILITY_FLAG_INVITE,
- 3, 0,
- G_MAXUINT);
-
- g_ptr_array_add (ret, g_value_get_boxed (&monster));
- }
+ gabble_connection_get_handle_capabilities (self, handle, ret);
}
tp_svc_connection_interface_capabilities_return_from_get_capabilities (
--
1.5.6.3
More information about the Telepathy-commits
mailing list