[telepathy-gabble/master] conn-location: factor out get_cached_location_or_query
Guillaume Desmottes
guillaume.desmottes at collabora.co.uk
Fri Aug 14 05:25:07 PDT 2009
---
src/conn-location.c | 56 ++++++++++++++++++++++++++++++++------------------
1 files changed, 36 insertions(+), 20 deletions(-)
diff --git a/src/conn-location.c b/src/conn-location.c
index 6bb2146..7cc08c1 100644
--- a/src/conn-location.c
+++ b/src/conn-location.c
@@ -93,6 +93,33 @@ pep_reply_cb (GabbleConnection *conn,
return LM_HANDLER_RESULT_REMOVE_MESSAGE;
}
+static GHashTable *
+get_cached_location_or_query (GabbleConnection *conn,
+ TpHandle contact,
+ GError **error)
+{
+ TpBaseConnection *base = (TpBaseConnection *) conn;
+ GHashTable *location;
+ const gchar *jid;
+ TpHandleRepoIface *contact_repo;
+
+ contact_repo = tp_base_connection_get_handles (base, TP_HANDLE_TYPE_CONTACT);
+ jid = tp_handle_inspect (contact_repo, contact);
+
+ location = gabble_presence_cache_get_location (conn->presence_cache, contact);
+ if (location != NULL)
+ {
+ DEBUG (" - %s: cached", jid);
+ return location;
+ }
+
+ /* Send a query */
+ if (pubsub_query (conn, jid, NS_GEOLOC, pep_reply_cb, error))
+ DEBUG (" - %s: requested", jid);
+
+ return NULL;
+}
+
static void
location_get_locations (GabbleSvcConnectionInterfaceLocation *iface,
const GArray *contacts,
@@ -122,43 +149,32 @@ location_get_locations (GabbleSvcConnectionInterfaceLocation *iface,
return;
}
-
for (i = 0; i < contacts->len; i++)
{
- TpHandleRepoIface *contact_repo;
- const gchar *jid;
GHashTable *location;
TpHandle contact = g_array_index (contacts, TpHandle, i);
- contact_repo = tp_base_connection_get_handles (base,
- TP_HANDLE_TYPE_CONTACT);
- jid = tp_handle_inspect (contact_repo, contact);
-
- location = gabble_presence_cache_get_location (conn->presence_cache,
- contact);
- if (location != NULL)
- {
- DEBUG (" - %s: cached", jid);
- g_hash_table_insert (return_locations, GUINT_TO_POINTER (contact),
- location);
- }
- else if (!pubsub_query (conn, jid, NS_GEOLOC, pep_reply_cb, NULL))
+ location = get_cached_location_or_query (conn, contact, &error);
+ if (error != NULL)
{
GError error2 = { TP_ERRORS, TP_ERROR_NETWORK_ERROR,
"Sending PEP location query failed" };
+ DEBUG ("Sending PEP location query failed: %s", error->message);
+ g_error_free (error);
dbus_g_method_return_error (context, &error2);
g_hash_table_unref (return_locations);
-
return;
- } else
- DEBUG (" - %s: requested", jid);
+ }
+
+ if (location != NULL)
+ g_hash_table_insert (return_locations, GUINT_TO_POINTER (contact),
+ location);
}
gabble_svc_connection_interface_location_return_from_get_locations
(context, return_locations);
g_hash_table_unref (return_locations);
-
}
static gboolean
--
1.5.6.5
More information about the telepathy-commits
mailing list