Add funtionality to rrdtool to run it as a 'server'
[rrdtool.git] / src / rrd_tool.h
1 /*****************************************************************************
2  * RRDtool 1.0.33  Copyright Tobias Oetiker, 1997 - 2000
3  *****************************************************************************
4  * rrd_tool.h   Common Header File
5  *****************************************************************************/
6 #ifdef  __cplusplus
7 extern "C" {
8 #endif
9
10
11 #ifndef _RRD_TOOL_H
12 #define _RRD_TOOL_H
13
14 #ifdef WIN32
15 #include "../confignt/config.h"
16 #else
17 #ifdef HAVE_CONFIG_H
18 #include <config.h>
19 #endif
20 #endif
21
22 #ifdef MUST_DISABLE_SIGFPE
23 #include <signal.h>
24 #endif
25
26 #ifdef MUST_DISABLE_FPMASK
27 #include <floatingpoint.h>
28 #endif
29     
30 #include <stdio.h>
31 #include <stdlib.h>
32 #include <errno.h>
33 #include <string.h>
34 #include <time.h>
35 #include <ctype.h>
36
37 #if HAVE_SYS_PARAM_H
38 #  include <sys/param.h>
39 #endif
40
41 #ifndef MAXPATH
42 #  define MAXPATH 1024
43 #endif
44
45 #if HAVE_MATH_H
46 # include <math.h>
47 #endif
48 /* Sorry: don't know autoconf as well how to check the exist of
49    dirent.h ans sys/stat.h
50 */
51 #include <sys/stat.h>
52 #include <dirent.h>
53 #include <sys/types.h>
54 /*
55 #endif
56 */
57 #if HAVE_UNISTD_H
58 # include <unistd.h>
59 #endif
60 #if HAVE_SYS_TIME_H
61 # include <sys/time.h>
62 #endif
63 #if HAVE_SYS_TIMES_H
64 # include <sys/times.h>
65 #endif
66 #if HAVE_SYS_RESOURCE_H
67 # include <sys/resource.h>
68 #if (defined(__svr4__) && defined(__sun__))
69 /* Solaris headers (pre 2.6) don't have a getrusage prototype.
70    Use this instead. */
71 extern int getrusage(int, struct rusage *);
72 #endif /* __svr4__ && __sun__ */
73 #endif
74
75 #include "rrd.h"
76
77 #ifndef WIN32
78
79 /* unix-only includes */
80 #ifndef isnan
81 int isnan(double value);
82 #endif
83
84 #else
85
86 /* Win32 only includes */
87
88 #include <float.h>        /* for _isnan  */
89 #define isnan _isnan
90 #define finite _finite
91 #define isinf(a) (_fpclass(a) == _FPCLASS_NINF || _fpclass(a) == _FPCLASS_PINF)
92 #endif
93
94 /* local include files -- need to be after the system ones */
95 #include "getopt.h"
96 #include "rrd_format.h"
97
98 #ifndef max
99 #define max(a,b) ((a) > (b) ? (a) : (b))
100 #endif
101
102 #ifndef min
103 #define min(a,b) ((a) < (b) ? (a) : (b))
104 #endif                                                   
105
106 #define DIM(x) (sizeof(x)/sizeof(x[0]))
107
108 /* rrd info interface */
109 enum info_type   { RD_I_VAL=0,
110                RD_I_CNT,
111                RD_I_STR  };
112
113 typedef union infoval { 
114     unsigned long u_cnt; 
115     rrd_value_t   u_val;
116     char         *u_str;
117 } infoval;
118
119 typedef struct info_t {
120     char            *key;
121     enum info_type  type;
122     union infoval   value;
123     struct info_t   *next;
124 } info_t;
125
126
127 info_t *rrd_info(int, char **);
128
129 /* HELPER FUNCTIONS */
130
131 int PngSize(FILE *, long *, long *);
132
133 int rrd_create_fn(char *file_name, rrd_t *rrd);
134 int rrd_fetch_fn(char *filename, enum cf_en cf_idx,
135                  time_t *start,time_t *end,
136                  unsigned long *step,
137                  unsigned long *ds_cnt,
138                  char        ***ds_namv,
139                  rrd_value_t **data);
140
141 void rrd_free(rrd_t *rrd);
142 void rrd_init(rrd_t *rrd);
143
144 int rrd_open(char *file_name, FILE **in_file, rrd_t *rrd, int rdwr);
145 int readfile(char *file, char **buffer, int skipfirst);
146
147 #define RRD_READONLY    0
148 #define RRD_READWRITE   1
149
150 enum cf_en cf_conv(char *string);
151 enum dst_en dst_conv(char *string);
152 long ds_match(rrd_t *rrd,char *ds_nam);
153 double rrd_diff(char *a, char *b);
154
155 #endif
156
157 #ifdef  __cplusplus
158 }
159 #endif