Skip to main content

glib/auto/
source.rs

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
5use crate::{ffi, translate::*};
6
7crate::wrapper! {
8    /// The `GSource` struct is an opaque data type
9    /// representing an event source.
10    #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
11    pub struct Source(Shared<ffi::GSource>);
12
13    match fn {
14        ref => |ptr| ffi::g_source_ref(ptr),
15        unref => |ptr| ffi::g_source_unref(ptr),
16        type_ => || ffi::g_source_get_type(),
17    }
18}
19
20impl Source {
21    //#[doc(alias = "g_source_new")]
22    //pub fn new(source_funcs: /*Ignored*/&mut SourceFuncs, struct_size: u32) -> Source {
23    //    unsafe { TODO: call ffi:g_source_new() }
24    //}
25
26    /// Adds @child_source to @self as a ‘polled’ source.
27    ///
28    /// When @self is added to a [`MainContext`][crate::MainContext], @child_source will be
29    /// automatically added with the same priority. When @child_source is triggered,
30    /// it will cause @self to dispatch (in addition to calling its own callback),
31    /// and when @self is destroyed, it will destroy @child_source as well.
32    ///
33    /// The @self will also still be dispatched if its own prepare/check functions
34    /// indicate that it is ready.
35    ///
36    /// If you don’t need @child_source to do anything on its own when it
37    /// triggers, you can call `g_source_set_dummy_callback()` on it to set a
38    /// callback that does nothing (except return true if appropriate).
39    ///
40    /// The @self will hold a reference on @child_source while @child_source
41    /// is attached to it.
42    ///
43    /// This API is only intended to be used by implementations of [`Source`][crate::Source].
44    /// Do not call this API on a [`Source`][crate::Source] that you did not create.
45    /// ## `child_source`
46    /// a second source that @self should ‘poll’
47    #[doc(alias = "g_source_add_child_source")]
48    pub fn add_child_source(&self, child_source: &Source) {
49        unsafe {
50            ffi::g_source_add_child_source(self.to_glib_none().0, child_source.to_glib_none().0);
51        }
52    }
53
54    //#[doc(alias = "g_source_add_poll")]
55    //pub fn add_poll(&self, fd: /*Ignored*/&mut PollFD) {
56    //    unsafe { TODO: call ffi:g_source_add_poll() }
57    //}
58
59    //#[doc(alias = "g_source_add_unix_fd")]
60    //pub fn add_unix_fd(&self, fd: i32, events: IOCondition) -> /*Unimplemented*/Basic: Pointer {
61    //    unsafe { TODO: call ffi:g_source_add_unix_fd() }
62    //}
63
64    /// Unsets any previously set ready time.
65    ///
66    /// If the source does not have a ready time set, this function
67    /// does nothing.
68    #[cfg(feature = "v2_90")]
69    #[cfg_attr(docsrs, doc(cfg(feature = "v2_90")))]
70    #[doc(alias = "g_source_clear_ready_time")]
71    pub fn clear_ready_time(&self) {
72        unsafe {
73            ffi::g_source_clear_ready_time(self.to_glib_none().0);
74        }
75    }
76
77    #[doc(alias = "g_source_destroy")]
78    pub fn destroy(&self) {
79        unsafe {
80            ffi::g_source_destroy(self.to_glib_none().0);
81        }
82    }
83
84    /// Checks whether a source is allowed to be called recursively.
85    ///
86    /// See `GLib::Source::set_can_recurse()`.
87    ///
88    /// # Returns
89    ///
90    /// whether recursion is allowed
91    #[doc(alias = "g_source_get_can_recurse")]
92    #[doc(alias = "get_can_recurse")]
93    pub fn can_recurse(&self) -> bool {
94        unsafe { from_glib(ffi::g_source_get_can_recurse(self.to_glib_none().0)) }
95    }
96
97    /// Gets a name for the source, used in debugging and profiling.
98    ///
99    /// The
100    /// name may be `NULL` if it has never been set with `GLib::Source::set_name()`.
101    ///
102    /// # Returns
103    ///
104    /// the name of the source
105    #[doc(alias = "g_source_get_name")]
106    #[doc(alias = "get_name")]
107    pub fn name(&self) -> Option<crate::GString> {
108        unsafe { from_glib_none(ffi::g_source_get_name(self.to_glib_none().0)) }
109    }
110
111    /// Gets the priority of a source.
112    ///
113    /// # Returns
114    ///
115    /// the priority of the source
116    #[doc(alias = "g_source_get_priority")]
117    #[doc(alias = "get_priority")]
118    pub fn priority(&self) -> i32 {
119        unsafe { ffi::g_source_get_priority(self.to_glib_none().0) }
120    }
121
122    /// Gets the ‘ready time’ of @self, as set by
123    /// `GLib::Source::set_ready_time()`.
124    ///
125    /// Any time before or equal to the current monotonic time (including zero)
126    /// is an indication that the source will fire immediately.
127    ///
128    /// # Returns
129    ///
130    /// the monotonic ready time, `-1` for ‘never’
131    #[doc(alias = "g_source_get_ready_time")]
132    #[doc(alias = "get_ready_time")]
133    pub fn ready_time(&self) -> i64 {
134        unsafe { ffi::g_source_get_ready_time(self.to_glib_none().0) }
135    }
136
137    /// Gets the ‘ready time’ of @self, as set by
138    /// `GLib::Source::set_ready_time_ns()`. If no ready time has been set
139    /// or it has been cleared via method@GLib.Source.clear_ready_time], this
140    /// function returns false.
141    ///
142    /// Any time before or equal to the current monotonic time (including zero)
143    /// is an indication that the source will fire immediately.
144    ///
145    /// # Returns
146    ///
147    /// true if the source has a ready time set.
148    ///
149    /// ## `ready_time`
150    /// Set to the ready time
151    ///   on success
152    #[cfg(feature = "v2_90")]
153    #[cfg_attr(docsrs, doc(cfg(feature = "v2_90")))]
154    #[doc(alias = "g_source_get_ready_time_ns")]
155    #[doc(alias = "get_ready_time_ns")]
156    pub fn ready_time_ns(&self) -> Option<u64> {
157        unsafe {
158            let mut ready_time = std::mem::MaybeUninit::uninit();
159            let ret = from_glib(ffi::g_source_get_ready_time_ns(
160                self.to_glib_none().0,
161                ready_time.as_mut_ptr(),
162            ));
163            if ret {
164                Some(ready_time.assume_init())
165            } else {
166                None
167            }
168        }
169    }
170
171    /// Gets the time to be used when checking this source.
172    ///
173    /// The advantage of
174    /// calling this function over calling [`monotonic_time()`][crate::monotonic_time()] directly is
175    /// that when checking multiple sources, GLib can cache a single value
176    /// instead of having to repeatedly get the system monotonic time.
177    ///
178    /// The time here is the system monotonic time, if available, or some
179    /// other reasonable alternative otherwise.  See [`monotonic_time()`][crate::monotonic_time()].
180    ///
181    /// # Returns
182    ///
183    /// the monotonic time in microseconds
184    #[doc(alias = "g_source_get_time")]
185    #[doc(alias = "get_time")]
186    pub fn time(&self) -> i64 {
187        unsafe { ffi::g_source_get_time(self.to_glib_none().0) }
188    }
189
190    /// Gets the time to be used when checking this source.
191    ///
192    /// The advantage of calling this function over calling
193    /// [`monotonic_time_ns()`][crate::monotonic_time_ns()] directly is
194    /// that when checking multiple sources, GLib can cache a single value
195    /// instead of having to repeatedly get the system monotonic time.
196    ///
197    /// The time here is the system monotonic time, if available, or some
198    /// other reasonable alternative otherwise.  See [`monotonic_time_ns()`][crate::monotonic_time_ns()].
199    ///
200    /// # Returns
201    ///
202    /// the monotonic time in nanoseconds
203    #[cfg(feature = "v2_90")]
204    #[cfg_attr(docsrs, doc(cfg(feature = "v2_90")))]
205    #[doc(alias = "g_source_get_time_ns")]
206    #[doc(alias = "get_time_ns")]
207    pub fn time_ns(&self) -> u64 {
208        unsafe { ffi::g_source_get_time_ns(self.to_glib_none().0) }
209    }
210
211    /// idle_id_mutex);
212    ///
213    ///   return FALSE;
214    /// }
215    /// ```text
216    ///
217    /// Calls to this function from a thread other than the one acquired by the
218    /// [`MainContext`][crate::MainContext] the [`Source`][crate::Source] is attached to are typically
219    /// redundant, as the source could be destroyed immediately after this function
220    /// returns. However, once a source is destroyed it cannot be un-destroyed, so
221    /// this function can be used for opportunistic checks from any thread.
222    ///
223    /// # Returns
224    ///
225    /// true if the source has been destroyed, false otherwise
226    #[doc(alias = "g_source_is_destroyed")]
227    pub fn is_destroyed(&self) -> bool {
228        unsafe { from_glib(ffi::g_source_is_destroyed(self.to_glib_none().0)) }
229    }
230
231    //#[doc(alias = "g_source_modify_unix_fd")]
232    //pub fn modify_unix_fd(&self, tag: /*Unimplemented*/Basic: Pointer, new_events: IOCondition) {
233    //    unsafe { TODO: call ffi:g_source_modify_unix_fd() }
234    //}
235
236    //#[doc(alias = "g_source_query_unix_fd")]
237    //pub fn query_unix_fd(&self, tag: /*Unimplemented*/Basic: Pointer) -> IOCondition {
238    //    unsafe { TODO: call ffi:g_source_query_unix_fd() }
239    //}
240
241    /// Detaches @child_source from @self and destroys it.
242    ///
243    /// This API is only intended to be used by implementations of [`Source`][crate::Source].
244    /// Do not call this API on a [`Source`][crate::Source] that you did not create.
245    /// ## `child_source`
246    /// a source previously passed to
247    ///   [`add_child_source()`][Self::add_child_source()]
248    #[doc(alias = "g_source_remove_child_source")]
249    pub fn remove_child_source(&self, child_source: &Source) {
250        unsafe {
251            ffi::g_source_remove_child_source(self.to_glib_none().0, child_source.to_glib_none().0);
252        }
253    }
254
255    //#[doc(alias = "g_source_remove_poll")]
256    //pub fn remove_poll(&self, fd: /*Ignored*/&mut PollFD) {
257    //    unsafe { TODO: call ffi:g_source_remove_poll() }
258    //}
259
260    //#[doc(alias = "g_source_remove_unix_fd")]
261    //pub fn remove_unix_fd(&self, tag: /*Unimplemented*/Basic: Pointer) {
262    //    unsafe { TODO: call ffi:g_source_remove_unix_fd() }
263    //}
264
265    //#[doc(alias = "g_source_remove_by_funcs_user_data")]
266    //pub fn remove_by_funcs_user_data(funcs: /*Ignored*/&mut SourceFuncs, user_data: /*Unimplemented*/Option<Basic: Pointer>) -> bool {
267    //    unsafe { TODO: call ffi:g_source_remove_by_funcs_user_data() }
268    //}
269
270    //#[doc(alias = "g_source_remove_by_user_data")]
271    //pub fn remove_by_user_data(user_data: /*Unimplemented*/Option<Basic: Pointer>) -> bool {
272    //    unsafe { TODO: call ffi:g_source_remove_by_user_data() }
273    //}
274}
275
276unsafe impl Send for Source {}
277unsafe impl Sync for Source {}