13 #include "../../src/rrd_tool.h"
15 /* perl 5.004 compatibility */
16 #if PERLPATCHLEVEL < 5
17 #define PL_sv_undef sv_undef
21 #define rrdcode(name) \
22 argv = (char **) malloc((items+1)*sizeof(char *));\
24 for (i = 0; i < items; i++) { \
26 char *handle= SvPV(ST(i),len);\
27 /* actually copy the data to make sure possible modifications \
28 on the argv data does not backfire into perl */ \
29 argv[i+1] = (char *) malloc((strlen(handle)+1)*sizeof(char)); \
30 strcpy(argv[i+1],handle); \
33 RETVAL=name(items+1,argv); \
34 for (i=0; i < items; i++) {\
39 if (rrd_test_error()) XSRETURN_UNDEF;
41 #define hvs(VAL) hv_store_ent(hash, sv_2mortal(newSVpv(data->key,0)),VAL,0)
43 #define rrdinfocode(name) \
44 /* prepare argument list */ \
45 argv = (char **) malloc((items+1)*sizeof(char *)); \
47 for (i = 0; i < items; i++) { \
49 char *handle= SvPV(ST(i),len); \
50 /* actually copy the data to make sure possible modifications \
51 on the argv data does not backfire into perl */ \
52 argv[i+1] = (char *) malloc((strlen(handle)+1)*sizeof(char)); \
53 strcpy(argv[i+1],handle); \
56 data=name(items+1, argv); \
57 for (i=0; i < items; i++) { \
61 if (rrd_test_error()) XSRETURN_UNDEF; \
65 /* the newSV will get copied by hv so we create it as a mortal \
66 to make sure it does not keep hanging round after the fact */ \
67 switch (data->type) { \
69 if (isnan(data->value.u_val)) \
72 hvs(newSVnv(data->value.u_val)); \
75 hvs(newSViv(data->value.u_int)); \
78 hvs(newSViv(data->value.u_cnt)); \
81 hvs(newSVpv(data->value.u_str,0)); \
82 rrd_freemem(data->value.u_str); \
85 rrd_freemem(data->key); \
90 RETVAL = newRV_noinc((SV*)hash);
93 * should not be needed if libc is linked (see ntmake.pl)
97 #define realloc realloc
102 MODULE = RRDs PACKAGE = RRDs PREFIX = rrd_
105 #ifdef MUST_DISABLE_SIGFPE
106 signal(SIGFPE,SIG_IGN);
108 #ifdef MUST_DISABLE_FPMASK
116 if (! rrd_test_error()) XSRETURN_UNDEF;
117 RETVAL = newSVpv(rrd_get_error(),0);
194 argv = (char **) malloc((items+1)*sizeof(char *));
196 for (i = 0; i < items; i++) {
198 char *handle = SvPV(ST(i),len);
199 /* actually copy the data to make sure possible modifications
200 on the argv data does not backfire into perl */
201 argv[i+1] = (char *) malloc((strlen(handle)+1)*sizeof(char));
202 strcpy(argv[i+1],handle);
205 rrd_graph(items+1,argv,&calcpr,&xsize,&ysize,NULL,&ymin,&ymax);
206 for (i=0; i < items; i++) {
211 if (rrd_test_error()) {
213 for(i=0;calcpr[i];i++)
214 rrd_freemem(calcpr[i]);
219 for(i=0;calcpr[i];i++){
220 av_push(retar,newSVpv(calcpr[i],0));
221 rrd_freemem(calcpr[i]);
226 PUSHs(sv_2mortal(newRV_noinc((SV*)retar)));
227 PUSHs(sv_2mortal(newSViv(xsize)));
228 PUSHs(sv_2mortal(newSViv(ysize)));
235 unsigned long step, ds_cnt,i,ii;
236 rrd_value_t *data,*datai;
239 AV *retar,*line,*names;
241 argv = (char **) malloc((items+1)*sizeof(char *));
243 for (i = 0; i < items; i++) {
245 char *handle= SvPV(ST(i),len);
246 /* actually copy the data to make sure possible modifications
247 on the argv data does not backfire into perl */
248 argv[i+1] = (char *) malloc((strlen(handle)+1)*sizeof(char));
249 strcpy(argv[i+1],handle);
252 rrd_fetch(items+1,argv,&start,&end,&step,&ds_cnt,&ds_namv,&data);
253 for (i=0; i < items; i++) {
257 if (rrd_test_error()) XSRETURN_UNDEF;
258 /* convert the ds_namv into perl format */
260 for (ii = 0; ii < ds_cnt; ii++){
261 av_push(names,newSVpv(ds_namv[ii],0));
262 rrd_freemem(ds_namv[ii]);
264 rrd_freemem(ds_namv);
265 /* convert the data array into perl format */
268 for (i = start+step; i <= end; i += step){
270 for (ii = 0; ii < ds_cnt; ii++){
271 av_push(line,(isnan(*datai) ? &PL_sv_undef : newSVnv(*datai)));
274 av_push(retar,newRV_noinc((SV*)line));
278 PUSHs(sv_2mortal(newSViv(start+step)));
279 PUSHs(sv_2mortal(newSViv(step)));
280 PUSHs(sv_2mortal(newRV_noinc((SV*)names)));
281 PUSHs(sv_2mortal(newRV_noinc((SV*)retar)));
284 rrd_times(start, end)
288 struct rrd_time_value start_tv, end_tv;
289 char *parsetime_error = NULL;
290 time_t start_tmp, end_tmp;
293 if( (parsetime_error = parsetime( start, &start_tv))) {
294 rrd_set_error( "start time: %s", parsetime_error);
297 if( (parsetime_error = parsetime( end, &end_tv))) {
298 rrd_set_error( "end time: %s", parsetime_error);
301 if( proc_start_end( &start_tv, &end_tv, &start_tmp, &end_tmp) == -1) {
305 PUSHs(sv_2mortal(newSVuv(start_tmp)));
306 PUSHs(sv_2mortal(newSVuv(end_tmp)));
314 unsigned long step, col_cnt,row_cnt,i,ii;
315 rrd_value_t *data,*ptr;
316 char **argv,**legend_v;
317 AV *retar,*line,*names;
319 argv = (char **) malloc((items+1)*sizeof(char *));
321 for (i = 0; i < items; i++) {
323 char *handle = SvPV(ST(i),len);
324 /* actually copy the data to make sure possible modifications
325 on the argv data does not backfire into perl */
326 argv[i+1] = (char *) malloc((strlen(handle)+1)*sizeof(char));
327 strcpy(argv[i+1],handle);
330 rrd_xport(items+1,argv,&xsize,&start,&end,&step,&col_cnt,&legend_v,&data);
331 for (i=0; i < items; i++) {
335 if (rrd_test_error()) XSRETURN_UNDEF;
337 /* convert the legend_v into perl format */
339 for (ii = 0; ii < col_cnt; ii++){
340 av_push(names,newSVpv(legend_v[ii],0));
341 rrd_freemem(legend_v[ii]);
343 rrd_freemem(legend_v);
345 /* convert the data array into perl format */
348 for (i = start+step; i <= end; i += step){
350 for (ii = 0; ii < col_cnt; ii++){
351 av_push(line,(isnan(*ptr) ? &PL_sv_undef : newSVnv(*ptr)));
354 av_push(retar,newRV_noinc((SV*)line));
359 PUSHs(sv_2mortal(newSViv(start+step)));
360 PUSHs(sv_2mortal(newSViv(end)));
361 PUSHs(sv_2mortal(newSViv(step)));
362 PUSHs(sv_2mortal(newSViv(col_cnt)));
363 PUSHs(sv_2mortal(newRV_noinc((SV*)names)));
364 PUSHs(sv_2mortal(newRV_noinc((SV*)retar)));
375 rrdinfocode(rrd_info);
388 rrdinfocode(rrd_update_v);
411 rrdcode(rrd_restore);