[Telepathy-commits] [telepathy-gabble/master] Apply Alban's peer review comments
Pierre-Luc Beaudoin
pierre-luc.beaudoin at collabora.co.uk
Sun Feb 1 05:23:59 PST 2009
---
src/conn-location.c | 51 +++++++++------------------------------
src/presence-cache.c | 40 ++++++++++++++-----------------
src/presence-cache.h | 4 +-
tests/twisted/test-location.py | 9 ++++--
4 files changed, 38 insertions(+), 66 deletions(-)
diff --git a/src/conn-location.c b/src/conn-location.c
index 51cafc5..21ec336 100644
--- a/src/conn-location.c
+++ b/src/conn-location.c
@@ -13,32 +13,8 @@
#include "namespaces.h"
#include "pubsub.h"
-#define XEP0080_ALT "alt"
-#define XEP0080_AREA "area"
-#define XEP0080_BEARING "bearing"
-#define XEP0080_BUILDING "building"
-#define XEP0080_COUNTRY "country"
-#define XEP0080_DESCRIPTION "description"
-#define XEP0080_ERROR "error"
-#define XEP0080_FLOOR "floor"
-#define XEP0080_LAT "lat"
-#define XEP0080_LOCALITY "locality"
-#define XEP0080_LON "lon"
-#define XEP0080_POSTAL_CODE "postalcode"
-#define XEP0080_REGION "region"
-#define XEP0080_ROOM "room"
-#define XEP0080_STREET "street"
-#define XEP0080_TEXT "text"
-#define XEP0080_TIMESTAMP "timestamp"
-#define XEP0080_URI "uri"
-
-#define LOCATION_ACCURACY_LEVEL "accuracy-level"
-#define LOCATION_COUNTRY_CODE "countrycode"
-#define LOCATION_VERTICAL_ERROR_M "vertical-error-m"
-#define LOCATION_HORIZONTAL_ERROR_M "horizontal-error-m"
-
-static gboolean update_location (GabbleConnection *conn, const gchar *from,
- LmMessage *msg);
+static gboolean update_location_from_msg (GabbleConnection *conn,
+ const gchar *from, LmMessage *msg);
/* XXX: similar to conn-olpc.c's inspect_contact(), except that it assumes
* that the handle is valid. (Does tp_handle_inspect check validity anyway?)
@@ -130,7 +106,7 @@ pep_reply_cb (GabbleConnection *conn,
from = lm_message_node_get_attribute (reply_msg->node, "from");
if (from != NULL)
- update_location (conn, from, reply_msg);
+ update_location_from_msg (conn, from, reply_msg);
return LM_HANDLER_RESULT_REMOVE_MESSAGE;
}
@@ -144,7 +120,7 @@ location_get_locations (GabbleSvcConnectionInterfaceLocation *iface,
TpBaseConnection *base = (TpBaseConnection *) conn;
guint i;
GHashTable *return_locations = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL,
- NULL);
+ (GDestroyNotify) g_hash_table_destroy);
GHashTable *location = NULL;
DEBUG ("GetLocation for contacts:");
@@ -158,10 +134,9 @@ location_get_locations (GabbleSvcConnectionInterfaceLocation *iface,
guint contact = g_array_index (contacts, guint, i);
const gchar *jid = inspect_contact (base, contact);
- /* Check for cached locations */
- if (gabble_presence_cache_get_location (conn->presence_cache, contact, &location))
+ location = gabble_presence_cache_get_location (conn->presence_cache, contact);
+ if (location != NULL)
{
- //FIXME: where to unref the location?
DEBUG (" - %s: cached", jid);
g_hash_table_insert (return_locations, GINT_TO_POINTER (contact), location);
}
@@ -302,9 +277,9 @@ conn_location_propeties_getter (GObject *object,
}
static gboolean
-update_location (GabbleConnection *conn,
- const gchar *from,
- LmMessage *msg)
+update_location_from_msg (GabbleConnection *conn,
+ const gchar *from,
+ LmMessage *msg)
{
LmMessageNode *node, *subloc_node;
gchar *key, *str;
@@ -347,12 +322,10 @@ update_location (GabbleConnection *conn,
g_hash_table_insert (location, g_strdup (key), value);
}
-
- gabble_presence_cache_update_location (conn->presence_cache, contact,
- location);
gabble_svc_connection_interface_location_emit_location_updated (conn,
contact, location);
- g_hash_table_unref (location);
+ gabble_presence_cache_update_location (conn->presence_cache, contact,
+ location);
return TRUE;
}
@@ -371,6 +344,6 @@ geolocation_event_handler (GabbleConnection *conn,
from = lm_message_node_get_attribute (msg->node, "from");
- return update_location (conn, from, msg);
+ return update_location_from_msg (conn, from, msg);
}
diff --git a/src/presence-cache.c b/src/presence-cache.c
index d3cdb1f..66cd37c 100644
--- a/src/presence-cache.c
+++ b/src/presence-cache.c
@@ -92,6 +92,13 @@ struct _GabblePresenceCachePrivate
guint caps_serial;
GTimeVal creation_time;
+
+ // The cached contacts' location.
+ // The key is the contact's handle.
+ // The value is a GHashTable of the user's location:
+ // - the key is a gchar* as per XEP-0080
+ // - the value is a slice allocation GValue, the exact
+ // type depends on the key.
GHashTable *location;
gboolean dispose_has_run;
@@ -382,7 +389,7 @@ gabble_presence_cache_init (GabblePresenceCache *cache)
priv->caps_serial = 1;
priv->location = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL,
- NULL);
+ (GDestroyNotify) g_hash_table_destroy);
}
static GObject *
@@ -1800,37 +1807,26 @@ gabble_presence_cache_update_location (GabblePresenceCache *cache,
GHashTable *new_location)
{
GabblePresenceCachePrivate *priv = GABBLE_PRESENCE_CACHE_PRIV (cache);
- GHashTable *cur_location;
-
- // FIXME: Necessary? should the destroy cb take care of that?
- cur_location = g_hash_table_lookup (priv->location, GINT_TO_POINTER (handle));
- if (!cur_location)
- cur_location = g_hash_table_new_full (g_str_hash, g_str_equal, NULL,
- (GDestroyNotify) tp_g_value_slice_free);
-
- // Copy keys
- g_hash_table_remove_all (cur_location);
- g_hash_table_foreach (new_location, update_location_for_each, cur_location);
- g_hash_table_replace (priv->location, GINT_TO_POINTER (handle), cur_location);
+ g_hash_table_insert (priv->location, GINT_TO_POINTER (handle), new_location);
g_signal_emit (cache, signals[LOCATION_UPDATED], 0, handle);
}
-
-gboolean
+// The return value should be g_object_unref'ed.
+GHashTable *
gabble_presence_cache_get_location (GabblePresenceCache *cache,
- TpHandle handle,
- GHashTable **location)
+ TpHandle handle)
{
GabblePresenceCachePrivate *priv = GABBLE_PRESENCE_CACHE_PRIV (cache);
+ GHashTable *location = NULL;
- *location = g_hash_table_lookup (priv->location, GINT_TO_POINTER (handle));
- if (*location != NULL)
+ location = g_hash_table_lookup (priv->location, GINT_TO_POINTER (handle));
+ if (location != NULL)
{
- g_hash_table_ref(*location);
- return TRUE;
+ g_hash_table_ref(location);
+ return location;
}
- return FALSE;
+ return NULL;
}
diff --git a/src/presence-cache.h b/src/presence-cache.h
index 65531b4..0c832d3 100644
--- a/src/presence-cache.h
+++ b/src/presence-cache.h
@@ -113,8 +113,8 @@ gboolean gabble_presence_cache_is_unsure (GabblePresenceCache *cache);
void gabble_presence_cache_update_location (GabblePresenceCache *cache,
TpHandle handle, GHashTable *location);
-gboolean gabble_presence_cache_get_location (GabblePresenceCache *cache,
- TpHandle handle, GHashTable **location);
+GHashTable* gabble_presence_cache_get_location (GabblePresenceCache *cache,
+ TpHandle handle);
G_END_DECLS
diff --git a/tests/twisted/test-location.py b/tests/twisted/test-location.py
index 959f0c6..a032a79 100644
--- a/tests/twisted/test-location.py
+++ b/tests/twisted/test-location.py
@@ -13,7 +13,10 @@ def test(q, bus, conn, stream):
dbus.Interface(conn, location_iface)
conn.Connect()
- q.expect('dbus-signal', signal='StatusChanged', args=[0, 1])
+ q.expect_many(
+ EventPattern('stream-iq', iq_type='set', query_ns='http://jabber.org/protocol/pubsub'),
+ EventPattern('dbus-signal', signal='StatusChanged', args=[0, 1]))
+ #q.expect('dbus-signal', signal='StatusChanged', args=[0, 1])
# check location properties
#properties = conn.GetAll(
@@ -24,8 +27,8 @@ def test(q, bus, conn, stream):
#assert properties.get('LocationAccessControl') is not None
# discard activities request
- q.expect('stream-iq', iq_type='set',
- query_ns='http://jabber.org/protocol/pubsub')
+ #q.expect('stream-iq', iq_type='set',
+ # query_ns='http://jabber.org/protocol/pubsub')
conn.Location.SetLocation({
'lat': dbus.Double(0.0, variant_level=1), 'lon': 0.0})
--
1.5.6.5
More information about the Telepathy-commits
mailing list