mirror of
https://github.com/libguestfs/libguestfs.git
synced 2026-03-22 07:03:38 +00:00
ruby: Add binding for guestfs_event_to_string.
This commit is contained in:
@@ -40,6 +40,8 @@ let rec generate_ruby_c () =
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored \"-Wstrict-prototypes\"
|
||||
@@ -265,6 +267,31 @@ ruby_delete_event_callback (VALUE gv, VALUE event_handlev)
|
||||
return Qnil;
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* Guestfs::Guestfs.event_to_string(events) -> string
|
||||
*
|
||||
* Call
|
||||
* +guestfs_event_to_string+[http://libguestfs.org/guestfs.3.html#guestfs_event_to_string]
|
||||
* to convert an event or event bitmask into a printable string.
|
||||
*/
|
||||
static VALUE
|
||||
ruby_event_to_string (VALUE modulev, VALUE eventsv)
|
||||
{
|
||||
uint64_t events;
|
||||
char *str;
|
||||
|
||||
events = NUM2ULL (eventsv);
|
||||
str = guestfs_event_to_string (events);
|
||||
if (str == NULL)
|
||||
rb_raise (e_Error, \"%%s\", strerror (errno));
|
||||
|
||||
volatile VALUE rv = rb_str_new2 (str);
|
||||
free (str);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
static void
|
||||
ruby_event_callback_wrapper (guestfs_h *g,
|
||||
void *data,
|
||||
@@ -702,6 +729,8 @@ Init__guestfs (void)
|
||||
ruby_set_event_callback, 2);
|
||||
rb_define_method (c_guestfs, \"delete_event_callback\",
|
||||
ruby_delete_event_callback, 1);
|
||||
rb_define_module_function (m_guestfs, \"event_to_string\",
|
||||
ruby_event_to_string, 1);
|
||||
rb_define_method (c_guestfs, \"user_cancel\",
|
||||
ruby_user_cancel, 0);
|
||||
|
||||
|
||||
@@ -28,7 +28,8 @@ class TestLoad < Test::Unit::TestCase
|
||||
if event == Guestfs::EVENT_APPLIANCE
|
||||
buf.chomp!
|
||||
end
|
||||
puts "ruby event logged: event=#{event} eh=#{event_handle} buf='#{buf}' array=#{array}"
|
||||
event_string = Guestfs::event_to_string(event)
|
||||
puts "ruby event logged: event=#{event_string} eh=#{event_handle} buf='#{buf}' array=#{array}"
|
||||
}
|
||||
|
||||
close_invoked = 0
|
||||
|
||||
Reference in New Issue
Block a user