[evolution-kolab] libekolabutil: new helper functions for folder timestamp bookkeeping



commit e3ee5e91f3ac9986b55572dca000cf6042f8ce59
Author: Christian Hilberg <hilberg kernelconcepts de>
Date:   Fri Sep 21 16:57:32 2012 +0200

    libekolabutil: new helper functions for folder timestamp bookkeeping
    
    * new API functions for maintaining monotone timestamps
      for folder names:
    * new/free functions for the hash table structure
    * folder timestamp update function (sets a new
      timestamp for the named folder)
    * lookup function for a folder timestamp
    * query function for elapsed time since last update

 src/libekolabutil/kolab-util-folder.c |   92 +++++++++++++++++++++++++++++++++
 src/libekolabutil/kolab-util-folder.h |   20 +++++++
 2 files changed, 112 insertions(+), 0 deletions(-)
---
diff --git a/src/libekolabutil/kolab-util-folder.c b/src/libekolabutil/kolab-util-folder.c
index 1cdc3e8..50c63d1 100644
--- a/src/libekolabutil/kolab-util-folder.c
+++ b/src/libekolabutil/kolab-util-folder.c
@@ -214,3 +214,95 @@ kolab_util_folder_descriptor_glist_free (GList *list)
 }
 
 /*----------------------------------------------------------------------------*/
+
+GHashTable*
+kolab_util_folder_timestamp_table_new (void)
+{
+	GHashTable *table =
+		g_hash_table_new_full (g_str_hash,
+		                       g_str_equal,
+		                       g_free,
+		                       g_free);
+	return table;
+}
+
+void
+kolab_util_folder_timestamp_table_free (GHashTable *table)
+{
+	g_return_if_fail (table != NULL);
+	g_hash_table_destroy (table);
+}
+
+void
+kolab_util_folder_timestamp_table_update (GHashTable *table,
+                                          const gchar *foldername)
+{
+	gint64 timestamp = 0;
+	gint64 *stamp_ptr = NULL;
+	
+	g_return_if_fail (table != NULL);
+	g_return_if_fail (foldername != NULL);
+
+	timestamp = g_get_monotonic_time ();
+	g_return_if_fail (timestamp >= 0);
+	
+	stamp_ptr = (gint64*) g_malloc0 (sizeof (gint64));
+	g_return_if_fail (stamp_ptr != NULL);
+
+	*stamp_ptr = timestamp;
+
+	g_hash_table_replace (table,
+	                      g_strdup (foldername),
+	                      stamp_ptr);
+}
+
+gint64
+kolab_util_folder_timestamp_table_lookup (GHashTable *table,
+                                          const gchar *foldername)
+{
+	gint64 timestamp = 0;
+	gpointer stamp_ptr = NULL;
+
+	g_return_val_if_fail (table != NULL, -1);
+	g_return_val_if_fail (foldername != NULL, -1);
+
+	stamp_ptr = g_hash_table_lookup (table,
+	                                 foldername);
+	if (stamp_ptr == NULL)
+		return -1;
+
+	timestamp = *((gint64*) stamp_ptr);
+
+	return timestamp;
+}
+
+gint64
+kolab_util_folder_timestamp_table_msec_since_update (GHashTable *table,
+                                                     const gchar *foldername)
+{
+	gint64 timestamp_current = 0;
+	gint64 timestamp_latest = 0;
+	gint64 timestamp_diff = 0;
+
+	g_return_val_if_fail (table != NULL, -1);
+	g_return_val_if_fail (foldername != NULL, -1);
+
+	timestamp_current = g_get_monotonic_time ();
+	g_return_val_if_fail (timestamp_current >= 0, -1);
+
+	timestamp_latest =
+		kolab_util_folder_timestamp_table_lookup (table,
+		                                          foldername);
+	if (timestamp_latest < 0)
+		return -1;
+
+	timestamp_diff = timestamp_current - timestamp_latest;
+
+	if (timestamp_diff < 0)
+		timestamp_diff = -1;
+
+	return timestamp_diff;
+}
+
+/*----------------------------------------------------------------------------*/
+
diff --git a/src/libekolabutil/kolab-util-folder.h b/src/libekolabutil/kolab-util-folder.h
index a2a1a3f..c57a44e 100644
--- a/src/libekolabutil/kolab-util-folder.h
+++ b/src/libekolabutil/kolab-util-folder.h
@@ -99,6 +99,8 @@ struct _KolabFolderDescriptor {
 	KolabFolderTypeID type_id;
 };
 
+#define KOLAB_FOLDER_UPDATE_DELAY_MICROSECS ((gint64) 13000000)
+
 /*----------------------------------------------------------------------------*/
 
 KolabFolderTypeID
@@ -123,6 +125,24 @@ kolab_util_folder_descriptor_free (KolabFolderDescriptor *desc);
 void
 kolab_util_folder_descriptor_glist_free (GList *list);
 
+GHashTable*
+kolab_util_folder_timestamp_table_new (void);
+
+void
+kolab_util_folder_timestamp_table_free (GHashTable *table);
+
+void
+kolab_util_folder_timestamp_table_update (GHashTable *table,
+                                          const gchar *foldername);
+
+gint64
+kolab_util_folder_timestamp_table_lookup (GHashTable *table,
+                                          const gchar *foldername);
+
+gint64
+kolab_util_folder_timestamp_table_msec_since_update (GHashTable *table,
+                                                     const gchar *foldername);
+
 /*----------------------------------------------------------------------------*/
 
 #endif /* _KOLAB_UTIL_FOLDER_ */



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]