1 // This file was generated by gir (https://github.com/gtk-rs/gir)
2 // from gir-files (https://github.com/gtk-rs/gir-files)
3 // DO NOT EDIT
4 
5 use glib::object::Cast;
6 use glib::object::IsA;
7 use glib::signal::connect_raw;
8 use glib::signal::SignalHandlerId;
9 use glib::translate::*;
10 use std::boxed::Box as Box_;
11 use std::fmt;
12 use std::mem::transmute;
13 use std::ptr;
14 
15 glib::wrapper! {
16     #[doc(alias = "GCancellable")]
17     pub struct Cancellable(Object<ffi::GCancellable, ffi::GCancellableClass>);
18 
19     match fn {
20         type_ => || ffi::g_cancellable_get_type(),
21     }
22 }
23 
24 impl Cancellable {
25     #[doc(alias = "g_cancellable_new")]
new() -> Cancellable26     pub fn new() -> Cancellable {
27         unsafe { from_glib_full(ffi::g_cancellable_new()) }
28     }
29 
30     #[doc(alias = "g_cancellable_get_current")]
31     #[doc(alias = "get_current")]
current() -> Option<Cancellable>32     pub fn current() -> Option<Cancellable> {
33         unsafe { from_glib_none(ffi::g_cancellable_get_current()) }
34     }
35 }
36 
37 impl Default for Cancellable {
default() -> Self38     fn default() -> Self {
39         Self::new()
40     }
41 }
42 
43 unsafe impl Send for Cancellable {}
44 unsafe impl Sync for Cancellable {}
45 
46 pub const NONE_CANCELLABLE: Option<&Cancellable> = None;
47 
48 pub trait CancellableExt: 'static {
49     #[doc(alias = "g_cancellable_cancel")]
cancel(&self)50     fn cancel(&self);
51 
52     //#[doc(alias = "g_cancellable_connect")]
53     //fn connect<P: Fn() + Send + Sync + 'static>(&self, callback: P, data: /*Unimplemented*/Option<Fundamental: Pointer>) -> libc::c_ulong;
54 
55     #[doc(alias = "g_cancellable_disconnect")]
disconnect(&self, handler_id: libc::c_ulong)56     fn disconnect(&self, handler_id: libc::c_ulong);
57 
58     #[doc(alias = "g_cancellable_get_fd")]
59     #[doc(alias = "get_fd")]
fd(&self) -> i3260     fn fd(&self) -> i32;
61 
62     #[doc(alias = "g_cancellable_is_cancelled")]
is_cancelled(&self) -> bool63     fn is_cancelled(&self) -> bool;
64 
65     //#[doc(alias = "g_cancellable_make_pollfd")]
66     //fn make_pollfd(&self, pollfd: /*Ignored*/&mut glib::PollFD) -> bool;
67 
68     #[doc(alias = "g_cancellable_pop_current")]
pop_current(&self)69     fn pop_current(&self);
70 
71     #[doc(alias = "g_cancellable_push_current")]
push_current(&self)72     fn push_current(&self);
73 
74     #[doc(alias = "g_cancellable_release_fd")]
release_fd(&self)75     fn release_fd(&self);
76 
77     #[doc(alias = "g_cancellable_set_error_if_cancelled")]
set_error_if_cancelled(&self) -> Result<(), glib::Error>78     fn set_error_if_cancelled(&self) -> Result<(), glib::Error>;
79 
80     #[doc(alias = "cancelled")]
connect_cancelled<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId81     fn connect_cancelled<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId;
82 }
83 
84 impl<O: IsA<Cancellable>> CancellableExt for O {
cancel(&self)85     fn cancel(&self) {
86         unsafe {
87             ffi::g_cancellable_cancel(self.as_ref().to_glib_none().0);
88         }
89     }
90 
91     //fn connect<P: Fn() + Send + Sync + 'static>(&self, callback: P, data: /*Unimplemented*/Option<Fundamental: Pointer>) -> libc::c_ulong {
92     //    unsafe { TODO: call ffi:g_cancellable_connect() }
93     //}
94 
disconnect(&self, handler_id: libc::c_ulong)95     fn disconnect(&self, handler_id: libc::c_ulong) {
96         unsafe {
97             ffi::g_cancellable_disconnect(self.as_ref().to_glib_none().0, handler_id);
98         }
99     }
100 
fd(&self) -> i32101     fn fd(&self) -> i32 {
102         unsafe { ffi::g_cancellable_get_fd(self.as_ref().to_glib_none().0) }
103     }
104 
is_cancelled(&self) -> bool105     fn is_cancelled(&self) -> bool {
106         unsafe {
107             from_glib(ffi::g_cancellable_is_cancelled(
108                 self.as_ref().to_glib_none().0,
109             ))
110         }
111     }
112 
113     //fn make_pollfd(&self, pollfd: /*Ignored*/&mut glib::PollFD) -> bool {
114     //    unsafe { TODO: call ffi:g_cancellable_make_pollfd() }
115     //}
116 
pop_current(&self)117     fn pop_current(&self) {
118         unsafe {
119             ffi::g_cancellable_pop_current(self.as_ref().to_glib_none().0);
120         }
121     }
122 
push_current(&self)123     fn push_current(&self) {
124         unsafe {
125             ffi::g_cancellable_push_current(self.as_ref().to_glib_none().0);
126         }
127     }
128 
release_fd(&self)129     fn release_fd(&self) {
130         unsafe {
131             ffi::g_cancellable_release_fd(self.as_ref().to_glib_none().0);
132         }
133     }
134 
set_error_if_cancelled(&self) -> Result<(), glib::Error>135     fn set_error_if_cancelled(&self) -> Result<(), glib::Error> {
136         unsafe {
137             let mut error = ptr::null_mut();
138             let _ = ffi::g_cancellable_set_error_if_cancelled(
139                 self.as_ref().to_glib_none().0,
140                 &mut error,
141             );
142             if error.is_null() {
143                 Ok(())
144             } else {
145                 Err(from_glib_full(error))
146             }
147         }
148     }
149 
connect_cancelled<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId150     fn connect_cancelled<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId {
151         unsafe extern "C" fn cancelled_trampoline<
152             P: IsA<Cancellable>,
153             F: Fn(&P) + Send + Sync + 'static,
154         >(
155             this: *mut ffi::GCancellable,
156             f: glib::ffi::gpointer,
157         ) {
158             let f: &F = &*(f as *const F);
159             f(Cancellable::from_glib_borrow(this).unsafe_cast_ref())
160         }
161         unsafe {
162             let f: Box_<F> = Box_::new(f);
163             connect_raw(
164                 self.as_ptr() as *mut _,
165                 b"cancelled\0".as_ptr() as *const _,
166                 Some(transmute::<_, unsafe extern "C" fn()>(
167                     cancelled_trampoline::<Self, F> as *const (),
168                 )),
169                 Box_::into_raw(f),
170             )
171         }
172     }
173 }
174 
175 impl fmt::Display for Cancellable {
fmt(&self, f: &mut fmt::Formatter) -> fmt::Result176     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
177         f.write_str("Cancellable")
178     }
179 }
180