[Telepathy-commits] [telepathy-gabble/master] PresenceCache: define an "unsure" period 5 seconds after cache creation

Senko Rasic senko.rasic at collabora.co.uk
Thu Dec 4 07:12:53 PST 2008


---
 src/presence-cache.c |   23 +++++++++++++++++++++++
 src/presence-cache.h |    2 ++
 2 files changed, 25 insertions(+), 0 deletions(-)

diff --git a/src/presence-cache.c b/src/presence-cache.c
index 9d53f74..6bb2c22 100644
--- a/src/presence-cache.c
+++ b/src/presence-cache.c
@@ -50,6 +50,10 @@
  */
 #define CAPABILITY_BUNDLE_ENOUGH_TRUST 5
 
+/* Time period from the cache creation in which we're unsure whether we
+ * got initial presence from all the contacts. */
+#define UNSURE_PERIOD (5 * G_USEC_PER_SEC)
+
 G_DEFINE_TYPE (GabblePresenceCache, gabble_presence_cache, G_TYPE_OBJECT);
 
 /* properties */
@@ -88,6 +92,7 @@ struct _GabblePresenceCachePrivate
   GHashTable *disco_pending;
   guint caps_serial;
 
+  GTimeVal creation_time;
   gboolean dispose_has_run;
 };
 
@@ -357,6 +362,8 @@ gabble_presence_cache_constructor (GType type, guint n_props,
   priv->status_changed_cb = g_signal_connect (priv->conn, "status-changed",
       G_CALLBACK (gabble_presence_cache_status_changed_cb), obj);
 
+  g_get_current_time (&priv->creation_time);
+
   return obj;
 }
 
@@ -1599,3 +1606,19 @@ gabble_presence_cache_caps_pending (GabblePresenceCache *cache,
   return FALSE;
 }
 
+gboolean
+gabble_presence_cache_is_unsure (GabblePresenceCache *cache)
+{
+  gulong diff;
+  GabblePresenceCachePrivate *priv = GABBLE_PRESENCE_CACHE_PRIV (cache);
+  GTimeVal now;
+
+  g_get_current_time (&now);
+  diff = (now.tv_sec - priv->creation_time.tv_sec) * G_USEC_PER_SEC +
+      (now.tv_usec - priv->creation_time.tv_usec);
+
+  DEBUG ("Diff: %lu", diff);
+
+  return (diff < UNSURE_PERIOD);
+}
+
diff --git a/src/presence-cache.h b/src/presence-cache.h
index dbfaccf..7a19ebe 100644
--- a/src/presence-cache.h
+++ b/src/presence-cache.h
@@ -94,6 +94,8 @@ void gabble_presence_cache_contacts_removed_from_olpc_view (
 gboolean gabble_presence_cache_caps_pending (GabblePresenceCache *cache,
     TpHandle handle);
 
+gboolean gabble_presence_cache_is_unsure (GabblePresenceCache *cache);
+
 G_END_DECLS
 
 #endif /* __GABBLE_PRESENCE_CACHE_H__ */
-- 
1.5.6.5




More information about the Telepathy-commits mailing list