1use crate::{ffi, translate::*};
6
7crate::wrapper! {
8 #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
9 pub struct Source(Shared<ffi::GSource>);
10
11 match fn {
12 ref => |ptr| ffi::g_source_ref(ptr),
13 unref => |ptr| ffi::g_source_unref(ptr),
14 type_ => || ffi::g_source_get_type(),
15 }
16}
17
18impl Source {
19 #[doc(alias = "g_source_add_child_source")]
25 pub fn add_child_source(&self, child_source: &Source) {
26 unsafe {
27 ffi::g_source_add_child_source(self.to_glib_none().0, child_source.to_glib_none().0);
28 }
29 }
30
31 #[cfg(feature = "v2_90")]
42 #[cfg_attr(docsrs, doc(cfg(feature = "v2_90")))]
43 #[doc(alias = "g_source_clear_ready_time")]
44 pub fn clear_ready_time(&self) {
45 unsafe {
46 ffi::g_source_clear_ready_time(self.to_glib_none().0);
47 }
48 }
49
50 #[doc(alias = "g_source_destroy")]
51 pub fn destroy(&self) {
52 unsafe {
53 ffi::g_source_destroy(self.to_glib_none().0);
54 }
55 }
56
57 #[doc(alias = "g_source_get_can_recurse")]
58 #[doc(alias = "get_can_recurse")]
59 pub fn can_recurse(&self) -> bool {
60 unsafe { from_glib(ffi::g_source_get_can_recurse(self.to_glib_none().0)) }
61 }
62
63 #[doc(alias = "g_source_get_name")]
64 #[doc(alias = "get_name")]
65 pub fn name(&self) -> Option<crate::GString> {
66 unsafe { from_glib_none(ffi::g_source_get_name(self.to_glib_none().0)) }
67 }
68
69 #[doc(alias = "g_source_get_priority")]
70 #[doc(alias = "get_priority")]
71 pub fn priority(&self) -> i32 {
72 unsafe { ffi::g_source_get_priority(self.to_glib_none().0) }
73 }
74
75 #[doc(alias = "g_source_get_ready_time")]
76 #[doc(alias = "get_ready_time")]
77 pub fn ready_time(&self) -> i64 {
78 unsafe { ffi::g_source_get_ready_time(self.to_glib_none().0) }
79 }
80
81 #[cfg(feature = "v2_90")]
82 #[cfg_attr(docsrs, doc(cfg(feature = "v2_90")))]
83 #[doc(alias = "g_source_get_ready_time_ns")]
84 #[doc(alias = "get_ready_time_ns")]
85 pub fn ready_time_ns(&self) -> Option<u64> {
86 unsafe {
87 let mut ready_time = std::mem::MaybeUninit::uninit();
88 let ret = from_glib(ffi::g_source_get_ready_time_ns(
89 self.to_glib_none().0,
90 ready_time.as_mut_ptr(),
91 ));
92 if ret {
93 Some(ready_time.assume_init())
94 } else {
95 None
96 }
97 }
98 }
99
100 #[doc(alias = "g_source_get_time")]
101 #[doc(alias = "get_time")]
102 pub fn time(&self) -> i64 {
103 unsafe { ffi::g_source_get_time(self.to_glib_none().0) }
104 }
105
106 #[cfg(feature = "v2_90")]
107 #[cfg_attr(docsrs, doc(cfg(feature = "v2_90")))]
108 #[doc(alias = "g_source_get_time_ns")]
109 #[doc(alias = "get_time_ns")]
110 pub fn time_ns(&self) -> u64 {
111 unsafe { ffi::g_source_get_time_ns(self.to_glib_none().0) }
112 }
113
114 #[doc(alias = "g_source_is_destroyed")]
115 pub fn is_destroyed(&self) -> bool {
116 unsafe { from_glib(ffi::g_source_is_destroyed(self.to_glib_none().0)) }
117 }
118
119 #[doc(alias = "g_source_remove_child_source")]
130 pub fn remove_child_source(&self, child_source: &Source) {
131 unsafe {
132 ffi::g_source_remove_child_source(self.to_glib_none().0, child_source.to_glib_none().0);
133 }
134 }
135
136 }
156
157unsafe impl Send for Source {}
158unsafe impl Sync for Source {}