-peer review
[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, const char *subsystem,
65                                            const char *name, uint64_t value,
66                                            int is_persistent);
67
68 /**
69  * Get handle for the statistics service.
70  *
71  * @param subsystem name of subsystem using the service
72  * @param cfg services configuration in use
73  * @return handle to use
74  */
75 struct GNUNET_STATISTICS_Handle *
76 GNUNET_STATISTICS_create (const char *subsystem,
77                           const struct GNUNET_CONFIGURATION_Handle *cfg);
78
79
80 /**
81  * Destroy a handle (free all state associated with
82  * it).
83  *
84  * @param h statistics handle to destroy
85  * @param sync_first set to GNUNET_YES if pending SET requests should
86  *        be completed
87  */
88 void
89 GNUNET_STATISTICS_destroy (struct GNUNET_STATISTICS_Handle *h, int sync_first);
90
91
92 /**
93  * Watch statistics from the peer (be notified whenever they change).
94  *
95  * @param handle identification of the statistics service
96  * @param subsystem limit to the specified subsystem, never NULL
97  * @param name name of the statistic value, never NULL
98  * @param proc function to call on each value
99  * @param proc_cls closure for proc
100  * @return GNUNET_OK on success, GNUNET_SYSERR on error
101  */
102 int
103 GNUNET_STATISTICS_watch (struct GNUNET_STATISTICS_Handle *handle,
104                          const char *subsystem, const char *name,
105                          GNUNET_STATISTICS_Iterator proc, void *proc_cls);
106
107
108 /**
109  * Stop watching statistics from the peer.
110  *
111  * @param handle identification of the statistics service
112  * @param subsystem limit to the specified subsystem, never NULL
113  * @param name name of the statistic value, never NULL
114  * @param proc function to call on each value
115  * @param proc_cls closure for proc
116  * @return GNUNET_OK on success, GNUNET_SYSERR on error (no such watch)
117  */
118 int
119 GNUNET_STATISTICS_watch_cancel (struct GNUNET_STATISTICS_Handle *handle,
120                                 const char *subsystem, const char *name,
121                                 GNUNET_STATISTICS_Iterator proc, void *proc_cls);
122
123
124 /**
125  * Continuation called by the "get_all" and "get" functions.
126  *
127  * @param cls closure
128  * @param success GNUNET_OK if statistics were
129  *        successfully obtained, GNUNET_SYSERR if not.
130  */
131 typedef void (*GNUNET_STATISTICS_Callback) (void *cls, int success);
132
133
134 /**
135  * Handle that can be used to cancel a statistics 'get' operation.
136  */
137 struct GNUNET_STATISTICS_GetHandle;
138
139 /**
140  * Get statistic from the peer.
141  *
142  * @param handle identification of the statistics service
143  * @param subsystem limit to the specified subsystem, NULL for our subsystem
144  * @param name name of the statistic value, NULL for all values
145  * @param timeout after how long should we give up (and call
146  *        notify with buf NULL and size 0)?
147  * @param cont continuation to call when done (can be NULL)
148  *        This callback CANNOT destroy the statistics handle in the same call.
149  * @param proc function to call on each value
150  * @param cls closure for proc and cont
151  * @return NULL on error
152  */
153 struct GNUNET_STATISTICS_GetHandle *
154 GNUNET_STATISTICS_get (struct GNUNET_STATISTICS_Handle *handle,
155                        const char *subsystem, const char *name,
156                        struct GNUNET_TIME_Relative timeout,
157                        GNUNET_STATISTICS_Callback cont,
158                        GNUNET_STATISTICS_Iterator proc, void *cls);
159
160
161 /**
162  * Cancel a 'get' request.  Must be called before the 'cont'
163  * function is called.
164  *
165  * @param gh handle of the request to cancel
166  */
167 void
168 GNUNET_STATISTICS_get_cancel (struct GNUNET_STATISTICS_GetHandle *gh);
169
170
171 /**
172  * Set statistic value for the peer.  Will always use our
173  * subsystem (the argument used when "handle" was created).
174  *
175  * @param handle identification of the statistics service
176  * @param name name of the statistic value
177  * @param value new value to set
178  * @param make_persistent should the value be kept across restarts?
179  */
180 void
181 GNUNET_STATISTICS_set (struct GNUNET_STATISTICS_Handle *handle,
182                        const char *name, uint64_t value, int make_persistent);
183
184 /**
185  * Set statistic value for the peer.  Will always use our
186  * subsystem (the argument used when "handle" was created).
187  *
188  * @param handle identification of the statistics service
189  * @param name name of the statistic value
190  * @param delta change in value (added to existing value)
191  * @param make_persistent should the value be kept across restarts?
192  */
193 void
194 GNUNET_STATISTICS_update (struct GNUNET_STATISTICS_Handle *handle,
195                           const char *name, int64_t delta, int make_persistent);
196
197
198
199 #if 0                           /* keep Emacsens' auto-indent happy */
200 {
201 #endif
202 #ifdef __cplusplus
203 }
204 #endif
205
206 #endif