Code

Imported upstream version 1.3.8.
[pkg-rrdtool.git] / src / rrd.h
1 /*****************************************************************************
2  * RRDtool 1.3.8  Copyright by Tobi Oetiker, 1997-2009
3  *****************************************************************************
4  * rrdlib.h   Public header file for librrd
5  *****************************************************************************
6  * $Id: rrd.h 1801 2009-05-19 13:45:05Z oetiker $
7  * $Log$
8  * Revision 1.9  2005/02/13 16:13:33  oetiker
9  * let rrd_graph return the actual value range it picked ...
10  * -- Henrik Stoerner <henrik@hswn.dk>
11  *
12  * Revision 1.8  2004/05/26 22:11:12  oetiker
13  * reduce compiler warnings. Many small fixes. -- Mike Slifcak <slif@bellsouth.net>
14  *
15  * Revision 1.7  2003/11/12 22:14:26  oetiker
16  * allow to pass an open filehandle into rrd_graph as an extra argument
17  *
18  * Revision 1.6  2003/11/11 19:46:21  oetiker
19  * replaced time_value with rrd_time_value as MacOS X introduced a struct of that name in their standard headers
20  *
21  * Revision 1.5  2003/04/25 18:35:08  jake
22  * Alternate update interface, updatev. Returns info about CDPs written to disk as result of update. Output format is similar to rrd_info, a hash of key-values.
23  *
24  * Revision 1.4  2003/04/01 22:52:23  jake
25  * Fix Win32 build. VC++ 6.0 and 7.0 now use the thread-safe code.
26  *
27  * Revision 1.3  2003/02/13 07:05:27  oetiker
28  * Find attached the patch I promised to send to you. Please note that there
29  * are three new source files (src/rrd_is_thread_safe.h, src/rrd_thread_safe.c
30  * and src/rrd_not_thread_safe.c) and the introduction of librrd_th. This
31  * library is identical to librrd, but it contains support code for per-thread
32  * global variables currently used for error information only. This is similar
33  * to how errno per-thread variables are implemented.  librrd_th must be linked
34  * alongside of libpthred
35  *
36  * There is also a new file "THREADS", holding some documentation.
37  *
38  * -- Peter Stamfest <peter@stamfest.at>
39  *
40  * Revision 1.2  2002/05/07 21:58:32  oetiker
41  * new command rrdtool xport integrated
42  * --  Wolfgang Schrimm <Wolfgang.Schrimm@urz.uni-heidelberg.de>
43  *
44  * Revision 1.1.1.1  2001/02/25 22:25:05  oetiker
45  * checkin
46  *
47  *****************************************************************************/
48 #ifdef  __cplusplus
49 extern    "C" {
50 #endif
52 #ifndef _RRDLIB_H
53 #define _RRDLIB_H
55 #include <sys/types.h>  /* for off_t */
57 #ifndef WIN32
58 #include <unistd.h>     /* for off_t */
59 #else
60 #include <string.h>
61 typedef size_t ssize_t;
62 typedef long off_t;
63 #endif 
65 #include <time.h>
66 #include <stdio.h>      /* for FILE */
69 /* Formerly rrd_nan_inf.h */
70 #ifndef DNAN
71 # define DNAN rrd_set_to_DNAN()
72 #endif
74 #ifndef DINF
75 # define DINF rrd_set_to_DINF()
76 #endif
77     double    rrd_set_to_DNAN(
78     void);
79     double    rrd_set_to_DINF(
80     void);
81 /* end of rrd_nan_inf.h */
83 /* Transplanted from rrd_format.h */
84     typedef double rrd_value_t; /* the data storage type is
85                                  * double */
86 /* END rrd_format.h */
88 /* information about an rrd file */
89     typedef struct rrd_file_t {
90         int       fd;   /* file descriptor if this rrd file */
91         char     *file_start;   /* start address of an open rrd file */
92         off_t     header_len;   /* length of the header of this rrd file */
93         off_t     file_len; /* total size of the rrd file */
94         off_t     pos;  /* current pos in file */
95     } rrd_file_t;
97 /* rrd info interface */
98     typedef struct rrd_blob_t {
99         unsigned long size; /* size of the blob */
100         unsigned char *ptr; /* pointer */
101     } rrd_blob_t;
103     typedef enum rrd_info_type { RD_I_VAL = 0,
104         RD_I_CNT,
105         RD_I_STR,
106         RD_I_INT,
107         RD_I_BLO
108     } rrd_info_type_t;
110     typedef union rrd_infoval {
111         unsigned long u_cnt;
112         rrd_value_t u_val;
113         char     *u_str;
114         int       u_int;
115         rrd_blob_t u_blo;
116     } rrd_infoval_t;
118     typedef struct rrd_info_t {
119         char     *key;
120         rrd_info_type_t type;
121         rrd_infoval_t value;
122         struct rrd_info_t *next;
123     } rrd_info_t;
126 /* main function blocks */
127     int       rrd_create(
128     int,
129     char **);
130     rrd_info_t *rrd_info(
131     int,
132     char **);
133     rrd_info_t *rrd_info_push(
134     rrd_info_t *,
135     char *,
136     rrd_info_type_t,
137     rrd_infoval_t);
138     void      rrd_info_print(
139     rrd_info_t * data);
140     void      rrd_info_free(
141     rrd_info_t *);
142     int       rrd_update(
143     int,
144     char **);
145     rrd_info_t *rrd_update_v(
146     int,
147     char **);
148     int       rrd_graph(
149     int,
150     char **,
151     char ***,
152     int *,
153     int *,
154     FILE *,
155     double *,
156     double *);
157     rrd_info_t *rrd_graph_v(
158     int,
159     char **);
161     int       rrd_fetch(
162     int,
163     char **,
164     time_t *,
165     time_t *,
166     unsigned long *,
167     unsigned long *,
168     char ***,
169     rrd_value_t **);
170     int       rrd_restore(
171     int,
172     char **);
173     int       rrd_dump(
174     int,
175     char **);
176     int       rrd_tune(
177     int,
178     char **);
179     time_t    rrd_last(
180     int,
181     char **);
182     int       rrd_lastupdate(
183     int argc,
184     char **argv,
185     time_t *last_update,
186     unsigned long *ds_cnt,
187     char ***ds_namv,
188     char ***last_ds);
189     time_t    rrd_first(
190     int,
191     char **);
192     int       rrd_resize(
193     int,
194     char **);
195     char     *rrd_strversion(
196     void);
197     double    rrd_version(
198     void);
199     int       rrd_xport(
200     int,
201     char **,
202     int *,
203     time_t *,
204     time_t *,
205     unsigned long *,
206     unsigned long *,
207     char ***,
208     rrd_value_t **);
210     void      rrd_freemem(
211     void *mem);
213 /* thread-safe (hopefully) */
214     int       rrd_create_r(
215     const char *filename,
216     unsigned long pdp_step,
217     time_t last_up,
218     int argc,
219     const char **argv);
220 /* NOTE: rrd_update_r are only thread-safe if no at-style time
221    specifications get used!!! */
223     int       rrd_update_r(
224     const char *filename,
225     const char *_template,
226     int argc,
227     const char **argv);
228     int       rrd_fetch_r(
229     const char *filename,
230     const char *cf,
231     time_t *start,
232     time_t *end,
233     unsigned long *step,
234     unsigned long *ds_cnt,
235     char ***ds_namv,
236     rrd_value_t **data);
237     int       rrd_dump_r(
238     const char *filename,
239     char *outname);
240     time_t    rrd_last_r(
241     const char *filename);
242     time_t    rrd_first_r(
243     const char *filename,
244     int rraindex);
246 /* Transplanted from rrd_parsetime.h */
247     typedef enum {
248         ABSOLUTE_TIME,
249         RELATIVE_TO_START_TIME,
250         RELATIVE_TO_END_TIME
251     } rrd_timetype_t;
253 #define TIME_OK NULL
255     typedef struct rrd_time_value {
256         rrd_timetype_t type;
257         long      offset;
258         struct tm tm;
259     } rrd_time_value_t;
261     char     *rrd_parsetime(
262     const char *spec,
263     rrd_time_value_t * ptv);
264 /* END rrd_parsetime.h */
266     typedef struct rrd_context {
267         char      lib_errstr[256];
268         char      rrd_error[4096];
269     } rrd_context_t;
271 /* returns the current per-thread rrd_context */
272     rrd_context_t *rrd_get_context(
273     void);
275 #ifdef WIN32
276 rrd_context_t *rrd_force_new_context(void);
277 #endif
279     int       rrd_proc_start_end(
280     rrd_time_value_t *,
281     rrd_time_value_t *,
282     time_t *,
283     time_t *);
285 /* HELPER FUNCTIONS */
286     void      rrd_set_error(
287     char *,
288     ...);
289     void      rrd_clear_error(
290     void);
291     int       rrd_test_error(
292     void);
293     char     *rrd_get_error(
294     void);
296     /* rrd_strerror is thread safe, but still it uses a global buffer
297        (but one per thread), thus subsequent calls within a single
298        thread overwrite the same buffer */
299     const char *rrd_strerror(
300     int err);
302 /** MULTITHREADED HELPER FUNCTIONS */
303     rrd_context_t *rrd_new_context(
304     void);
305     void      rrd_free_context(
306     rrd_context_t * buf);
308 /* void   rrd_set_error_r  (rrd_context_t *, char *, ...); */
309 /* void   rrd_clear_error_r(rrd_context_t *); */
310 /* int    rrd_test_error_r (rrd_context_t *); */
311 /* char  *rrd_get_error_r  (rrd_context_t *); */
313 /*
314  * The following functions are _internal_ functions needed to read the raw RRD
315  * files. Since they are _internal_ they may change with the file format and
316  * will be replaced with a more general interface in RRDTool 1.4. Don't use
317  * these functions unless you have good reasons to do so. If you do use these
318  * functions you will have to adapt your code for RRDTool 1.4!
319  *
320  * To enable the deprecated functions define `RRD_EXPORT_DEPRECATED' before
321  * including <rrd_test.h>. You have been warned! If you come back to the
322  * RRDTool mailing list and whine about your broken application, you will get
323  * hit with something smelly!
324  */
325 #if defined(_RRD_TOOL_H) || defined(RRD_EXPORT_DEPRECATED)
327 # if defined(_RRD_TOOL_H)
328 #  include "rrd_format.h"
329 # else
330 #  include <rrd_format.h>
331 # endif
333 #if defined(__GNUC__) && defined (RRD_EXPORT_DEPRECATED)
334 # define RRD_DEPRECATED __attribute__((deprecated))
335 #else
336 # define RRD_DEPRECATED          /**/
337 #endif
338      void     rrd_free(
339     rrd_t *rrd)
340               RRD_DEPRECATED;
341     void      rrd_init(
342     rrd_t *rrd)
343               RRD_DEPRECATED;
345     rrd_file_t *rrd_open(
346     const char *const file_name,
347     rrd_t *rrd,
348     unsigned rdwr)
349               RRD_DEPRECATED;
351     void      rrd_dontneed(
352     rrd_file_t *rrd_file,
353     rrd_t *rrd)
354               RRD_DEPRECATED;
355     int       rrd_close(
356     rrd_file_t *rrd_file)
357               RRD_DEPRECATED;
358     ssize_t   rrd_read(
359     rrd_file_t *rrd_file,
360     void *buf,
361     size_t count)
362               RRD_DEPRECATED;
363     ssize_t   rrd_write(
364     rrd_file_t *rrd_file,
365     const void *buf,
366     size_t count)
367               RRD_DEPRECATED;
368     void      rrd_flush(
369     rrd_file_t *rrd_file)
370               RRD_DEPRECATED;
371     off_t     rrd_seek(
372     rrd_file_t *rrd_file,
373     off_t off,
374     int whence)
375               RRD_DEPRECATED;
376     off_t     rrd_tell(
377     rrd_file_t *rrd_file)
378               RRD_DEPRECATED;
379     int       rrd_lock(
380     rrd_file_t *file)
381               RRD_DEPRECATED;
382 #endif                  /* defined(_RRD_TOOL_H) || defined(RRD_EXPORT_DEPRECATED) */
384 #endif                  /* _RRDLIB_H */
386 #ifdef  __cplusplus
388 #endif