prepare for the release of rrdtool-1.2.21
[rrdtool.git] / src / rrd.h
1 /*****************************************************************************
2  * RRDtool 1.2.21  Copyright by Tobi Oetiker, 1997-2007
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
51
52 #ifndef _RRDLIB_H
53 #define _RRDLIB_H
54
55 #include <time.h>
56 #include <stdio.h> /* for FILE */
57
58 /* Transplanted from rrd_format.h */
59 typedef double       rrd_value_t;         /* the data storage type is
60                                            * double */
61 /* END rrd_format.h */
62
63 /* main function blocks */
64 int    rrd_create(int, char **);
65 int    rrd_update(int, char **);
66 int    rrd_graph(int, char **, char ***, int *, int *, FILE *, double *, double *);
67 int    rrd_fetch(int, char **, time_t *, time_t *, unsigned long *,
68                  unsigned long *, char ***, rrd_value_t **);
69 int    rrd_restore(int, char **);
70 int    rrd_dump(int, char **);
71 int    rrd_tune(int, char **);
72 time_t rrd_last(int, char **);
73 time_t rrd_first(int, char **);
74 int    rrd_resize(int, char **);
75 char * rrd_strversion(void);
76 double rrd_version(void);
77 int    rrd_xport(int, char **, int *, time_t *, time_t *,
78                  unsigned long *, unsigned long *,
79                  char ***, rrd_value_t **);
80
81 /* thread-safe (hopefully) */
82 int    rrd_create_r(const char *filename,
83                     unsigned long pdp_step, time_t last_up,
84                     int argc, const char **argv);
85 /* NOTE: rrd_update_r are only thread-safe if no at-style time
86    specifications get used!!! */
87
88 int    rrd_update_r(const char *filename, const char *_template,
89                     int argc, const char **argv);
90 int    rrd_fetch_r(const char *filename, const char* cf,
91                    time_t *start, time_t *end,
92                    unsigned long *step,
93                    unsigned long *ds_cnt,
94                    char        ***ds_namv,
95                    rrd_value_t **data);
96 int    rrd_dump_r(const char *filename, char *outname);
97 time_t rrd_last_r(const char *filename);
98 time_t rrd_first_r(const char *filename, int rraindex);
99
100 /* Transplanted from parsetime.h */
101 typedef enum {
102         ABSOLUTE_TIME,
103         RELATIVE_TO_START_TIME, 
104         RELATIVE_TO_END_TIME
105 } timetype;
106
107 #define TIME_OK NULL
108
109 struct rrd_time_value {
110   timetype type;
111   long offset;
112   struct tm tm;
113 };
114
115 char *parsetime(const char *spec, struct rrd_time_value *ptv);
116 /* END parsetime.h */
117
118 struct rrd_context {
119     int len;
120     int errlen;
121     char *lib_errstr;
122     char *rrd_error;
123 };
124
125 /* returns the current per-thread rrd_context */
126 struct rrd_context *rrd_get_context(void);
127
128
129 int proc_start_end (struct rrd_time_value *,  struct rrd_time_value *, time_t *, time_t *);
130
131 /* HELPER FUNCTIONS */
132 void rrd_set_error(char *,...);
133 void rrd_clear_error(void);
134 int  rrd_test_error(void);
135 char *rrd_get_error(void);
136
137 /** MULTITHREADED HELPER FUNCTIONS */
138 struct rrd_context *rrd_new_context(void);
139 void   rrd_free_context (struct rrd_context *buf);
140
141 /* void   rrd_set_error_r  (struct rrd_context *, char *, ...); */
142 /* void   rrd_clear_error_r(struct rrd_context *); */
143 /* int    rrd_test_error_r (struct rrd_context *); */
144 /* char  *rrd_get_error_r  (struct rrd_context *); */
145
146 int  LockRRD(FILE *);
147
148 #endif /* _RRDLIB_H */
149
150 #ifdef  __cplusplus
151 }
152 #endif