~ubuntu-branches/ubuntu/maverick/rrdtool/maverick

« back to all changes in this revision

Viewing changes to bindings/ruby/main.c

  • Committer: Bazaar Package Importer
  • Author(s): Clint Byrum
  • Date: 2010-07-22 08:07:01 UTC
  • mfrom: (1.2.8 upstream) (3.1.6 sid)
  • Revision ID: james.westby@ubuntu.com-20100722080701-k46mgdfz6euxwqsm
Tags: 1.4.3-1ubuntu1
* Merge from debian unstable, Remaining changes:
  - debian/control: Don't build against ruby1.9 as we don't want
    it in main.
* require libdbi >= 0.8.3 to prevent aborts when using dbi datasources

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* $Id: main.c 1791 2009-04-14 13:55:29Z oetiker $
 
1
/* $Id: main.c 2022 2010-02-16 13:04:18Z oetiker $
2
2
 * Substantial penalty for early withdrawal.
3
3
 */
4
4
 
5
5
#include <unistd.h>
6
6
#include <ruby.h>
 
7
#include <math.h>
7
8
#include "../../src/rrd_tool.h"
8
9
 
9
10
typedef struct string_arr_t {
19
20
    int argc,
20
21
    char **argv);
21
22
 
 
23
typedef rrd_info_t *(
 
24
    *RRDINFOFUNC) (
 
25
    int argc,
 
26
    char **argv);
 
27
 
22
28
#define RRD_CHECK_ERROR  \
23
29
    if (rrd_test_error()) \
24
30
      rb_raise(rb_eRRDError, rrd_get_error()); \
138
144
    return rrd_call(rrd_update, args);
139
145
}
140
146
 
 
147
VALUE rb_rrd_flushcached(
 
148
    VALUE self,
 
149
    VALUE args)
 
150
{
 
151
    return rrd_call(rrd_flushcached, args);
 
152
}
 
153
 
141
154
 
142
155
/* Calls Returning Data via the Info Interface */
143
156
 
144
157
VALUE rb_rrd_infocall(
145
 
    RRDFUNC func,
 
158
    RRDINFOFUNC func,
146
159
    VALUE args)
147
160
{
148
161
    string_arr a;
150
163
    VALUE     result;
151
164
 
152
165
    a = string_arr_new(args);
 
166
    reset_rrd_state();
153
167
    data = func(a.len, a.strings);
154
168
    string_arr_delete(a);
155
169
 
173
187
        case RD_I_STR:
174
188
            rb_hash_aset(result, key, rb_str_new2(data->value.u_str));
175
189
            break;
 
190
        case RD_I_INT:
 
191
            rb_hash_aset(result, key, INT2FIX(data->value.u_int));
 
192
            break;
176
193
        case RD_I_BLO:
177
194
            rb_hash_aset(result, key,
178
 
                         rb_str_new(data->value.u_blo.ptr,
 
195
                         rb_str_new((char *)data->value.u_blo.ptr,
179
196
                                    data->value.u_blo.size));
180
197
            break;
181
198
        }
303
320
        return rb_funcall(rb_cTime, rb_intern("at"), 1, UINT2NUM(last));
304
321
}
305
322
 
 
323
VALUE rb_rrd_xport(
 
324
    VALUE self,
 
325
    VALUE args)
 
326
{
 
327
    string_arr a;
 
328
    unsigned long i, j, k, step, col_cnt;
 
329
    int xxsize;
 
330
    rrd_value_t *data;
 
331
    char **legend_v;
 
332
    VALUE legend, result, rdata;
 
333
    time_t start, end;
 
334
 
 
335
    a = string_arr_new(args);
 
336
    rrd_xport(a.len, a.strings, &xxsize, &start, &end, &step, &col_cnt, &legend_v, &data);
 
337
    string_arr_delete(a);
 
338
 
 
339
    RRD_CHECK_ERROR;
 
340
            
 
341
    legend = rb_ary_new();
 
342
    for (i = 0; i < col_cnt; i++) {
 
343
        rb_ary_push(legend, rb_str_new2(legend_v[i]));
 
344
        free(legend_v[i]);
 
345
    }
 
346
    free(legend_v);
 
347
 
 
348
    k = 0;
 
349
    rdata = rb_ary_new();
 
350
    for (i = start; i <= end; i += step) {
 
351
        VALUE line = rb_ary_new2(col_cnt);
 
352
        for (j = 0; j < col_cnt; j++) {
 
353
            rb_ary_store(line, j, rb_float_new(data[k]));
 
354
            k++;
 
355
        }
 
356
        rb_ary_push(rdata, line);
 
357
    }
 
358
    free(data);
 
359
 
 
360
    result = rb_ary_new2(6);
 
361
    rb_ary_store(result, 0, INT2FIX(start));
 
362
    rb_ary_store(result, 1, INT2FIX(end));
 
363
    rb_ary_store(result, 2, INT2FIX(step));
 
364
    rb_ary_store(result, 3, INT2FIX(col_cnt));
 
365
    rb_ary_store(result, 4, legend);
 
366
    rb_ary_store(result, 5, rdata);
 
367
    return result;
 
368
}
 
369
 
306
370
void Init_RRD(
307
371
    )
308
372
{
318
382
    rb_define_module_function(mRRD, "restore", rb_rrd_restore, -2);
319
383
    rb_define_module_function(mRRD, "tune", rb_rrd_tune, -2);
320
384
    rb_define_module_function(mRRD, "update", rb_rrd_update, -2);
 
385
    rb_define_module_function(mRRD, "flushcached", rb_rrd_flushcached, -2);
321
386
    rb_define_module_function(mRRD, "info", rb_rrd_info, -2);
322
387
    rb_define_module_function(mRRD, "updatev", rb_rrd_updatev, -2);
323
388
    rb_define_module_function(mRRD, "graphv", rb_rrd_graphv, -2);
 
389
    rb_define_module_function(mRRD, "xport", rb_rrd_xport, -2);
324
390
}