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

Initial GMainLoop/GMainContext bindings #194

Merged
merged 10 commits into from Jul 11, 2017
49 changes: 49 additions & 0 deletions Gir.toml
Expand Up @@ -180,6 +180,26 @@ status = "generate"
name = "markup_escape_text"
#gsize
ignore = true
[[object.function]]
name = "child_watch_source_new"
# Need manual bindings to be useful
ignore = true
[[object.function]]
name = "idle_source_new"
# Need manual bindings to be useful
ignore = true
[[object.function]]
name = "timeout_source_new"
# Need manual bindings to be useful
ignore = true
[[object.function]]
name = "timeout_source_new_seconds"
# Need manual bindings to be useful
ignore = true
[[object.function]]
name = "unix_signal_source_new"
# Need manual bindings to be useful
ignore = true

[[object]]
name = "GLib.KeyFile"
Expand Down Expand Up @@ -209,3 +229,32 @@ status = "generate"
name = "load_from_data"
#gsize
ignore = true

[[object]]
name = "GLib.MainContext"
status = "generate"
concurrency = "send+sync"
[[object.function]]
name = "prepare"
# out parameter not marked as such
ignore = true

[[object.function]]
name = "find_source_by_id"
# source id is a newtype
ignore = true

[[object]]
name = "GLib.MainLoop"
status = "generate"
concurrency = "send+sync"

[[object]]
name = "GLib.Source"
status = "generate"
concurrency = "send+sync"
[[object.function]]
pattern = "set_.+"
# Setters are generally not thread-safe
# while GSource itself is
ignore = true
2 changes: 1 addition & 1 deletion src/auto/enums.rs
@@ -1,4 +1,4 @@
// This file was generated by gir (3c73dd9) from gir-files (71d73f0)
// This file was generated by gir (7504fb6) from gir-files (71d73f0)
// DO NOT EDIT

use ffi;
Expand Down
2 changes: 1 addition & 1 deletion src/auto/flags.rs
@@ -1,4 +1,4 @@
// This file was generated by gir (3c73dd9) from gir-files (71d73f0)
// This file was generated by gir (7504fb6) from gir-files (71d73f0)
// DO NOT EDIT

use ffi;
Expand Down
36 changes: 9 additions & 27 deletions src/auto/functions.rs
@@ -1,8 +1,9 @@
// This file was generated by gir (3c73dd9) from gir-files (71d73f0)
// This file was generated by gir (7504fb6) from gir-files (71d73f0)
// DO NOT EDIT

