<div dir="ltr">I fixed based on comments.<div><br></div><div>I'll send these two patches to this mailing list.</div><div><br></div><div>- Fix Handle -> Handle<'a></div><div>- Add events</div><div><br></div><div>Regards,</div><div>Hiroyuki</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">2019年8月1日(木) 0:01 Pino Toscano <<a href="mailto:ptoscano@redhat.com">ptoscano@redhat.com</a>>:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi Hiroyuki,<br>
<br>
On Tuesday, 30 July 2019 07:51:37 CEST Hiroyuki Katsura wrote:<br>
> This patch includes:<br>
> <br>
> - Event callback handlers<br>
> - Tests related to events(410-430)<br>
> ---<br>
<br>
Would it be possible to split the Handle -> Handle<'a> change in an own<br>
small patch? This way it can be documented why it was changed.<br>
<br>
> +pub fn event_to_string(events: &[guestfs::Event]) -> Result<String, error::Error> {<br>
> +    let bitmask = events_to_bitmask(events);<br>
> +<br>
> +    let r = unsafe { guestfs_event_to_string(bitmask) };<br>
> +    if r.is_null() {<br>
> +        Err(error::unix_error("event_to_string"))<br>
> +    } else {<br>
> +        let s = unsafe { ffi::CStr::from_ptr(r) };<br>
> +        let s = s.to_str()?.to_string();<br>
<br>
These two look like utils::char_ptr_to_string().<br>
<br>
> diff --git a/rust/tests/<a href="http://410_close_event.rs" rel="noreferrer" target="_blank">410_close_event.rs</a> b/rust/tests/<a href="http://410_close_event.rs" rel="noreferrer" target="_blank">410_close_event.rs</a><br>
> new file mode 100644<br>
> index 000000000..308471098<br>
> --- /dev/null<br>
> +++ b/rust/tests/<a href="http://410_close_event.rs" rel="noreferrer" target="_blank">410_close_event.rs</a><br>
> @@ -0,0 +1,38 @@<br>
> +/* libguestfs Rust bindings<br>
> + * Copyright (C) 2019 Hiroyuki Katsura <<a href="mailto:hiroyuki.katsura.0513@gmail.com" target="_blank">hiroyuki.katsura.0513@gmail.com</a>><br>
> + *<br>
> + * This program is free software; you can redistribute it and/or modify<br>
> + * it under the terms of the GNU General Public License as published by<br>
> + * the Free Software Foundation; either version 2 of the License, or<br>
> + * (at your option) any later version.<br>
> + *<br>
> + * This program is distributed in the hope that it will be useful,<br>
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of<br>
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the<br>
> + * GNU General Public License for more details.<br>
> + *<br>
> + * You should have received a copy of the GNU General Public License<br>
> + * along with this program; if not, write to the Free Software<br>
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.<br>
> + */<br>
> +<br>
> +extern crate guestfs;<br>
> +<br>
> +use std::sync::{Arc, Mutex};<br>
> +<br>
> +#[test]<br>
> +fn close_event() {<br>
> +    let close_invoked = Arc::new(Mutex::new(0));<br>
<br>
Maybe a thread-safe Arc is not needed for this test -- it's just a<br>
single-threaded test with just one handle.<br>
<br>
> +    {<br>
> +        let mut g = guestfs::Handle::create().expect("create");<br>
> +        g.set_event_callback(<br>
> +            |_, _, _, _| {<br>
> +                let mut data = (&close_invoked).lock().unwrap();<br>
> +                *data += 1;<br>
> +            },<br>
> +            &[guestfs::Event::Close],<br>
> +        )<br>
> +        .unwrap();<br>
<br>
Check that the close_invoked count is still 0 before the block ending.<br>
<br>
> diff --git a/rust/tests/<a href="http://420_log_messages.rs" rel="noreferrer" target="_blank">420_log_messages.rs</a> b/rust/tests/<a href="http://420_log_messages.rs" rel="noreferrer" target="_blank">420_log_messages.rs</a><br>
> new file mode 100644<br>
> index 000000000..1e9627ca7<br>
> --- /dev/null<br>
> +++ b/rust/tests/<a href="http://420_log_messages.rs" rel="noreferrer" target="_blank">420_log_messages.rs</a><br>
> @@ -0,0 +1,60 @@<br>
> +/* libguestfs Rust bindings<br>
> + * Copyright (C) 2019 Hiroyuki Katsura <<a href="mailto:hiroyuki.katsura.0513@gmail.com" target="_blank">hiroyuki.katsura.0513@gmail.com</a>><br>
> + *<br>
> + * This program is free software; you can redistribute it and/or modify<br>
> + * it under the terms of the GNU General Public License as published by<br>
> + * the Free Software Foundation; either version 2 of the License, or<br>
> + * (at your option) any later version.<br>
> + *<br>
> + * This program is distributed in the hope that it will be useful,<br>
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of<br>
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the<br>
> + * GNU General Public License for more details.<br>
> + *<br>
> + * You should have received a copy of the GNU General Public License<br>
> + * along with this program; if not, write to the Free Software<br>
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.<br>
> + */<br>
> +<br>
> +extern crate guestfs;<br>
> +<br>
> +use std::str;<br>
> +use std::sync::{Arc, Mutex};<br>
> +<br>
> +#[test]<br>
> +fn log_messages() {<br>
> +    let close_invoked = Arc::new(Mutex::new(0));<br>
<br>
Ditto as in <a href="http://410_close_event.rs" rel="noreferrer" target="_blank">410_close_event.rs</a>.<br>
<br>
> diff --git a/rust/tests/<a href="http://430_progress_messages.rs" rel="noreferrer" target="_blank">430_progress_messages.rs</a> b/rust/tests/<a href="http://430_progress_messages.rs" rel="noreferrer" target="_blank">430_progress_messages.rs</a><br>
> new file mode 100644<br>
> index 000000000..a1d33aff7<br>
> --- /dev/null<br>
> +++ b/rust/tests/<a href="http://430_progress_messages.rs" rel="noreferrer" target="_blank">430_progress_messages.rs</a><br>
> @@ -0,0 +1,61 @@<br>
> +/* libguestfs Rust bindings<br>
> + * Copyright (C) 2019 Hiroyuki Katsura <<a href="mailto:hiroyuki.katsura.0513@gmail.com" target="_blank">hiroyuki.katsura.0513@gmail.com</a>><br>
> + *<br>
> + * This program is free software; you can redistribute it and/or modify<br>
> + * it under the terms of the GNU General Public License as published by<br>
> + * the Free Software Foundation; either version 2 of the License, or<br>
> + * (at your option) any later version.<br>
> + *<br>
> + * This program is distributed in the hope that it will be useful,<br>
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of<br>
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the<br>
> + * GNU General Public License for more details.<br>
> + *<br>
> + * You should have received a copy of the GNU General Public License<br>
> + * along with this program; if not, write to the Free Software<br>
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.<br>
> + */<br>
> +<br>
> +extern crate guestfs;<br>
> +<br>
> +use std::default::Default;<br>
> +use std::sync::{Arc, Mutex};<br>
> +<br>
> +#[test]<br>
> +fn progress_messages() {<br>
> +    let callback_invoked = Arc::new(Mutex::new(0));<br>
<br>
Ditto as in <a href="http://410_close_event.rs" rel="noreferrer" target="_blank">410_close_event.rs</a>.<br>
<br>
> +    {<br>
> +        let mut g = guestfs::Handle::create().expect("create");<br>
> +        g.add_drive("/dev/null", Default::default()).unwrap();<br>
> +        g.launch().unwrap();<br>
> +<br>
> +        let eh = g<br>
> +            .set_event_callback(<br>
> +                |_, _, _, _| {<br>
> +                    let mut data = (&callback_invoked).lock().unwrap();<br>
> +                    *data += 1;<br>
> +                },<br>
> +                &[guestfs::Event::Progress],<br>
> +            )<br>
> +            .unwrap();<br>
> +        assert_eq!("ok", g.debug("progress", &["5"]).unwrap());<br>
> +        assert!(*(&callback_invoked).lock().unwrap() > 0);<br>
> +<br>
> +        *(&callback_invoked).lock().unwrap() = 0;<br>
> +        g.delete_event_callback(eh).unwrap();<br>
> +        assert_eq!("ok", g.debug("progress", &["5"]).unwrap());<br>
> +        assert_eq!(*(&callback_invoked).lock().unwrap(), 0);<br>
> +<br>
> +        g.set_event_callback(<br>
> +            |_, _, _, _| {<br>
> +                let mut data = (&callback_invoked).lock().unwrap();<br>
> +                *data += 1;<br>
> +            },<br>
> +            &[guestfs::Event::Progress],<br>
> +        )<br>
> +        .unwrap();<br>
> +        assert_eq!("ok", g.debug("progress", &["5"]).unwrap());<br>
> +        assert!(*(&callback_invoked).lock().unwrap() > 0);<br>
> +    }<br>
> +    assert!(*(&callback_invoked).lock().unwrap() > 0);<br>
<br>
This assert is not needed, and most probably the whole scope here can<br>
be removed.<br>
<br>
-- <br>
Pino Toscano</blockquote></div>