[telepathy-gabble/master] Make GabblePresence::caps private, with a getter for read-only access
Simon McVittie
simon.mcvittie at collabora.co.uk
Mon Aug 24 09:57:52 PDT 2009
---
src/connection.c | 14 +++++++-------
src/presence-cache.c | 27 +++++++++++++++------------
src/presence.c | 29 ++++++++++++++++++-----------
src/presence.h | 4 +++-
4 files changed, 43 insertions(+), 31 deletions(-)
diff --git a/src/connection.c b/src/connection.c
index 008fdf4..089e89f 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -1694,7 +1694,7 @@ connection_iq_disco_cb (LmMessageHandler *handler,
lm_message_node_set_attribute (result_query, "node", node);
DEBUG ("got disco request for node %s, caps are %x", node,
- self->self_presence->caps);
+ gabble_presence_get_caps_bitfield (self->self_presence));
/* Every entity MUST have at least one identity (XEP-0030). Gabble publishs
* one identity. If you change the identity here, you also need to change
@@ -2463,7 +2463,7 @@ gabble_connection_advertise_capabilities (TpSvcConnectionInterfaceCapabilities *
TP_BASE_CONNECTION_ERROR_IF_NOT_CONNECTED (base, context);
- DEBUG ("caps before: %x", pres->caps);
+ DEBUG ("caps before: %x", gabble_presence_get_caps_bitfield (pres));
add_set = gabble_capability_set_new ();
remove_set = gabble_capability_set_new ();
@@ -2514,14 +2514,14 @@ gabble_connection_advertise_capabilities (TpSvcConnectionInterfaceCapabilities *
DEBUG ("before != after, changing");
gabble_presence_set_capabilities (pres, priv->resource, cap_set,
capabilities_parse (cap_set), priv->caps_serial++);
- DEBUG ("set caps: %x", pres->caps);
+ DEBUG ("set caps: %x", gabble_presence_get_caps_bitfield (pres));
}
ret = g_ptr_array_new ();
for (ccd = capabilities_conversions; NULL != ccd->iface; ccd++)
{
- guint tp_caps = ccd->c2tf_fn (pres->caps);
+ guint tp_caps = ccd->c2tf_fn (gabble_presence_get_caps_bitfield (pres));
if (tp_caps != 0)
{
@@ -2609,8 +2609,8 @@ gabble_connection_set_self_capabilities (
}
}
- gabble_presence_set_capabilities (pres, priv->resource, new_caps, pres->caps,
- priv->caps_serial++);
+ gabble_presence_set_capabilities (pres, priv->resource, new_caps,
+ gabble_presence_get_caps_bitfield (pres), priv->caps_serial++);
if (_gabble_connection_signal_own_presence (self, &error))
{
@@ -2666,7 +2666,7 @@ gabble_connection_get_handle_capabilities (GabbleConnection *self,
{
for (ccd = capabilities_conversions; NULL != ccd->iface; ccd++)
{
- typeflags = ccd->c2tf_fn (pres->caps);
+ typeflags = ccd->c2tf_fn (gabble_presence_get_caps_bitfield (pres));
if (typeflags)
{
diff --git a/src/presence-cache.c b/src/presence-cache.c
index 7d5ae2a..b2214ae 100644
--- a/src/presence-cache.c
+++ b/src/presence-cache.c
@@ -869,7 +869,7 @@ set_caps_for (DiscoWaiter *waiter,
if (presence == NULL)
return;
- save_caps = presence->caps;
+ save_caps = gabble_presence_get_caps_bitfield (presence);
old_cap_set = gabble_presence_dup_caps (presence);
DEBUG ("setting caps for %d (thanks to %d %s) to %d (save_caps %d)",
@@ -878,12 +878,13 @@ set_caps_for (DiscoWaiter *waiter,
gabble_presence_set_capabilities (presence, waiter->resource, cap_set,
caps, waiter->serial);
- DEBUG ("caps for %d now %d", waiter->handle, presence->caps);
+ DEBUG ("caps for %d now %d", waiter->handle,
+ gabble_presence_get_caps_bitfield (presence));
new_cap_set = gabble_presence_dup_caps (presence);
- emit_capabilities_update (cache, waiter->handle, save_caps, presence->caps,
- old_cap_set, new_cap_set);
+ emit_capabilities_update (cache, waiter->handle, save_caps,
+ gabble_presence_get_caps_bitfield (presence), old_cap_set, new_cap_set);
gabble_capability_set_free (old_cap_set);
gabble_capability_set_free (new_cap_set);
@@ -1094,7 +1095,8 @@ _process_caps_uri (GabblePresenceCache *cache,
{
gabble_presence_set_capabilities (presence, resource, info->cap_set,
capabilities_parse (info->cap_set), serial);
- DEBUG ("caps for %d (%s) now %d", handle, from, presence->caps);
+ DEBUG ("caps for %d (%s) now %d", handle, from,
+ gabble_presence_get_caps_bitfield (presence));
}
else
{
@@ -1179,7 +1181,7 @@ _process_caps (GabblePresenceCache *cache,
if (presence)
{
- old_caps = presence->caps;
+ old_caps = gabble_presence_get_caps_bitfield (presence);
old_cap_set = gabble_presence_dup_caps (presence);
}
@@ -1196,9 +1198,10 @@ _process_caps (GabblePresenceCache *cache,
GabbleCapabilitySet *new_cap_set = gabble_presence_dup_caps (presence);
DEBUG ("Emitting caps update: handle %u, old %u, new %u",
- handle, old_caps, presence->caps);
+ handle, old_caps, gabble_presence_get_caps_bitfield (presence));
- emit_capabilities_update (cache, handle, old_caps, presence->caps,
+ emit_capabilities_update (cache, handle, old_caps,
+ gabble_presence_get_caps_bitfield (presence),
old_cap_set, new_cap_set);
gabble_capability_set_free (new_cap_set);
@@ -1206,7 +1209,7 @@ _process_caps (GabblePresenceCache *cache,
else
{
DEBUG ("No change in caps %u for handle %u, not updating",
- presence->caps, handle);
+ gabble_presence_get_caps_bitfield (presence), handle);
}
if (old_cap_set != NULL)
@@ -1491,7 +1494,7 @@ gabble_presence_cache_do_update (
if (presence == NULL)
presence = _cache_insert (cache, handle);
- caps_before = presence->caps;
+ caps_before = gabble_presence_get_caps_bitfield (presence);
old_cap_set = gabble_presence_dup_caps (presence);
ret = gabble_presence_update (presence, resource, presence_id,
@@ -1499,8 +1502,8 @@ gabble_presence_cache_do_update (
new_cap_set = gabble_presence_dup_caps (presence);
- emit_capabilities_update (cache, handle, caps_before, presence->caps,
- old_cap_set, new_cap_set);
+ emit_capabilities_update (cache, handle, caps_before,
+ gabble_presence_get_caps_bitfield (presence), old_cap_set, new_cap_set);
gabble_capability_set_free (old_cap_set);
gabble_capability_set_free (new_cap_set);
diff --git a/src/presence.c b/src/presence.c
index 0e0f8e1..8f282f7 100644
--- a/src/presence.c
+++ b/src/presence.c
@@ -52,6 +52,7 @@ struct _Resource {
struct _GabblePresencePrivate {
/* The aggregated caps of all the contacts' resources. */
+ GabblePresenceCapabilities caps;
GabbleCapabilitySet *cap_set;
gchar *no_resource_status_message;
@@ -152,6 +153,12 @@ resource_better_than (Resource *a, Resource *b)
return (a->priority > b->priority);
}
+GabblePresenceCapabilities
+gabble_presence_get_caps_bitfield (GabblePresence *presence)
+{
+ return presence->priv->caps;
+}
+
gboolean
gabble_presence_has_cap (GabblePresence *presence,
const gchar *ns)
@@ -170,7 +177,7 @@ gabble_presence_dup_caps (GabblePresence *presence)
ret = gabble_capability_set_copy (presence->priv->cap_set);
- tmp = gabble_capability_set_new_from_flags (presence->caps);
+ tmp = gabble_capability_set_new_from_flags (presence->priv->caps);
gabble_capability_set_update (ret, tmp);
gabble_capability_set_free (tmp);
@@ -246,13 +253,13 @@ gabble_presence_set_capabilities (GabblePresence *presence,
return;
}
- presence->caps = 0;
+ presence->priv->caps = 0;
gabble_capability_set_clear (priv->cap_set);
if (resource == NULL)
{
DEBUG ("adding caps %u to bare jid", caps);
- presence->caps = caps;
+ presence->priv->caps = caps;
gabble_capability_set_update (priv->cap_set, cap_set);
return;
}
@@ -287,11 +294,11 @@ gabble_presence_set_capabilities (GabblePresence *presence,
}
}
- presence->caps |= tmp->caps;
+ presence->priv->caps |= tmp->caps;
gabble_capability_set_update (priv->cap_set, tmp->cap_set);
}
- DEBUG ("total caps now %u", presence->caps);
+ DEBUG ("total caps now %u", presence->priv->caps);
}
static Resource *
@@ -320,7 +327,7 @@ aggregate_resources (GabblePresence *presence)
/* select the most preferable Resource and update presence->* based on our
* choice */
- presence->caps = 0;
+ presence->priv->caps = 0;
gabble_capability_set_clear (priv->cap_set);
presence->status = GABBLE_PRESENCE_OFFLINE;
@@ -330,7 +337,7 @@ aggregate_resources (GabblePresence *presence)
{
Resource *r = (Resource *) i->data;
- presence->caps |= r->caps;
+ presence->priv->caps |= r->caps;
gabble_capability_set_update (priv->cap_set, r->cap_set);
/* trump existing status & message if it's more present
@@ -406,14 +413,14 @@ gabble_presence_update (GabblePresence *presence,
res = NULL;
/* recalculate aggregate capability mask */
- presence->caps = 0;
+ presence->priv->caps = 0;
gabble_capability_set_clear (priv->cap_set);
for (i = priv->resources; i; i = i->next)
{
Resource *r = (Resource *) i->data;
- presence->caps |= r->caps;
+ presence->priv->caps |= r->caps;
gabble_capability_set_update (priv->cap_set, r->cap_set);
}
}
@@ -442,7 +449,7 @@ gabble_presence_update (GabblePresence *presence,
/* select the most preferable Resource and update presence->* based on our
* choice */
- presence->caps = 0;
+ presence->priv->caps = 0;
gabble_capability_set_clear (priv->cap_set);
presence->status = GABBLE_PRESENCE_OFFLINE;
@@ -541,7 +548,7 @@ gabble_presence_dump (GabblePresence *presence)
"accumulated capabilities: %d\n"
"kept while unavailable: %d\n"
"resources:\n", presence->nickname, presence->status,
- presence->status_message, presence->caps,
+ presence->status_message, presence->priv->caps,
presence->keep_unavailable);
for (i = priv->resources; i; i = i->next)
diff --git a/src/presence.h b/src/presence.h
index 0746046..76faf51 100644
--- a/src/presence.h
+++ b/src/presence.h
@@ -56,7 +56,6 @@ typedef struct _GabblePresencePrivate GabblePresencePrivate;
struct _GabblePresence {
GObject parent;
- GabblePresenceCapabilities caps;
GabblePresenceId status;
gchar *status_message;
gchar *nickname;
@@ -85,6 +84,9 @@ void gabble_presence_set_capabilities (GabblePresence *presence,
GabblePresenceCapabilities caps,
guint serial);
+GabblePresenceCapabilities gabble_presence_get_caps_bitfield (
+ GabblePresence *presence);
+
gboolean gabble_presence_has_cap (GabblePresence *presence, const gchar *ns);
GabbleCapabilitySet *gabble_presence_dup_caps (GabblePresence *presence);
--
1.5.6.5
More information about the telepathy-commits
mailing list