From 70514c7f7e34243cc2b9c8ee925bcc243a1001b2 Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Tue, 19 Feb 2013 12:59:23 +0000 Subject: [PATCH] ruby: Add binding for guestfs_event_to_string. --- generator/ruby.ml | 29 +++++++++++++++++++++++++++++ ruby/tests/tc_400_events.rb | 3 ++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/generator/ruby.ml b/generator/ruby.ml index 4f2c60bb2..0988e22d5 100644 --- a/generator/ruby.ml +++ b/generator/ruby.ml @@ -40,6 +40,8 @@ let rec generate_ruby_c () = #include #include #include +#include +#include #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); diff --git a/ruby/tests/tc_400_events.rb b/ruby/tests/tc_400_events.rb index 4e045700a..7c911c436 100644 --- a/ruby/tests/tc_400_events.rb +++ b/ruby/tests/tc_400_events.rb @@ -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