telepathy-glib: contacts-mixin: Implement GetContactByID

Xavier Claessens xclaesse at kemper.freedesktop.org
Wed May 9 05:59:54 PDT 2012


Module: telepathy-glib
Branch: master
Commit: a9c13065262e3b679d537b8240971a88909ddacf
URL:    http://cgit.freedesktop.org/telepathy/telepathy-glib/commit/?id=a9c13065262e3b679d537b8240971a88909ddacf

Author: Xavier Claessens <xavier.claessens at collabora.co.uk>
Date:   Tue May  8 11:45:26 2012 +0200

contacts-mixin: Implement GetContactByID

---

 telepathy-glib/contacts-mixin.c |   57 +++++++++++++++++++++++++++++++++++---
 1 files changed, 52 insertions(+), 5 deletions(-)

diff --git a/telepathy-glib/contacts-mixin.c b/telepathy-glib/contacts-mixin.c
index 47dc85d..9a2792d 100644
--- a/telepathy-glib/contacts-mixin.c
+++ b/telepathy-glib/contacts-mixin.c
@@ -82,6 +82,11 @@ static TpDBusPropertiesMixinPropImpl known_contacts_props[] = {
   { NULL }
 };
 
+static const gchar *always_included_interfaces[] = {
+  TP_IFACE_CONNECTION,
+  NULL
+};
+
 static void
 tp_presence_mixin_get_contacts_dbus_property (GObject *object,
                                               GQuark interface,
@@ -371,10 +376,6 @@ tp_contacts_mixin_get_contact_attributes_impl (
   TpBaseConnection *conn = TP_BASE_CONNECTION (iface);
   GHashTable *result;
   gchar *sender = NULL;
-  const gchar *assumed_interfaces[] = {
-    TP_IFACE_CONNECTION,
-    NULL
-  };
 
   TP_BASE_CONNECTION_ERROR_IF_NOT_CONNECTED (conn, context);
 
@@ -382,7 +383,7 @@ tp_contacts_mixin_get_contact_attributes_impl (
     sender = dbus_g_method_get_sender (context);
 
   result = tp_contacts_mixin_get_contact_attributes (G_OBJECT (conn),
-      handles, interfaces, assumed_interfaces, sender);
+      handles, interfaces, always_included_interfaces, sender);
 
   tp_svc_connection_interface_contacts_return_from_get_contact_attributes (
       context, result);
@@ -391,6 +392,51 @@ tp_contacts_mixin_get_contact_attributes_impl (
   g_hash_table_unref (result);
 }
 
+static void
+tp_contacts_mixin_get_contact_by_id_impl (
+  TpSvcConnectionInterfaceContacts *iface,
+  const gchar *id,
+  const gchar **interfaces,
+  DBusGMethodInvocation *context)
+{
+  TpBaseConnection *conn = TP_BASE_CONNECTION (iface);
+  TpHandleRepoIface *contact_repo = tp_base_connection_get_handles (conn,
+      TP_HANDLE_TYPE_CONTACT);
+  TpHandle handle;
+  GArray *handles;
+  GHashTable *attributes;
+  GHashTable *result;
+  gchar *sender = NULL;
+  GError *error = NULL;
+
+  TP_BASE_CONNECTION_ERROR_IF_NOT_CONNECTED (conn, context);
+
+  handle = tp_handle_ensure (contact_repo, id, NULL, &error);
+  if (handle == 0)
+    {
+      dbus_g_method_return_error (context, error);
+      g_clear_error (&error);
+      return;
+    }
+
+  sender = dbus_g_method_get_sender (context);
+  handles = g_array_new (FALSE, FALSE, sizeof (TpHandle));
+  g_array_append_val (handles, handle);
+
+  attributes = tp_contacts_mixin_get_contact_attributes (G_OBJECT (conn),
+      handles, interfaces, always_included_interfaces, sender);
+
+  result = g_hash_table_lookup (attributes, GUINT_TO_POINTER (handle));
+  g_assert (result != NULL);
+
+  tp_svc_connection_interface_contacts_return_from_get_contact_by_id (context,
+      handle, result);
+
+  g_free (sender);
+  g_array_unref (handles);
+  g_hash_table_unref (attributes);
+}
+
 /**
  * tp_contacts_mixin_iface_init: (skip)
  * @g_iface: A pointer to the #TpSvcConnectionInterfaceContacts in an object
@@ -413,6 +459,7 @@ tp_contacts_mixin_iface_init (gpointer g_iface, gpointer iface_data)
 #define IMPLEMENT(x) tp_svc_connection_interface_contacts_implement_##x ( \
     klass, tp_contacts_mixin_##x##_impl)
   IMPLEMENT(get_contact_attributes);
+  IMPLEMENT(get_contact_by_id);
 #undef IMPLEMENT
 }
 



More information about the telepathy-commits mailing list