This moves selection of the initial RRA row into the rrd_open.c API
[rrdtool.git] / src / rrd.h
1 /*****************************************************************************
2  * RRDtool 1.3.2  Copyright by Tobi Oetiker, 1997-2008
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 <sys/types.h>  /* for off_t */
56 #include <unistd.h>     /* for off_t */
57 #include <time.h>
58 #include <stdio.h>      /* for FILE */
59
60
61 /* Formerly rrd_nan_inf.h */
62 #ifndef DNAN
63 # define DNAN rrd_set_to_DNAN()
64 #endif
65
66 #ifndef DINF
67 # define DINF rrd_set_to_DINF()
68 #endif
69     double    rrd_set_to_DNAN(
70     void);
71     double    rrd_set_to_DINF(
72     void);
73 /* end of rrd_nan_inf.h */
74
75 /* Transplanted from rrd_format.h */
76     typedef double rrd_value_t; /* the data storage type is
77                                  * double */
78 /* END rrd_format.h */
79
80 /* information about an rrd file */
81     typedef struct rrd_file_t {
82         int       fd;   /* file descriptor if this rrd file */
83         char     *file_start;   /* start address of an open rrd file */
84         off_t     header_len;   /* length of the header of this rrd file */
85         off_t     file_len; /* total size of the rrd file */
86         off_t     pos;  /* current pos in file */
87     } rrd_file_t;
88
89 /* rrd info interface */
90     typedef struct rrd_blob_t {
91         unsigned long size; /* size of the blob */
92         unsigned char *ptr; /* pointer */
93     } rrd_blob_t;
94
95     typedef enum rrd_info_type { RD_I_VAL = 0,
96         RD_I_CNT,
97         RD_I_STR,
98         RD_I_INT,
99         RD_I_BLO
100     } rrd_info_type_t;
101
102     typedef union rrd_infoval {
103         unsigned long u_cnt;
104         rrd_value_t u_val;
105         char     *u_str;
106         int       u_int;
107         rrd_blob_t u_blo;
108     } rrd_infoval_t;
109
110     typedef struct rrd_info_t {
111         char     *key;
112         rrd_info_type_t type;
113         rrd_infoval_t value;
114         struct rrd_info_t *next;
115     } rrd_info_t;
116
117
118 /* main function blocks */
119     int       rrd_create(
120     int,
121     char **);
122     rrd_info_t *rrd_info(
123     int,
124     char **);
125     rrd_info_t *rrd_info_push(
126     rrd_info_t *,
127     char *,
128     rrd_info_type_t,
129     rrd_infoval_t);
130     void      rrd_info_print(
131     rrd_info_t * data);
132     void      rrd_info_free(
133     rrd_info_t *);
134     int       rrd_update(
135     int,
136     char **);
137     rrd_info_t *rrd_update_v(
138     int,
139     char **);
140     int       rrd_graph(
141     int,
142     char **,
143     char ***,
144     int *,
145     int *,
146     FILE *,
147     double *,
148     double *);
149     rrd_info_t *rrd_graph_v(
150     int,
151     char **);
152
153     int       rrd_fetch(
154     int,
155     char **,
156     time_t *,
157     time_t *,
158     unsigned long *,
159     unsigned long *,
160     char ***,
161     rrd_value_t **);
162     int       rrd_restore(
163     int,
164     char **);
165     int       rrd_dump(
166     int,
167     char **);
168     int       rrd_tune(
169     int,
170     char **);
171     time_t    rrd_last(
172     int,
173     char **);
174     int rrd_lastupdate(int argc, char **argv);
175     time_t    rrd_first(
176     int,
177     char **);
178     int       rrd_resize(
179     int,
180     char **);
181     char     *rrd_strversion(
182     void);
183     double    rrd_version(
184     void);
185     int       rrd_xport(
186     int,
187     char **,
188     int *,
189     time_t *,
190     time_t *,
191     unsigned long *,
192     unsigned long *,
193     char ***,
194     rrd_value_t **);
195     int       rrd_cmd_flush (int argc, char **argv);
196
197     void      rrd_freemem(
198     void *mem);
199
200 /* thread-safe (hopefully) */
201     int       rrd_create_r(
202     const char *filename,
203     unsigned long pdp_step,
204     time_t last_up,
205     int argc,
206     const char **argv);
207     rrd_info_t *rrd_info_r(
208     char *);
209 /* NOTE: rrd_update_r are only thread-safe if no at-style time
210    specifications get used!!! */
211
212     int       rrd_update_r(
213     const char *filename,
214     const char *_template,
215     int argc,
216     const char **argv);
217     int rrd_fetch_r (
218             const char *filename,
219             const char *cf,
220             time_t *start,
221             time_t *end,
222             unsigned long *step,
223             unsigned long *ds_cnt,
224             char ***ds_namv,
225             rrd_value_t **data);
226     int       rrd_dump_r(
227     const char *filename,
228     char *outname);
229     time_t    rrd_last_r (const char *filename);
230     int rrd_lastupdate_r (const char *filename,
231             time_t *ret_last_update,
232             unsigned long *ret_ds_count,
233             char ***ret_ds_names,
234             char ***ret_last_ds);
235     time_t    rrd_first_r(
236     const char *filename,
237     int rraindex);
238
239 /* Transplanted from rrd_parsetime.h */
240     typedef enum {
241         ABSOLUTE_TIME,
242         RELATIVE_TO_START_TIME,
243         RELATIVE_TO_END_TIME
244     } rrd_timetype_t;
245
246 #define TIME_OK NULL
247
248     typedef struct rrd_time_value {
249         rrd_timetype_t type;
250         long      offset;
251         struct tm tm;
252     } rrd_time_value_t;
253
254     char     *rrd_parsetime(
255     const char *spec,
256     rrd_time_value_t * ptv);
257 /* END rrd_parsetime.h */
258
259     typedef struct rrd_context {
260         char      lib_errstr[256];
261         char      rrd_error[4096];
262     } rrd_context_t;
263
264 /* returns the current per-thread rrd_context */
265     rrd_context_t *rrd_get_context(
266     void);
267
268
269     int       rrd_proc_start_end(
270     rrd_time_value_t *,
271     rrd_time_value_t *,
272     time_t *,
273     time_t *);
274
275 /* HELPER FUNCTIONS */
276     void      rrd_set_error(
277     char *,
278     ...);
279     void      rrd_clear_error(
280     void);
281     int       rrd_test_error(
282     void);
283     char     *rrd_get_error(
284     void);
285
286     /* rrd_strerror is thread safe, but still it uses a global buffer
287        (but one per thread), thus subsequent calls within a single
288        thread overwrite the same buffer */
289     const char *rrd_strerror(
290     int err);
291
292 /** MULTITHREADED HELPER FUNCTIONS */
293     rrd_context_t *rrd_new_context(
294     void);
295     void      rrd_free_context(
296     rrd_context_t * buf);
297
298 /* void   rrd_set_error_r  (rrd_context_t *, char *, ...); */
299 /* void   rrd_clear_error_r(rrd_context_t *); */
300 /* int    rrd_test_error_r (rrd_context_t *); */
301 /* char  *rrd_get_error_r  (rrd_context_t *); */
302
303 /*
304  * The following functions are _internal_ functions needed to read the raw RRD
305  * files. Since they are _internal_ they may change with the file format and
306  * will be replaced with a more general interface in RRDTool 1.4. Don't use
307  * these functions unless you have good reasons to do so. If you do use these
308  * functions you will have to adapt your code for RRDTool 1.4!
309  *
310  * To enable the deprecated functions define `RRD_EXPORT_DEPRECATED' before
311  * including <rrd_test.h>. You have been warned! If you come back to the
312  * RRDTool mailing list and whine about your broken application, you will get
313  * hit with something smelly!
314  */
315 #if defined(_RRD_TOOL_H) || defined(RRD_EXPORT_DEPRECATED)
316
317 # if defined(_RRD_TOOL_H)
318 #  include "rrd_format.h"
319 # else
320 #  include <rrd_format.h>
321 # endif
322
323 #if defined(__GNUC__) && defined (RRD_EXPORT_DEPRECATED)
324 # define RRD_DEPRECATED __attribute__((deprecated))
325 #else
326 # define RRD_DEPRECATED          /**/
327 #endif
328      void     rrd_free(
329     rrd_t *rrd)
330               RRD_DEPRECATED;
331     void      rrd_init(
332     rrd_t *rrd)
333               RRD_DEPRECATED;
334
335     rrd_file_t *rrd_open(
336     const char *const file_name,
337     rrd_t *rrd,
338     unsigned rdwr)
339               RRD_DEPRECATED;
340
341     void      rrd_dontneed(
342     rrd_file_t *rrd_file,
343     rrd_t *rrd)
344               RRD_DEPRECATED;
345     int       rrd_close(
346     rrd_file_t *rrd_file)
347               RRD_DEPRECATED;
348     ssize_t   rrd_read(
349     rrd_file_t *rrd_file,
350     void *buf,
351     size_t count)
352               RRD_DEPRECATED;
353     ssize_t   rrd_write(
354     rrd_file_t *rrd_file,
355     const void *buf,
356     size_t count)
357               RRD_DEPRECATED;
358     void      rrd_flush(
359     rrd_file_t *rrd_file)
360               RRD_DEPRECATED;
361     off_t     rrd_seek(
362     rrd_file_t *rrd_file,
363     off_t off,
364     int whence)
365               RRD_DEPRECATED;
366     off_t     rrd_tell(
367     rrd_file_t *rrd_file)
368               RRD_DEPRECATED;
369     int       rrd_lock(
370     rrd_file_t *file)
371               RRD_DEPRECATED;
372     void      rrd_notify_row(
373     rrd_file_t *rrd_file,
374     int rra_idx,
375     unsigned long rra_row,
376     time_t rra_time)
377               RRD_DEPRECATED;
378     unsigned long rrd_select_initial_row(
379     rrd_file_t *rrd_file,
380     int rra_idx,
381     rra_def_t *rra
382     )
383               RRD_DEPRECATED;
384 #endif                  /* defined(_RRD_TOOL_H) || defined(RRD_EXPORT_DEPRECATED) */
385
386 #endif                  /* _RRDLIB_H */
387
388 #ifdef  __cplusplus
389 }
390 #endif