X-Git-Url: https://git.octo.it/?p=rrdtool.git;a=blobdiff_plain;f=bindings%2Fruby%2Fmain.c;h=6dc229b8691d1625404ea3ca54311f7d68a6adca;hp=355625f9c2ec5d87b6124b1ec05cca1243decfdf;hb=513304e8a967fa471a0028711ddd3d95ce812d7d;hpb=88f9f8473259baa892d8819b7cf374c0e561103f diff --git a/bindings/ruby/main.c b/bindings/ruby/main.c index 355625f..6dc229b 100644 --- a/bindings/ruby/main.c +++ b/bindings/ruby/main.c @@ -48,7 +48,7 @@ string_arr string_arr_new( switch (TYPE(v)) { case T_STRING: - a.strings[i + 1] = strdup(STR2CSTR(v)); + a.strings[i + 1] = strdup(StringValuePtr(v)); break; case T_FIXNUM: snprintf(buf, 63, "%d", FIX2INT(v)); @@ -163,6 +163,7 @@ VALUE rb_rrd_infocall( VALUE result; a = string_arr_new(args); + reset_rrd_state(); data = func(a.len, a.strings); string_arr_delete(a); @@ -319,6 +320,53 @@ VALUE rb_rrd_last( return rb_funcall(rb_cTime, rb_intern("at"), 1, UINT2NUM(last)); } +VALUE rb_rrd_xport( + VALUE self, + VALUE args) +{ + string_arr a; + unsigned long i, j, k, step, col_cnt; + int xxsize; + rrd_value_t *data; + char **legend_v; + VALUE legend, result, rdata; + time_t start, end; + + a = string_arr_new(args); + rrd_xport(a.len, a.strings, &xxsize, &start, &end, &step, &col_cnt, &legend_v, &data); + string_arr_delete(a); + + RRD_CHECK_ERROR; + + legend = rb_ary_new(); + for (i = 0; i < col_cnt; i++) { + rb_ary_push(legend, rb_str_new2(legend_v[i])); + free(legend_v[i]); + } + free(legend_v); + + k = 0; + rdata = rb_ary_new(); + for (i = start; i <= end; i += step) { + VALUE line = rb_ary_new2(col_cnt); + for (j = 0; j < col_cnt; j++) { + rb_ary_store(line, j, rb_float_new(data[k])); + k++; + } + rb_ary_push(rdata, line); + } + free(data); + + result = rb_ary_new2(6); + rb_ary_store(result, 0, INT2FIX(start)); + rb_ary_store(result, 1, INT2FIX(end)); + rb_ary_store(result, 2, INT2FIX(step)); + rb_ary_store(result, 3, INT2FIX(col_cnt)); + rb_ary_store(result, 4, legend); + rb_ary_store(result, 5, rdata); + return result; +} + void Init_RRD( ) { @@ -338,4 +386,5 @@ void Init_RRD( rb_define_module_function(mRRD, "info", rb_rrd_info, -2); rb_define_module_function(mRRD, "updatev", rb_rrd_updatev, -2); rb_define_module_function(mRRD, "graphv", rb_rrd_graphv, -2); + rb_define_module_function(mRRD, "xport", rb_rrd_xport, -2); }