client_manager: add API for async operations
[oweals/gnunet.git] / src / include / gnunet_datastore_plugin.h
index 082173fff2540f189e75c841e9136948fca1971b..efca0baed941dde7ebd0e5adc1b96f1074adefad 100644 (file)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet
-     (C) 2009, 2011 Christian Grothoff (and other contributing authors)
+     Copyright (C) 2009, 2011 Christian Grothoff (and other contributing authors)
 
      GNUnet is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published
@@ -102,10 +102,27 @@ typedef int (*PluginDatumProcessor) (void *cls, const struct GNUNET_HashCode * k
  * Get an estimate of how much space the database is
  * currently using.
  *
+ * NB: estimate is an output parameter because emscripten cannot handle
+ * returning 64-bit integers from dynamically loaded modules.
+ *
  * @param cls closure
+ * @param estimate location to store estimate
  * @return number of bytes used on disk
  */
-typedef unsigned long long (*PluginEstimateSize) (void *cls);
+typedef void (*PluginEstimateSize) (void *cls, unsigned long long *estimate);
+
+
+/**
+ * Put continuation.
+ *
+ * @param cls closure
+ * @param key key for the item stored
+ * @param size size of the item stored
+ * @param status GNUNET_OK or GNUNET_SYSERROR
+ * @param msg error message on error
+ */
+typedef void (*PluginPutCont) (void *cls, const struct GNUNET_HashCode *key,
+                               uint32_t size, int status, char *msg);
 
 
 /**
@@ -122,22 +139,23 @@ typedef unsigned long long (*PluginEstimateSize) (void *cls);
  * @param anonymity anonymity-level for the content
  * @param replication replication-level for the content
  * @param expiration expiration time for the content
- * @param msg set to an error message (on failure)
- * @return #GNUNET_OK on success,
- *         #GNUNET_SYSERR on failure
+ * @param cont continuation called with success or failure status
+ * @param cont_cls continuation closure
  */
-typedef int (*PluginPut) (void *cls, const struct GNUNET_HashCode * key, uint32_t size,
-                          const void *data, enum GNUNET_BLOCK_Type type,
-                          uint32_t priority, uint32_t anonymity,
-                          uint32_t replication,
-                          struct GNUNET_TIME_Absolute expiration, char **msg);
+typedef void (*PluginPut) (void *cls, const struct GNUNET_HashCode * key,
+                           uint32_t size,
+                           const void *data, enum GNUNET_BLOCK_Type type,
+                           uint32_t priority, uint32_t anonymity,
+                           uint32_t replication,
+                           struct GNUNET_TIME_Absolute expiration,
+                           PluginPutCont cont, void *cont_cls);
 
 
 /**
  * An processor over a set of keys stored in the datastore.
  *
  * @param cls closure
- * @param key key in the data store
+ * @param key key in the data store, if NULL iteration is finished
  * @param count how many values are stored under this key in the datastore
  */
 typedef void (*PluginKeyProcessor) (void *cls,
@@ -170,8 +188,6 @@ typedef void (*PluginGetKeys) (void *cls,
  *        there may be!
  * @param type entries of which type are relevant?
  *     Use 0 for any type.
- * @param min find the smallest key that is larger than the given min,
- *            NULL for no minimum (return smallest key)
  * @param proc function to call on the matching value;
  *        proc should be called with NULL if there is no result
  * @param proc_cls closure for @a proc
@@ -197,6 +213,14 @@ typedef void (*PluginGetRandom) (void *cls, PluginDatumProcessor proc,
                                  void *proc_cls);
 
 
+/**
+ * Update continuation.
+ *
+ * @param cls closure
+ * @param status GNUNET_OK or GNUNET_SYSERROR
+ * @param msg error message on error
+ */
+typedef void (*PluginUpdateCont) (void *cls, int status, char *msg);
 
 
 /**
@@ -216,11 +240,12 @@ typedef void (*PluginGetRandom) (void *cls, PluginDatumProcessor proc,
  * @param expire new expiration time should be the
  *     MAX of any existing expiration time and
  *     this value
- * @param msg set to an error message (on error)
- * @return #GNUNET_OK on success
+ * @param cont continuation called with success or failure status
+ * @param cons_cls continuation closure
  */
-typedef int (*PluginUpdate) (void *cls, uint64_t uid, int delta,
-                             struct GNUNET_TIME_Absolute expire, char **msg);
+typedef void (*PluginUpdate) (void *cls, uint64_t uid, int delta,
+                              struct GNUNET_TIME_Absolute expire,
+                              PluginUpdateCont cont, void *cont_cls);
 
 
 /**