Smallers steps to keep plugin running
[oweals/gnunet.git] / src / include / gnunet_statistics_service.h
index 8dd11094c88ddcc3c2c94801e6e11935420fcde3..71c834f2afc7c52420b93a78292c627c6754bdd1 100644 (file)
@@ -1,6 +1,6 @@
 /*
       This file is part of GNUnet
-      (C) 2009 Christian Grothoff (and other contributing authors)
+      (C) 2009, 2010 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
@@ -64,7 +64,7 @@ struct GNUNET_STATISTICS_Handle;
 typedef int (*GNUNET_STATISTICS_Iterator) (void *cls,
                                            const char *subsystem,
                                            const char *name,
-                                           unsigned long long value,
+                                           uint64_t value,
                                            int is_persistent);
 
 /**
@@ -78,14 +78,39 @@ typedef int (*GNUNET_STATISTICS_Iterator) (void *cls,
 struct GNUNET_STATISTICS_Handle
   *GNUNET_STATISTICS_create (struct GNUNET_SCHEDULER_Handle *sched,
                              const char *subsystem,
-                             struct GNUNET_CONFIGURATION_Handle *cfg);
+                             const struct GNUNET_CONFIGURATION_Handle *cfg);
 
 
 /**
  * Destroy a handle (free all state associated with
  * it).
+ *
+ * @param h statistics handle to destroy
+ * @param sync_first set to GNUNET_YES if pending SET requests should
+ *        be completed
+ */
+void GNUNET_STATISTICS_destroy (struct GNUNET_STATISTICS_Handle *h,
+                               int sync_first);
+
+
+/**
+ * Watch statistics from the peer (be notified whenever they change).
+ * Note that the only way to cancel a "watch" request is to destroy
+ * the statistics handle given as the first argument to this call.
+ *
+ * @param handle identification of the statistics service
+ * @param subsystem limit to the specified subsystem, never NULL
+ * @param name name of the statistic value, never NULL
+ * @param proc function to call on each value
+ * @param proc_cls closure for proc
+ * @return GNUNET_OK on success, GNUNET_SYSERR on error
  */
-void GNUNET_STATISTICS_destroy (struct GNUNET_STATISTICS_Handle *handle);
+int
+GNUNET_STATISTICS_watch (struct GNUNET_STATISTICS_Handle *handle,
+                        const char *subsystem,
+                        const char *name,
+                        GNUNET_STATISTICS_Iterator proc, 
+                        void *proc_cls);
 
 
 /**
@@ -97,6 +122,11 @@ void GNUNET_STATISTICS_destroy (struct GNUNET_STATISTICS_Handle *handle);
  */
 typedef void (*GNUNET_STATISTICS_Callback) (void *cls, int success);
 
+/**
+ * Handle that can be used to cancel a statistics 'get' operation.
+ */
+struct GNUNET_STATISTICS_GetHandle;
+
 /**
  * Get statistic from the peer.
  *
@@ -108,8 +138,9 @@ typedef void (*GNUNET_STATISTICS_Callback) (void *cls, int success);
  * @param cont continuation to call when done (can be NULL)
  * @param proc function to call on each value
  * @param cls closure for proc and cont
+ * @return NULL on error
  */
-void
+struct GNUNET_STATISTICS_GetHandle *
 GNUNET_STATISTICS_get (struct GNUNET_STATISTICS_Handle *handle,
                        const char *subsystem,
                        const char *name,
@@ -117,6 +148,17 @@ GNUNET_STATISTICS_get (struct GNUNET_STATISTICS_Handle *handle,
                        GNUNET_STATISTICS_Callback cont,
                        GNUNET_STATISTICS_Iterator proc, void *cls);
 
+
+/**
+ * Cancel a 'get' request.  Must be called before the 'cont' 
+ * function is called.
+ *
+ * @param gh handle of the request to cancel
+ */
+void
+GNUNET_STATISTICS_get_cancel (struct GNUNET_STATISTICS_GetHandle *gh);
+
+
 /**
  * Set statistic value for the peer.  Will always use our
  * subsystem (the argument used when "handle" was created).
@@ -129,7 +171,7 @@ GNUNET_STATISTICS_get (struct GNUNET_STATISTICS_Handle *handle,
 void
 GNUNET_STATISTICS_set (struct GNUNET_STATISTICS_Handle *handle,
                        const char *name,
-                       unsigned long long value, int make_persistent);
+                       uint64_t value, int make_persistent);
 
 /**
  * Set statistic value for the peer.  Will always use our
@@ -143,7 +185,7 @@ GNUNET_STATISTICS_set (struct GNUNET_STATISTICS_Handle *handle,
 void
 GNUNET_STATISTICS_update (struct GNUNET_STATISTICS_Handle *handle,
                           const char *name,
-                          long long delta, int make_persistent);
+                          int64_t delta, int make_persistent);