Skip to content
This repository was archived by the owner on Jun 8, 2021. It is now read-only.

Commit 7f2cf76

Browse files
committed
Fix up some Source API to work with SourceId instead of raw u32
1 parent 51b753e commit 7f2cf76

File tree

4 files changed

+32
-20
lines changed

4 files changed

+32
-20
lines changed

Gir.toml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,21 @@ concurrency = "send+sync"
494494
# while GSource itself is
495495
ignore = true
496496

497+
[[object.function]]
498+
pattern = "attach"
499+
# return type
500+
ignore = true
501+
502+
[[object.function]]
503+
pattern = "get_id"
504+
# unsafe as it would allow multiple times to remove
505+
ignore = true
506+
507+
[[object.function]]
508+
pattern = "remove"
509+
# parameter type
510+
ignore = true
511+
497512
[[object]]
498513
name = "GLib.TimeZone"
499514
status = "generate"

src/auto/source.rs

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,6 @@ impl Source {
3737
// unsafe { TODO: call ffi::g_source_add_unix_fd() }
3838
//}
3939

40-
pub fn attach<'a, P: Into<Option<&'a MainContext>>>(&self, context: P) -> u32 {
41-
let context = context.into();
42-
unsafe {
43-
ffi::g_source_attach(self.to_glib_none().0, context.to_glib_none().0)
44-
}
45-
}
46-
4740
pub fn destroy(&self) {
4841
unsafe {
4942
ffi::g_source_destroy(self.to_glib_none().0);
@@ -62,12 +55,6 @@ impl Source {
6255
}
6356
}
6457

65-
pub fn get_id(&self) -> u32 {
66-
unsafe {
67-
ffi::g_source_get_id(self.to_glib_none().0)
68-
}
69-
}
70-
7158
pub fn get_name(&self) -> Option<GString> {
7259
unsafe {
7360
from_glib_none(ffi::g_source_get_name(self.to_glib_none().0))
@@ -120,12 +107,6 @@ impl Source {
120107
// unsafe { TODO: call ffi::g_source_remove_unix_fd() }
121108
//}
122109

123-
pub fn remove(tag: u32) -> bool {
124-
unsafe {
125-
from_glib(ffi::g_source_remove(tag))
126-
}
127-
}
128-
129110
//pub fn remove_by_funcs_user_data(funcs: /*Ignored*/&mut SourceFuncs, user_data: /*Unimplemented*/Option<Fundamental: Pointer>) -> bool {
130111
// unsafe { TODO: call ffi::g_source_remove_by_funcs_user_data() }
131112
//}

src/main_context_channel.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use Continue;
1313
use MainContext;
1414
use Priority;
1515
use Source;
16+
use SourceId;
1617

1718
use get_thread_id;
1819

@@ -295,7 +296,7 @@ impl<T> Receiver<T> {
295296
mut self,
296297
context: P,
297298
func: F,
298-
) -> u32 {
299+
) -> SourceId {
299300
let context = context.into();
300301
unsafe {
301302
let source = self.0.take().expect("No Source anymore");

src/source.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,3 +551,18 @@ where F: FnMut(RawFd, IOCondition) -> Continue + Send + 'static {
551551
from_glib_full(source)
552552
}
553553
}
554+
555+
impl Source {
556+
pub fn attach<'a, P: Into<Option<&'a MainContext>>>(&self, context: P) -> SourceId {
557+
let context = context.into();
558+
unsafe {
559+
from_glib(ffi::g_source_attach(self.to_glib_none().0, context.to_glib_none().0))
560+
}
561+
}
562+
563+
pub fn remove(tag: SourceId) -> Result<(), ::BoolError> {
564+
unsafe {
565+
glib_result_from_gboolean!(ffi::g_source_remove(tag.to_glib()), "Failed to remove source")
566+
}
567+
}
568+
}

0 commit comments

Comments
 (0)