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
27 #include "../../rrd_config.h"
28 #include "../../src/rrd_tool.h"
30 #define VERSION VERSION_SAVED
33 /* perl 5.004 compatibility */
34 #if PERLPATCHLEVEL < 5
35 #define PL_sv_undef sv_undef
39 #define rrdcode(name) \
40 argv = (char **) malloc((items+1)*sizeof(char *));\
42 for (i = 0; i < items; i++) { \
44 char *handle= SvPV(ST(i),len);\
45 /* actually copy the data to make sure possible modifications \
46 on the argv data does not backfire into perl */ \
47 argv[i+1] = (char *) malloc((strlen(handle)+1)*sizeof(char)); \
48 strcpy(argv[i+1],handle); \
51 RETVAL=name(items+1,argv); \
52 for (i=0; i < items; i++) {\
57 if (rrd_test_error()) XSRETURN_UNDEF;
59 #define hvs(VAL) hv_store_ent(hash, sv_2mortal(newSVpv(data->key,0)),VAL,0)
61 #define rrdinfocode(name) \
62 /* prepare argument list */ \
63 argv = (char **) malloc((items+1)*sizeof(char *)); \
65 for (i = 0; i < items; i++) { \
67 char *handle= SvPV(ST(i),len); \
68 /* actually copy the data to make sure possible modifications \
69 on the argv data does not backfire into perl */ \
70 argv[i+1] = (char *) malloc((strlen(handle)+1)*sizeof(char)); \
71 strcpy(argv[i+1],handle); \
74 data=name(items+1, argv); \
75 for (i=0; i < items; i++) { \
79 if (rrd_test_error()) XSRETURN_UNDEF; \
83 /* the newSV will get copied by hv so we create it as a mortal \
84 to make sure it does not keep hanging round after the fact */ \
85 switch (data->type) { \
87 if (isnan(data->value.u_val)) \
90 hvs(newSVnv(data->value.u_val)); \
93 hvs(newSViv(data->value.u_int)); \
96 hvs(newSViv(data->value.u_cnt)); \
99 hvs(newSVpv(data->value.u_str,0)); \
102 hvs(newSVpv(data->value.u_blo.ptr,data->value.u_blo.size)); \
107 rrd_info_free(save); \
108 RETVAL = newRV_noinc((SV*)hash);
111 * should not be needed if libc is linked (see ntmake.pl)
114 #define malloc malloc
115 #define realloc realloc
120 MODULE = RRDs PACKAGE = RRDs PREFIX = rrd_
123 #ifdef MUST_DISABLE_SIGFPE
124 signal(SIGFPE,SIG_IGN);
126 #ifdef MUST_DISABLE_FPMASK
134 if (! rrd_test_error()) XSRETURN_UNDEF;
135 RETVAL = newSVpv(rrd_get_error(),0);
212 argv = (char **) malloc((items+1)*sizeof(char *));
214 for (i = 0; i < items; i++) {
216 char *handle = SvPV(ST(i),len);
217 /* actually copy the data to make sure possible modifications
218 on the argv data does not backfire into perl */
219 argv[i+1] = (char *) malloc((strlen(handle)+1)*sizeof(char));
220 strcpy(argv[i+1],handle);
223 rrd_graph(items+1,argv,&calcpr,&xsize,&ysize,NULL,&ymin,&ymax);
224 for (i=0; i < items; i++) {
229 if (rrd_test_error()) {
231 for(i=0;calcpr[i];i++)
232 rrd_freemem(calcpr[i]);
237 for(i=0;calcpr[i];i++){
238 av_push(retar,newSVpv(calcpr[i],0));
239 rrd_freemem(calcpr[i]);
244 PUSHs(sv_2mortal(newRV_noinc((SV*)retar)));
245 PUSHs(sv_2mortal(newSViv(xsize)));
246 PUSHs(sv_2mortal(newSViv(ysize)));
253 unsigned long step, ds_cnt,i,ii;
254 rrd_value_t *data,*datai;
257 AV *retar,*line,*names;
259 argv = (char **) malloc((items+1)*sizeof(char *));
261 for (i = 0; i < items; i++) {
263 char *handle= SvPV(ST(i),len);
264 /* actually copy the data to make sure possible modifications
265 on the argv data does not backfire into perl */
266 argv[i+1] = (char *) malloc((strlen(handle)+1)*sizeof(char));
267 strcpy(argv[i+1],handle);
270 rrd_fetch(items+1,argv,&start,&end,&step,&ds_cnt,&ds_namv,&data);
271 for (i=0; i < items; i++) {
275 if (rrd_test_error()) XSRETURN_UNDEF;
276 /* convert the ds_namv into perl format */
278 for (ii = 0; ii < ds_cnt; ii++){
279 av_push(names,newSVpv(ds_namv[ii],0));
280 rrd_freemem(ds_namv[ii]);
282 rrd_freemem(ds_namv);
283 /* convert the data array into perl format */
286 for (i = start+step; i <= end; i += step){
288 for (ii = 0; ii < ds_cnt; ii++){
289 av_push(line,(isnan(*datai) ? &PL_sv_undef : newSVnv(*datai)));
292 av_push(retar,newRV_noinc((SV*)line));
296 PUSHs(sv_2mortal(newSViv(start+step)));
297 PUSHs(sv_2mortal(newSViv(step)));
298 PUSHs(sv_2mortal(newRV_noinc((SV*)names)));
299 PUSHs(sv_2mortal(newRV_noinc((SV*)retar)));
302 rrd_times(start, end)
306 rrd_time_value_t start_tv, end_tv;
307 char *parsetime_error = NULL;
308 time_t start_tmp, end_tmp;
311 if ((parsetime_error = rrd_parsetime(start, &start_tv))) {
312 rrd_set_error("start time: %s", parsetime_error);
315 if ((parsetime_error = rrd_parsetime(end, &end_tv))) {
316 rrd_set_error("end time: %s", parsetime_error);
319 if (rrd_proc_start_end(&start_tv, &end_tv, &start_tmp, &end_tmp) == -1) {
323 PUSHs(sv_2mortal(newSVuv(start_tmp)));
324 PUSHs(sv_2mortal(newSVuv(end_tmp)));
332 unsigned long step, col_cnt,row_cnt,i,ii;
333 rrd_value_t *data,*ptr;
334 char **argv,**legend_v;
335 AV *retar,*line,*names;
337 argv = (char **) malloc((items+1)*sizeof(char *));
339 for (i = 0; i < items; i++) {
341 char *handle = SvPV(ST(i),len);
342 /* actually copy the data to make sure possible modifications
343 on the argv data does not backfire into perl */
344 argv[i+1] = (char *) malloc((strlen(handle)+1)*sizeof(char));
345 strcpy(argv[i+1],handle);
348 rrd_xport(items+1,argv,&xsize,&start,&end,&step,&col_cnt,&legend_v,&data);
349 for (i=0; i < items; i++) {
353 if (rrd_test_error()) XSRETURN_UNDEF;
355 /* convert the legend_v into perl format */
357 for (ii = 0; ii < col_cnt; ii++){
358 av_push(names,newSVpv(legend_v[ii],0));
359 rrd_freemem(legend_v[ii]);
361 rrd_freemem(legend_v);
363 /* convert the data array into perl format */
366 for (i = start+step; i <= end; i += step){
368 for (ii = 0; ii < col_cnt; ii++){
369 av_push(line,(isnan(*ptr) ? &PL_sv_undef : newSVnv(*ptr)));
372 av_push(retar,newRV_noinc((SV*)line));
377 PUSHs(sv_2mortal(newSViv(start+step)));
378 PUSHs(sv_2mortal(newSViv(end)));
379 PUSHs(sv_2mortal(newSViv(step)));
380 PUSHs(sv_2mortal(newSViv(col_cnt)));
381 PUSHs(sv_2mortal(newRV_noinc((SV*)names)));
382 PUSHs(sv_2mortal(newRV_noinc((SV*)retar)));
388 rrd_info_t *data,*save;
393 rrdinfocode(rrd_info);
401 rrd_info_t *data,*save;
406 rrdinfocode(rrd_update_v);
414 rrd_info_t *data,*save;
419 rrdinfocode(rrd_graph_v);
442 rrdcode(rrd_restore);
454 rrdcode(rrd_cmd_flush);