3cfe8450e5bf850ca184e39249e0498cb0a13f8f
1 /*****************************************************************************
2 * RRDtool 1.2.23 Copyright by Tobi Oetiker, 1997-2007
3 *****************************************************************************
4 * rrd_tool.h Common Header File
5 *****************************************************************************/
6 #ifdef __cplusplus
7 extern "C" {
8 #endif
10 #ifndef _RRD_TOOL_H
11 #define _RRD_TOOL_H
13 #ifdef HAVE_CONFIG_H
14 #include "../rrd_config.h"
15 #elif defined(_WIN32) && !defined(__CYGWIN__) && !defined(__CYGWIN32__)
16 #include "../win32/config.h"
17 #endif
19 #include "rrd.h"
21 #if defined(_WIN32) && !defined(__CYGWIN__) && !defined(__CYGWIN32__)
23 /* Win32 only includes */
25 #include <float.h> /* for _isnan */
26 #include <io.h> /* for chdir */
28 struct tm *localtime_r(
29 const time_t *timep,
30 struct tm *result);
31 char *ctime_r(
32 const time_t *timep,
33 char *result);
34 struct tm *gmtime_r(
35 const time_t *timep,
36 struct tm *result);
37 char *strtok_r(
38 char *str,
39 const char *sep,
40 char **last);
42 #else
44 /* unix-only includes */
45 #if !defined isnan && !defined HAVE_ISNAN
46 int isnan(
47 double value);
48 #endif
50 #endif
52 /* local include files -- need to be after the system ones */
53 #include "rrd_getopt.h"
54 #include "rrd_format.h"
56 #ifndef max
57 #define max(a,b) ((a) > (b) ? (a) : (b))
58 #endif
60 #ifndef min
61 #define min(a,b) ((a) < (b) ? (a) : (b))
62 #endif
64 #define DIM(x) (sizeof(x)/sizeof(x[0]))
66 /* rrd info interface */
67 enum info_type { RD_I_VAL = 0,
68 RD_I_CNT,
69 RD_I_STR,
70 RD_I_INT
71 };
73 typedef union infoval {
74 unsigned long u_cnt;
75 rrd_value_t u_val;
76 char *u_str;
77 int u_int;
78 } infoval;
80 typedef struct info_t {
81 char *key;
82 enum info_type type;
83 union infoval value;
84 struct info_t *next;
85 } info_t;
87 info_t *rrd_info(
88 int,
89 char **);
90 int rrd_lastupdate(
91 int argc,
92 char **argv,
93 time_t *last_update,
94 unsigned long *ds_cnt,
95 char ***ds_namv,
96 char ***last_ds);
97 info_t *rrd_update_v(
98 int,
99 char **);
100 char *sprintf_alloc(
101 char *,
102 ...);
103 info_t *info_push(
104 info_t *,
105 char *,
106 enum info_type,
107 infoval);
109 /* HELPER FUNCTIONS */
111 int PngSize(
112 FILE *,
113 long *,
114 long *);
116 int rrd_create_fn(
117 const char *file_name,
118 rrd_t *rrd);
119 int rrd_fetch_fn(
120 const char *filename,
121 enum cf_en cf_idx,
122 time_t *start,
123 time_t *end,
124 unsigned long *step,
125 unsigned long *ds_cnt,
126 char ***ds_namv,
127 rrd_value_t **data);
129 void rrd_free(
130 rrd_t *rrd);
131 void rrd_freemem(
132 void *mem);
133 void rrd_init(
134 rrd_t *rrd);
136 rrd_file_t *rrd_open(
137 const char *const file_name,
138 rrd_t *rrd,
139 unsigned rdwr);
140 void rrd_dontneed(
141 rrd_file_t *rrd_file,
142 rrd_t *rrd);
143 int rrd_close(
144 rrd_file_t *rrd_file);
145 ssize_t rrd_read(
146 rrd_file_t *rrd_file,
147 void *buf,
148 size_t count);
149 ssize_t rrd_write(
150 rrd_file_t *rrd_file,
151 const void *buf,
152 size_t count);
153 void rrd_flush(
154 rrd_file_t *rrd_file);
155 off_t rrd_seek(
156 rrd_file_t *rrd_file,
157 off_t off,
158 int whence);
159 off_t rrd_tell(
160 rrd_file_t *rrd_file);
161 int readfile(
162 const char *file,
163 char **buffer,
164 int skipfirst);
166 #define RRD_READONLY (1<<0)
167 #define RRD_READWRITE (1<<1)
168 #define RRD_CREAT (1<<2)
169 #define RRD_READAHEAD (1<<3)
170 #define RRD_COPY (1<<4)
172 enum cf_en cf_conv(
173 const char *string);
174 enum dst_en dst_conv(
175 char *string);
176 long ds_match(
177 rrd_t *rrd,
178 char *ds_nam);
179 double rrd_diff(
180 char *a,
181 char *b);
183 /* rrd_strerror is thread safe, but still it uses a global buffer
184 (but one per thread), thus subsequent calls within a single
185 thread overwrite the same buffer */
186 const char *rrd_strerror(
187 int err);
189 #endif
191 #ifdef __cplusplus
192 }
193 #endif