Skip to content
This repository has been archived by the owner on Nov 26, 2020. It is now read-only.

Commit

Permalink
Implement the wrapper for g_file_read_finish()
Browse files Browse the repository at this point in the history
  • Loading branch information
mzabaluev committed Apr 24, 2013
1 parent 4f9ba96 commit 5d81d4e
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 9 deletions.
61 changes: 56 additions & 5 deletions fauxgen/gio.rc
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,15 @@ pub mod raw {
fn g_file_get_type() -> GType;
fn g_file_new_for_path(path: *gchar) -> *GFile;
fn g_file_get_path(file: *GFile) -> *gchar;
fn g_file_read_async(file : *GFile,
io_priority: libc::c_int,
cancellable: *GCancellable,
callback : *u8,
user_data : *());
fn g_file_read_async (file : *GFile,
io_priority : libc::c_int,
cancellable : *GCancellable,
callback : *u8,
user_data : *());
fn g_file_read_finish (file : *GFile,
res : *GAsyncResult,
error : **glib::raw::GError)
-> *GFileInputStream;
}
}

Expand Down Expand Up @@ -135,6 +139,8 @@ pub trait File {
io_priority: int,
cancellable: Option<&classes::Cancellable>,
callback: AsyncReadyCallback);
fn read_finish(&self, res: &interfaces::AsyncResult)
-> object::Reference<raw::GFileInputStream>;
}

impl File {
Expand Down Expand Up @@ -231,4 +237,49 @@ impl File for interfaces::File {
}
}
}

fn read_finish(&self, res: &interfaces::AsyncResult)
-> object::Reference<raw::GFileInputStream> {
unsafe {
let self_ptr = self.raw();
let self_ctx = self.context();
let res_raw = res.raw();
let mut stack_out: (*plumbing::GMainContext,
*raw::GFileInputStream,
*glib::raw::GError)
= (ptr::null(), ptr::null(), ptr::null());
let mut owned_out: ~(*plumbing::GMainContext,
*raw::GFileInputStream,
*glib::raw::GError);
let mut out = ptr::to_unsafe_ptr(&stack_out);
if !plumbing::call_on_stack(self_ctx,
|_ctx| unsafe {
let error: *glib::raw::GError = ptr::null();
let ret = raw::symbols::g_file_read_finish(self_ptr,
res_raw, ptr::to_unsafe_ptr(&error));
stack_out = (_ctx, ret, error);
}) {
owned_out = ~(ptr::null(), ptr::null(), ptr::null());
let po = ptr::to_mut_unsafe_ptr(owned_out);
plumbing::call_off_stack(self_ctx,
|_ctx| unsafe {
let error: *glib::raw::GError = ptr::null();
let ret = raw::symbols::g_file_read_finish(self_ptr,
res_raw, ptr::to_unsafe_ptr(&error));
*po = (_ctx, ret, error);
});
out = ptr::to_unsafe_ptr(owned_out);
}
match (*out) {
(ctx, obj, error) => {
if ptr::is_not_null(error) {
let msg = str::raw::from_c_str((*error).message);
glib::raw::symbols::g_error_free(error);
fail!(msg);
}
object::take_object(obj, ctx)
}
}
}
}
}
9 changes: 9 additions & 0 deletions fauxgen/glib.rc
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,18 @@ extern mod grust (name="grust", vers="0.1");
pub mod raw {
use grust::types::*;

pub type GQuark = u32;

pub struct GError {
domain: GQuark,
code: gint,
message: *gchar
}

#[link_name="glib-2.0"]
pub extern mod symbols {
pub fn g_free(mem: *());
pub fn g_strdup(str: *gchar) -> *gchar;
pub fn g_error_free(err: *GError);
}
}
9 changes: 5 additions & 4 deletions grust/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@
* 02110-1301 USA
*/

pub type gchar = libc::c_char;
pub type guint = libc::c_uint;
pub type gsize = libc::size_t;
pub type gboolean = libc::c_int;
pub type gboolean = libc::c_int;
pub type gchar = libc::c_char;
pub type gint = libc::c_int;
pub type guint = libc::c_uint;
pub type gsize = libc::size_t;

pub static FALSE: gboolean = 0;
pub static TRUE: gboolean = !FALSE;

0 comments on commit 5d81d4e

Please sign in to comment.