Code

Imported upstream version 1.4.8
[pkg-rrdtool.git] / src / rrd.h
1 /*****************************************************************************
2  * RRDtool 1.4.8  Copyright by Tobi Oetiker, 1997-2013
3  *****************************************************************************
4  * rrdlib.h   Public header file for librrd
5  *****************************************************************************
6  * $Id$
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 #ifdef _MSC_VER
61 #ifndef PERLPATCHLEVEL
62         typedef int mode_t;
63 #endif
64         #define strtoll _strtoi64 
65 #endif
66         typedef size_t ssize_t;
67         typedef long off_t;
68 #endif 
70 #include <time.h>
71 #include <stdio.h>      /* for FILE */
72 #include <string.h>
74 /* Formerly rrd_nan_inf.h */
75 #ifndef DNAN
76 # define DNAN rrd_set_to_DNAN()
77 #endif
79 #ifndef DINF
80 # define DINF rrd_set_to_DINF()
81 #endif
82     double    rrd_set_to_DNAN(
83     void);
84     double    rrd_set_to_DINF(
85     void);
86 /* end of rrd_nan_inf.h */
88 /* Transplanted from rrd_format.h */
89     typedef double rrd_value_t; /* the data storage type is
90                                  * double */
91 /* END rrd_format.h */
93 /* information about an rrd file */
94     typedef struct rrd_file_t {
95         size_t     header_len;   /* length of the header of this rrd file */
96         size_t     file_len; /* total size of the rrd file */
97         size_t     pos;  /* current pos in file */
98         void      *pvt;
99     } rrd_file_t;
101 /* information used for the conventional file access methods */
102     typedef struct rrd_simple_file_t {
103         int       fd;  /* file descriptor of this rrd file */
104 #ifdef HAVE_MMAP
105         char     *file_start;   /* start address of an open rrd file */
106         int       mm_prot;
107         int       mm_flags;
108 #endif
109     } rrd_simple_file_t;
111 /* rrd info interface */
112     typedef struct rrd_blob_t {
113         unsigned long size; /* size of the blob */
114         unsigned char *ptr; /* pointer */
115     } rrd_blob_t;
117     typedef enum rrd_info_type { RD_I_VAL = 0,
118         RD_I_CNT,
119         RD_I_STR,
120         RD_I_INT,
121         RD_I_BLO
122     } rrd_info_type_t;
124     typedef union rrd_infoval {
125         unsigned long u_cnt;
126         rrd_value_t u_val;
127         char     *u_str;
128         int       u_int;
129         rrd_blob_t u_blo;
130     } rrd_infoval_t;
132     typedef struct rrd_info_t {
133         char     *key;
134         rrd_info_type_t type;
135         rrd_infoval_t value;
136         struct rrd_info_t *next;
137     } rrd_info_t;
139     typedef size_t (* rrd_output_callback_t)(
140     const void *,
141     size_t,
142     void *);
144 /* main function blocks */
145     int       rrd_create(
146     int,
147     char **);
148     rrd_info_t *rrd_info(
149     int,
150     char **);
151     rrd_info_t *rrd_info_push(
152     rrd_info_t *,
153     char *,
154     rrd_info_type_t,
155     rrd_infoval_t);
156     void      rrd_info_print(
157     rrd_info_t * data);
158     void      rrd_info_free(
159     rrd_info_t *);
160     int       rrd_update(
161     int,
162     char **);
163     rrd_info_t *rrd_update_v(
164     int,
165     char **);
166     int       rrd_graph(
167     int,
168     char **,
169     char ***,
170     int *,
171     int *,
172     FILE *,
173     double *,
174     double *);
175     rrd_info_t *rrd_graph_v(
176     int,
177     char **);
179     int       rrd_fetch(
180     int,
181     char **,
182     time_t *,
183     time_t *,
184     unsigned long *,
185     unsigned long *,
186     char ***,
187     rrd_value_t **);
188     int       rrd_restore(
189     int,
190     char **);
191     int       rrd_dump(
192     int,
193     char **);
194     int       rrd_tune(
195     int,
196     char **);
197     time_t    rrd_last(
198     int,
199     char **);
200     int rrd_lastupdate(int argc, char **argv);
201     time_t    rrd_first(
202     int,
203     char **);
204     int       rrd_resize(
205     int,
206     char **);
207     char     *rrd_strversion(
208     void);
209     double    rrd_version(
210     void);
211     int       rrd_xport(
212     int,
213     char **,
214     int *,
215     time_t *,
216     time_t *,
217     unsigned long *,
218     unsigned long *,
219     char ***,
220     rrd_value_t **);
221     int       rrd_flushcached (int argc, char **argv);
223     void      rrd_freemem(
224     void *mem);
226 /* thread-safe (hopefully) */
227     int       rrd_create_r(
228     const char *filename,
229     unsigned long pdp_step,
230     time_t last_up,
231     int argc,
232     const char **argv);
233     rrd_info_t *rrd_info_r(
234     char *);
235 /* NOTE: rrd_update_r are only thread-safe if no at-style time
236    specifications get used!!! */
238     int       rrd_update_r(
239     const char *filename,
240     const char *_template,
241     int argc,
242     const char **argv);
243     int rrd_fetch_r (
244             const char *filename,
245             const char *cf,
246             time_t *start,
247             time_t *end,
248             unsigned long *step,
249             unsigned long *ds_cnt,
250             char ***ds_namv,
251             rrd_value_t **data);
252     int       rrd_dump_r(
253     const char *filename,
254     char *outname);
255     time_t    rrd_last_r (const char *filename);
256     int rrd_lastupdate_r (const char *filename,
257             time_t *ret_last_update,
258             unsigned long *ret_ds_count,
259             char ***ret_ds_names,
260             char ***ret_last_ds);
261     time_t    rrd_first_r(
262     const char *filename,
263     int rraindex);
265     int rrd_dump_cb_r(
266     const char *filename,
267     int opt_header,
268     rrd_output_callback_t cb,
269     void *user);
271 /* Transplanted from rrd_parsetime.h */
272     typedef enum {
273         ABSOLUTE_TIME,
274         RELATIVE_TO_START_TIME,
275         RELATIVE_TO_END_TIME,
276         RELATIVE_TO_EPOCH
277     } rrd_timetype_t;
279 #define TIME_OK NULL
281     typedef struct rrd_time_value {
282         rrd_timetype_t type;
283         long      offset;
284         struct tm tm;
285     } rrd_time_value_t;
287     char     *rrd_parsetime(
288     const char *spec,
289     rrd_time_value_t * ptv);
290 /* END rrd_parsetime.h */
292     typedef struct rrd_context {
293         char      lib_errstr[256];
294         char      rrd_error[4096];
295     } rrd_context_t;
297 /* returns the current per-thread rrd_context */
298     rrd_context_t *rrd_get_context(void);
300 #ifdef WIN32
301 /* this was added by the win32 porters Christof.Wegmann@exitgames.com */
302     rrd_context_t *rrd_force_new_context(void);
303 #endif
305 int       rrd_proc_start_end(
306     rrd_time_value_t *,
307     rrd_time_value_t *,
308     time_t *,
309     time_t *);
311 /* HELPER FUNCTIONS */
312     void      rrd_set_error(
313     char *,
314     ...);
315     void      rrd_clear_error(
316     void);
317     int       rrd_test_error(
318     void);
319     char     *rrd_get_error(
320     void);
322     /* rrd_strerror is thread safe, but still it uses a global buffer
323        (but one per thread), thus subsequent calls within a single
324        thread overwrite the same buffer */
325     const char *rrd_strerror(
326     int err);
328 /** MULTITHREADED HELPER FUNCTIONS */
329     rrd_context_t *rrd_new_context(
330     void);
331     void      rrd_free_context(
332     rrd_context_t * buf);
334 /* void   rrd_set_error_r  (rrd_context_t *, char *, ...); */
335 /* void   rrd_clear_error_r(rrd_context_t *); */
336 /* int    rrd_test_error_r (rrd_context_t *); */
337 /* char  *rrd_get_error_r  (rrd_context_t *); */
339 /** UTILITY FUNCTIONS */
341     long rrd_random(void);
343     int rrd_add_ptr(void ***dest, size_t *dest_size, void *src);
344     int rrd_add_strdup(char ***dest, size_t *dest_size, char *src);
345     void rrd_free_ptrs(void ***src, size_t *cnt);
347     int rrd_mkdir_p(const char *pathname, mode_t mode);
349 /*
350  * The following functions are _internal_ functions needed to read the raw RRD
351  * files. Since they are _internal_ they may change with the file format and
352  * will be replaced with a more general interface in RRDTool 1.4. Don't use
353  * these functions unless you have good reasons to do so. If you do use these
354  * functions you will have to adapt your code for RRDTool 1.4!
355  *
356  * To enable the deprecated functions define `RRD_EXPORT_DEPRECATED' before
357  * including <rrd_test.h>. You have been warned! If you come back to the
358  * RRDTool mailing list and whine about your broken application, you will get
359  * hit with something smelly!
360  */
361 #if defined(_RRD_TOOL_H) || defined(RRD_EXPORT_DEPRECATED)
363 # if defined(_RRD_TOOL_H)
364 #  include "rrd_format.h"
365 # else
366 #  include <rrd_format.h>
367 # endif
369 #if defined(__GNUC__) && defined (RRD_EXPORT_DEPRECATED)
370 # define RRD_DEPRECATED __attribute__((deprecated))
371 #else
372 # define RRD_DEPRECATED          /**/
373 #endif
374      void     rrd_free(
375     rrd_t *rrd)
376               RRD_DEPRECATED;
377     void      rrd_init(
378     rrd_t *rrd)
379               RRD_DEPRECATED;
381     rrd_file_t *rrd_open(
382     const char *const file_name,
383     rrd_t *rrd,
384     unsigned rdwr)
385               RRD_DEPRECATED;
387     void      rrd_dontneed(
388     rrd_file_t *rrd_file,
389     rrd_t *rrd)
390               RRD_DEPRECATED;
391     int       rrd_close(
392     rrd_file_t *rrd_file)
393               RRD_DEPRECATED;
394     ssize_t   rrd_read(
395     rrd_file_t *rrd_file,
396     void *buf,
397     size_t count)
398               RRD_DEPRECATED;
399     ssize_t   rrd_write(
400     rrd_file_t *rrd_file,
401     const void *buf,
402     size_t count)
403               RRD_DEPRECATED;
404     void      rrd_flush(
405     rrd_file_t *rrd_file)
406               RRD_DEPRECATED;
407     off_t     rrd_seek(
408     rrd_file_t *rrd_file,
409     off_t off,
410     int whence)
411               RRD_DEPRECATED;
412     off_t     rrd_tell(
413     rrd_file_t *rrd_file)
414               RRD_DEPRECATED;
415     int       rrd_lock(
416     rrd_file_t *file)
417               RRD_DEPRECATED;
418     void      rrd_notify_row(
419     rrd_file_t *rrd_file,
420     int rra_idx,
421     unsigned long rra_row,
422     time_t rra_time)
423               RRD_DEPRECATED;
424     unsigned long rrd_select_initial_row(
425     rrd_file_t *rrd_file,
426     int rra_idx,
427     rra_def_t *rra
428     )
429               RRD_DEPRECATED;
430 #endif                  /* defined(_RRD_TOOL_H) || defined(RRD_EXPORT_DEPRECATED) */
432 #endif                  /* _RRDLIB_H */
434 #ifdef  __cplusplus
436 #endif