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