From 8e156f28bd5507eecba1362da3dc0dc66e76dc59 Mon Sep 17 00:00:00 2001 From: Doug MacEachern Date: Mon, 3 Sep 2007 00:49:22 +0000 Subject: [PATCH] start ruby bindings --- bindings/ruby/extconf.rb | 16 +++++ bindings/ruby/rbsigar.c | 127 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 143 insertions(+) create mode 100644 bindings/ruby/extconf.rb create mode 100644 bindings/ruby/rbsigar.c diff --git a/bindings/ruby/extconf.rb b/bindings/ruby/extconf.rb new file mode 100644 index 00000000..e343d9c9 --- /dev/null +++ b/bindings/ruby/extconf.rb @@ -0,0 +1,16 @@ +require 'mkmf' + +extension_name = 'rbsigar' + +installdir = '../java/sigar-bin' +#XXX hardwired for the moment +libname = 'sigar-universal-macosx' + +$CPPFLAGS += ' -I' + installdir + '/include' +$LOCAL_LIBS += '-L' + installdir + '/lib -l' + libname + +dir_config(extension_name) + +system('perl -Mlib=.. -MSigarWrapper -e generate Ruby .') + +create_makefile(extension_name) diff --git a/bindings/ruby/rbsigar.c b/bindings/ruby/rbsigar.c new file mode 100644 index 00000000..d1d42a76 --- /dev/null +++ b/bindings/ruby/rbsigar.c @@ -0,0 +1,127 @@ +#include +#include "sigar.h" +#include "sigar_fileinfo.h" +#include "sigar_format.h" + +#define RB_SIGAR_CROAK rb_raise(rb_eArgError, "%s", sigar_strerror(sigar, status)) + +static sigar_t *rb_sigar_get(VALUE obj) +{ + sigar_t *sigar; + Data_Get_Struct(obj, sigar_t, sigar); + return sigar; +} + +static void rb_sigar_free(void *obj) +{ + free(obj); +} + +static void rb_sigar_close(void *obj) +{ + sigar_close((sigar_t *)obj); +} + +static VALUE rb_sigar_new(VALUE module) +{ + sigar_t *sigar; + sigar_open(&sigar); + return Data_Wrap_Struct(module, 0, rb_sigar_close, sigar); +} + +static VALUE rb_sigar_net_address_to_string(sigar_net_address_t address) +{ + char addr_str[SIGAR_INET6_ADDRSTRLEN]; + sigar_net_address_to_string(NULL, &address, addr_str); + return rb_str_new2(addr_str); +} + +static VALUE rb_sigar_new_list(char *data, unsigned long number, + int size, VALUE rclass) +{ + unsigned long i; + VALUE av = rb_ary_new2(number); + + for (i=0; i