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

Commit aaad196

Browse files
Merge pull request #194 from sdroege/mainloop
Initial GMainLoop/GMainContext bindings
2 parents f874842 + 3a1e912 commit aaad196

File tree

13 files changed

+678
-52
lines changed

13 files changed

+678
-52
lines changed

Gir.toml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,26 @@ status = "generate"
180180
name = "markup_escape_text"
181181
#gsize
182182
ignore = true
183+
[[object.function]]
184+
name = "child_watch_source_new"
185+
# Need manual bindings to be useful
186+
ignore = true
187+
[[object.function]]
188+
name = "idle_source_new"
189+
# Need manual bindings to be useful
190+
ignore = true
191+
[[object.function]]
192+
name = "timeout_source_new"
193+
# Need manual bindings to be useful
194+
ignore = true
195+
[[object.function]]
196+
name = "timeout_source_new_seconds"
197+
# Need manual bindings to be useful
198+
ignore = true
199+
[[object.function]]
200+
name = "unix_signal_source_new"
201+
# Need manual bindings to be useful
202+
ignore = true
183203

184204
[[object]]
185205
name = "GLib.KeyFile"
@@ -209,3 +229,32 @@ status = "generate"
209229
name = "load_from_data"
210230
#gsize
211231
ignore = true
232+
233+
[[object]]
234+
name = "GLib.MainContext"
235+
status = "generate"
236+
concurrency = "send+sync"
237+
[[object.function]]
238+
name = "prepare"
239+
# out parameter not marked as such
240+
ignore = true
241+
242+
[[object.function]]
243+
name = "find_source_by_id"
244+
# source id is a newtype
245+
ignore = true
246+
247+
[[object]]
248+
name = "GLib.MainLoop"
249+
status = "generate"
250+
concurrency = "send+sync"
251+
252+
[[object]]
253+
name = "GLib.Source"
254+
status = "generate"
255+
concurrency = "send+sync"
256+
[[object.function]]
257+
pattern = "set_.+"
258+
# Setters are generally not thread-safe
259+
# while GSource itself is
260+
ignore = true

src/auto/enums.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// This file was generated by gir (3c73dd9) from gir-files (71d73f0)
1+
// This file was generated by gir (7504fb6) from gir-files (71d73f0)
22
// DO NOT EDIT
33

44
use ffi;

src/auto/flags.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// This file was generated by gir (3c73dd9) from gir-files (71d73f0)
1+
// This file was generated by gir (7504fb6) from gir-files (71d73f0)
22
// DO NOT EDIT
33

44
use ffi;

src/auto/functions.rs

Lines changed: 9 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
// This file was generated by gir (3c73dd9) from gir-files (71d73f0)
1+
// This file was generated by gir (7504fb6) from gir-files (71d73f0)
22
// DO NOT EDIT
33

