[telepathy-gabble/master] Use WockyPepService to catch location changes events

Guillaume Desmottes guillaume.desmottes at collabora.co.uk
Mon Sep 21 05:26:21 PDT 2009


---
 src/conn-location.c |   32 +++++++++++++++++++-------------
 src/connection.c    |    9 +++++++--
 src/connection.h    |    3 ++-
 3 files changed, 28 insertions(+), 16 deletions(-)

diff --git a/src/conn-location.c b/src/conn-location.c
index 05dee81..a0397af 100644
--- a/src/conn-location.c
+++ b/src/conn-location.c
@@ -519,30 +519,34 @@ update_location_from_msg (GabbleConnection *conn,
   return TRUE;
 }
 
-static gboolean
-geolocation_event_handler (WockyPubsub *pubsub,
-    LmMessage *msg,
-    const gchar *from,
-    gpointer user_data)
+static void
+location_pep_node_changed (WockyPepService *pep,
+    WockyBareContact *contact,
+    WockyXmppStanza *stanza,
+    GabbleConnection *conn)
 {
-  GabbleConnection *conn = GABBLE_CONNECTION (user_data);
   TpHandleRepoIface *contact_repo = tp_base_connection_get_handles (
       (TpBaseConnection *) conn, TP_HANDLE_TYPE_CONTACT);
   TpBaseConnection *base = (TpBaseConnection *) conn;
   TpHandle handle;
+  const gchar *jid;
 
-  handle = tp_handle_ensure (contact_repo, from, NULL, NULL);
+  jid = wocky_bare_contact_get_jid (contact);
+  handle = tp_handle_ensure (contact_repo, jid, NULL, NULL);
   if (handle == 0)
     {
-      DEBUG ("Invalid from: %s", from);
-      return FALSE;
+      DEBUG ("Invalid from: %s", jid);
+      return;
     }
 
   if (handle == base->self_handle)
     /* Ignore echoed pubsub notifications */
-    return TRUE;
+    goto out;
+
+  update_location_from_msg (conn, jid, stanza);
 
-  return update_location_from_msg (conn, from, msg);
+out:
+  tp_handle_unref (contact_repo, handle);
 }
 
 static void
@@ -580,6 +584,8 @@ conn_location_init (GabbleConnection *conn)
     TP_IFACE_CONNECTION_INTERFACE_LOCATION,
     conn_location_fill_contact_attributes);
 
-  conn->pubsub_location_event_id = wocky_pubsub_register_event_handler (
-      conn->pubsub, NS_GEOLOC, geolocation_event_handler, conn);
+  conn->pep_location = wocky_pep_service_new (NS_GEOLOC, TRUE);
+
+  g_signal_connect (conn->pep_location, "changed",
+      G_CALLBACK (location_pep_node_changed), conn);
 }
diff --git a/src/connection.c b/src/connection.c
index 13efe77..a1ac29c 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -994,8 +994,6 @@ gabble_connection_dispose (GObject *object)
   wocky_pubsub_unregister_event_handler (self->pubsub,
       self->pubsub_alias_event_id);
   wocky_pubsub_unregister_event_handler (self->pubsub,
-      self->pubsub_location_event_id);
-  wocky_pubsub_unregister_event_handler (self->pubsub,
       self->pubsub_olpc_buddy_props_event_id);
   wocky_pubsub_unregister_event_handler (self->pubsub,
       self->pubsub_olpc_activities_event_id);
@@ -1004,6 +1002,12 @@ gabble_connection_dispose (GObject *object)
   wocky_pubsub_unregister_event_handler (self->pubsub,
       self->pubsub_olpc_act_props_props_event_id);
 
+  if (self->pep_location != NULL)
+    {
+      g_object_unref (self->pep_location);
+      self->pep_location = NULL;
+    }
+
   if (self->pubsub != NULL)
     {
       g_object_unref (self->pubsub);
@@ -1541,6 +1545,7 @@ connector_connected (GabbleConnection *self,
   lm_connection_set_porter (self->lmconn, priv->porter);
 
   wocky_pubsub_start (self->pubsub, self->session);
+  wocky_pep_service_start (self->pep_location, self->session);
 
   /* Don't use wocky_session_start as we don't want to start all the
    * components (Roster, presence-manager, etc) for now */
diff --git a/src/connection.h b/src/connection.h
index b9b5b6f..2ffee45 100644
--- a/src/connection.h
+++ b/src/connection.h
@@ -30,6 +30,7 @@
 #include <telepathy-glib/dbus-properties-mixin.h>
 
 #include <wocky/wocky-session.h>
+#include "wocky-pep-service.h"
 
 #include "capabilities.h"
 #include "error.h"
@@ -194,7 +195,7 @@ struct _GabbleConnection {
     /* pubsub */
     WockyPubsub *pubsub;
     guint pubsub_alias_event_id;
-    guint pubsub_location_event_id;
+    WockyPepService *pep_location;
     guint pubsub_olpc_buddy_props_event_id;
     guint pubsub_olpc_activities_event_id;
     guint pubsub_olpc_current_act_props_event_id;
-- 
1.5.6.5




More information about the telepathy-commits mailing list