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    /// t need @child_source to do anything on its own when it
27    /// triggers, you can call `g_source_set_dummy_callback()` on it to set a
28    /// callback that does nothing (except return true if appropriate).
29    ///
30    /// The @self will hold a reference on @child_source while @child_source
31    /// is attached to it.
32    ///
33    /// This API is only intended to be used by implementations of [`Source`][crate::Source].
34    /// Do not call this API on a [`Source`][crate::Source] that you did not create.
35    /// ## `child_source`
36    /// poll
37    #[doc(alias = "g_source_add_child_source")]
38    pub fn add_child_source(&self, child_source: &Source) {
39        unsafe {
40            ffi::g_source_add_child_source(self.to_glib_none().0, child_source.to_glib_none().0);
41        }
42    }
43
44    //#[doc(alias = "g_source_add_poll")]
45    //pub fn add_poll(&self, fd: /*Ignored*/&mut PollFD) {
46    //    unsafe { TODO: call ffi:g_source_add_poll() }
47    //}
48
49    //#[doc(alias = "g_source_add_unix_fd")]
50    //pub fn add_unix_fd(&self, fd: i32, events: IOCondition) -> /*Unimplemented*/Basic: Pointer {
51    //    unsafe { TODO: call ffi:g_source_add_unix_fd() }
52    //}
53
54    #[doc(alias = "g_source_destroy")]
55    pub fn destroy(&self) {
56        unsafe {
57            ffi::g_source_destroy(self.to_glib_none().0);
58        }
59    }
60
61    /// Checks whether a source is allowed to be called recursively.
62    ///
63    /// See `GLib::Source::set_can_recurse()`.
64    ///
65    /// # Returns
66    ///
67    /// whether recursion is allowed
68    #[doc(alias = "g_source_get_can_recurse")]
69    #[doc(alias = "get_can_recurse")]
70    pub fn can_recurse(&self) -> bool {
71        unsafe { from_glib(ffi::g_source_get_can_recurse(self.to_glib_none().0)) }
72    }
73
74    /// Gets a name for the source, used in debugging and profiling.
75    ///
76    /// The
77    /// name may be `NULL` if it has never been set with `GLib::Source::set_name()`.
78    ///
79    /// # Returns
80    ///
81    /// the name of the source
82    #[doc(alias = "g_source_get_name")]
83    #[doc(alias = "get_name")]
84    pub fn name(&self) -> Option<crate::GString> {
85        unsafe { from_glib_none(ffi::g_source_get_name(self.to_glib_none().0)) }
86    }
87
88    /// Gets the priority of a source.
89    ///
90    /// # Returns
91    ///
92    /// the priority of the source
93    #[doc(alias = "g_source_get_priority")]
94    #[doc(alias = "get_priority")]
95    pub fn priority(&self) -> i32 {
96        unsafe { ffi::g_source_get_priority(self.to_glib_none().0) }
97    }
98
99    ///  of @self, as set by
100    /// `GLib::Source::set_ready_time()`.
101    ///
102    /// Any time before or equal to the current monotonic time (including zero)
103    /// is an indication that the source will fire immediately.
104    ///
105    /// # Returns
106    ///
107    /// never
108    #[doc(alias = "g_source_get_ready_time")]
109    #[doc(alias = "get_ready_time")]
110    pub fn ready_time(&self) -> i64 {
111        unsafe { ffi::g_source_get_ready_time(self.to_glib_none().0) }
112    }
113
114    /// Gets the time to be used when checking this source.
115    ///
116    /// The advantage of
117    /// calling this function over calling [`monotonic_time()`][crate::monotonic_time()] directly is
118    /// that when checking multiple sources, GLib can cache a single value
119    /// instead of having to repeatedly get the system monotonic time.
120    ///
121    /// The time here is the system monotonic time, if available, or some
122    /// other reasonable alternative otherwise.  See [`monotonic_time()`][crate::monotonic_time()].
123    ///
124    /// # Returns
125    ///
126    /// the monotonic time in microseconds
127    #[doc(alias = "g_source_get_time")]
128    #[doc(alias = "get_time")]
129    pub fn time(&self) -> i64 {
130        unsafe { ffi::g_source_get_time(self.to_glib_none().0) }
131    }
132
133    /// idle_id_mutex);
134    ///
135    ///   return FALSE;
136    /// }
137    /// ```text
138    ///
139    /// Calls to this function from a thread other than the one acquired by the
140    /// [`MainContext`][crate::MainContext] the [`Source`][crate::Source] is attached to are typically
141    /// redundant, as the source could be destroyed immediately after this function
142    /// returns. However, once a source is destroyed it cannot be un-destroyed, so
143    /// this function can be used for opportunistic checks from any thread.
144    ///
145    /// # Returns
146    ///
147    /// true if the source has been destroyed, false otherwise
148    #[doc(alias = "g_source_is_destroyed")]
149    pub fn is_destroyed(&self) -> bool {
150        unsafe { from_glib(ffi::g_source_is_destroyed(self.to_glib_none().0)) }
151    }
152
153    //#[doc(alias = "g_source_modify_unix_fd")]
154    //pub fn modify_unix_fd(&self, tag: /*Unimplemented*/Basic: Pointer, new_events: IOCondition) {
155    //    unsafe { TODO: call ffi:g_source_modify_unix_fd() }
156    //}
157
158    //#[doc(alias = "g_source_query_unix_fd")]
159    //pub fn query_unix_fd(&self, tag: /*Unimplemented*/Basic: Pointer) -> IOCondition {
160    //    unsafe { TODO: call ffi:g_source_query_unix_fd() }
161    //}
162
163    /// Detaches @child_source from @self and destroys it.
164    ///
165    /// This API is only intended to be used by implementations of [`Source`][crate::Source].
166    /// Do not call this API on a [`Source`][crate::Source] that you did not create.
167    /// ## `child_source`
168    /// a source previously passed to
169    ///   [`add_child_source()`][Self::add_child_source()]
170    #[doc(alias = "g_source_remove_child_source")]
171    pub fn remove_child_source(&self, child_source: &Source) {
172        unsafe {
173            ffi::g_source_remove_child_source(self.to_glib_none().0, child_source.to_glib_none().0);
174        }
175    }
176
177    //#[doc(alias = "g_source_remove_poll")]
178    //pub fn remove_poll(&self, fd: /*Ignored*/&mut PollFD) {
179    //    unsafe { TODO: call ffi:g_source_remove_poll() }
180    //}
181
182    //#[doc(alias = "g_source_remove_unix_fd")]
183    //pub fn remove_unix_fd(&self, tag: /*Unimplemented*/Basic: Pointer) {
184    //    unsafe { TODO: call ffi:g_source_remove_unix_fd() }
185    //}
186
187    //#[doc(alias = "g_source_remove_by_funcs_user_data")]
188    //pub fn remove_by_funcs_user_data(funcs: /*Ignored*/&mut SourceFuncs, user_data: /*Unimplemented*/Option<Basic: Pointer>) -> bool {
189    //    unsafe { TODO: call ffi:g_source_remove_by_funcs_user_data() }
190    //}
191
192    //#[doc(alias = "g_source_remove_by_user_data")]
193    //pub fn remove_by_user_data(user_data: /*Unimplemented*/Option<Basic: Pointer>) -> bool {
194    //    unsafe { TODO: call ffi:g_source_remove_by_user_data() }
195    //}
196}
197
198unsafe impl Send for Source {}
199unsafe impl Sync for Source {}