d56522d4008497ff3040c6b92f897c2ad92a297e
[oweals/gnunet.git] / src / include / gnunet_load_lib.h
1 /*
2      This file is part of GNUnet.
3      (C) 2010 Christian Grothoff (and other contributing authors)
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 2, 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., 59 Temple Place - Suite 330,
18      Boston, MA 02111-1307, USA.
19 */
20
21 /**
22  * @file include/gnunet_load_lib.h
23  * @brief functions related to load calculations
24  * @author Christian Grothoff
25  */
26
27 #ifndef GNUNET_LOAD_LIB_H
28 #define GNUNET_LOAD_LIB_H
29
30 #ifdef __cplusplus
31 extern "C"
32 {
33 #if 0                           /* keep Emacsens' auto-indent happy */
34 }
35 #endif
36 #endif
37
38 #include "gnunet_common.h"
39 #include "gnunet_time_lib.h"
40
41 /**
42  * Opaque load handle.
43  */
44 struct GNUNET_LOAD_Value;
45
46 /**
47  * Create a new load value.
48  *
49  * @param autodecline speed at which this value should automatically
50  *        decline in the absence of external events; at the given
51  *        frequency, 0-load values will be added to the load
52  * @return the new load value
53  */
54 struct GNUNET_LOAD_Value *GNUNET_LOAD_value_init (struct GNUNET_TIME_Relative
55                                                   autodecline);
56
57
58 /**
59  * Change the value by which the load automatically declines.
60  *
61  * @param load load to update
62  * @param autodecline frequency of load decline
63  */
64 void GNUNET_LOAD_value_set_decline (struct GNUNET_LOAD_Value *load,
65                                     struct GNUNET_TIME_Relative autodecline);
66
67
68 /**
69  * Free a load value.
70  *
71  * @param lv value to free
72  */
73 #define GNUNET_LOAD_value_free(lv) GNUNET_free (lv)
74
75
76 /**
77  * Get the current load.
78  *
79  * @param load load handle
80  * @return zero for below-average load, otherwise
81  *         number of std. devs we are above average;
82  *         100 if the latest updates were so large
83  *         that we could not do proper calculations
84  */
85 double GNUNET_LOAD_get_load (struct GNUNET_LOAD_Value *load);
86
87
88 /**
89  * Get the average value given to update so far.
90  *
91  * @param load load handle
92  * @return zero if update was never called
93  */
94 double GNUNET_LOAD_get_average (struct GNUNET_LOAD_Value *load);
95
96
97 /**
98  * Update the current load.
99  *
100  * @param load to update
101  * @param data latest measurement value (for example, delay)
102  */
103 void GNUNET_LOAD_update (struct GNUNET_LOAD_Value *load, uint64_t data);
104
105
106 #if 0                           /* keep Emacsens' auto-indent happy */
107 {
108 #endif
109 #ifdef __cplusplus
110 }
111 #endif
112
113 /* ifndef GNUNET_LOAD_LIB_H */
114 #endif
115 /* end of gnunet_load_lib.h */