check
[oweals/gnunet.git] / src / include / gnunet_statistics_service.h
1 /*
2       This file is part of GNUnet
3       (C) 2009, 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_statistics_service.h
23  * @brief API to create, modify and access statistics about
24  *        the operation of GNUnet; all statistical values
25  *        must be of type "unsigned long long".
26  * @author Christian Grothoff
27  */
28
29 #ifndef GNUNET_STATISTICS_SERVICE_H
30 #define GNUNET_STATISTICS_SERVICE_H
31
32 #ifdef __cplusplus
33 extern "C"
34 {
35 #if 0                           /* keep Emacsens' auto-indent happy */
36 }
37 #endif
38 #endif
39
40 #include "gnunet_common.h"
41 #include "gnunet_configuration_lib.h"
42 #include "gnunet_scheduler_lib.h"
43
44 /**
45  * Version of the statistics API.
46  */
47 #define GNUNET_STATISTICS_VERSION 0x00000000
48
49 /**
50  * Opaque handle for the statistics service.
51  */
52 struct GNUNET_STATISTICS_Handle;
53
54 /**
55  * Callback function to process statistic values.
56  *
57  * @param cls closure
58  * @param subsystem name of subsystem that created the statistic
59  * @param name the name of the datum
60  * @param value the current value
61  * @param is_persistent GNUNET_YES if the value is persistent, GNUNET_NO if not
62  * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration
63  */
64 typedef int (*GNUNET_STATISTICS_Iterator) (void *cls,
65                                            const char *subsystem,
66                                            const char *name,
67                                            uint64_t value,
68                                            int is_persistent);
69
70 /**
71  * Get handle for the statistics service.
72  *
73  * @param subsystem name of subsystem using the service
74  * @param cfg services configuration in use
75  * @return handle to use
76  */
77 struct GNUNET_STATISTICS_Handle
78   *GNUNET_STATISTICS_create (const char *subsystem,
79                              const struct GNUNET_CONFIGURATION_Handle *cfg);
80
81
82 /**
83  * Destroy a handle (free all state associated with
84  * it).
85  *
86  * @param h statistics handle to destroy
87  * @param sync_first set to GNUNET_YES if pending SET requests should
88  *        be completed
89  */
90 void GNUNET_STATISTICS_destroy (struct GNUNET_STATISTICS_Handle *h,
91                                 int sync_first);
92
93
94 /**
95  * Watch statistics from the peer (be notified whenever they change).
96  * Note that the only way to cancel a "watch" request is to destroy
97  * the statistics handle given as the first argument to this call.
98  *
99  * @param handle identification of the statistics service
100  * @param subsystem limit to the specified subsystem, never NULL
101  * @param name name of the statistic value, never NULL
102  * @param proc function to call on each value
103  * @param proc_cls closure for proc
104  * @return GNUNET_OK on success, GNUNET_SYSERR on error
105  */
106 int
107 GNUNET_STATISTICS_watch (struct GNUNET_STATISTICS_Handle *handle,
108                          const char *subsystem,
109                          const char *name,
110                          GNUNET_STATISTICS_Iterator proc, 
111                          void *proc_cls);
112
113
114 /**
115  * Continuation called by the "get_all" and "get" functions.
116  *
117  * @param cls closure
118  * @param success GNUNET_OK if statistics were
119  *        successfully obtained, GNUNET_SYSERR if not.
120  */
121 typedef void (*GNUNET_STATISTICS_Callback) (void *cls, int success);
122
123 /**
124  * Handle that can be used to cancel a statistics 'get' operation.
125  */
126 struct GNUNET_STATISTICS_GetHandle;
127
128 /**
129  * Get statistic from the peer.
130  *
131  * @param handle identification of the statistics service
132  * @param subsystem limit to the specified subsystem, NULL for our subsystem
133  * @param name name of the statistic value, NULL for all values
134  * @param timeout after how long should we give up (and call
135  *        notify with buf NULL and size 0)?
136  * @param cont continuation to call when done (can be NULL)
137  * @param proc function to call on each value
138  * @param cls closure for proc and cont
139  * @return NULL on error
140  */
141 struct GNUNET_STATISTICS_GetHandle *
142 GNUNET_STATISTICS_get (struct GNUNET_STATISTICS_Handle *handle,
143                        const char *subsystem,
144                        const char *name,
145                        struct GNUNET_TIME_Relative timeout,
146                        GNUNET_STATISTICS_Callback cont,
147                        GNUNET_STATISTICS_Iterator proc, void *cls);
148
149
150 /**
151  * Cancel a 'get' request.  Must be called before the 'cont' 
152  * function is called.
153  *
154  * @param gh handle of the request to cancel
155  */
156 void
157 GNUNET_STATISTICS_get_cancel (struct GNUNET_STATISTICS_GetHandle *gh);
158
159
160 /**
161  * Set statistic value for the peer.  Will always use our
162  * subsystem (the argument used when "handle" was created).
163  *
164  * @param handle identification of the statistics service
165  * @param name name of the statistic value
166  * @param value new value to set
167  * @param make_persistent should the value be kept across restarts?
168  */
169 void
170 GNUNET_STATISTICS_set (struct GNUNET_STATISTICS_Handle *handle,
171                        const char *name,
172                        uint64_t value, int make_persistent);
173
174 /**
175  * Set statistic value for the peer.  Will always use our
176  * subsystem (the argument used when "handle" was created).
177  *
178  * @param handle identification of the statistics service
179  * @param name name of the statistic value
180  * @param delta change in value (added to existing value)
181  * @param make_persistent should the value be kept across restarts?
182  */
183 void
184 GNUNET_STATISTICS_update (struct GNUNET_STATISTICS_Handle *handle,
185                           const char *name,
186                           int64_t delta, int make_persistent);
187
188
189
190 #if 0                           /* keep Emacsens' auto-indent happy */
191 {
192 #endif
193 #ifdef __cplusplus
194 }
195 #endif
196
197 #endif