44
use Error;
55
use FormatSizeFlags;
6+
use Source;
67
use UserDirectory;
78
use ffi;
89
use libc;
@@ -142,10 +143,6 @@ pub fn check_version(required_major: u32, required_minor: u32, required_micro: u
142143
// unsafe { TODO: call ffi::g_child_watch_add_full() }
143144
//}
144145

145-
//pub fn child_watch_source_new(pid: Pid) -> /*Ignored*/Option<Source> {
146-
// unsafe { TODO: call ffi::g_child_watch_source_new() }
147-
//}
148-
149146
pub fn clear_error() -> Result<(), Error> {
150147
unsafe {
151148
let mut error = ptr::null_mut();
@@ -572,10 +569,6 @@ pub fn hostname_to_unicode(hostname: &str) -> Option<String> {
572569
// unsafe { TODO: call ffi::g_idle_remove_by_data() }
573570
//}
574571

575-
//pub fn idle_source_new() -> /*Ignored*/Option<Source> {
576-
// unsafe { TODO: call ffi::g_idle_source_new() }
577-
//}
578-
579572
//pub fn int64_equal(v1: /*Unimplemented*/Fundamental: Pointer, v2: /*Unimplemented*/Fundamental: Pointer) -> bool {
580573
// unsafe { TODO: call ffi::g_int64_equal() }
581574
//}
@@ -616,7 +609,7 @@ pub fn intern_string<'a, P: Into<Option<&'a str>>>(string: P) -> Option<String>
616609
// unsafe { TODO: call ffi::g_io_add_watch_full() }
617610
//}
618611

619-
//pub fn io_create_watch(channel: /*Ignored*/&IOChannel, condition: /*Ignored*/IOCondition) -> /*Ignored*/Option<Source> {
612+
//pub fn io_create_watch(channel: /*Ignored*/&IOChannel, condition: /*Ignored*/IOCondition) -> Option<Source> {
620613
// unsafe { TODO: call ffi::g_io_create_watch() }
621614
//}
622615

@@ -719,9 +712,11 @@ pub fn log_writer_supports_color(output_fd: i32) -> bool {
719712
// unsafe { TODO: call ffi::g_logv() }
720713
//}
721714

722-
//pub fn main_current_source() -> /*Ignored*/Option<Source> {
723-
// unsafe { TODO: call ffi::g_main_current_source() }
724-
//}
715+
pub fn main_current_source() -> Option<Source> {
716+
unsafe {
717+
from_glib_none(ffi::g_main_current_source())
718+
}
719+
}
725720

726721
pub fn main_depth() -> i32 {
727722
unsafe {
@@ -1324,14 +1319,6 @@ pub fn test_trap_reached_timeout() -> bool {
13241319
// unsafe { TODO: call ffi::g_timeout_add_seconds_full() }
13251320
//}
13261321

1327-
//pub fn timeout_source_new(interval: u32) -> /*Ignored*/Option<Source> {
1328-
// unsafe { TODO: call ffi::g_timeout_source_new() }
1329-
//}
1330-
1331-
//pub fn timeout_source_new_seconds(interval: u32) -> /*Ignored*/Option<Source> {
1332-
// unsafe { TODO: call ffi::g_timeout_source_new_seconds() }
1333-
//}
1334-
13351322
//pub fn try_malloc(n_bytes: usize) -> /*Unimplemented*/Option<Fundamental: Pointer> {
13361323
// unsafe { TODO: call ffi::g_try_malloc() }
13371324
//}
@@ -1378,7 +1365,7 @@ pub fn test_trap_reached_timeout() -> bool {
13781365

13791366
//#[cfg(unix)]
13801367
//#[cfg(feature = "v2_36")]
1381-
//pub fn unix_fd_source_new(fd: i32, condition: /*Ignored*/IOCondition) -> /*Ignored*/Option<Source> {
1368+
//pub fn unix_fd_source_new(fd: i32, condition: /*Ignored*/IOCondition) -> Option<Source> {
13821369
// unsafe { TODO: call ffi::g_unix_fd_source_new() }
13831370
//}
13841371

@@ -1401,11 +1388,6 @@ pub fn unix_set_fd_nonblocking(fd: i32, nonblock: bool) -> Result<(), Error> {
14011388
// unsafe { TODO: call ffi::g_unix_signal_add_full() }
14021389
//}
14031390

1404-
//#[cfg(unix)]
1405-
//pub fn unix_signal_source_new(signum: i32) -> /*Ignored*/Option<Source> {
1406-
// unsafe { TODO: call ffi::g_unix_signal_source_new() }
1407-
//}
1408-
14091391
pub fn unlink<P: AsRef<std::path::Path>>(filename: P) -> i32 {
14101392
unsafe {
14111393
ffi::g_unlink(filename.as_ref().to_glib_none().0)

src/auto/key_file.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// This file was generated by gir (3c73dd9) from gir-files (71d73f0)
1+
// This file was generated by gir (7504fb6) from gir-files (71d73f0)
22
// DO NOT EDIT
33

44
#[cfg(feature = "v2_50")]

src/auto/main_context.rs

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
// This file was generated by gir (7504fb6) from gir-files (71d73f0)
2+
// DO NOT EDIT
3+
4+
use ffi;
5+
use translate::*;
6+
7+
glib_wrapper! {
8+
pub struct MainContext(Shared<ffi::GMainContext>);
9+
10+
match fn {
11+
ref => |ptr| ffi::g_main_context_ref(ptr),
12+
unref => |ptr| ffi::g_main_context_unref(ptr),
13+
}
14+
}
15+
16+
impl MainContext {
17+
pub fn new() -> MainContext {
18+
unsafe {
19+
from_glib_full(ffi::g_main_context_new())
20+
}
21+
}
22+
23+
pub fn acquire(&self) -> bool {
24+
unsafe {
25+
from_glib(ffi::g_main_context_acquire(self.to_glib_none().0))
26+
}
27+
}
28+
29+
//pub fn add_poll(&self, fd: /*Ignored*/&mut PollFD, priority: i32) {
30+
// unsafe { TODO: call ffi::g_main_context_add_poll() }
31+
//}
32+
33+
//pub fn check(&self, max_priority: i32, fds: /*Ignored*/&[&PollFD]) -> i32 {
34+
// unsafe { TODO: call ffi::g_main_context_check() }
35+
//}
36+
37+
pub fn dispatch(&self) {
38+
unsafe {
39+
ffi::g_main_context_dispatch(self.to_glib_none().0);
40+
}
41+
}
42+
43+
//pub fn find_source_by_funcs_user_data<P: Into<Option</*Unimplemented*/Fundamental: Pointer>>>(&self, funcs: /*Ignored*/&mut SourceFuncs, user_data: P) -> Option<Source> {
44+
// unsafe { TODO: call ffi::g_main_context_find_source_by_funcs_user_data() }
45+
//}
46+
47+
//pub fn find_source_by_user_data<P: Into<Option</*Unimplemented*/Fundamental: Pointer>>>(&self, user_data: P) -> Option<Source> {
48+
// unsafe { TODO: call ffi::g_main_context_find_source_by_user_data() }
49+
//}
50+
51+
//pub fn get_poll_func(&self) -> /*Unknown conversion*//*Unimplemented*/PollFunc {
52+
// unsafe { TODO: call ffi::g_main_context_get_poll_func() }
53+
//}
54+
55+
//pub fn invoke<P: Into<Option</*Unimplemented*/Fundamental: Pointer>>>(&self, function: /*Unknown conversion*//*Unimplemented*/SourceFunc, data: P) {
56+
// unsafe { TODO: call ffi::g_main_context_invoke() }
57+
//}
58+
59+
//pub fn invoke_full<'a, P: Into<Option</*Unimplemented*/Fundamental: Pointer>>, Q: Into<Option<&'a /*Unimplemented*/DestroyNotify>>>(&self, priority: i32, function: /*Unknown conversion*//*Unimplemented*/SourceFunc, data: P, notify: Q) {
60+
// unsafe { TODO: call ffi::g_main_context_invoke_full() }
61+
//}
62+
63+
pub fn is_owner(&self) -> bool {
64+
unsafe {
65+
from_glib(ffi::g_main_context_is_owner(self.to_glib_none().0))
66+
}
67+
}
68+
69+
pub fn iteration(&self, may_block: bool) -> bool {
70+
unsafe {
71+
from_glib(ffi::g_main_context_iteration(self.to_glib_none().0, may_block.to_glib()))
72+
}
73+
}
74+
75+
pub fn pending(&self) -> bool {
76+
unsafe {
77+
from_glib(ffi::g_main_context_pending(self.to_glib_none().0))
78+
}
79+
}
80+
81+
pub fn pop_thread_default(&self) {
82+
unsafe {
83+
ffi::g_main_context_pop_thread_default(self.to_glib_none().0);
84+
}
85+
}
86+
87+
pub fn push_thread_default(&self) {
88+
unsafe {
89+
ffi::g_main_context_push_thread_default(self.to_glib_none().0);
90+
}
91+
}
92+
93+
//pub fn query(&self, max_priority: i32, fds: /*Unimplemented*/Vec<PollFD>) -> (i32, i32) {
94+
// unsafe { TODO: call ffi::g_main_context_query() }
95+
//}
96+
97+
pub fn release(&self) {
98+
unsafe {
99+
ffi::g_main_context_release(self.to_glib_none().0);
100+
}
101+
}
102+
103+
//pub fn remove_poll(&self, fd: /*Ignored*/&mut PollFD) {
104+
// unsafe { TODO: call ffi::g_main_context_remove_poll() }
105+
//}
106+
107+
//pub fn set_poll_func(&self, func: /*Unknown conversion*//*Unimplemented*/PollFunc) {
108+
// unsafe { TODO: call ffi::g_main_context_set_poll_func() }
109+
//}
110+
111+
//pub fn wait(&self, cond: /*Ignored*/&mut Cond, mutex: /*Ignored*/&mut Mutex) -> bool {
112+
// unsafe { TODO: call ffi::g_main_context_wait() }
113+
//}
114+
115+
pub fn wakeup(&self) {
116+
unsafe {
117+
ffi::g_main_context_wakeup(self.to_glib_none().0);
118+
}
119+
}
120+
121+
pub fn default() -> Option<MainContext> {
122+
unsafe {
123+
from_glib_none(ffi::g_main_context_default())
124+
}
125+
}
126+
127+
pub fn get_thread_default() -> Option<MainContext> {
128+
unsafe {
129+
from_glib_none(ffi::g_main_context_get_thread_default())
130+
}
131+
}
132+
133+
pub fn ref_thread_default() -> Option<MainContext> {
134+
unsafe {
135+
from_glib_full(ffi::g_main_context_ref_thread_default())
136+
}
137+
}
138+
}
139+
140+
unsafe impl Send for MainContext {}
141+
unsafe impl Sync for MainContext {}

src/auto/main_loop.rs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// This file was generated by gir (7504fb6) from gir-files (71d73f0)
2+
// DO NOT EDIT
3+
4+
use MainContext;
5+
use ffi;
6+
use translate::*;
7+
8+
glib_wrapper! {
9+
pub struct MainLoop(Shared<ffi::GMainLoop>);
10+
11+
match fn {
12+
ref => |ptr| ffi::g_main_loop_ref(ptr),
13+
unref => |ptr| ffi::g_main_loop_unref(ptr),
14+
}
15+
}
16+
17+
impl MainLoop {
18+
pub fn new<'a, P: Into<Option<&'a MainContext>>>(context: P, is_running: bool) -> MainLoop {
19+
let context = context.into();
20+
let context = context.to_glib_none();
21+
unsafe {
22+
from_glib_full(ffi::g_main_loop_new(context.0, is_running.to_glib()))
23+
}
24+
}
25+
26+
pub fn get_context(&self) -> Option<MainContext> {
27+
unsafe {
28+
from_glib_none(ffi::g_main_loop_get_context(self.to_glib_none().0))
29+
}
30+
}
31+
32+
pub fn is_running(&self) -> bool {
33+
unsafe {
34+
from_glib(ffi::g_main_loop_is_running(self.to_glib_none().0))
35+
}
36+
}
37+
38+
pub fn quit(&self) {
39+
unsafe {
40+
ffi::g_main_loop_quit(self.to_glib_none().0);
41+
}
42+
}
43+
44+
pub fn run(&self) {
45+
unsafe {
46+
ffi::g_main_loop_run(self.to_glib_none().0);
47+
}
48+
}
49+
}
50+
51+
unsafe impl Send for MainLoop {}
52+
unsafe impl Sync for MainLoop {}

src/auto/mod.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
1-
// This file was generated by gir (3c73dd9) from gir-files (71d73f0)
1+
// This file was generated by gir (7504fb6) from gir-files (71d73f0)
22
// DO NOT EDIT
33

44
mod key_file;
55
pub use self::key_file::KeyFile;
66

7+
mod main_context;
8+
pub use self::main_context::MainContext;
9+
10+
mod main_loop;
11+
pub use self::main_loop::MainLoop;
12+
13+
mod source;
14+
pub use self::source::Source;
15+
716
mod enums;
817
pub use self::enums::KeyFileError;
918

0 commit comments

Comments
 (0)