[telepathy-gabble/master] gabble_connection_ensure_capabilities: use capability sets

Simon McVittie simon.mcvittie at collabora.co.uk
Tue Sep 8 04:10:09 PDT 2009


---
 src/conn-location.c |    6 ++++--
 src/conn-olpc.c     |   32 ++++++++++++++++++++++++--------
 src/connection.c    |   34 ++++++++++++++++------------------
 src/connection.h    |    5 +++--
 4 files changed, 47 insertions(+), 30 deletions(-)

diff --git a/src/conn-location.c b/src/conn-location.c
index 4238da9..f22575c 100644
--- a/src/conn-location.c
+++ b/src/conn-location.c
@@ -137,7 +137,8 @@ location_get_locations (TpSvcConnectionInterfaceLocation *iface,
 
   DEBUG ("GetLocation for contacts:");
 
-  gabble_connection_ensure_capabilities (conn, PRESENCE_CAP_GEOLOCATION);
+  gabble_connection_ensure_capabilities (conn,
+      gabble_capabilities_get_geoloc_notify ());
 
   /* Validate contacts */
   contact_handles = tp_base_connection_get_handles (base,
@@ -268,7 +269,8 @@ location_set_location (TpSvcConnectionInterfaceLocation *iface,
       return;
     }
 
-  gabble_connection_ensure_capabilities (conn, PRESENCE_CAP_GEOLOCATION);
+  gabble_connection_ensure_capabilities (conn,
+      gabble_capabilities_get_geoloc_notify ());
   msg = pubsub_make_publish_msg (NULL, NS_GEOLOC, NS_GEOLOC, "geoloc",
       &geoloc);
 
diff --git a/src/conn-olpc.c b/src/conn-olpc.c
index ee4d866..7623a4e 100644
--- a/src/conn-olpc.c
+++ b/src/conn-olpc.c
@@ -393,7 +393,9 @@ olpc_buddy_info_get_properties (GabbleSvcOLPCBuddyInfo *iface,
 
   DEBUG ("called");
 
-  gabble_connection_ensure_capabilities (conn, PRESENCE_CAP_OLPC_1);
+  gabble_connection_ensure_capabilities (conn,
+      gabble_capabilities_get_olpc_notify ());
+
   if (!check_pep (conn, context))
     return;
 
@@ -451,7 +453,9 @@ transmit_properties (GabbleConnection *conn,
   LmMessage *msg;
   LmMessageNode *publish;
 
-  gabble_connection_ensure_capabilities (conn, PRESENCE_CAP_OLPC_1);
+  gabble_connection_ensure_capabilities (conn,
+      gabble_capabilities_get_olpc_notify ());
+
   if (!check_pep (conn, context))
     return;
 
@@ -938,7 +942,9 @@ olpc_buddy_info_get_activities (GabbleSvcOLPCBuddyInfo *iface,
 
   DEBUG ("called");
 
-  gabble_connection_ensure_capabilities (conn, PRESENCE_CAP_OLPC_1);
+  gabble_connection_ensure_capabilities (conn,
+      gabble_capabilities_get_olpc_notify ());
+
   if (!check_pep (conn, context))
     return;
 
@@ -1042,7 +1048,9 @@ olpc_buddy_info_set_activities (GabbleSvcOLPCBuddyInfo *iface,
 
   DEBUG ("called");
 
-  gabble_connection_ensure_capabilities (conn, PRESENCE_CAP_OLPC_1);
+  gabble_connection_ensure_capabilities (conn,
+      gabble_capabilities_get_olpc_notify ());
+
   if (!check_pep (conn, context))
     return;
 
@@ -1353,7 +1361,9 @@ olpc_buddy_info_get_current_activity (GabbleSvcOLPCBuddyInfo *iface,
 
   DEBUG ("called for contact#%u", contact);
 
-  gabble_connection_ensure_capabilities (conn, PRESENCE_CAP_OLPC_1);
+  gabble_connection_ensure_capabilities (conn,
+      gabble_capabilities_get_olpc_notify ());
+
   if (!check_pep (conn, context))
     return;
 
@@ -1442,7 +1452,9 @@ olpc_buddy_info_set_current_activity (GabbleSvcOLPCBuddyInfo *iface,
 
   DEBUG ("called");
 
-  gabble_connection_ensure_capabilities (conn, PRESENCE_CAP_OLPC_1);
+  gabble_connection_ensure_capabilities (conn,
+      gabble_capabilities_get_olpc_notify ());
+
   if (!check_pep (conn, context))
     return;
 
@@ -1727,7 +1739,9 @@ olpc_activity_properties_set_properties (GabbleSvcOLPCActivityProperties *iface,
 
   DEBUG ("called");
 
-  gabble_connection_ensure_capabilities (conn, PRESENCE_CAP_OLPC_1);
+  gabble_connection_ensure_capabilities (conn,
+      gabble_capabilities_get_olpc_notify ());
+
   if (!check_pep (conn, context))
     return;
 
@@ -1841,7 +1855,9 @@ olpc_activity_properties_get_properties (GabbleSvcOLPCActivityProperties *iface,
 
   DEBUG ("called");
 
-  gabble_connection_ensure_capabilities (conn, PRESENCE_CAP_OLPC_1);
+  gabble_connection_ensure_capabilities (conn,
+      gabble_capabilities_get_olpc_notify ());
+
   if (!check_pep (conn, context))
     return;
 
diff --git a/src/connection.c b/src/connection.c
index 36cd454..7c5be36 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -3273,31 +3273,29 @@ gabble_connection_request_handles (TpSvcConnection *iface,
 
 void
 gabble_connection_ensure_capabilities (GabbleConnection *self,
-                                       GabblePresenceCapabilities caps)
+    const GabbleCapabilitySet *ensured)
 {
   GabbleConnectionPrivate *priv = self->priv;
-  GabblePresenceCapabilities old_caps, new_caps;
   GabbleCapabilitySet *cap_set;
+  GError *error = NULL;
 
-  old_caps = self->self_presence->caps;
-  new_caps = old_caps;
-  new_caps |= caps;
-
-  if (old_caps ^ new_caps)
+  if (gabble_presence_resource_has_caps (self->self_presence,
+        priv->resource, gabble_capability_set_predicate_at_least, ensured))
     {
-      /* We changed capabilities */
-      GError *error = NULL;
+      DEBUG ("nothing to do");
+      return;
+    }
 
-      cap_set = gabble_capability_set_new_from_flags (caps);
-      gabble_presence_set_capabilities (self->self_presence, priv->resource,
-          cap_set, new_caps, priv->caps_serial++);
-      gabble_capability_set_free (cap_set);
+  cap_set = gabble_presence_dup_caps (self->self_presence);
+  gabble_capability_set_update (cap_set, ensured);
+  gabble_presence_set_capabilities (self->self_presence, priv->resource,
+      cap_set, capabilities_parse (cap_set), priv->caps_serial++);
+  gabble_capability_set_free (cap_set);
 
-      if (!_gabble_connection_signal_own_presence (self, &error))
-        {
-          DEBUG ("error sending presence: %s", error->message);
-          g_error_free (error);
-        }
+  if (!_gabble_connection_signal_own_presence (self, &error))
+    {
+      DEBUG ("error sending presence: %s", error->message);
+      g_error_free (error);
     }
 }
 
diff --git a/src/connection.h b/src/connection.h
index 1d48070..f17e70d 100644
--- a/src/connection.h
+++ b/src/connection.h
@@ -29,6 +29,7 @@
 #include <telepathy-glib/presence-mixin.h>
 #include <telepathy-glib/dbus-properties-mixin.h>
 
+#include "capabilities.h"
 #include "error.h"
 #include "ft-manager.h"
 #include "jingle-factory.h"
@@ -242,8 +243,8 @@ const char *_gabble_connection_find_conference_server (GabbleConnection *);
 gboolean _gabble_connection_signal_own_presence (GabbleConnection *,
     GError **);
 
-void gabble_connection_ensure_capabilities (GabbleConnection *conn,
-    GabblePresenceCapabilities caps);
+void gabble_connection_ensure_capabilities (GabbleConnection *self,
+    const GabbleCapabilitySet *ensured);
 
 gboolean gabble_connection_send_presence (GabbleConnection *conn,
     LmMessageSubType sub_type, const gchar *contact, const gchar *status,
-- 
1.5.6.5




More information about the telepathy-commits mailing list