use Error;
use FormatSizeFlags;
use Source;
use UserDirectory;
use ffi;
use libc;
Expand Down Expand Up @@ -142,10 +143,6 @@ pub fn check_version(required_major: u32, required_minor: u32, required_micro: u
// unsafe { TODO: call ffi::g_child_watch_add_full() }
//}

//pub fn child_watch_source_new(pid: Pid) -> /*Ignored*/Option<Source> {
// unsafe { TODO: call ffi::g_child_watch_source_new() }
//}

pub fn clear_error() -> Result<(), Error> {
unsafe {
let mut error = ptr::null_mut();
Expand Down Expand Up @@ -572,10 +569,6 @@ pub fn hostname_to_unicode(hostname: &str) -> Option<String> {
// unsafe { TODO: call ffi::g_idle_remove_by_data() }
//}

//pub fn idle_source_new() -> /*Ignored*/Option<Source> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we bound Source, why is this ignored?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah nevermind...

// unsafe { TODO: call ffi::g_idle_source_new() }
//}

//pub fn int64_equal(v1: /*Unimplemented*/Fundamental: Pointer, v2: /*Unimplemented*/Fundamental: Pointer) -> bool {
// unsafe { TODO: call ffi::g_int64_equal() }
//}
Expand Down Expand Up @@ -616,7 +609,7 @@ pub fn intern_string<'a, P: Into<Option<&'a str>>>(string: P) -> Option<String>
// unsafe { TODO: call ffi::g_io_add_watch_full() }
//}

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

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

//pub fn main_current_source() -> /*Ignored*/Option<Source> {
// unsafe { TODO: call ffi::g_main_current_source() }
//}
pub fn main_current_source() -> Option<Source> {
unsafe {
from_glib_none(ffi::g_main_current_source())
}
}

pub fn main_depth() -> i32 {
unsafe {
Expand Down Expand Up @@ -1324,14 +1319,6 @@ pub fn test_trap_reached_timeout() -> bool {
// unsafe { TODO: call ffi::g_timeout_add_seconds_full() }
//}

//pub fn timeout_source_new(interval: u32) -> /*Ignored*/Option<Source> {
// unsafe { TODO: call ffi::g_timeout_source_new() }
//}

//pub fn timeout_source_new_seconds(interval: u32) -> /*Ignored*/Option<Source> {
// unsafe { TODO: call ffi::g_timeout_source_new_seconds() }
//}

//pub fn try_malloc(n_bytes: usize) -> /*Unimplemented*/Option<Fundamental: Pointer> {
// unsafe { TODO: call ffi::g_try_malloc() }
//}
Expand Down Expand Up @@ -1378,7 +1365,7 @@ pub fn test_trap_reached_timeout() -> bool {

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

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

//#[cfg(unix)]
//pub fn unix_signal_source_new(signum: i32) -> /*Ignored*/Option<Source> {
// unsafe { TODO: call ffi::g_unix_signal_source_new() }
//}

pub fn unlink<P: AsRef<std::path::Path>>(filename: P) -> i32 {
unsafe {
ffi::g_unlink(filename.as_ref().to_glib_none().0)
Expand Down
2 changes: 1 addition & 1 deletion src/auto/key_file.rs
@@ -1,4 +1,4 @@
// This file was generated by gir (3c73dd9) from gir-files (71d73f0)
// This file was generated by gir (7504fb6) from gir-files (71d73f0)
// DO NOT EDIT

#[cfg(feature = "v2_50")]
Expand Down
141 changes: 141 additions & 0 deletions src/auto/main_context.rs
@@ -0,0 +1,141 @@
// This file was generated by gir (7504fb6) from gir-files (71d73f0)
// DO NOT EDIT

use ffi;
use translate::*;

glib_wrapper! {
pub struct MainContext(Shared<ffi::GMainContext>);

match fn {
ref => |ptr| ffi::g_main_context_ref(ptr),
unref => |ptr| ffi::g_main_context_unref(ptr),
}
}

impl MainContext {
pub fn new() -> MainContext {
unsafe {
from_glib_full(ffi::g_main_context_new())
}
}

pub fn acquire(&self) -> bool {
unsafe {
from_glib(ffi::g_main_context_acquire(self.to_glib_none().0))
}
}

//pub fn add_poll(&self, fd: /*Ignored*/&mut PollFD, priority: i32) {
// unsafe { TODO: call ffi::g_main_context_add_poll() }
//}

//pub fn check(&self, max_priority: i32, fds: /*Ignored*/&[&PollFD]) -> i32 {
// unsafe { TODO: call ffi::g_main_context_check() }
//}

pub fn dispatch(&self) {
unsafe {
ffi::g_main_context_dispatch(self.to_glib_none().0);
}
}

//pub fn find_source_by_funcs_user_data<P: Into<Option</*Unimplemented*/Fundamental: Pointer>>>(&self, funcs: /*Ignored*/&mut SourceFuncs, user_data: P) -> Option<Source> {
// unsafe { TODO: call ffi::g_main_context_find_source_by_funcs_user_data() }
//}

//pub fn find_source_by_user_data<P: Into<Option</*Unimplemented*/Fundamental: Pointer>>>(&self, user_data: P) -> Option<Source> {
// unsafe { TODO: call ffi::g_main_context_find_source_by_user_data() }
//}

//pub fn get_poll_func(&self) -> /*Unknown conversion*//*Unimplemented*/PollFunc {
// unsafe { TODO: call ffi::g_main_context_get_poll_func() }
//}

//pub fn invoke<P: Into<Option</*Unimplemented*/Fundamental: Pointer>>>(&self, function: /*Unknown conversion*//*Unimplemented*/SourceFunc, data: P) {
// unsafe { TODO: call ffi::g_main_context_invoke() }
//}

//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) {
// unsafe { TODO: call ffi::g_main_context_invoke_full() }
//}

pub fn is_owner(&self) -> bool {
unsafe {
from_glib(ffi::g_main_context_is_owner(self.to_glib_none().0))
}
}

pub fn iteration(&self, may_block: bool) -> bool {
unsafe {
from_glib(ffi::g_main_context_iteration(self.to_glib_none().0, may_block.to_glib()))
}
}

pub fn pending(&self) -> bool {
unsafe {
from_glib(ffi::g_main_context_pending(self.to_glib_none().0))
}
}

pub fn pop_thread_default(&self) {
unsafe {
ffi::g_main_context_pop_thread_default(self.to_glib_none().0);
}
}

pub fn push_thread_default(&self) {
unsafe {
ffi::g_main_context_push_thread_default(self.to_glib_none().0);
}
}

//pub fn query(&self, max_priority: i32, fds: /*Unimplemented*/Vec<PollFD>) -> (i32, i32) {
// unsafe { TODO: call ffi::g_main_context_query() }
//}

pub fn release(&self) {
unsafe {
ffi::g_main_context_release(self.to_glib_none().0);
}
}

//pub fn remove_poll(&self, fd: /*Ignored*/&mut PollFD) {
// unsafe { TODO: call ffi::g_main_context_remove_poll() }
//}

//pub fn set_poll_func(&self, func: /*Unknown conversion*//*Unimplemented*/PollFunc) {
// unsafe { TODO: call ffi::g_main_context_set_poll_func() }
//}

//pub fn wait(&self, cond: /*Ignored*/&mut Cond, mutex: /*Ignored*/&mut Mutex) -> bool {
// unsafe { TODO: call ffi::g_main_context_wait() }
//}

pub fn wakeup(&self) {
unsafe {
ffi::g_main_context_wakeup(self.to_glib_none().0);
}
}

pub fn default() -> Option<MainContext> {
unsafe {
from_glib_none(ffi::g_main_context_default())
}
}

pub fn get_thread_default() -> Option<MainContext> {
unsafe {
from_glib_none(ffi::g_main_context_get_thread_default())
}
}

pub fn ref_thread_default() -> Option<MainContext> {
unsafe {
from_glib_full(ffi::g_main_context_ref_thread_default())
}
}
}

unsafe impl Send for MainContext {}
unsafe impl Sync for MainContext {}
52 changes: 52 additions & 0 deletions src/auto/main_loop.rs
@@ -0,0 +1,52 @@
// This file was generated by gir (7504fb6) from gir-files (71d73f0)
// DO NOT EDIT

use MainContext;
use ffi;
use translate::*;

glib_wrapper! {
pub struct MainLoop(Shared<ffi::GMainLoop>);

match fn {
ref => |ptr| ffi::g_main_loop_ref(ptr),
unref => |ptr| ffi::g_main_loop_unref(ptr),
}
}

impl MainLoop {
pub fn new<'a, P: Into<Option<&'a MainContext>>>(context: P, is_running: bool) -> MainLoop {
let context = context.into();
let context = context.to_glib_none();
unsafe {
from_glib_full(ffi::g_main_loop_new(context.0, is_running.to_glib()))
}
}

pub fn get_context(&self) -> Option<MainContext> {
unsafe {
from_glib_none(ffi::g_main_loop_get_context(self.to_glib_none().0))
}
}

pub fn is_running(&self) -> bool {
unsafe {
from_glib(ffi::g_main_loop_is_running(self.to_glib_none().0))
}
}

pub fn quit(&self) {
unsafe {
ffi::g_main_loop_quit(self.to_glib_none().0);
}
}

pub fn run(&self) {
unsafe {
ffi::g_main_loop_run(self.to_glib_none().0);
}
}
}

unsafe impl Send for MainLoop {}
unsafe impl Sync for MainLoop {}
11 changes: 10 additions & 1 deletion src/auto/mod.rs
@@ -1,9 +1,18 @@
// This file was generated by gir (3c73dd9) from gir-files (71d73f0)
// This file was generated by gir (7504fb6) from gir-files (71d73f0)
// DO NOT EDIT

mod key_file;
pub use self::key_file::KeyFile;

mod main_context;
pub use self::main_context::MainContext;

mod main_loop;
pub use self::main_loop::MainLoop;

mod source;
pub use self::source::Source;

mod enums;
pub use self::enums::KeyFileError;

Expand Down