-more datacache integration work
[oweals/gnunet.git] / src / include / gnunet_statistics_service.h
1 /*
2       This file is part of GNUnet
3       Copyright (C) 2009-2013 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 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., 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  * @defgroup statistics track statistics or provide access to statistics
28  * @{
29  */
30
31 #ifndef GNUNET_STATISTICS_SERVICE_H
32 #define GNUNET_STATISTICS_SERVICE_H
33
34 #ifdef __cplusplus
35 extern "C"
36 {
37 #if 0                           /* keep Emacsens' auto-indent happy */
38 }
39 #endif
40 #endif
41
42 #include "gnunet_util_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
65 (*GNUNET_STATISTICS_Iterator) (void *cls,
66                                const char *subsystem,
67                                const char *name,
68                                uint64_t value,
69                                int is_persistent);
70
71
72 /**
73  * Get handle for the statistics service.
74  *
75  * @param subsystem name of subsystem using the service
76  * @param cfg services configuration in use
77  * @return handle to use
78  */
79 struct GNUNET_STATISTICS_Handle *
80 GNUNET_STATISTICS_create (const char *subsystem,
81                           const struct GNUNET_CONFIGURATION_Handle *cfg);
82
83
84 /**
85  * Destroy a handle (free all state associated with it).
86  *
87  * @param h statistics handle to destroy
88  * @param sync_first set to #GNUNET_YES if pending SET requests should
89  *        be completed
90  */
91 void
92 GNUNET_STATISTICS_destroy (struct GNUNET_STATISTICS_Handle *h,
93                            int sync_first);
94
95
96 /**
97  * Watch statistics from the peer (be notified whenever they change).
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 @a 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  * Stop watching statistics from the peer.
116  *
117  * @param handle identification of the statistics service
118  * @param subsystem limit to the specified subsystem, never NULL
119  * @param name name of the statistic value, never NULL
120  * @param proc function to call on each value
121  * @param proc_cls closure for @a proc
122  * @return #GNUNET_OK on success, #GNUNET_SYSERR on error (no such watch)
123  */
124 int
125 GNUNET_STATISTICS_watch_cancel (struct GNUNET_STATISTICS_Handle *handle,
126                                 const char *subsystem,
127                                 const char *name,
128                                 GNUNET_STATISTICS_Iterator proc,
129                                 void *proc_cls);
130
131
132 /**
133  * Continuation called by #GNUNET_STATISTICS_get functions.
134  *
135  * @param cls closure
136  * @param success #GNUNET_OK if statistics were
137  *        successfully obtained, #GNUNET_SYSERR if not.
138  */
139 typedef void (*GNUNET_STATISTICS_Callback) (void *cls,
140                                             int success);
141
142
143 /**
144  * Handle that can be used to cancel a statistics 'get' operation.
145  */
146 struct GNUNET_STATISTICS_GetHandle;
147
148
149 /**
150  * Get statistic from the peer.
151  *
152  * @param handle identification of the statistics service
153  * @param subsystem limit to the specified subsystem, NULL for all subsystems
154  * @param name name of the statistic value, NULL for all values
155  * @param timeout after how long should we give up (and call
156  *        notify with buf NULL and size 0)?
157  * @param cont continuation to call when done (can be NULL)
158  *        This callback CANNOT destroy the statistics handle in the same call.
159  * @param proc function to call on each value
160  * @param cls closure for @a proc and @a cont
161  * @return NULL on error
162  */
163 struct GNUNET_STATISTICS_GetHandle *
164 GNUNET_STATISTICS_get (struct GNUNET_STATISTICS_Handle *handle,
165                        const char *subsystem,
166                        const char *name,
167                        struct GNUNET_TIME_Relative timeout,
168                        GNUNET_STATISTICS_Callback cont,
169                        GNUNET_STATISTICS_Iterator proc, void *cls);
170
171
172 /**
173  * Cancel a #GNUNET_STATISTICS_get request.  Must be called before the 'cont'
174  * function is called.
175  *
176  * @param gh handle of the request to cancel
177  */
178 void
179 GNUNET_STATISTICS_get_cancel (struct GNUNET_STATISTICS_GetHandle *gh);
180
181
182 /**
183  * Set statistic value for the peer.  Will always use our
184  * subsystem (the argument used when @a handle was created).
185  *
186  * @param handle identification of the statistics service
187  * @param name name of the statistic value
188  * @param value new value to set
189  * @param make_persistent should the value be kept across restarts?
190  */
191 void
192 GNUNET_STATISTICS_set (struct GNUNET_STATISTICS_Handle *handle,
193                        const char *name,
194                        uint64_t value,
195                        int make_persistent);
196
197
198 /**
199  * Set statistic value for the peer.  Will always use our
200  * subsystem (the argument used when @a handle was created).
201  *
202  * @param handle identification of the statistics service
203  * @param name name of the statistic value
204  * @param delta change in value (added to existing value)
205  * @param make_persistent should the value be kept across restarts?
206  */
207 void
208 GNUNET_STATISTICS_update (struct GNUNET_STATISTICS_Handle *handle,
209                           const char *name,
210                           int64_t delta,
211                           int make_persistent);
212
213
214
215 #if 0                           /* keep Emacsens' auto-indent happy */
216 {
217 #endif
218 #ifdef __cplusplus
219 }
220 #endif
221
222 /** @} */ /* end of group statistics */
223
224 #endif