/* * Copyright (C) [2004, 2005, 2006], Hyperic, Inc. * This file is part of SIGAR. * * SIGAR is free software; you can redistribute it and/or modify * it under the terms version 2 of the GNU General Public License as * published by the Free Software Foundation. This program is distributed * in the hope that it will be useful, but WITHOUT ANY WARRANTY; without * even the implied warranty of MERCHANTABILITY or FITNESS FOR A * PARTICULAR PURPOSE. See the GNU General Public License for more * details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA. */ #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_format_size(VALUE rclass, VALUE size) { char buffer[56]; return rb_str_new2(sigar_format_size(NUM2LL(size), buffer)); } static VALUE rb_sigar_net_interface_flags_to_s(VALUE rclass, VALUE flags) { char buffer[1024]; return rb_str_new2(sigar_net_interface_flags_to_string(NUM2LL(flags), buffer)); } 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