14 * rrd_tool.h includes config.h, but at least on Ubuntu Breezy Badger
15 * 5.10 with gcc 4.0.2, the C preprocessor picks up Perl's config.h
16 * which is included from the Perl includes and never reads rrdtool's
17 * config.h. Without including rrdtool's config.h, this module does
18 * not compile, so include it here with an explicit path.
20 * Because rrdtool's config.h redefines VERSION which is originally
21 * set via Perl's Makefile.PL and passed down to the C compiler's
22 * command line, save the original value and reset it after the
25 #define VERSION_SAVED VERSION
28 #include "../../rrd_config.h"
30 #include "../../src/rrd_tool.h"
32 #define VERSION VERSION_SAVED
35 /* perl 5.004 compatibility */
37 #define PL_sv_undef sv_undef
41 #define rrdcode(name) \
42 argv = (char **) malloc((items+1)*sizeof(char *));\
44 for (i = 0; i < items; i++) { \
46 char *handle= SvPV(ST(i),len);\
47 /* actually copy the data to make sure possible modifications \
48 on the argv data does not backfire into perl */ \
49 argv[i+1] = (char *) malloc((strlen(handle)+1)*sizeof(char)); \
50 strcpy(argv[i+1],handle); \
53 RETVAL=name(items+1,argv); \
54 for (i=0; i < items; i++) {\
59 if (rrd_test_error()) XSRETURN_UNDEF;
61 #define hvs(VAL) hv_store_ent(hash, sv_2mortal(newSVpv(data->key,0)),VAL,0)
63 #define rrdinfocode(name) \
64 /* prepare argument list */ \
65 argv = (char **) malloc((items+1)*sizeof(char *)); \
67 for (i = 0; i < items; i++) { \
69 char *handle= SvPV(ST(i),len); \
70 /* actually copy the data to make sure possible modifications \
71 on the argv data does not backfire into perl */ \
72 argv[i+1] = (char *) malloc((strlen(handle)+1)*sizeof(char)); \
73 strcpy(argv[i+1],handle); \
76 data=name(items+1, argv); \
77 for (i=0; i < items; i++) { \
81 if (rrd_test_error()) XSRETURN_UNDEF; \
85 /* the newSV will get copied by hv so we create it as a mortal \
86 to make sure it does not keep hanging round after the fact */ \
87 switch (data->type) { \
89 if (isnan(data->value.u_val)) \
92 hvs(newSVnv(data->value.u_val)); \
95 hvs(newSViv(data->value.u_int)); \
98 hvs(newSViv(data->value.u_cnt)); \
101 hvs(newSVpv(data->value.u_str,0)); \
104 hvs(newSVpv(data->value.u_blo.ptr,data->value.u_blo.size)); \
109 rrd_info_free(save); \
110 RETVAL = newRV_noinc((SV*)hash);
113 * should not be needed if libc is linked (see ntmake.pl)
116 #define malloc malloc
117 #define realloc realloc
122 MODULE = RRDs PACKAGE = RRDs PREFIX = rrd_
125 #ifdef MUST_DISABLE_SIGFPE
126 signal(SIGFPE,SIG_IGN);
128 #ifdef MUST_DISABLE_FPMASK
135 if (! rrd_test_error()) XSRETURN_UNDEF;
136 RETVAL = newSVpv(rrd_get_error(),0);
208 argv = (char **) malloc((items+1)*sizeof(char *));
210 for (i = 0; i < items; i++) {
212 char *handle = SvPV(ST(i),len);
213 /* actually copy the data to make sure possible modifications
214 on the argv data does not backfire into perl */
215 argv[i+1] = (char *) malloc((strlen(handle)+1)*sizeof(char));
216 strcpy(argv[i+1],handle);
219 rrd_graph(items+1,argv,&calcpr,&xsize,&ysize,NULL,&ymin,&ymax);
220 for (i=0; i < items; i++) {
225 if (rrd_test_error()) {
227 for(i=0;calcpr[i];i++)
228 rrd_freemem(calcpr[i]);
233 for(i=0;calcpr[i];i++){
234 av_push(retar,newSVpv(calcpr[i],0));
235 rrd_freemem(calcpr[i]);
240 PUSHs(sv_2mortal(newRV_noinc((SV*)retar)));
241 PUSHs(sv_2mortal(newSViv(xsize)));
242 PUSHs(sv_2mortal(newSViv(ysize)));
249 unsigned long step, ds_cnt,i,ii;
250 rrd_value_t *data,*datai;
253 AV *retar,*line,*names;
255 argv = (char **) malloc((items+1)*sizeof(char *));
257 for (i = 0; i < items; i++) {
259 char *handle= SvPV(ST(i),len);
260 /* actually copy the data to make sure possible modifications
261 on the argv data does not backfire into perl */
262 argv[i+1] = (char *) malloc((strlen(handle)+1)*sizeof(char));
263 strcpy(argv[i+1],handle);
266 rrd_fetch(items+1,argv,&start,&end,&step,&ds_cnt,&ds_namv,&data);
267 for (i=0; i < items; i++) {
271 if (rrd_test_error()) XSRETURN_UNDEF;
272 /* convert the ds_namv into perl format */
274 for (ii = 0; ii < ds_cnt; ii++){
275 av_push(names,newSVpv(ds_namv[ii],0));
276 rrd_freemem(ds_namv[ii]);
278 rrd_freemem(ds_namv);
279 /* convert the data array into perl format */
282 for (i = start+step; i <= end; i += step){
284 for (ii = 0; ii < ds_cnt; ii++){
285 av_push(line,(isnan(*datai) ? &PL_sv_undef : newSVnv(*datai)));
288 av_push(retar,newRV_noinc((SV*)line));
292 PUSHs(sv_2mortal(newSViv(start+step)));
293 PUSHs(sv_2mortal(newSViv(step)));
294 PUSHs(sv_2mortal(newRV_noinc((SV*)names)));
295 PUSHs(sv_2mortal(newRV_noinc((SV*)retar)));
298 rrd_times(start, end)
302 rrd_time_value_t start_tv, end_tv;
303 char *parsetime_error = NULL;
304 time_t start_tmp, end_tmp;
307 if ((parsetime_error = rrd_parsetime(start, &start_tv))) {
308 rrd_set_error("start time: %s", parsetime_error);
311 if ((parsetime_error = rrd_parsetime(end, &end_tv))) {
312 rrd_set_error("end time: %s", parsetime_error);
315 if (rrd_proc_start_end(&start_tv, &end_tv, &start_tmp, &end_tmp) == -1) {
319 PUSHs(sv_2mortal(newSVuv(start_tmp)));
320 PUSHs(sv_2mortal(newSVuv(end_tmp)));
328 unsigned long step, col_cnt,row_cnt,i,ii;
329 rrd_value_t *data,*ptr;
330 char **argv,**legend_v;
331 AV *retar,*line,*names;
333 argv = (char **) malloc((items+1)*sizeof(char *));
335 for (i = 0; i < items; i++) {
337 char *handle = SvPV(ST(i),len);
338 /* actually copy the data to make sure possible modifications
339 on the argv data does not backfire into perl */
340 argv[i+1] = (char *) malloc((strlen(handle)+1)*sizeof(char));
341 strcpy(argv[i+1],handle);
344 rrd_xport(items+1,argv,&xsize,&start,&end,&step,&col_cnt,&legend_v,&data);
345 for (i=0; i < items; i++) {
349 if (rrd_test_error()) XSRETURN_UNDEF;
351 /* convert the legend_v into perl format */
353 for (ii = 0; ii < col_cnt; ii++){
354 av_push(names,newSVpv(legend_v[ii],0));
355 rrd_freemem(legend_v[ii]);
357 rrd_freemem(legend_v);
359 /* convert the data array into perl format */
362 for (i = start+step; i <= end; i += step){
364 for (ii = 0; ii < col_cnt; ii++){
365 av_push(line,(isnan(*ptr) ? &PL_sv_undef : newSVnv(*ptr)));
368 av_push(retar,newRV_noinc((SV*)line));
373 PUSHs(sv_2mortal(newSViv(start+step)));
374 PUSHs(sv_2mortal(newSViv(end)));
375 PUSHs(sv_2mortal(newSViv(step)));
376 PUSHs(sv_2mortal(newSViv(col_cnt)));
377 PUSHs(sv_2mortal(newRV_noinc((SV*)names)));
378 PUSHs(sv_2mortal(newRV_noinc((SV*)retar)));
384 rrd_info_t *data,*save;
389 rrdinfocode(rrd_info);
397 rrd_info_t *data,*save;
402 rrdinfocode(rrd_update_v);
410 rrd_info_t *data,*save;
415 rrdinfocode(rrd_graph_v);
438 rrdcode(rrd_restore);
451 rrdcode(rrd_flushcached);