Updates from Bernhard Fischer rep dot nop gmail com
[rrdtool.git] / src / rrd_tool.h
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
9
10 #ifndef _RRD_TOOL_H
11 #define _RRD_TOOL_H
12
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
18
19 #include "rrd.h"
20
21 #if defined(_WIN32) && !defined(__CYGWIN__) && !defined(__CYGWIN32__)
22
23 /* Win32 only includes */
24
25 #include <float.h>      /* for _isnan  */
26 #include <io.h>         /* for chdir   */
27
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);
41
42 #else
43
44 /* unix-only includes */
45 #if !defined isnan && !defined HAVE_ISNAN
46     int       isnan(
47     double value);
48 #endif
49
50 #endif
51
52 /* local include files -- need to be after the system ones */
53 #include "rrd_getopt.h"
54 #include "rrd_format.h"
55
56 #ifndef max
57 #define max(a,b) ((a) > (b) ? (a) : (b))
58 #endif
59
60 #ifndef min
61 #define min(a,b) ((a) < (b) ? (a) : (b))
62 #endif
63
64 #define DIM(x) (sizeof(x)/sizeof(x[0]))
65
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     };
72
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;
79
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;
86
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);
108
109 /* HELPER FUNCTIONS */
110
111     int       PngSize(
112     FILE *,
113     long *,
114     long *);
115
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);
128
129     void      rrd_free(
130     rrd_t *rrd);
131     void      rrd_freemem(
132     void *mem);
133     void      rrd_init(
134     rrd_t *rrd);
135
136     rrd_file_t *rrd_open(
137     const char *const file_name,
138     rrd_t *rrd,
139     unsigned rdwr);
140     int       rrd_close(
141     rrd_file_t *rrd_file);
142     ssize_t   rrd_read(
143     rrd_file_t *rrd_file,
144     void *buf,
145     size_t count);
146     ssize_t   rrd_write(
147     rrd_file_t *rrd_file,
148     const void *buf,
149     size_t count);
150     void      rrd_flush(
151     rrd_file_t *rrd_file);
152     off_t     rrd_seek(
153     rrd_file_t *rrd_file,
154     off_t off,
155     int whence);
156     off_t     rrd_tell(
157     rrd_file_t *rrd_file);
158     int       readfile(
159     const char *file,
160     char **buffer,
161     int skipfirst);
162
163 #define RRD_READONLY    (1<<0)
164 #define RRD_READWRITE   (1<<1)
165 #define RRD_CREAT       (1<<2)
166 #define RRD_READAHEAD   (1<<3)
167 #define RRD_COPY        (1<<4)
168
169     enum cf_en cf_conv(
170     const char *string);
171     enum dst_en dst_conv(
172     char *string);
173     long      ds_match(
174     rrd_t *rrd,
175     char *ds_nam);
176     double    rrd_diff(
177     char *a,
178     char *b);
179
180     /* rrd_strerror is thread safe, but still it uses a global buffer
181        (but one per thread), thus subsequent calls within a single
182        thread overwrite the same buffer */
183     const char *rrd_strerror(
184     int err);
185
186 #endif
187
188 #ifdef  __cplusplus
189 }
190 #endif