Implement data ack in CADET MQ API
[oweals/gnunet.git] / src / include / gnunet_load_lib.h
1 /*
2      This file is part of GNUnet.
3      Copyright (C) 2010 GNUnet e.V.
4
5      GNUnet is free software; you can redistribute it and/or modify
6      it under the terms of the GNU General Public License as published
7      by the Free Software Foundation; either version 3, or (at your
8      option) any later version.
9
10      GNUnet is distributed in the hope that it will be useful, but
11      WITHOUT ANY WARRANTY; without even the implied warranty of
12      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13      General Public License for more details.
14
15      You should have received a copy of the GNU General Public License
16      along with GNUnet; see the file COPYING.  If not, write to the
17      Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18      Boston, MA 02110-1301, USA.
19 */
20
21 /**
22  * @author Christian Grothoff
23  *
24  * @file
25  * Functions related to load calculations
26  *
27  * @defgroup load  Load library
28  * Load calculations.
29  * @{
30  */
31
32 #ifndef GNUNET_LOAD_LIB_H
33 #define GNUNET_LOAD_LIB_H
34
35 #ifdef __cplusplus
36 extern "C"
37 {
38 #if 0                           /* keep Emacsens' auto-indent happy */
39 }
40 #endif
41 #endif
42
43 #include "gnunet_common.h"
44 #include "gnunet_time_lib.h"
45
46 /**
47  * Opaque load handle.
48  */
49 struct GNUNET_LOAD_Value;
50
51 /**
52  * Create a new load value.
53  *
54  * @param autodecline speed at which this value should automatically
55  *        decline in the absence of external events; at the given
56  *        frequency, 0-load values will be added to the load
57  * @return the new load value
58  */
59 struct GNUNET_LOAD_Value *
60 GNUNET_LOAD_value_init (struct GNUNET_TIME_Relative autodecline);
61
62
63 /**
64  * Change the value by which the load automatically declines.
65  *
66  * @param load load to update
67  * @param autodecline frequency of load decline
68  */
69 void
70 GNUNET_LOAD_value_set_decline (struct GNUNET_LOAD_Value *load,
71                                struct GNUNET_TIME_Relative autodecline);
72
73
74 /**
75  * Free a load value.
76  *
77  * @param lv value to free
78  */
79 #define GNUNET_LOAD_value_free(lv) GNUNET_free (lv)
80
81
82 /**
83  * Get the current load.
84  *
85  * @param load load handle
86  * @return zero for below-average load, otherwise
87  *         number of std. devs we are above average;
88  *         100 if the latest updates were so large
89  *         that we could not do proper calculations
90  */
91 double
92 GNUNET_LOAD_get_load (struct GNUNET_LOAD_Value *load);
93
94
95 /**
96  * Get the average value given to update so far.
97  *
98  * @param load load handle
99  * @return zero if update was never called
100  */
101 double
102 GNUNET_LOAD_get_average (struct GNUNET_LOAD_Value *load);
103
104
105 /**
106  * Update the current load.
107  *
108  * @param load to update
109  * @param data latest measurement value (for example, delay)
110  */
111 void
112 GNUNET_LOAD_update (struct GNUNET_LOAD_Value *load, uint64_t data);
113
114
115 #if 0                           /* keep Emacsens' auto-indent happy */
116 {
117 #endif
118 #ifdef __cplusplus
119 }
120 #endif
121
122 /* ifndef GNUNET_LOAD_LIB_H */
123 #endif
124
125 /** @} */  /* end of group */
126
127 /* end of gnunet_load_lib.h */