Skip to main content

glib/auto/
main_context.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
5#[cfg(feature = "v2_72")]
6#[cfg_attr(docsrs, doc(cfg(feature = "v2_72")))]
7use crate::MainContextFlags;
8use crate::{ffi, translate::*};
9
10crate::wrapper! {
11    /// The `GMainContext` struct is an opaque data
12    /// type representing a set of sources to be handled in a main loop.
13    #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
14    pub struct MainContext(Shared<ffi::GMainContext>);
15
16    match fn {
17        ref => |ptr| ffi::g_main_context_ref(ptr),
18        unref => |ptr| ffi::g_main_context_unref(ptr),
19        type_ => || ffi::g_main_context_get_type(),
20    }
21}
22
23impl MainContext {
24    /// Creates a new [`MainContext`][crate::MainContext] structure.
25    ///
26    /// # Returns
27    ///
28    /// the new main context
29    #[doc(alias = "g_main_context_new")]
30    pub fn new() -> MainContext {
31        unsafe { from_glib_full(ffi::g_main_context_new()) }
32    }
33
34    /// Creates a new [`MainContext`][crate::MainContext] structure.
35    /// ## `flags`
36    /// a bitwise-OR combination of flags that can only be set at creation
37    ///   time
38    ///
39    /// # Returns
40    ///
41    /// the new main context
42    #[cfg(feature = "v2_72")]
43    #[cfg_attr(docsrs, doc(cfg(feature = "v2_72")))]
44    #[doc(alias = "g_main_context_new_with_flags")]
45    #[doc(alias = "new_with_flags")]
46    pub fn with_flags(flags: MainContextFlags) -> MainContext {
47        unsafe { from_glib_full(ffi::g_main_context_new_with_flags(flags.into_glib())) }
48    }
49
50    //#[doc(alias = "g_main_context_add_poll")]
51    //pub fn add_poll(&self, fd: /*Ignored*/&mut PollFD, priority: i32) {
52    //    unsafe { TODO: call ffi:g_main_context_add_poll() }
53    //}
54
55    //#[doc(alias = "g_main_context_check")]
56    //pub fn check(&self, max_priority: i32, fds: /*Ignored*/&[PollFD]) -> bool {
57    //    unsafe { TODO: call ffi:g_main_context_check() }
58    //}
59
60    /// Dispatches all pending sources.
61    ///
62    /// You must have successfully acquired the context with
63    /// [`acquire()`][Self::acquire()] before you may call this function.
64    ///
65    /// Since 2.76 @self can be `NULL` to use the global-default
66    /// main context.
67    #[doc(alias = "g_main_context_dispatch")]
68    pub fn dispatch(&self) {
69        unsafe {
70            ffi::g_main_context_dispatch(self.to_glib_none().0);
71        }
72    }
73
74    //#[doc(alias = "g_main_context_find_source_by_funcs_user_data")]
75    //pub fn find_source_by_funcs_user_data(&self, funcs: /*Ignored*/&mut SourceFuncs, user_data: /*Unimplemented*/Option<Basic: Pointer>) -> Option<Source> {
76    //    unsafe { TODO: call ffi:g_main_context_find_source_by_funcs_user_data() }
77    //}
78
79    //#[doc(alias = "g_main_context_find_source_by_user_data")]
80    //pub fn find_source_by_user_data(&self, user_data: /*Unimplemented*/Option<Basic: Pointer>) -> Option<Source> {
81    //    unsafe { TODO: call ffi:g_main_context_find_source_by_user_data() }
82    //}
83
84    //#[doc(alias = "g_main_context_get_poll_func")]
85    //#[doc(alias = "get_poll_func")]
86    //pub fn poll_func(&self) -> /*Unimplemented*/Fn(/*Ignored*/PollFD, u32) -> i32 {
87    //    unsafe { TODO: call ffi:g_main_context_get_poll_func() }
88    //}
89
90    /// Determines whether this thread holds the (recursive)
91    /// ownership of this [`MainContext`][crate::MainContext].
92    ///
93    /// This is useful to
94    /// know before waiting on another thread that may be
95    /// blocking to get ownership of @self.
96    ///
97    /// # Returns
98    ///
99    /// true if current thread is owner of @self, false otherwise
100    #[doc(alias = "g_main_context_is_owner")]
101    pub fn is_owner(&self) -> bool {
102        unsafe { from_glib(ffi::g_main_context_is_owner(self.to_glib_none().0)) }
103    }
104
105    /// Runs a single iteration for the given main loop.
106    ///
107    /// This involves
108    /// checking to see if any event sources are ready to be processed,
109    /// then if no events sources are ready and @may_block is true, waiting
110    /// for a source to become ready, then dispatching the highest priority
111    /// events sources that are ready. Otherwise, if @may_block is false,
112    /// this function does not wait for sources to become ready, and only the highest
113    /// priority sources which are already ready (if any) will be dispatched.
114    ///
115    /// Note that even when @may_block is true, it is still possible for
116    /// [`iteration()`][Self::iteration()] to return false, since the wait may
117    /// be interrupted for other reasons than an event source becoming ready.
118    /// ## `may_block`
119    /// whether the call may block
120    ///
121    /// # Returns
122    ///
123    /// true if events were dispatched, false otherwise
124    #[doc(alias = "g_main_context_iteration")]
125    pub fn iteration(&self, may_block: bool) -> bool {
126        unsafe {
127            from_glib(ffi::g_main_context_iteration(
128                self.to_glib_none().0,
129                may_block.into_glib(),
130            ))
131        }
132    }
133
134    /// Checks if any sources have pending events for the given context.
135    ///
136    /// # Returns
137    ///
138    /// true if events are pending, false otherwise
139    #[doc(alias = "g_main_context_pending")]
140    pub fn pending(&self) -> bool {
141        unsafe { from_glib(ffi::g_main_context_pending(self.to_glib_none().0)) }
142    }
143
144    //#[cfg(feature = "v2_64")]
145    //#[cfg_attr(docsrs, doc(cfg(feature = "v2_64")))]
146    //#[doc(alias = "g_main_context_pusher_new")]
147    //pub fn pusher_new(&self) -> /*Unknown conversion*//*Unimplemented*/MainContextPusher {
148    //    unsafe { TODO: call ffi:g_main_context_pusher_new() }
149    //}
150
151    //#[doc(alias = "g_main_context_query")]
152    //pub fn query(&self, max_priority: i32, fds: /*Ignored*/Vec<PollFD>) -> (i32, i32) {
153    //    unsafe { TODO: call ffi:g_main_context_query() }
154    //}
155
156    //#[doc(alias = "g_main_context_remove_poll")]
157    //pub fn remove_poll(&self, fd: /*Ignored*/&mut PollFD) {
158    //    unsafe { TODO: call ffi:g_main_context_remove_poll() }
159    //}
160
161    //#[doc(alias = "g_main_context_set_poll_func")]
162    //pub fn set_poll_func(&self, func: /*Unimplemented*/Fn(/*Ignored*/PollFD, u32) -> i32) {
163    //    unsafe { TODO: call ffi:g_main_context_set_poll_func() }
164    //}
165
166    //#[cfg_attr(feature = "v2_58", deprecated = "Since 2.58")]
167    //#[allow(deprecated)]
168    //#[doc(alias = "g_main_context_wait")]
169    //pub fn wait(&self, cond: /*Ignored*/&mut Cond, mutex: /*Ignored*/&mut Mutex) -> bool {
170    //    unsafe { TODO: call ffi:g_main_context_wait() }
171    //}
172
173    /// tasks_remaining))
174    ///     g_main_context_wakeup (NULL);
175    /// ```text
176    ///
177    #[doc(alias = "g_main_context_wakeup")]
178    pub fn wakeup(&self) {
179        unsafe {
180            ffi::g_main_context_wakeup(self.to_glib_none().0);
181        }
182    }
183
184    ///  main loop. See also
185    /// [`thread_default()`][Self::thread_default()].
186    ///
187    /// # Returns
188    ///
189    /// the global-default main context.
190    #[doc(alias = "g_main_context_default")]
191    #[allow(clippy::should_implement_trait)]
192    pub fn default() -> MainContext {
193        unsafe { from_glib_none(ffi::g_main_context_default()) }
194    }
195
196    /// Gets the thread-default main context for this thread.
197    ///
198    /// Asynchronous operations that want to be able to be run in contexts other than
199    /// the default one should call this method or
200    /// [`ref_thread_default()`][Self::ref_thread_default()] to get a
201    /// [`MainContext`][crate::MainContext] to add their [`Source`][crate::Source]s to. (Note that
202    /// even in single-threaded programs applications may sometimes want to
203    /// temporarily push a non-default context, so it is not safe to assume that
204    /// this will always return `NULL` if you are running in the default thread.)
205    ///
206    /// If you need to hold a reference on the context, use
207    /// [`ref_thread_default()`][Self::ref_thread_default()] instead.
208    ///
209    /// # Returns
210    ///
211    /// the thread-default main context, or
212    ///   `NULL` if the thread-default context is the global-default main context
213    #[doc(alias = "g_main_context_get_thread_default")]
214    #[doc(alias = "get_thread_default")]
215    pub fn thread_default() -> Option<MainContext> {
216        unsafe { from_glib_none(ffi::g_main_context_get_thread_default()) }
217    }
218
219    //#[cfg(feature = "v2_64")]
220    //#[cfg_attr(docsrs, doc(cfg(feature = "v2_64")))]
221    //#[doc(alias = "g_main_context_pusher_free")]
222    //pub fn pusher_free(pusher: /*Unknown conversion*//*Unimplemented*/MainContextPusher) {
223    //    unsafe { TODO: call ffi:g_main_context_pusher_free() }
224    //}
225
226    /// Gets a reference to the thread-default [`MainContext`][crate::MainContext] for this
227    /// thread
228    ///
229    /// This is the same as [`thread_default()`][Self::thread_default()], but it also
230    /// adds a reference to the returned main context with `GLib::MainContext::ref()`.
231    /// In addition, unlike
232    /// [`thread_default()`][Self::thread_default()], if the thread-default context
233    /// is the global-default context, this will return that
234    /// [`MainContext`][crate::MainContext] (with a ref added to it) rather than returning
235    /// `NULL`.
236    ///
237    /// # Returns
238    ///
239    /// the thread-default main context
240    #[doc(alias = "g_main_context_ref_thread_default")]
241    pub fn ref_thread_default() -> MainContext {
242        unsafe { from_glib_full(ffi::g_main_context_ref_thread_default()) }
243    }
244}
245
246impl Default for MainContext {
247    fn default() -> Self {
248        Self::new()
249    }
250}
251
252unsafe impl Send for MainContext {}
253unsafe impl Sync for MainContext {}