[Telepathy-commits] [telepathy-glib/master] Add hook to register the base connection to the Contacts interface

Sjoerd Simons sjoerd at luon.net
Tue Aug 19 04:25:20 PDT 2008


20080728172216-93b9a-71c5cda8087f651c633acc002d5eae90097698f6.gz
---
 telepathy-glib/base-connection.c |   48 ++++++++++++++++++++++++++++++++++++++
 telepathy-glib/base-connection.h |    2 +
 2 files changed, 50 insertions(+), 0 deletions(-)

diff --git a/telepathy-glib/base-connection.c b/telepathy-glib/base-connection.c
index 7a8ac69..e477604 100644
--- a/telepathy-glib/base-connection.c
+++ b/telepathy-glib/base-connection.c
@@ -42,10 +42,12 @@
 #include <dbus/dbus-glib-lowlevel.h>
 
 #include <telepathy-glib/connection-manager.h>
+#include <telepathy-glib/contacts-mixin.h>
 #include <telepathy-glib/channel-factory-iface.h>
 #include <telepathy-glib/dbus.h>
 #include <telepathy-glib/gtypes.h>
 #include <telepathy-glib/util.h>
+#include <telepathy-glib/interfaces.h>
 
 #define DEBUG_FLAG TP_DEBUG_CONNECTION
 #include "debug-internal.h"
@@ -1719,3 +1721,49 @@ service_iface_init (gpointer g_iface, gpointer iface_data)
   IMPLEMENT(dbus_,request_handles);
 #undef IMPLEMENT
 }
+
+static void
+tp_base_connection_get_contact_attributes (GObject *obj,
+  const GArray *contacts, GHashTable *attributes_hash)
+{
+  TpBaseConnection *self = TP_BASE_CONNECTION (obj);
+  TpBaseConnectionPrivate *priv =
+    TP_BASE_CONNECTION_GET_PRIVATE (self);
+  guint i;
+
+  for (i = 0; i < contacts->len; i++)
+    {
+      TpHandle handle;
+      const gchar *tmp;
+      GValue *val;
+
+
+      handle = g_array_index (contacts, TpHandle, i);
+      tmp = tp_handle_inspect (priv->handles[TP_HANDLE_TYPE_CONTACT], handle);
+      g_assert (tmp != NULL);
+
+      val = tp_g_value_slice_new (G_TYPE_STRING);
+      g_value_set_static_string (val, tmp);
+
+      tp_contacts_mixin_set_contact_attribute (attributes_hash,
+          handle, TP_IFACE_CONNECTION"/contact-id", val);
+    }
+}
+
+/**
+ * tp_base_connection_register_with_contacts_iface:
+ * @self: An instance of the #TpBaseConnections that uses the Contacts
+ * mixin
+ *
+ * Register the Connection interface with the Contacts interface to make it
+ * inspectable. The Contacts mixin should be initialized before this function
+ * is called
+ */
+void
+tp_base_connection_register_with_contacts_iface (TpBaseConnection *self)
+{
+  tp_contacts_mixin_add_inspectable_iface (G_OBJECT (self),
+      TP_IFACE_CONNECTION,
+      tp_base_connection_get_contact_attributes);
+}
+
diff --git a/telepathy-glib/base-connection.h b/telepathy-glib/base-connection.h
index ab4f215..aa9a3b3 100644
--- a/telepathy-glib/base-connection.h
+++ b/telepathy-glib/base-connection.h
@@ -263,6 +263,8 @@ void tp_base_connection_add_interfaces (TpBaseConnection *self,
 void tp_base_connection_dbus_request_handles (TpSvcConnection *iface,
     guint handle_type, const gchar **names, DBusGMethodInvocation *context);
 
+void tp_base_connection_register_with_contacts_iface (TpBaseConnection *self);
+
 /* TYPE MACROS */
 #define TP_TYPE_BASE_CONNECTION \
   (tp_base_connection_get_type ())
-- 
1.5.6.3




More information about the Telepathy-commits mailing list