Close file descriptor on error handling.
[oweals/gnunet.git] / src / statistics / statistics.h
1 /*
2      This file is part of GNUnet.
3      Copyright (C) 2001-2014 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  * @file statistics/statistics.h
24  */
25 #ifndef STATISTICS_H
26 #define STATISTICS_H
27
28 #include "gnunet_common.h"
29
30
31 GNUNET_NETWORK_STRUCT_BEGIN
32
33 /**
34  * Statistics message. Contains how long the system is up
35  * and one value.
36  *
37  * The struct is be followed by the service name and
38  * name of the statistic, both 0-terminated.
39  */
40 struct GNUNET_STATISTICS_ReplyMessage
41 {
42   /**
43    * Type:  GNUNET_MESSAGE_TYPE_STATISTICS_VALUE
44    */
45   struct GNUNET_MessageHeader header;
46
47   /**
48    * Unique numerical identifier for the value (will
49    * not change during the same client-session).  Highest
50    * bit will be set for persistent values (see
51    * #GNUNET_STATISTICS_PERSIST_BIT).
52    */
53   uint32_t uid GNUNET_PACKED;
54
55   /**
56    * The value.
57    */
58   uint64_t value GNUNET_PACKED;
59
60 };
61
62 /**
63  * Flag for the `struct GNUNET_STATISTICS_ReplyMessage` UID only.
64  * Note that other messages use #GNUNET_STATISTICS_SETFLAG_PERSISTENT.
65  */
66 #define GNUNET_STATISTICS_PERSIST_BIT ((uint32_t) (1LLU<<31))
67
68 /**
69  * The value being set is an absolute change.
70  */
71 #define GNUNET_STATISTICS_SETFLAG_ABSOLUTE 0
72
73 /**
74  * The value being set is a relative change.
75  */
76 #define GNUNET_STATISTICS_SETFLAG_RELATIVE 1
77
78 /**
79  * The value being set is to be persistent (note that
80  * this bit can be combined with #GNUNET_STATISTICS_SETFLAG_RELATIVE).
81  * This value must not be used for the `uid` member of
82  * `struct GNUNET_STATISTICS_ReplyMessage`!
83  */
84 #define GNUNET_STATISTICS_SETFLAG_PERSISTENT 2
85
86
87 /**
88  * Message to set a statistic.  Followed
89  * by the subsystem name and the name of
90  * the statistic (each 0-terminated).
91  */
92 struct GNUNET_STATISTICS_SetMessage
93 {
94   /**
95    * Type: #GNUNET_MESSAGE_TYPE_STATISTICS_SET
96    */
97   struct GNUNET_MessageHeader header;
98
99   /**
100    * 0 for absolute value, 1 for relative value; 2 to make persistent
101    * (see GNUNET_STATISTICS_SETFLAG_*).
102    */
103   uint32_t flags GNUNET_PACKED;
104
105   /**
106    * Value. Note that if this is a relative value, it will
107    * be signed even though the type given here is unsigned.
108    */
109   uint64_t value GNUNET_PACKED;
110
111 };
112
113
114 /**
115  * Message transmitted if a watched value changes.
116  */
117 struct GNUNET_STATISTICS_WatchValueMessage
118 {
119   /**
120    * Type: #GNUNET_MESSAGE_TYPE_STATISTICS_WATCH_VALUE
121    */
122   struct GNUNET_MessageHeader header;
123
124   /**
125    * 0 for absolute value, 1 for relative value; 2 to make persistent
126    * (see GNUNET_STATISTICS_SETFLAG_*).
127    */
128   uint32_t flags GNUNET_PACKED;
129
130   /**
131    * Unique watch identification number (watch
132    * requests are enumerated in the order they
133    * are received, the first request having
134    * a wid of zero).
135    */
136   uint32_t wid GNUNET_PACKED;
137
138   /**
139    * Reserved (always 0).
140    */
141   uint32_t reserved GNUNET_PACKED;
142
143   /**
144    * Value. Note that if this is a relative value, it will
145    * be signed even though the type given here is unsigned.
146    */
147   uint64_t value GNUNET_PACKED;
148
149 };
150 GNUNET_NETWORK_STRUCT_END
151
152 #endif