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

Commit 5d81d4e

Browse files
committed
Implement the wrapper for g_file_read_finish()
1 parent 4f9ba96 commit 5d81d4e

File tree

3 files changed

+70
-9
lines changed

3 files changed

+70
-9
lines changed

fauxgen/gio.rc

+56-5
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,15 @@ pub mod raw {
6262
fn g_file_get_type() -> GType;
6363
fn g_file_new_for_path(path: *gchar) -> *GFile;
6464
fn g_file_get_path(file: *GFile) -> *gchar;
65-
fn g_file_read_async(file : *GFile,
66-
io_priority: libc::c_int,
67-
cancellable: *GCancellable,
68-
callback : *u8,
69-
user_data : *());
65+
fn g_file_read_async (file : *GFile,
66+
io_priority : libc::c_int,
67+
cancellable : *GCancellable,
68+
callback : *u8,
69+
user_data : *());
70+
fn g_file_read_finish (file : *GFile,
71+
res : *GAsyncResult,
72+
error : **glib::raw::GError)
73+
-> *GFileInputStream;
7074
}
7175
}
7276

@@ -135,6 +139,8 @@ pub trait File {
135139
io_priority: int,
136140
cancellable: Option<&classes::Cancellable>,
137141
callback: AsyncReadyCallback);
142+
fn read_finish(&self, res: &interfaces::AsyncResult)
143+
-> object::Reference<raw::GFileInputStream>;
138144
}
139145

140146
impl File {
@@ -231,4 +237,49 @@ impl File for interfaces::File {
231237
}
232238
}
233239
}
240+
241+
fn read_finish(&self, res: &interfaces::AsyncResult)
242+
-> object::Reference<raw::GFileInputStream> {
243+
unsafe {
244+
let self_ptr = self.raw();
245+
let self_ctx = self.context();
246+
let res_raw = res.raw();
247+
let mut stack_out: (*plumbing::GMainContext,
248+
*raw::GFileInputStream,
249+
*glib::raw::GError)
250+
= (ptr::null(), ptr::null(), ptr::null());
251+
let mut owned_out: ~(*plumbing::GMainContext,
252+
*raw::GFileInputStream,
253+
*glib::raw::GError);
254+
let mut out = ptr::to_unsafe_ptr(&stack_out);
255+
if !plumbing::call_on_stack(self_ctx,
256+
|_ctx| unsafe {
257+
let error: *glib::raw::GError = ptr::null();
258+
let ret = raw::symbols::g_file_read_finish(self_ptr,
259+
res_raw, ptr::to_unsafe_ptr(&error));
260+
stack_out = (_ctx, ret, error);
261+
}) {
262+
owned_out = ~(ptr::null(), ptr::null(), ptr::null());
263+
let po = ptr::to_mut_unsafe_ptr(owned_out);
264+
plumbing::call_off_stack(self_ctx,
265+
|_ctx| unsafe {
266+
let error: *glib::raw::GError = ptr::null();
267+
let ret = raw::symbols::g_file_read_finish(self_ptr,
268+
res_raw, ptr::to_unsafe_ptr(&error));
269+
*po = (_ctx, ret, error);
270+
});
271+
out = ptr::to_unsafe_ptr(owned_out);
272+
}
273+
match (*out) {
274+
(ctx, obj, error) => {
275+
if ptr::is_not_null(error) {
276+
let msg = str::raw::from_c_str((*error).message);
277+
glib::raw::symbols::g_error_free(error);
278+
fail!(msg);
279+
}
280+
object::take_object(obj, ctx)
281+
}
282+
}
283+
}
284+
}
234285
}

fauxgen/glib.rc

+9
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,18 @@ extern mod grust (name="grust", vers="0.1");
2828
pub mod raw {
2929
use grust::types::*;
3030

31+
pub type GQuark = u32;
32+
33+
pub struct GError {
34+
domain: GQuark,
35+
code: gint,
36+
message: *gchar
37+
}
38+
3139
#[link_name="glib-2.0"]
3240
pub extern mod symbols {
3341
pub fn g_free(mem: *());
3442
pub fn g_strdup(str: *gchar) -> *gchar;
43+
pub fn g_error_free(err: *GError);
3544
}
3645
}

grust/types.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@
1818
* 02110-1301 USA
1919
*/
2020

21-
pub type gchar = libc::c_char;
22-
pub type guint = libc::c_uint;
23-
pub type gsize = libc::size_t;
24-
pub type gboolean = libc::c_int;
21+
pub type gboolean = libc::c_int;
22+
pub type gchar = libc::c_char;
23+
pub type gint = libc::c_int;
24+
pub type guint = libc::c_uint;
25+
pub type gsize = libc::size_t;
2526

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

0 commit comments

Comments
 (0)