X-Git-Url: https://git.octo.it/?p=rrdtool.git;a=blobdiff_plain;f=bindings%2Fperl-shared%2FRRDs.xs;h=830a779d5f0f090c395cfeed3c0a445aa0b8b4f2;hp=e2a0c8f8252d05d05028aad19754c878dfc58d13;hb=b0a526a0bcba4a883645db7c228f905c3906be77;hpb=97a69ea53c90c6141e692cf77b3202df989eb505 diff --git a/bindings/perl-shared/RRDs.xs b/bindings/perl-shared/RRDs.xs index e2a0c8f..830a779 100644 --- a/bindings/perl-shared/RRDs.xs +++ b/bindings/perl-shared/RRDs.xs @@ -10,13 +10,27 @@ extern "C" { } #endif -#include "../../src/rrd_tool.h" - -/* perl 5.004 compatibility */ -#if PERLPATCHLEVEL < 5 -#define PL_sv_undef sv_undef +/* + * rrd_tool.h includes config.h, but at least on Ubuntu Breezy Badger + * 5.10 with gcc 4.0.2, the C preprocessor picks up Perl's config.h + * which is included from the Perl includes and never reads rrdtool's + * config.h. Without including rrdtool's config.h, this module does + * not compile, so include it here with an explicit path. + * + * Because rrdtool's config.h redefines VERSION which is originally + * set via Perl's Makefile.PL and passed down to the C compiler's + * command line, save the original value and reset it after the + * includes. + */ +#define VERSION_SAVED VERSION +#undef VERSION +#ifndef WIN32 +#include "../../rrd_config.h" #endif - +#include "../../src/rrd_tool.h" +#undef VERSION +#define VERSION VERSION_SAVED +#undef VERSION_SAVED #define rrdcode(name) \ argv = (char **) malloc((items+1)*sizeof(char *));\ @@ -29,7 +43,6 @@ extern "C" { argv[i+1] = (char *) malloc((strlen(handle)+1)*sizeof(char)); \ strcpy(argv[i+1],handle); \ } \ - optind=0; opterr=0; \ rrd_clear_error();\ RETVAL=name(items+1,argv); \ for (i=0; i < items; i++) {\ @@ -53,7 +66,6 @@ extern "C" { argv[i+1] = (char *) malloc((strlen(handle)+1)*sizeof(char)); \ strcpy(argv[i+1],handle); \ } \ - optind=0; opterr=0; \ rrd_clear_error(); \ data=name(items+1, argv); \ for (i=0; i < items; i++) { \ @@ -62,14 +74,14 @@ extern "C" { free(argv); \ if (rrd_test_error()) XSRETURN_UNDEF; \ hash = newHV(); \ + save=data; \ while (data) { \ - save=data; \ /* the newSV will get copied by hv so we create it as a mortal \ to make sure it does not keep hanging round after the fact */ \ switch (data->type) { \ case RD_I_VAL: \ if (isnan(data->value.u_val)) \ - hvs(&PL_sv_undef); \ + hvs(newSV(0)); \ else \ hvs(newSVnv(data->value.u_val)); \ break; \ @@ -81,14 +93,14 @@ extern "C" { break; \ case RD_I_STR: \ hvs(newSVpv(data->value.u_str,0)); \ - rrd_freemem(data->value.u_str); \ + break; \ + case RD_I_BLO: \ + hvs(newSVpv(data->value.u_blo.ptr,data->value.u_blo.size)); \ break; \ } \ - rrd_freemem(data->key); \ data = data->next; \ - rrd_freemem(save); \ - } \ - rrd_freemem(data); \ + } \ + rrd_info_free(save); \ RETVAL = newRV_noinc((SV*)hash); /* @@ -110,7 +122,6 @@ BOOT: #ifdef MUST_DISABLE_FPMASK fpsetmask(0); #endif - SV* rrd_error() @@ -120,7 +131,6 @@ rrd_error() OUTPUT: RETVAL - int rrd_last(...) PROTOTYPE: @ @@ -132,6 +142,16 @@ rrd_last(...) OUTPUT: RETVAL +int +rrd_first(...) + PROTOTYPE: @ + PREINIT: + int i; + char **argv; + CODE: + rrdcode(rrd_first); + OUTPUT: + RETVAL int rrd_create(...) @@ -145,7 +165,6 @@ rrd_create(...) OUTPUT: RETVAL - int rrd_update(...) PROTOTYPE: @ @@ -158,7 +177,6 @@ rrd_update(...) OUTPUT: RETVAL - int rrd_tune(...) PROTOTYPE: @ @@ -171,13 +189,13 @@ rrd_tune(...) OUTPUT: RETVAL - -void +SV * rrd_graph(...) PROTOTYPE: @ PREINIT: char **calcpr=NULL; int i,xsize,ysize; + double ymin,ymax; char **argv; AV *retar; PPCODE: @@ -191,9 +209,8 @@ rrd_graph(...) argv[i+1] = (char *) malloc((strlen(handle)+1)*sizeof(char)); strcpy(argv[i+1],handle); } - optind=0; opterr=0; rrd_clear_error(); - rrd_graph(items+1,argv,&calcpr,&xsize,&ysize,NULL); + rrd_graph(items+1,argv,&calcpr,&xsize,&ysize,NULL,&ymin,&ymax); for (i=0; i < items; i++) { free(argv[i+1]); } @@ -218,7 +235,7 @@ rrd_graph(...) PUSHs(sv_2mortal(newSViv(xsize))); PUSHs(sv_2mortal(newSViv(ysize))); -void +SV * rrd_fetch(...) PROTOTYPE: @ PREINIT: @@ -239,7 +256,6 @@ rrd_fetch(...) argv[i+1] = (char *) malloc((strlen(handle)+1)*sizeof(char)); strcpy(argv[i+1],handle); } - optind=0; opterr=0; rrd_clear_error(); rrd_fetch(items+1,argv,&start,&end,&step,&ds_cnt,&ds_namv,&data); for (i=0; i < items; i++) { @@ -260,7 +276,7 @@ rrd_fetch(...) for (i = start+step; i <= end; i += step){ line = newAV(); for (ii = 0; ii < ds_cnt; ii++){ - av_push(line,(isnan(*datai) ? &PL_sv_undef : newSVnv(*datai))); + av_push(line,(isnan(*datai) ? newSV(0) : newSVnv(*datai))); datai++; } av_push(retar,newRV_noinc((SV*)line)); @@ -272,6 +288,30 @@ rrd_fetch(...) PUSHs(sv_2mortal(newRV_noinc((SV*)names))); PUSHs(sv_2mortal(newRV_noinc((SV*)retar))); +SV * +rrd_times(start, end) + char *start + char *end + PREINIT: + rrd_time_value_t start_tv, end_tv; + char *parsetime_error = NULL; + time_t start_tmp, end_tmp; + PPCODE: + rrd_clear_error(); + if ((parsetime_error = rrd_parsetime(start, &start_tv))) { + rrd_set_error("start time: %s", parsetime_error); + XSRETURN_UNDEF; + } + if ((parsetime_error = rrd_parsetime(end, &end_tv))) { + rrd_set_error("end time: %s", parsetime_error); + XSRETURN_UNDEF; + } + if (rrd_proc_start_end(&start_tv, &end_tv, &start_tmp, &end_tmp) == -1) { + XSRETURN_UNDEF; + } + EXTEND(sp,2); + PUSHs(sv_2mortal(newSVuv(start_tmp))); + PUSHs(sv_2mortal(newSVuv(end_tmp))); int rrd_xport(...) @@ -294,7 +334,6 @@ rrd_xport(...) argv[i+1] = (char *) malloc((strlen(handle)+1)*sizeof(char)); strcpy(argv[i+1],handle); } - optind=0; opterr=0; rrd_clear_error(); rrd_xport(items+1,argv,&xsize,&start,&end,&step,&col_cnt,&legend_v,&data); for (i=0; i < items; i++) { @@ -317,7 +356,7 @@ rrd_xport(...) for (i = start+step; i <= end; i += step){ line = newAV(); for (ii = 0; ii < col_cnt; ii++){ - av_push(line,(isnan(*ptr) ? &PL_sv_undef : newSVnv(*ptr))); + av_push(line,(isnan(*ptr) ? newSV(0) : newSVnv(*ptr))); ptr++; } av_push(retar,newRV_noinc((SV*)line)); @@ -336,7 +375,7 @@ SV* rrd_info(...) PROTOTYPE: @ PREINIT: - info_t *data,*save; + rrd_info_t *data,*save; int i; char **argv; HV *hash; @@ -349,7 +388,7 @@ SV* rrd_updatev(...) PROTOTYPE: @ PREINIT: - info_t *data,*save; + rrd_info_t *data,*save; int i; char **argv; HV *hash; @@ -358,3 +397,53 @@ rrd_updatev(...) OUTPUT: RETVAL +SV* +rrd_graphv(...) + PROTOTYPE: @ + PREINIT: + rrd_info_t *data,*save; + int i; + char **argv; + HV *hash; + CODE: + rrdinfocode(rrd_graph_v); + OUTPUT: + RETVAL + +int +rrd_dump(...) + PROTOTYPE: @ + PREINIT: + int i; + char **argv; + CODE: + rrdcode(rrd_dump); + RETVAL = 1; + OUTPUT: + RETVAL + +int +rrd_restore(...) + PROTOTYPE: @ + PREINIT: + int i; + char **argv; + CODE: + rrdcode(rrd_restore); + RETVAL = 1; + OUTPUT: + RETVAL + +#ifndef WIN32 +int +rrd_flushcached(...) + PROTOTYPE: @ + PREINIT: + int i; + char **argv; + CODE: + rrdcode(rrd_flushcached); + OUTPUT: + RETVAL + +#endif